From: hansonr Date: Mon, 17 Dec 2018 22:44:18 +0000 (-0600) Subject: Merge branch 'Jalview-BH/JAL-3026-JAL-3063-JAXB' of https://source.jalview.org/git... X-Git-Tag: Develop-2_11_2_0-d20201215~24^2~68^2~350 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=62b9c61f3e8b1e1212dc53626f644ba0f647fdb0;hp=04f92d566aca0391b42c8e06a3e1334da06f3e69;p=jalview.git Merge branch 'Jalview-BH/JAL-3026-JAL-3063-JAXB' of https://source.jalview.org/git/jalview.git into Jalview-BH/JAL-3026-JAL-3063-JAXB --- diff --git a/src/jalview/gui/ImageExporter.java b/src/jalview/gui/ImageExporter.java index 4c2c8ba..51d7d82 100644 --- a/src/jalview/gui/ImageExporter.java +++ b/src/jalview/gui/ImageExporter.java @@ -88,6 +88,10 @@ public class ImageExporter String imageSource) { final long messageId = System.currentTimeMillis(); + setStatus( + MessageManager.formatMessage( + "status.exporting_alignment_as_x_file", imageType), + messageId); /* * prompt user for output file if not provided @@ -186,10 +190,10 @@ public class ImageExporter String type = imageType.getName(); try { - setStatus( - MessageManager.formatMessage( - "status.exporting_alignment_as_x_file", type), - messageId); +// setStatus( +// MessageManager.formatMessage( +// "status.exporting_alignment_as_x_file", type), +// messageId); ImageMaker im = new ImageMaker(imageType, width, height, chosenFile, title, asLineart); imageWriter.exportImage(im.getGraphics()); diff --git a/src/jalview/io/BioJsHTMLOutput.java b/src/jalview/io/BioJsHTMLOutput.java index 11436d3..9db3df2 100644 --- a/src/jalview/io/BioJsHTMLOutput.java +++ b/src/jalview/io/BioJsHTMLOutput.java @@ -56,7 +56,7 @@ public class BioJsHTMLOutput extends HTMLOutput public BioJsHTMLOutput(AlignmentPanel ap) { - super(ap); + super(ap, "BioJS MSA"); } public static void refreshVersionInfo(String dirName) @@ -275,10 +275,4 @@ public class BioJsHTMLOutput extends HTMLOutput } - @Override - protected String getDescription() - { - return "BioJS MSA"; - } - } diff --git a/src/jalview/io/HTMLOutput.java b/src/jalview/io/HTMLOutput.java index f7179cf..54e7e4b 100644 --- a/src/jalview/io/HTMLOutput.java +++ b/src/jalview/io/HTMLOutput.java @@ -39,23 +39,34 @@ public abstract class HTMLOutput implements Runnable { protected AlignmentPanel ap; + /* + * key for progress or status messages + */ protected long pSessionId; + /* + * (optional) place to write progress messages to + */ protected IProgressIndicator pIndicator; protected File generatedFile; String _bioJson = null; + private String description; + /** * Constructor given an alignment panel (which should not be null) * * @param ap + * @param desc */ - public HTMLOutput(AlignmentPanel ap) + public HTMLOutput(AlignmentPanel ap, String desc) { this.ap = ap; this.pIndicator = ap.alignFrame; + this.description = desc; + this.pSessionId = System.currentTimeMillis(); } /** @@ -243,16 +254,6 @@ public abstract class HTMLOutput implements Runnable /** * This method provides implementation of consistent behaviour which should - * occur before a HTML file export. It MUST be called at the start of the - * exportHTML() method implementation. - */ - protected void exportStarted() - { - pSessionId = System.currentTimeMillis(); - } - - /** - * This method provides implementation of consistent behaviour which should * occur after a HTML file export. It MUST be called at the end of the * exportHTML() method implementation. */ @@ -299,7 +300,8 @@ public abstract class HTMLOutput implements Runnable public void exportHTML(String outputFile) { - exportStarted(); + setProgressMessage(MessageManager.formatMessage( + "status.exporting_alignment_as_x_file", getDescription())); try { if (outputFile == null) @@ -334,5 +336,8 @@ public abstract class HTMLOutput implements Runnable * * @return */ - protected abstract String getDescription(); + protected final String getDescription() + { + return description; + } } \ No newline at end of file diff --git a/src/jalview/io/HtmlSvgOutput.java b/src/jalview/io/HtmlSvgOutput.java index a943a81..d653e4b 100644 --- a/src/jalview/io/HtmlSvgOutput.java +++ b/src/jalview/io/HtmlSvgOutput.java @@ -44,34 +44,7 @@ public class HtmlSvgOutput extends HTMLOutput { public HtmlSvgOutput(AlignmentPanel ap) { - super(ap); - } - - @Override - public void exportHTML(String outputFile) - { - exportStarted(); - try - { - if (outputFile == null) - { - outputFile = getOutputFile(); - if (outputFile == null) - { - setProgressMessage(MessageManager.formatMessage( - "status.cancelled_image_export_operation", "HTML")); - return; - } - } - generatedFile = new File(outputFile); - } catch (Exception e) - { - setProgressMessage(MessageManager - .formatMessage("info.error_creating_file", "HTML")); - e.printStackTrace(); - return; - } - new Thread(this).start(); + super(ap, "HTML"); } public int printUnwrapped(int pwidth, int pheight, int pi, @@ -233,10 +206,6 @@ public class HtmlSvgOutput extends HTMLOutput { try { - setProgressMessage(null); - setProgressMessage(MessageManager.formatMessage( - "status.exporting_alignment_as_x_file", getDescription())); - String renderStyle = Cache.getDefault("HTML_RENDERING", "Prompt each time"); AtomicBoolean textOption = new AtomicBoolean( @@ -349,10 +318,4 @@ public class HtmlSvgOutput extends HTMLOutput .formatMessage("info.error_creating_file", getDescription())); } } - - @Override - protected String getDescription() - { - return "HTML"; - } } diff --git a/src/jalview/io/JalviewFileChooser.java b/src/jalview/io/JalviewFileChooser.java index b7eeaab..2419bef 100755 --- a/src/jalview/io/JalviewFileChooser.java +++ b/src/jalview/io/JalviewFileChooser.java @@ -62,7 +62,7 @@ import javax.swing.plaf.basic.BasicFileChooserUI; * */ public class JalviewFileChooser extends JFileChooser - implements PropertyChangeListener, DialogRunnerI + implements PropertyChangeListener, DialogRunnerI { DialogRunner runner = new DialogRunner<>(this); @@ -331,16 +331,35 @@ public class JalviewFileChooser extends JFileChooser return selfile; } - Component saveparent; - RunResponse overwriteCheck = new RunResponse( - JalviewFileChooser.APPROVE_OPTION) + @Override + public int showSaveDialog(Component parent) throws HeadlessException { - @Override - public void run() + this.setAccessory(null); + // Java 9,10,11 on OSX - clear selected file so name isn't auto populated + this.setSelectedFile(null); + + return super.showSaveDialog(parent); + } + + /** + * If doing a Save, and an existing file is chosen or entered, prompt for + * confirmation of overwrite. Proceed if Yes, else leave the file chooser + * open. + * + * @see https://stackoverflow.com/questions/8581215/jfilechooser-and-checking-for-overwrite + */ + @Override + public void approveSelection() + { + if (getDialogType() != SAVE_DIALOG) { + super.approveSelection(); + return; + } + ourselectedFile = getSelectedFile(); - if (getSelectedFile() == null) + if (ourselectedFile == null) { // Workaround for Java 9,10 on OSX - no selected file, but there is a // filename typed in @@ -357,92 +376,42 @@ public class JalviewFileChooser extends JFileChooser "Unexpected exception when trying to get filename."); x.printStackTrace(); } + // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND + // THE + // USER PROMPTED FOR A NEW FILENAME } if (ourselectedFile == null) { - returned = new Response(JalviewFileChooser.CANCEL_OPTION); return; } - // 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(getSelectedFile())) - { - String withExtension = getSelectedFile() + "." - + jvf.getAcceptableExtension(); - setSelectedFile(new File(withExtension)); - } - } - // All good, so we continue to save - returned = new Response(JalviewFileChooser.APPROVE_OPTION); + if (getFileFilter() instanceof JalviewFileFilter) + { + JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter(); - // TODO: ENSURE THAT FILES SAVED WITH A ':' IN THE NAME ARE REFUSED AND THE - // USER PROMPTED FOR A NEW FILENAME - /** - * @j2sNative - */ + if (!jvf.accept(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); - } - } + String withExtension = getSelectedFile().getName() + "." + + jvf.getAcceptableExtension(); + ourselectedFile = (new File(getCurrentDirectory(), withExtension)); + setSelectedFile(ourselectedFile); } - }; - }; - - /** - * Overridden for JalviewJS compatibility: only one thread in Javascript, - * so we can't wait for user choice in another thread and then perform the - * desired action - */ - @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); } - else - { - // reset response flags - runner.resetResponses(); - } - - 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 - */ + if (ourselectedFile.exists()) { - runner.firstRun(value); + int confirm = JvOptionPane.showConfirmDialog(this, + MessageManager.getString("label.overwrite_existing_file"), + MessageManager.getString("label.file_already_exists"), + JvOptionPane.YES_NO_OPTION); + + if (confirm != JvOptionPane.YES_OPTION) + { + return; + } } - return value; + + super.approveSelection(); } void recentListSelectionChanged(Object selection) diff --git a/test/jalview/util/dialogrunner/DialogRunnerTest.java b/test/jalview/util/dialogrunner/DialogRunnerTest.java index e69ae87..ec61551 100644 --- a/test/jalview/util/dialogrunner/DialogRunnerTest.java +++ b/test/jalview/util/dialogrunner/DialogRunnerTest.java @@ -5,14 +5,14 @@ import org.testng.annotations.Test; public class DialogRunnerTest { - public class MockDialog implements DialogRunnerI + public class MockDialog implements DialogRunnerI { DialogRunner runner = new DialogRunner<>(this); @Override - public MockDialog response(RunResponse action) + public MockDialog addResponse(RunResponse action) { - return runner.response(action); + return runner.addResponse(action); } public void doDialog(String resp) @@ -80,7 +80,7 @@ public class DialogRunnerTest Assert.assertFalse(dialog.runner.isRegistered(ok)); - dialog.response(ok).response(cancel).response(help).response(ineed); + dialog.addResponse(ok).addResponse(cancel).addResponse(help).addResponse(ineed); Assert.assertTrue(dialog.runner.isRegistered(ok));