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
{
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;
}
/**
- * 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)
}
/**
- * 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"));
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;
@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)))
import java.util.List;
import java.util.Vector;
--import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
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,
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;
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());
}
});
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);
}
}
else
{
- treeCanvas.ap.alignFrame
- .addHistoryItem(sortAlignmentIn(treeCanvas.ap));
- getTreeCanvas().getAssociatedPanel().alignFrame
- .addHistoryItem(sortAlignmentIn(getTreeCanvas().getAssociatedPanel()));
++ treeCanvas.getAssociatedPanel().alignFrame
++ .addHistoryItem(
++ sortAlignmentIn(treeCanvas.getAssociatedPanel()));
}
}
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;
+ }
}
}
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)
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);