{
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();
}
/**
/**
* 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.
*/
public void exportHTML(String outputFile)
{
- exportStarted();
+ setProgressMessage(MessageManager.formatMessage(
+ "status.exporting_alignment_as_x_file", getDescription()));
try
{
if (outputFile == null)
*
* @return
*/
- protected abstract String getDescription();
+ protected final String getDescription()
+ {
+ return description;
+ }
}
\ No newline at end of file
{
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,
{
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(
.formatMessage("info.error_creating_file", getDescription()));
}
}
-
- @Override
- protected String getDescription()
- {
- return "HTML";
- }
}
*
*/
public class JalviewFileChooser extends JFileChooser
- implements PropertyChangeListener, DialogRunnerI
+ implements PropertyChangeListener, DialogRunnerI<JalviewFileChooser>
{
DialogRunner<JalviewFileChooser> runner = new DialogRunner<>(this);
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
"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)