AlignmentPanel ap;
+ /*
+ * the colour scheme when the dialog was opened, or
+ * the scheme last saved to file
+ */
ColourSchemeI oldColourScheme;
+ /*
+ * flag is true if the colour scheme has been changed since the
+ * dialog was opened, or the changes last saved to file
+ */
+ boolean changed;
+
JInternalFrame frame;
List<JButton> upperCaseButtons;
button.setBackground(newColour);
button.setForeground(ColorUtils.brighterThan(newColour));
}
+
+ changed = true;
}
/**
}
else
{
+ /*
+ * OK is treated as 'apply colours and close'
+ */
applyButton_actionPerformed();
+ /*
+ * If editing a named colour scheme, warn if changes
+ * have not been saved
+ */
+ warnIfUnsavedChanges();
+
try
{
frame.setClosed(true);
}
/**
+ * If we have made changes to an existing user defined colour scheme but not
+ * saved them, show a dialog with the option to save. If the user chooses to
+ * save, do so, else clear the colour scheme name to indicate a new colour
+ * scheme.
+ */
+ protected void warnIfUnsavedChanges()
+ {
+ if (!changed)
+ {
+ return;
+ }
+
+ String name = schemeName.getText().trim();
+ if (oldColourScheme != null && !"".equals(name)
+ && name.equals(oldColourScheme.getSchemeName()))
+ {
+ String message = MessageManager.formatMessage("label.scheme_changed",
+ name);
+ String title = MessageManager.getString("label.save_changes");
+ String[] options = new String[] { title,
+ MessageManager.getString("label.dont_save_changes"), };
+ final String question = JvSwingUtils.wrapTooltip(true, message);
+ int response = JvOptionPane.showOptionDialog(Desktop.desktop,
+ question, title, JvOptionPane.DEFAULT_OPTION,
+ JvOptionPane.PLAIN_MESSAGE, null, options, options[0]);
+
+ boolean saved = false;
+ if (response == 0)
+ {
+ /*
+ * prompt to save changes to file
+ */
+ saved = 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)
+ {
+ /*
+ * clear scheme name and re-apply as an anonymous scheme
+ */
+ schemeName.setText("");
+ applyButton_actionPerformed();
+ }
+ }
+ }
+
+ /**
* Returns true if the user has not made any colour selection (including if
* 'case-sensitive' selected and no lower-case colour chosen).
*
* <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
*/
@Override
- protected void savebutton_actionPerformed()
+ protected boolean 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;
+ return false;
}
if (ColourSchemes.getInstance().nameExists(name))
JvOptionPane.YES_NO_OPTION);
if (reply != JvOptionPane.YES_OPTION)
{
- return;
+ return false;
}
}
JalviewFileChooser chooser = new JalviewFileChooser("jc",
int value = chooser.showSaveDialog(this);
- if (value == JalviewFileChooser.APPROVE_OPTION)
+ if (value != JalviewFileChooser.APPROVE_OPTION)
{
- File file = chooser.getSelectedFile();
- UserColourScheme updatedScheme = addNewColourScheme(file.getPath());
- saveToFile(file);
+ return 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();
- }
+ 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();
}
+ return true;
}
/**