chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.save_state"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ int option = chooser.showSaveDialog(this);
+ if (option == JalviewFileChooser.APPROVE_OPTION)
{
- final Desktop me = this;
- final java.io.File choice = chooser.getSelectedFile();
+ File choice = chooser.getSelectedFile();
setProjectFile(choice);
new Thread(new Runnable()
Cache.log.error(
"Problems whilst trying to save to " + choice.getName(),
ex);
- JvOptionPane.showMessageDialog(me,
+ JvOptionPane.showMessageDialog(Desktop.this,
MessageManager.formatMessage(
"label.error_whilst_saving_current_state_to",
new Object[]
setProgressBar(null, choice.hashCode());
}
}).start();
- }
+ }
}
- private void setProjectFile(File choice)
+ void setProjectFile(File choice)
{
this.projectFile = choice;
}
"Jalview Project");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
-
- int value = chooser.showOpenDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION)
{
- final File selectedFile = chooser.getSelectedFile();
- setProjectFile(selectedFile);
- final String choice = selectedFile.getAbsolutePath();
- Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
- new Thread(new Runnable()
+ @Override
+ public void run()
{
- @Override
- public void run()
+ File selectedFile = chooser.getSelectedFile();
+ setProjectFile(selectedFile);
+ final String choice = selectedFile.getAbsolutePath();
+ Cache.setProperty("LAST_DIRECTORY", selectedFile.getParent());
+ new Thread(new Runnable()
{
- setProgressBar(MessageManager.formatMessage(
- "label.loading_jalview_project", new Object[]
- { choice }), choice.hashCode());
- try
- {
- new Jalview2XML().loadJalviewAlign(choice);
- } catch (OutOfMemoryError oom)
+ @Override
+ public void run()
{
- new OOMWarning("Whilst loading project from " + choice, oom);
- } catch (Exception ex)
- {
- Cache.log.error(
- "Problems whilst loading project from " + choice, ex);
- JvOptionPane.showMessageDialog(Desktop.desktop,
- MessageManager.formatMessage(
- "label.error_whilst_loading_project_from",
- new Object[]
- { choice }),
- MessageManager.getString("label.couldnt_load_project"),
- JvOptionPane.WARNING_MESSAGE);
+ setProgressBar(MessageManager.formatMessage(
+ "label.loading_jalview_project", new Object[]
+ { choice }), choice.hashCode());
+ try
+ {
+ new Jalview2XML().loadJalviewAlign(choice);
+ } catch (OutOfMemoryError oom)
+ {
+ new OOMWarning("Whilst loading project from " + choice, oom);
+ } catch (Exception ex)
+ {
+ Cache.log.error(
+ "Problems whilst loading project from " + choice, ex);
+ JvOptionPane.showMessageDialog(Desktop.desktop,
+ MessageManager.formatMessage(
+ "label.error_whilst_loading_project_from",
+ new Object[]
+ { choice }),
+ MessageManager.getString("label.couldnt_load_project"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
+ setProgressBar(null, choice.hashCode());
}
- setProgressBar(null, choice.hashCode());
- }
- }).start();
- }
+ }).start();
+ }
+ });
+
+ chooser.showOpenDialog(this);
}
@Override
import jalview.api.FeatureColourI;
import jalview.api.FeatureSettingsControllerI;
-import jalview.bin.Jalview;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.SequenceI;
import jalview.datamodel.features.FeatureMatcher;
import jalview.schemes.FeatureColour;
import jalview.util.MessageManager;
import jalview.util.Platform;
+import jalview.util.dialogrunner.RunResponse;
import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
-import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
*/
void load()
{
- // TODO: JAL-3048 relies on Castor XML parsing: not needed for JS-jalview core
- // functionalty
-
JalviewFileChooser chooser = new JalviewFileChooser("fc",
SEQUENCE_FEATURE_COLOURS);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(
MessageManager.getString("label.load_feature_colours"));
chooser.setToolTipText(MessageManager.getString("action.load"));
-
- int value = chooser.showOpenDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- File file = chooser.getSelectedFile();
- load(file);
- }
+ chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION){
+
+ @Override
+ public void run() {
+ File file = chooser.getSelectedFile();
+ load(file);
+ }});
+ chooser.showOpenDialog(this);
}
/**
*/
void save()
{
- // TODO: JAL-3048 not needed for Jalview-JS - save colours
JalviewFileChooser chooser = new JalviewFileChooser("fc",
SEQUENCE_FEATURE_COLOURS);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(
MessageManager.getString("label.save_feature_colours"));
chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value == JalviewFileChooser.APPROVE_OPTION)
- {
- save(chooser.getSelectedFile());
- }
+ int option = chooser.showSaveDialog(this);
+ if (option == JalviewFileChooser.APPROVE_OPTION)
+ {
+ File file = chooser.getSelectedFile();
+ save(file);
+ }
}
/**
JPanel buttonPanel = new JPanel();
buttonPanel.add(ok);
buttonPanel.add(cancel);
- if (!Jalview.isJS())
- {
- /*
- * no save/load XML in JalviewJS for now
- */
- buttonPanel.add(loadColours);
- buttonPanel.add(saveColours);
- }
+ buttonPanel.add(loadColours);
+ buttonPanel.add(saveColours);
bigPanel.add(scrollPane, BorderLayout.CENTER);
settingsPane.add(bigPanel, BorderLayout.CENTER);
settingsPane.add(buttonPanel, BorderLayout.SOUTH);
import jalview.util.ColorUtils;
import jalview.util.Format;
import jalview.util.MessageManager;
+import jalview.util.dialogrunner.RunResponse;
import java.awt.Color;
import java.awt.Font;
* flag is true if the colour scheme has been changed since the
* dialog was opened, or the changes last saved to file
*/
- boolean changed;
+ boolean changedButNotSaved;
JInternalFrame frame;
button.setForeground(ColorUtils.brighterThan(newColour));
}
- changed = true;
+ changedButNotSaved = true;
}
/**
{
// BH 2018 no warning in JavaScript TODO
- if (/** @j2sNative true || */ !changed)
+ if (/** @j2sNative true || */ !changedButNotSaved)
{
return;
}
question, title, JvOptionPane.DEFAULT_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, options, options[0]);
- boolean saved = false;
if (response == 0)
{
/*
- * prompt to save changes to file
+ * prompt to save changes to file; if done,
+ * resets 'changed' flag to false
*/
- saved = savebutton_actionPerformed();
+ savebutton_actionPerformed();
}
/*
* if user chooses not to save (either in this dialog or in the
* save as dialogs), treat this as a new user defined colour scheme
*/
- if (!saved)
+ if (changedButNotSaved)
{
/*
* clear scheme name and re-apply as an anonymous scheme
{
upperCaseButtons = new ArrayList<>();
lowerCaseButtons = new ArrayList<>();
- // TODO: JAL-3048 requires Castor dependency for Jalview-JS
JalviewFileChooser chooser = new JalviewFileChooser("jc",
"Jalview User Colours");
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(
MessageManager.getString("label.load_colour_scheme"));
chooser.setToolTipText(MessageManager.getString("action.load"));
-
- int value = chooser.showOpenDialog(this);
-
- if (value != JalviewFileChooser.APPROVE_OPTION)
- {
- return;
- }
- File choice = chooser.getSelectedFile();
- Cache.setProperty(LAST_DIRECTORY, choice.getParent());
-
- UserColourScheme ucs = ColourSchemeLoader
- .loadColourScheme(choice.getAbsolutePath());
- Color[] colors = ucs.getColours();
- schemeName.setText(ucs.getSchemeName());
-
- if (ucs.getLowerCaseColours() != null)
- {
- caseSensitive.setSelected(true);
- lcaseColour.setEnabled(true);
- resetButtonPanel(true);
- for (int i = 0; i < lowerCaseButtons.size(); i++)
- {
- JButton button = lowerCaseButtons.get(i);
- button.setBackground(ucs.getLowerCaseColours()[i]);
- }
- }
- else
- {
- caseSensitive.setSelected(false);
- lcaseColour.setEnabled(false);
- resetButtonPanel(false);
- }
-
- for (int i = 0; i < upperCaseButtons.size(); i++)
- {
- JButton button = upperCaseButtons.get(i);
- button.setBackground(colors[i]);
- }
-
- addNewColourScheme(choice.getPath());
+ chooser.response(new RunResponse(JalviewFileChooser.APPROVE_OPTION) {
+ @Override
+ public void run() {
+ File choice = chooser.getSelectedFile();
+ Cache.setProperty(LAST_DIRECTORY, choice.getParent());
+
+ UserColourScheme ucs = ColourSchemeLoader
+ .loadColourScheme(choice.getAbsolutePath());
+ Color[] colors = ucs.getColours();
+ schemeName.setText(ucs.getSchemeName());
+
+ if (ucs.getLowerCaseColours() != null)
+ {
+ caseSensitive.setSelected(true);
+ lcaseColour.setEnabled(true);
+ resetButtonPanel(true);
+ for (int i = 0; i < lowerCaseButtons.size(); i++)
+ {
+ JButton button = lowerCaseButtons.get(i);
+ button.setBackground(ucs.getLowerCaseColours()[i]);
+ }
+ }
+ else
+ {
+ caseSensitive.setSelected(false);
+ lcaseColour.setEnabled(false);
+ resetButtonPanel(false);
+ }
+
+ for (int i = 0; i < upperCaseButtons.size(); i++)
+ {
+ JButton button = upperCaseButtons.get(i);
+ button.setBackground(colors[i]);
+ }
+
+ addNewColourScheme(choice.getPath());
+ }});
+
+ chooser.showOpenDialog(this);
}
/**
* <li>Don't apply the changes if the currently selected scheme is different,
* to allow a new scheme to be configured and saved but not applied</li>
* </ul>
- * Returns true if the scheme is saved to file, false if it is not
- *
- * @return
+ * If the scheme is saved to file, the 'changed' flag field is reset to false.
*/
@Override
- protected boolean savebutton_actionPerformed()
+ protected void savebutton_actionPerformed()
{
String name = schemeName.getText().trim();
if (name.length() < 1)
.getString("label.user_colour_scheme_must_have_name"),
MessageManager.getString("label.no_name_colour_scheme"),
JvOptionPane.WARNING_MESSAGE);
- return false;
}
if (ColourSchemes.getInstance().nameExists(name))
JvOptionPane.YES_NO_OPTION);
if (reply != JvOptionPane.YES_OPTION)
{
- return false;
}
}
- // TODO: JAL-3048 saveas, also requires Castor dependency for Jalview-JS
JalviewFileChooser chooser = new JalviewFileChooser("jc",
"Jalview User Colours");
chooser.setDialogTitle(
MessageManager.getString("label.save_colour_scheme"));
chooser.setToolTipText(MessageManager.getString("action.save"));
-
- int value = chooser.showSaveDialog(this);
-
- if (value != JalviewFileChooser.APPROVE_OPTION)
- {
- return false;
- }
-
- File file = chooser.getSelectedFile();
- UserColourScheme updatedScheme = addNewColourScheme(file.getPath());
- saveToFile(file);
- changed = false;
-
- /*
- * changes saved - apply to alignment if we are changing
- * the currently selected colour scheme; also make the updated
- * colours the 'backout' scheme on Cancel
- */
- if (oldColourScheme != null
- && name.equals(oldColourScheme.getSchemeName()))
- {
- oldColourScheme = updatedScheme;
- applyButton_actionPerformed();
+ int option = chooser.showSaveDialog(this);
+ if (option == JalviewFileChooser.APPROVE_OPTION)
+ {
+ File file = chooser.getSelectedFile();
+ UserColourScheme updatedScheme = addNewColourScheme(file.getPath());
+ saveToFile(file);
+ changedButNotSaved = false;
+
+ /*
+ * changes saved - apply to alignment if we are changing
+ * the currently selected colour scheme; also make the updated
+ * colours the 'backout' scheme on Cancel
+ */
+ if (oldColourScheme != null
+ && name.equals(oldColourScheme.getSchemeName()))
+ {
+ oldColourScheme = updatedScheme;
+ applyButton_actionPerformed();
+ }
}
- return true;
}
/**
desktopMenubar.add(windowMenu);
FileMenu.add(inputMenu);
FileMenu.add(inputSequence);
- if (!Jalview.isJS())
- {
- FileMenu.addSeparator();
- FileMenu.add(saveState);
- FileMenu.add(loadState);
- }
- FileMenu.addSeparator();
+ FileMenu.addSeparator();
+ FileMenu.add(saveState);
+ FileMenu.add(loadState);
+ FileMenu.addSeparator();
FileMenu.add(quit);
HelpMenu.add(aboutMenuItem);
HelpMenu.add(documentationMenuItem);
JLabel jLabel1 = new JLabel();
- protected JTextField schemeName = new JTextField();
+ public JTextField schemeName = new JTextField();
BorderLayout borderLayout1 = new BorderLayout();
protected JPanel casePanel = new JPanel();
- protected JCheckBox caseSensitive = new JCheckBox();
+ public JCheckBox caseSensitive = new JCheckBox();
- protected JCheckBox lcaseColour = new JCheckBox();
+ public JCheckBox lcaseColour = new JCheckBox();
protected List<JButton> selectedButtons;
okCancelPanel.add(applyButton);
okCancelPanel.add(okButton);
okCancelPanel.add(cancelButton);
- if (!Jalview.isJS())
- {
- lowerPanel.add(saveLoadPanel, java.awt.BorderLayout.NORTH);
- }
+ lowerPanel.add(saveLoadPanel, java.awt.BorderLayout.NORTH);
lowerPanel.add(okCancelPanel, java.awt.BorderLayout.SOUTH);
namePanel.add(schemeName, java.awt.BorderLayout.CENTER);
{
}
- protected boolean savebutton_actionPerformed()
+ protected void savebutton_actionPerformed()
{
- return false;
}
/**