+ /**
+ * Action on pressing the Save button.
+ * <ul>
+ * <li>Check a name has been entered</li>
+ * <li>Warn if the name already exists, remove any existing scheme of the same
+ * name if overwriting</li>
+ * <li>Do the standard file chooser thing to write with extension .jc</li>
+ * <li>If saving changes (possibly not yet applied) to the currently selected
+ * colour scheme, then apply the changes, as it is too late to back out
+ * now</li>
+ * <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>
+ * If the scheme is saved to file, the 'changed' flag field is reset to false.
+ */
+ @Override
+ protected void savebutton_actionPerformed()
+ {
+ String name = schemeName.getText().trim();
+ if (name.length() < 1)
+ {
+ JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ MessageManager
+ .getString("label.user_colour_scheme_must_have_name"),
+ MessageManager.getString("label.no_name_colour_scheme"),
+ JvOptionPane.WARNING_MESSAGE);
+ }
+
+ if (ColourSchemes.getInstance().nameExists(name))
+ {
+ // BH 2018 SwingJS bypasses this question with YES_OPTION
+ int reply = /** @j2sNative 0 && */ JvOptionPane.showInternalConfirmDialog(Desktop.desktop,
+ MessageManager.formatMessage(
+ "label.colour_scheme_exists_overwrite", new Object[]
+ { name, name }),
+ MessageManager.getString("label.duplicate_scheme_name"),
+ JvOptionPane.YES_NO_OPTION);
+ if (reply != JvOptionPane.YES_OPTION)
+ {
+ }
+ }
+
+ JalviewFileChooser chooser = new JalviewFileChooser("jc",
+ "Jalview User Colours");
+
+ JalviewFileView fileView = new JalviewFileView();
+ chooser.setFileView(fileView);
+ chooser.setDialogTitle(
+ MessageManager.getString("label.save_colour_scheme"));
+ chooser.setToolTipText(MessageManager.getString("action.save"));
+ 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();
+ }