Skip to content
Snippets Groups Projects
Commit 971a7f8e authored by Alexander BURNETT's avatar Alexander BURNETT
Browse files

Fixed pres V2 cover compatibility

parent eb6e5e8d
Branches
No related merge requests found
...@@ -17,8 +17,9 @@ package org.interreg.docexplore.authoring; ...@@ -17,8 +17,9 @@ package org.interreg.docexplore.authoring;
import java.io.File; import java.io.File;
import java.util.Collection; import java.util.Collection;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.interreg.docexplore.DocExploreTool; import org.interreg.docexplore.DocExploreTool;
import org.interreg.docexplore.Startup; import org.interreg.docexplore.Startup;
import org.interreg.docexplore.authoring.explorer.edit.ImportOptions; import org.interreg.docexplore.authoring.explorer.edit.ImportOptions;
...@@ -28,9 +29,11 @@ import org.interreg.docexplore.authoring.rois.RegionSidePanel; ...@@ -28,9 +29,11 @@ import org.interreg.docexplore.authoring.rois.RegionSidePanel;
import org.interreg.docexplore.gui.ErrorHandler; import org.interreg.docexplore.gui.ErrorHandler;
import org.interreg.docexplore.internationalization.Lang; import org.interreg.docexplore.internationalization.Lang;
import org.interreg.docexplore.manuscript.AnnotatedObject; import org.interreg.docexplore.manuscript.AnnotatedObject;
import org.interreg.docexplore.manuscript.Book; import org.interreg.docexplore.manuscript.Book;
import org.interreg.docexplore.manuscript.CoverUtils;
import org.interreg.docexplore.manuscript.DocExploreDataLink; import org.interreg.docexplore.manuscript.DocExploreDataLink;
import org.interreg.docexplore.manuscript.MetaData; import org.interreg.docexplore.manuscript.MetaData;
import org.interreg.docexplore.manuscript.MetaDataKey;
import org.interreg.docexplore.manuscript.Page; import org.interreg.docexplore.manuscript.Page;
import org.interreg.docexplore.manuscript.Region; import org.interreg.docexplore.manuscript.Region;
import org.interreg.docexplore.manuscript.app.ActionRequestListener; import org.interreg.docexplore.manuscript.app.ActionRequestListener;
...@@ -102,7 +105,7 @@ public class ATAppHost extends ManuscriptAppHost implements ManuscriptAppHost.Do ...@@ -102,7 +105,7 @@ public class ATAppHost extends ManuscriptAppHost implements ManuscriptAppHost.Do
@Override public DocumentPanel getActiveDocument() {return app.document;} @Override public DocumentPanel getActiveDocument() {return app.document;}
@Override public void setActiveDocument(AnnotatedObject document) {} @Override public void setActiveDocument(AnnotatedObject document) {}
public DocumentPanel getDocument(AnnotatedObject document) @Override public DocumentPanel getDocument(AnnotatedObject document)
{ {
if (app.isCurrentDocument(document)) if (app.isCurrentDocument(document))
return app.document; return app.document;
...@@ -135,10 +138,31 @@ public class ATAppHost extends ManuscriptAppHost implements ManuscriptAppHost.Do ...@@ -135,10 +138,31 @@ public class ATAppHost extends ManuscriptAppHost implements ManuscriptAppHost.Do
Book book = new Book(link, Lang.s("collectionDefaultBookLabel")); Book book = new Book(link, Lang.s("collectionDefaultBookLabel"));
books = new LinkedList<Integer>(); books = new LinkedList<Integer>();
books.add(book.getId()); books.add(book.getId());
} }
app.setPanel(link.getBook(books.get(0)), null); app.setPanel(link.getBook(books.get(0)), null);
} }
catch (Exception e) {ErrorHandler.defaultHandler.submit(e);} catch (Exception e) {ErrorHandler.defaultHandler.submit(e);}
}
@Override protected void onLinkSet()
{
try
{
DocExploreDataLink link = getLink();
if (link == null)
return;
List<Integer> books = link.getLink().getAllBookIds();
Book book = !books.isEmpty() ? link.getBook(books.get(0)) : null;
if (book == null)
return;
if (CoverUtils.updatePresV2(link, book))
{
link.setProperty("autoWrite", true);
link.getLink().setProperty("autoWrite", false);
}
}
catch (Exception e) {e.printStackTrace();}
} }
@Override public void refreshTabNames() {} @Override public void refreshTabNames() {}
......
...@@ -82,11 +82,11 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -82,11 +82,11 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
this.file = new JMenu(Lang.s("generalMenuFile")); this.file = new JMenu(Lang.s("generalMenuFile"));
add(file); add(file);
newItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuNew")) {public void actionPerformed(ActionEvent arg0) {newFile();}}); newItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuNew")) {@Override public void actionPerformed(ActionEvent arg0) {newFile();}});
loadItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuLoad")) {public void actionPerformed(ActionEvent arg0) {load();}}); loadItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuLoad")) {@Override public void actionPerformed(ActionEvent arg0) {load();}});
saveItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuSave")) {public void actionPerformed(ActionEvent arg0) {save();}}); saveItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuSave")) {@Override public void actionPerformed(ActionEvent arg0) {save();}});
saveAsItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuSaveAs")) {public void actionPerformed(ActionEvent arg0) {saveAs();}}); saveAsItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuSaveAs")) {@Override public void actionPerformed(ActionEvent arg0) {saveAs();}});
exportItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuExport")) {public void actionPerformed(ActionEvent arg0) exportItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuExport")) {@Override public void actionPerformed(ActionEvent arg0)
{ {
try try
{ {
...@@ -101,27 +101,27 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -101,27 +101,27 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
GuiUtils.centerOnComponent(host.exportDialog, host.getFrame()); GuiUtils.centerOnComponent(host.exportDialog, host.getFrame());
host.exportDialog.setVisible(true); host.exportDialog.setVisible(true);
}}); }});
quitItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuQuit")) {public void actionPerformed(ActionEvent arg0) quitItem = new JMenuItem(new AbstractAction(Lang.s("generalMenuQuit")) {@Override public void actionPerformed(ActionEvent arg0)
{host.app.close();}}); {host.app.close();}});
buildFileMenu(); buildFileMenu();
JMenu edit = new JMenu(Lang.s("generalMenuEdit")); JMenu edit = new JMenu(Lang.s("generalMenuEdit"));
this.undoItem = new JMenuItem(); this.undoItem = new JMenuItem();
undoItem.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) undoItem.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e)
{ {
try {host.historyManager.undo();} try {host.historyManager.undo();}
catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex);} catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex);}
}}); }});
edit.add(undoItem); edit.add(undoItem);
this.redoItem = new JMenuItem(); this.redoItem = new JMenuItem();
redoItem.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) redoItem.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e)
{ {
try {host.historyManager.redo();} try {host.historyManager.redo();}
catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex);} catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex);}
}}); }});
edit.add(redoItem); edit.add(redoItem);
JMenuItem viewHistory = new JMenuItem(Lang.s("generalMenuEditViewHistory")); JMenuItem viewHistory = new JMenuItem(Lang.s("generalMenuEditViewHistory"));
viewHistory.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) viewHistory.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e)
{ {
host.showHistoryDialog(); host.showHistoryDialog();
}}); }});
...@@ -130,9 +130,9 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -130,9 +130,9 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
edit.add(new JSeparator() {{setOpaque(true); setBackground(GuiConstants.toolBackground);}}); edit.add(new JSeparator() {{setOpaque(true); setBackground(GuiConstants.toolBackground);}});
JMenuItem styles = new JMenuItem(Lang.s("styleEdit")+"...", ImageUtils.getIcon("pencil-24x24.png")); JMenuItem styles = new JMenuItem(Lang.s("styleEdit")+"...", ImageUtils.getIcon("pencil-24x24.png"));
styles.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {host.styles.styleDialog.setVisible(true);}}); styles.addActionListener(new ActionListener() {@Override public void actionPerformed(ActionEvent e) {host.styles.styleDialog.setVisible(true);}});
edit.add(styles); edit.add(styles);
edit.add(new JMenuItem(new AbstractAction(Lang.s("fixChars")) {public void actionPerformed(ActionEvent arg0) edit.add(new JMenuItem(new AbstractAction(Lang.s("fixChars")) {@Override public void actionPerformed(ActionEvent arg0)
{ {
Object res = JOptionPane.showInputDialog(host.getFrame(), Lang.s("fixCharsMsg"), Lang.s("fixChars"), Object res = JOptionPane.showInputDialog(host.getFrame(), Lang.s("fixCharsMsg"), Lang.s("fixChars"),
JOptionPane.QUESTION_MESSAGE, null, new Object [] {Lang.s("fixCharsWin"), Lang.s("fixCharsMac")}, JOptionPane.QUESTION_MESSAGE, null, new Object [] {Lang.s("fixCharsWin"), Lang.s("fixCharsMac")},
...@@ -164,7 +164,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -164,7 +164,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
// catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex, true);} // catch (Exception ex) {ErrorHandler.defaultHandler.submit(ex, true);}
// }}); // }});
helpMenu.add(new AbstractAction(Lang.s("generalMenuHelpWebsite")) { helpMenu.add(new AbstractAction(Lang.s("generalMenuHelpWebsite")) {
public void actionPerformed(ActionEvent e) @Override public void actionPerformed(ActionEvent e)
{ {
try try
{ {
...@@ -176,7 +176,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -176,7 +176,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
} }
} }
helpMenu.add(new AbstractAction(Lang.s("generalMenuHelpAbout")) { helpMenu.add(new AbstractAction(Lang.s("generalMenuHelpAbout")) {
public void actionPerformed(ActionEvent e) @Override public void actionPerformed(ActionEvent e)
{ {
final JDialog splash = new JDialog(host.getFrame(), true); final JDialog splash = new JDialog(host.getFrame(), true);
splash.setLayout(new BorderLayout()); splash.setLayout(new BorderLayout());
...@@ -193,7 +193,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -193,7 +193,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
splash.setVisible(true); splash.setVisible(true);
}}); }});
helpMenu.add(new AbstractAction(Lang.s("feedbackTitle")+"...") { helpMenu.add(new AbstractAction(Lang.s("feedbackTitle")+"...") {
public void actionPerformed(ActionEvent e) @Override public void actionPerformed(ActionEvent e)
{ {
FeedbackDialog.get().showDialog(); FeedbackDialog.get().showDialog();
}}); }});
...@@ -273,19 +273,19 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -273,19 +273,19 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
GuiUtils.blockUntilComplete(new ProgressRunnable() GuiUtils.blockUntilComplete(new ProgressRunnable()
{ {
float [] progress = {0}; float [] progress = {0};
public void run() @Override public void run()
{ {
try try
{ {
FileUtils.deleteDirectory(host.app.defaultFile); FileUtils.deleteDirectory(host.app.defaultFile);
host.app.defaultFile.mkdirs(); host.app.defaultFile.mkdirs();
ZipUtils.unzip(curFile, host.app.defaultFile, progress); ZipUtils.unzip(curFile, host.app.defaultFile, progress);
DataLink link = new DataLinkFS2Source(host.app.defaultFile.getAbsolutePath()).getDataLink(); DataLink link = new DataLinkFS2Source(host.app.defaultFile.getAbsolutePath()).getDataLink();
host.setLink(link); host.setLink(link);
} }
catch (Exception e) {ErrorHandler.defaultHandler.submit(e);} catch (Exception e) {ErrorHandler.defaultHandler.submit(e);}
} }
public float getProgress() {return (float)progress[0];} @Override public float getProgress() {return (float)progress[0];}
}, host.getFrame()); }, host.getFrame());
lastLoad = System.currentTimeMillis(); lastLoad = System.currentTimeMillis();
return true; return true;
...@@ -309,12 +309,12 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -309,12 +309,12 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
GuiUtils.blockUntilComplete(new ProgressRunnable() GuiUtils.blockUntilComplete(new ProgressRunnable()
{ {
float [] progress = {0}; float [] progress = {0};
public void run() @Override public void run()
{ {
try {ZipUtils.zip(host.app.defaultFile, curFile, progress, 0);} try {ZipUtils.zip(host.app.defaultFile, curFile, progress, 0);}
catch (Exception e) {ErrorHandler.defaultHandler.submit(e);} catch (Exception e) {ErrorHandler.defaultHandler.submit(e);}
} }
public float getProgress() {return (float)progress[0];} @Override public float getProgress() {return (float)progress[0];}
}, host.getFrame()); }, host.getFrame());
lastLoad = System.currentTimeMillis(); lastLoad = System.currentTimeMillis();
return true; return true;
...@@ -352,7 +352,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -352,7 +352,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
return max; return max;
} }
public void historyChanged(HistoryManager manager) @Override public void historyChanged(HistoryManager manager)
{ {
String undoLabel = Lang.s("generalMenuEditUndo"); String undoLabel = Lang.s("generalMenuEditUndo");
String redoLabel = Lang.s("generalMenuEditRedo"); String redoLabel = Lang.s("generalMenuEditRedo");
...@@ -372,7 +372,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener ...@@ -372,7 +372,7 @@ public class ATMenu extends JMenuBar implements HistoryManager.HistoryListener
{ {
public RecentItem(final ATMenu menu, final String path) public RecentItem(final ATMenu menu, final String path)
{ {
super(new AbstractAction(path) {public void actionPerformed(ActionEvent e) {menu.load(new File(path));}}); super(new AbstractAction(path) {@Override public void actionPerformed(ActionEvent e) {menu.load(new File(path));}});
} }
} }
int recentLim = 10; int recentLim = 10;
......
...@@ -14,14 +14,14 @@ The fact that you are presently reading this means that you have had knowledge o ...@@ -14,14 +14,14 @@ The fact that you are presently reading this means that you have had knowledge o
*/ */
package org.interreg.docexplore.manuscript; package org.interreg.docexplore.manuscript;
import java.util.List; import java.util.List;
import org.interreg.docexplore.datalink.DataLinkException; import org.interreg.docexplore.datalink.DataLinkException;
import org.interreg.docexplore.internationalization.Lang; import org.interreg.docexplore.internationalization.Lang;
import org.interreg.docexplore.manuscript.actions.AddMetaDataAction; import org.interreg.docexplore.manuscript.actions.AddMetaDataAction;
import org.interreg.docexplore.manuscript.actions.DeleteMetaDataAction; import org.interreg.docexplore.manuscript.actions.DeleteMetaDataAction;
import org.interreg.docexplore.manuscript.app.DocumentEvents; import org.interreg.docexplore.manuscript.app.DocumentEvents;
import org.interreg.docexplore.manuscript.app.ManuscriptAppHost; import org.interreg.docexplore.manuscript.app.ManuscriptAppHost;
import org.interreg.docexplore.util.history.ReversibleAction; import org.interreg.docexplore.util.history.ReversibleAction;
public class CoverUtils public class CoverUtils
...@@ -37,7 +37,35 @@ public class CoverUtils ...@@ -37,7 +37,35 @@ public class CoverUtils
FrontInnerTrans {@Override public MetaDataKey getKey(DocExploreDataLink link) {return link.frontInnerCoverTrans;}}, FrontInnerTrans {@Override public MetaDataKey getKey(DocExploreDataLink link) {return link.frontInnerCoverTrans;}},
BackInnerTrans {@Override public MetaDataKey getKey(DocExploreDataLink link) {return link.backInnerCoverTrans;}}; BackInnerTrans {@Override public MetaDataKey getKey(DocExploreDataLink link) {return link.backInnerCoverTrans;}};
public abstract MetaDataKey getKey(DocExploreDataLink link); public abstract MetaDataKey getKey(DocExploreDataLink link);
}; };
public static boolean updatePresV2(DocExploreDataLink link, Book book) throws DataLinkException
{
boolean updated = false;
updated |= updatePresV2MetaDataKey(link, book, "frontCover", link.frontCover);
updated |= updatePresV2MetaDataKey(link, book, "frontInnerCover", link.frontInnerCover);
updated |= updatePresV2MetaDataKey(link, book, "backCover", link.backCover);
updated |= updatePresV2MetaDataKey(link, book, "backInnerCover", link.backInnerCover);
return updated;
}
public static boolean updatePresV2MetaDataKey(DocExploreDataLink link, Book book, String from, MetaDataKey to) throws DataLinkException
{
if (!book.getMetaDataListForKey(to).isEmpty())
return false;
MetaDataKey key = link.getKey(from);
if (key == null)
return false;
List<MetaData> mds = book.getMetaDataListForKey(key);
for (MetaData md : mds)
{
MetaData updated = new MetaData(md.link, to, md.type, md.getValue());
book.addMetaData(updated);
// //Keep old keys for AT V2 compatibility?
// book.removeMetaData(md);
// link.getLink().removeMetaData(md.id);
}
return true;
}
public static MetaData [] getCoverImages(DocExploreDataLink link, Book book) throws DataLinkException public static MetaData [] getCoverImages(DocExploreDataLink link, Book book) throws DataLinkException
{ {
......
...@@ -89,9 +89,11 @@ public abstract class ManuscriptAppHost ...@@ -89,9 +89,11 @@ public abstract class ManuscriptAppHost
public DocExploreDataLink getLink() {return link;} public DocExploreDataLink getLink() {return link;}
public void setLink(DataLink link) throws DataLinkException public void setLink(DataLink link) throws DataLinkException
{ {
this.link.setLink(link); this.link.setLink(link);
onLinkSet();
notifyDataLinkChanged(); notifyDataLinkChanged();
} }
protected void onLinkSet() {}
public void showHistoryDialog() public void showHistoryDialog()
{ {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment