X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FUserDefinedColours.java;h=f75a0a38797236e8f41ee0300861bee4bb6ba93d;hb=2ef218faa692153c09a328d40b8f4724d69355f2;hp=369dde67928ad52d6563b89d71672f4a4cf8a6b5;hpb=8e9cee1be3194bacb353d94a2166fff1afe8029b;p=jalview.git diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 369dde6..f75a0a3 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -77,8 +77,18 @@ public class UserDefinedColours extends GUserDefinedColours implements 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 upperCaseButtons; @@ -248,6 +258,8 @@ public class UserDefinedColours extends GUserDefinedColours implements button.setBackground(newColour); button.setForeground(ColorUtils.brighterThan(newColour)); } + + changed = true; } /** @@ -435,8 +447,17 @@ public class UserDefinedColours extends GUserDefinedColours implements } 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); @@ -447,6 +468,57 @@ public class UserDefinedColours extends GUserDefinedColours implements } /** + * 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). * @@ -644,9 +716,12 @@ public class UserDefinedColours extends GUserDefinedColours implements *
  • 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
  • * + * 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) @@ -655,7 +730,7 @@ public class UserDefinedColours extends GUserDefinedColours implements .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)) @@ -668,7 +743,7 @@ public class UserDefinedColours extends GUserDefinedColours implements JvOptionPane.YES_NO_OPTION); if (reply != JvOptionPane.YES_OPTION) { - return; + return false; } } JalviewFileChooser chooser = new JalviewFileChooser("jc", @@ -682,22 +757,28 @@ public class UserDefinedColours extends GUserDefinedColours implements int value = chooser.showSaveDialog(this); - if (value == JalviewFileChooser.APPROVE_OPTION) + if (value != JalviewFileChooser.APPROVE_OPTION) { - File file = chooser.getSelectedFile(); - addNewColourScheme(file.getPath()); - saveToFile(file); + return false; + } - /* - * changes saved - apply to alignment if we are changing - * the currently selected colour scheme - */ - if (oldColourScheme != null - && name.equals(oldColourScheme.getSchemeName())) - { - 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; } /** @@ -707,8 +788,9 @@ public class UserDefinedColours extends GUserDefinedColours implements * the colour scheme. * * @param filePath + * @return */ - protected void addNewColourScheme(String filePath) + protected UserColourScheme addNewColourScheme(String filePath) { /* * update the delimited list of user defined colour files in @@ -739,6 +821,8 @@ public class UserDefinedColours extends GUserDefinedColours implements { ap.alignFrame.buildColourMenu(); } + + return ucs; } /**