From: Jim Procter Date: Wed, 17 Oct 2018 15:52:01 +0000 (+0100) Subject: Merge branch 'feature/JAL-3063JAXB' into Jalview-BH/JAL-3026-JAL-3063-JAXB X-Git-Tag: Release_2_11_4_0~45^2~18^2~443 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fab0afc9e1e7a5ca460f0cbd48545536f989a435;p=jalview.git Merge branch 'feature/JAL-3063JAXB' into Jalview-BH/JAL-3026-JAL-3063-JAXB --- fab0afc9e1e7a5ca460f0cbd48545536f989a435 diff --cc src/jalview/gui/AlignFrame.java index 161fd7e,477db0c..6b3e5d8 --- a/src/jalview/gui/AlignFrame.java +++ b/src/jalview/gui/AlignFrame.java @@@ -1230,73 -1147,82 +1230,78 @@@ public class AlignFrame extends GAlignF if (FileFormat.Jalview.equals(format)) { String shortName = title; - - if (shortName.indexOf(java.io.File.separatorChar) > -1) + if (shortName.indexOf(File.separatorChar) > -1) { shortName = shortName.substring( - shortName.lastIndexOf(java.io.File.separatorChar) + 1); + shortName.lastIndexOf(File.separatorChar) + 1); } - lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file, - - success = new jalview.project.Jalview2XML().saveAlignment(this, file, ++ lastSaveSuccessful = new jalview.project.Jalview2XML().saveAlignment(this, file, shortName); - ++ + statusBar.setText(MessageManager.formatMessage( + "label.successfully_saved_to_file_in_format", new Object[] + { fileName, format })); - ++ + return; } - else + + AlignExportSettingsI options = new AlignExportSettingsAdapter(false); + RunResponse cancelAction = new RunResponse(JvOptionPane.CANCEL_OPTION) { - AlignmentExportData exportData = getAlignmentForExport(format, - viewport, null); - if (exportData.getSettings().isCancelled()) - { - return false; - } - FormatAdapter f = new FormatAdapter(alignPanel, - exportData.getSettings()); - String output = f.formatSequences(format, exportData.getAlignment(), // class - // cast - // exceptions - // will - // occur in the distant future - exportData.getOmitHidden(), exportData.getStartEndPostions(), - f.getCacheSuffixDefault(format), - viewport.getAlignment().getHiddenColumns()); - - if (output == null) + @Override + public void run() { - success = false; + lastSaveSuccessful = false; } - else + }; + RunResponse outputAction = new RunResponse(JvOptionPane.OK_OPTION) + { + @Override + public void run() { - try + // todo defer this to inside formatSequences (or later) + AlignmentExportData exportData = viewport + .getAlignExportData(options); + String output = new FormatAdapter(alignPanel, options) + .formatSequences(format, exportData.getAlignment(), + exportData.getOmitHidden(), + exportData.getStartEndPostions(), + viewport.getAlignment().getHiddenColumns()); + if (output == null) { - PrintWriter out = new PrintWriter(new FileWriter(file)); - - out.print(output); - out.close(); - this.setTitle(file); - statusBar.setText(MessageManager.formatMessage( - "label.successfully_saved_to_file_in_format", new Object[] - { fileName, format.getName() })); - } catch (Exception ex) + lastSaveSuccessful = false; + } + else { - success = false; - ex.printStackTrace(); + try + { + PrintWriter out = new PrintWriter(new FileWriter(file)); + out.print(output); + out.close(); + AlignFrame.this.setTitle(file); + setStatus(MessageManager.formatMessage( + "label.successfully_saved_to_file_in_format", + new Object[] + { fileName, format.getName() })); + } catch (Exception ex) + { + lastSaveSuccessful = false; + ex.printStackTrace(); + } } } - } - - if (!success) - { - JvOptionPane.showInternalMessageDialog(this, MessageManager - .formatMessage("label.couldnt_save_file", new Object[] - { fileName }), - MessageManager.getString("label.error_saving_file"), - JvOptionPane.WARNING_MESSAGE); - } + }; - return success; - } - - private void warningMessage(String warning, String title) - { - if (new jalview.util.Platform().isHeadless()) + /* + * show dialog with export options if applicable; else just do it + */ + if (AlignExportOptions.isNeeded(viewport, format)) { - System.err.println("Warning: " + title + "\nWarning: " + warning); - + AlignExportOptions choices = new AlignExportOptions( + alignPanel.getAlignViewport(), format, options); + choices.setResponseAction(outputAction); + choices.setResponseAction(cancelAction); + choices.showDialog(); } else { diff --cc src/jalview/gui/AlignmentPanel.java index f133f8e,c03b56d..61b4565 --- a/src/jalview/gui/AlignmentPanel.java +++ b/src/jalview/gui/AlignmentPanel.java @@@ -38,9 -36,7 +38,8 @@@ import jalview.math.AlignmentDimension import jalview.schemes.ResidueProperties; import jalview.structure.StructureSelectionManager; import jalview.util.Comparison; +import jalview.util.ImageMaker; import jalview.util.MessageManager; - import jalview.util.Platform; import jalview.viewmodel.ViewportListenerI; import jalview.viewmodel.ViewportRanges; diff --cc src/jalview/gui/Desktop.java index ceea332,bbdddbb..855ccbc --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@@ -1636,18 -1599,21 +1637,19 @@@ public class Desktop extends jalview.jb } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Prompts the user to choose a file and then saves the Jalview state as a + * Jalview project file */ @Override - public void saveState_actionPerformed() + public void saveState_actionPerformed(boolean asCastor) { - JalviewFileChooser chooser = new JalviewFileChooser("jvp", + JalviewFileChooser chooser = new JalviewFileChooser( + asCastor ? "jvp" : "jvx", "Jalview Project"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.save_state")); -- ++ // TODO: JAL-3048 Dialog runner refactoring here int value = chooser.showSaveDialog(this); if (value == JalviewFileChooser.APPROVE_OPTION) @@@ -1707,16 -1680,25 +1716,23 @@@ } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Prompts the user to choose a file and loads in as a Jalview project file */ @Override - public void loadState_actionPerformed() + public void loadState_actionPerformed(boolean asCastor) { ++ // TODO: GET RID OF .JVX BEFORE RELEASE JIM! + final String[] suffix = asCastor ? new String[] { "jvp", "jar" } + : new String[] + { "jvx" }; + final String[] desc = asCastor + ? new String[] + { "Jalview Project", "Jalview Project (old)" } + : new String[] + { "Jalview Project" }; JalviewFileChooser chooser = new JalviewFileChooser( - Cache.getProperty("LAST_DIRECTORY"), new String[] - { "jvp", "jar" }, - new String[] - { "Jalview Project", "Jalview Project (old)" }, + Cache.getProperty("LAST_DIRECTORY"), suffix, + desc, "Jalview Project"); chooser.setFileView(new JalviewFileView()); chooser.setDialogTitle(MessageManager.getString("label.restore_state")); diff --cc src/jalview/gui/FeatureSettings.java index a0bd69e,90d7c35..44265ed --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@@ -30,12 -28,8 +30,9 @@@ import jalview.datamodel.features.Featu import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.gui.Help.HelpId; +import jalview.gui.JalviewColourChooser.ColourChooserListener; import jalview.io.JalviewFileChooser; import jalview.io.JalviewFileView; - import jalview.schemabinding.version2.Filter; - import jalview.schemabinding.version2.JalviewUserColours; - import jalview.schemabinding.version2.MatcherSet; import jalview.schemes.FeatureColour; import jalview.util.MessageManager; import jalview.util.Platform; diff --cc src/jalview/gui/SeqCanvas.java index 7606ee6,5c404f0..641365d --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@@ -355,19 -351,19 +355,20 @@@ public class SeqCanvas extends JPanel i @Override public void paintComponent(Graphics g) { - super.paintComponent(g); - + super.paintComponent(g); + int charHeight = av.getCharHeight(); int charWidth = av.getCharWidth(); - + ViewportRanges ranges = av.getRanges(); - + int width = getWidth(); int height = getHeight(); - + width -= (width % charWidth); height -= (height % charHeight); + + if ((img != null) && (fastPaint || (getVisibleRect().width != g.getClipBounds().width) || (getVisibleRect().height != g.getClipBounds().height))) diff --cc src/jalview/gui/TreeCanvas.java index f7faa6c,45def89..a0296ec --- a/src/jalview/gui/TreeCanvas.java +++ b/src/jalview/gui/TreeCanvas.java @@@ -57,7 -56,7 +57,6 @@@ import java.util.Hashtable import java.util.List; import java.util.Vector; --import javax.swing.JColorChooser; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.SwingUtilities; diff --cc src/jalview/gui/TreePanel.java index 5450102,084f461..30604cb --- a/src/jalview/gui/TreePanel.java +++ b/src/jalview/gui/TreePanel.java @@@ -125,7 -126,7 +125,8 @@@ public class TreePanel extends GTreePan public AlignmentViewport getViewPort() { - return treeCanvas.av; ++ // @Mungo - Why don't we return our own viewport ??? + return getTreeCanvas().getViewport(); } void initTreePanel(AlignmentPanel ap, String type, String modelName, @@@ -212,8 -213,8 +213,8 @@@ void buildAssociatedViewMenu() { AlignmentPanel[] aps = PaintRefresher - .getAssociatedPanels(getViewport().getSequenceSetId()); + .getAssociatedPanels(av.getSequenceSetId()); - if (aps.length == 1 && treeCanvas.ap == aps[0]) + if (aps.length == 1 && getTreeCanvas().getAssociatedPanel() == aps[0]) { associateLeavesMenu.setVisible(false); return; @@@ -236,16 -237,16 +237,17 @@@ for (i = 0; i < iSize; i++) { final AlignmentPanel ap = aps[i]; - item = new JRadioButtonMenuItem(ap.av.viewName, ap == treeCanvas.ap); - item = new JRadioButtonMenuItem(ap.av.getViewName(), ap == getTreeCanvas().getAssociatedPanel()); ++ item = new JRadioButtonMenuItem(ap.av.getViewName(), ++ ap == treeCanvas.getAssociatedPanel()); buttonGroup.add(item); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { - getTreeCanvas().applyToAllViews = false; - getTreeCanvas().setAssociatedPanel(ap); - getTreeCanvas().setViewport(ap.av); + treeCanvas.applyToAllViews = false; - treeCanvas.ap = ap; - treeCanvas.av = ap.av; ++ treeCanvas.setAssociatedPanel(ap); ++ treeCanvas.setViewport(ap.av); PaintRefresher.Register(thisTreePanel, ap.av.getSequenceSetId()); } }); @@@ -305,10 -306,10 +307,11 @@@ else { ScoreModelI sm = ScoreModels.getInstance() - .getScoreModel(scoreModelName, treeCanvas.ap); - .getScoreModel(scoreModelName, getTreeCanvas().getAssociatedPanel()); ++ .getScoreModel(scoreModelName, ++ treeCanvas.getAssociatedPanel()); TreeBuilder njtree = treeType.equals(TreeBuilder.NEIGHBOUR_JOINING) - ? new NJTree(getViewport(), sm, similarityParams) - : new AverageDistanceTree(getViewport(), sm, similarityParams); + ? new NJTree(av, sm, similarityParams) + : new AverageDistanceTree(av, sm, similarityParams); tree = new TreeModel(njtree); showDistances(true); } @@@ -571,8 -571,8 +574,9 @@@ } else { - treeCanvas.ap.alignFrame - .addHistoryItem(sortAlignmentIn(treeCanvas.ap)); - getTreeCanvas().getAssociatedPanel().alignFrame - .addHistoryItem(sortAlignmentIn(getTreeCanvas().getAssociatedPanel())); ++ treeCanvas.getAssociatedPanel().alignFrame ++ .addHistoryItem( ++ sortAlignmentIn(treeCanvas.getAssociatedPanel())); } } @@@ -785,33 -884,18 +789,48 @@@ return ttl; } + /** + * Builds an EPS image and writes it to the specified file. + * + * @param outFile + * @param textOption + * true for Text character rendering, false for Lineart + */ + protected void writeEpsFile(File outFile, boolean textOption) + { + try + { + int width = treeCanvas.getWidth(); + int height = treeCanvas.getHeight(); + + FileOutputStream out = new FileOutputStream( + outFile); + EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, + height); + pg.setAccurateTextMode(!textOption); + treeCanvas.draw(pg, width, height); + + pg.flush(); + pg.close(); + } catch (Exception ex) + { + System.err.println("Error writing tree as EPS"); + ex.printStackTrace(); + } + } ++ + public AlignViewport getViewport() + { + return av; + } + + public void setViewport(AlignViewport av) + { + this.av = av; + } + + public TreeCanvas getTreeCanvas() + { + return treeCanvas; + } } diff --cc src/jalview/io/JalviewFileChooser.java index 809985d,7a21c16..c90ecdc --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@@ -309,85 -277,82 +309,127 @@@ public class JalviewFileChooser extend } return null; } - ++ + File ourselectedFile = null; + + @Override + public File getSelectedFile() + { + File selfile = super.getSelectedFile(); + if (selfile == null && ourselectedFile != null) + { + return ourselectedFile; + } + return selfile; + } - @Override - public int showSaveDialog(Component parent) throws HeadlessException + Component saveparent; + RunResponse overwriteCheck = new RunResponse( + JalviewFileChooser.APPROVE_OPTION) { - this.setAccessory(null); - - setDialogType(SAVE_DIALOG); - - this.setSelectedFile(null); - int ret = showDialog(parent, MessageManager.getString("action.save")); + @Override + public void run() + { + ourselectedFile = getSelectedFile(); + + if (getSelectedFile() == null) + { + // Workaround for Java 9,10 on OSX - no selected file, but there is a + // filename typed in + try + { + String filename = ((BasicFileChooserUI) getUI()).getFileName(); + if (filename != null && filename.length() > 0) + { + ourselectedFile = new File(getCurrentDirectory(), filename); + } + } catch (Throwable x) + { + System.err.println( + "Unexpected exception when trying to get filename."); + x.printStackTrace(); + } + } + if (ourselectedFile == null) + { - return JalviewFileChooser.CANCEL_OPTION; ++ returned = new Response(JalviewFileChooser.CANCEL_OPTION); ++ return; + } - if (getFileFilter() instanceof JalviewFileFilter) - { - JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter(); + // JBP Note - this code was executed regardless of 'SAVE' being pressed + // need to see if there were side effects + if (getFileFilter() instanceof JalviewFileFilter) + { + JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter(); - if (!jvf.accept(ourselectedFile)) + if (!jvf.accept(getSelectedFile())) + { + String withExtension = getSelectedFile() + "." + + jvf.getAcceptableExtension(); + setSelectedFile(new File(withExtension)); + } + } + // All good, so we continue to save + returned = new Response(JalviewFileChooser.APPROVE_OPTION); + + // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE + // USER PROMPTED FOR A NEW FILENAME + /** + * @j2sNative + */ { - String withExtension = getSelectedFile().getName() + "." - + jvf.getAcceptableExtension(); - ourselectedFile = (new File(getCurrentDirectory(), withExtension)); - setSelectedFile(ourselectedFile); + if (getSelectedFile().exists()) + { + // JAL-3048 - may not need to raise this for browser saves + + // yes/no cancel + int confirm = JvOptionPane.showConfirmDialog(saveparent, + MessageManager.getString("label.overwrite_existing_file"), + MessageManager.getString("label.file_already_exists"), + JvOptionPane.YES_NO_OPTION); + + if (confirm != JvOptionPane.YES_OPTION) + { + returned = new Response(JalviewFileChooser.CANCEL_OPTION); + } + } } + }; + }; + + @Override + public int showSaveDialog(Component parent) throws HeadlessException + { + this.setAccessory(null); + + /* + * Save dialog is opened until user picks a file format + */ + if (!runner.isRegistered(overwriteCheck)) + { + // first call for this instance + runner.firstResponse(overwriteCheck); } - // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE - // USER PROMPTED FOR A NEW FILENAME - if ((ret == JalviewFileChooser.APPROVE_OPTION) - && ourselectedFile.exists()) + else { - int confirm = JvOptionPane.showConfirmDialog(parent, - MessageManager.getString("label.overwrite_existing_file"), - MessageManager.getString("label.file_already_exists"), - JvOptionPane.YES_NO_OPTION); - - if (confirm != JvOptionPane.YES_OPTION) - { - ret = JalviewFileChooser.CANCEL_OPTION; - } + // reset response flags + runner.resetResponses(); } - return ret; + setDialogType(SAVE_DIALOG); ++ ++ // Java 9,10,11 on OSX - clear selected file so name isn't auto populated ++ this.setSelectedFile(null); ++ + saveparent = parent; + + int value = showDialog(parent, MessageManager.getString("action.save")); + /** + * @j2sNative + */ + { + runner.firstRun(value); + } + return value; } void recentListSelectionChanged(Object selection) diff --cc src/jalview/jbgui/GDesktop.java index 4b4d28d,290c4a4..17f36cb --- a/src/jalview/jbgui/GDesktop.java +++ b/src/jalview/jbgui/GDesktop.java @@@ -441,12 -440,11 +459,15 @@@ public class GDesktop extends JFram desktopMenubar.add(windowMenu); FileMenu.add(inputMenu); FileMenu.add(inputSequence); - FileMenu.addSeparator(); - FileMenu.add(saveState); + if (!Jalview.isJS()) + { + FileMenu.addSeparator(); + FileMenu.add(saveState); + FileMenu.add(loadState); + } ++ + FileMenu.add(saveAsJaxb); - FileMenu.add(loadState); + FileMenu.add(loadAsJaxb); FileMenu.addSeparator(); FileMenu.add(quit); HelpMenu.add(aboutMenuItem);