From: gmungoc Date: Mon, 10 Apr 2017 07:48:59 +0000 (+0100) Subject: JAL-2361 option to save on OK of changed named colour scheme X-Git-Tag: Release_2_10_2~3^2~134 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7e82c1426d70a5072fa6fc0eb869e22a11775cd7;p=jalview.git JAL-2361 option to save on OK of changed named colour scheme --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index f284ff9..2e92717 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -3,6 +3,9 @@ action.reset_services = Reset Services action.merge_results = Merge Results action.load_scheme = Load scheme action.save_scheme = Save scheme +label.scheme_changed = Changes to scheme {0} have not been saved
Save changes, or continue without saving to make a new colour scheme +label.save_changes = Save Changes +label.dont_save_changes = Don't Save action.save_image = Save Image action.paste = Paste action.show_html_source = Show HTML Source diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 0187aa3..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,24 +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(); - 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; } /** diff --git a/src/jalview/jbgui/GUserDefinedColours.java b/src/jalview/jbgui/GUserDefinedColours.java index c3645a8..5384cc0 100755 --- a/src/jalview/jbgui/GUserDefinedColours.java +++ b/src/jalview/jbgui/GUserDefinedColours.java @@ -286,8 +286,9 @@ public class GUserDefinedColours extends JPanel { } - protected void savebutton_actionPerformed() + protected boolean savebutton_actionPerformed() { + return false; } /**