import jalview.schemes.ResidueColourScheme;
import jalview.schemes.TCoffeeColourScheme;
import jalview.util.MessageManager;
+import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.AlignmentViewport;
import jalview.viewmodel.ViewportRanges;
import jalview.ws.DBRefFetcher;
String format = currentFileFormat == null ? null
: currentFileFormat.getName();
- JalviewFileChooser chooser = JalviewFileChooser
+ final JalviewFileChooser chooser = JalviewFileChooser
.forWrite(Cache.getProperty("LAST_DIRECTORY"), format);
-
+ final AlignFrame us = this;
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(
MessageManager.getString("label.save_alignment_to_file"));
chooser.setToolTipText(MessageManager.getString("action.save"));
- int value = chooser.showSaveDialog(this);
-
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
{
- currentFileFormat = chooser.getSelectedFormat();
- while (currentFileFormat == null)
- {
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
- MessageManager.getString(
- "label.select_file_format_before_saving"),
- MessageManager.getString("label.file_format_not_specified"),
- JvOptionPane.WARNING_MESSAGE);
+ @Override
+ public void run()
+ {
currentFileFormat = chooser.getSelectedFormat();
- value = chooser.showSaveDialog(this);
- if (value != JalviewFileChooser.APPROVE_OPTION)
+ while (currentFileFormat == null)
{
- return;
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ MessageManager.getString(
+ "label.select_file_format_before_saving"),
+ MessageManager
+ .getString("label.file_format_not_specified"),
+ JvOptionPane.WARNING_MESSAGE);
+ currentFileFormat = chooser.getSelectedFormat();
+ chooser.showSaveDialog(us);
}
- }
- fileName = chooser.getSelectedFile().getPath();
+ fileName = chooser.getSelectedFile().getPath();
- Cache.setProperty("DEFAULT_FILE_FORMAT", currentFileFormat.getName());
+ Cache.setProperty("DEFAULT_FILE_FORMAT",
+ currentFileFormat.getName());
- Cache.setProperty("LAST_DIRECTORY", fileName);
- saveAlignment(fileName, currentFileFormat);
- }
+ Cache.setProperty("LAST_DIRECTORY", fileName);
+ saveAlignment(fileName, currentFileFormat);
+ }
+ }).showSaveDialog(this);
}
public boolean saveAlignment(String file, FileFormatI format)
import jalview.util.MessageManager;
import jalview.util.Platform;
import jalview.util.dialogrunner.DialogRunnerI;
+import jalview.util.dialogrunner.Response;
import jalview.util.dialogrunner.RunResponse;
import java.awt.Component;
return null;
}
- @Override
- public int showSaveDialog(Component parent) throws HeadlessException
+ Component saveparent;
+ RunResponse overwriteCheck = new RunResponse(
+ JalviewFileChooser.APPROVE_OPTION)
{
- this.setAccessory(null);
+ @Override
+ public void run()
+ {
+ // 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();
- setDialogType(SAVE_DIALOG);
+ 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
+ */
+ {
+ if (getSelectedFile().exists())
+ {
+ // TODO JAL-3048 - may not need to raise this for browser saves
- int ret = showDialog(parent, MessageManager.getString("action.save"));
+ // 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);
+ }
+ }
+ }
+ };
+ };
- if (getFileFilter() instanceof JalviewFileFilter)
- {
- JalviewFileFilter jvf = (JalviewFileFilter) getFileFilter();
+ @Override
+ public int showSaveDialog(Component parent) throws HeadlessException
+ {
+ this.setAccessory(null);
- if (!jvf.accept(getSelectedFile()))
- {
- String withExtension = getSelectedFile() + "."
- + jvf.getAcceptableExtension();
- setSelectedFile(new File(withExtension));
- }
+ /*
+ * 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)
- && getSelectedFile().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);
+ saveparent = parent;
+
+ int value = showDialog(parent, MessageManager.getString("action.save"));
+
+ runner.run(value);
+ return value;
}
void recentListSelectionChanged(Object selection)