From 1ddaca03529cd2b02502a1dae10c18582164972d Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 5 Apr 2017 14:21:44 +0100 Subject: [PATCH] JAL-2361 apply any saved changes to current colour scheme --- src/jalview/gui/ColourMenuHelper.java | 6 +- src/jalview/gui/UserDefinedColours.java | 105 +++++++++++++--------------- src/jalview/jbgui/GUserDefinedColours.java | 32 ++++----- src/jalview/schemes/ColourSchemes.java | 17 ++--- 4 files changed, 71 insertions(+), 89 deletions(-) diff --git a/src/jalview/gui/ColourMenuHelper.java b/src/jalview/gui/ColourMenuHelper.java index 19ad939..801615c 100644 --- a/src/jalview/gui/ColourMenuHelper.java +++ b/src/jalview/gui/ColourMenuHelper.java @@ -104,14 +104,14 @@ public class ColourMenuHelper /* * user-defined colour scheme loaded on startup or during the * Jalview session; right-click on this offers the option to - * remove it as a colour choice + * remove it as a colour choice (unless currently selected) */ radioItem.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { - if (evt.isPopupTrigger()) // Mac + if (evt.isPopupTrigger() && !radioItem.isSelected()) // Mac { offerRemoval(); } @@ -120,7 +120,7 @@ public class ColourMenuHelper @Override public void mouseReleased(MouseEvent evt) { - if (evt.isPopupTrigger()) // Windows + if (evt.isPopupTrigger() && !radioItem.isSelected()) // Windows { offerRemoval(); } diff --git a/src/jalview/gui/UserDefinedColours.java b/src/jalview/gui/UserDefinedColours.java index 9ab4327..5ec95ed 100755 --- a/src/jalview/gui/UserDefinedColours.java +++ b/src/jalview/gui/UserDefinedColours.java @@ -20,7 +20,6 @@ */ package jalview.gui; -import jalview.api.structures.JalviewStructureDisplayI; import jalview.bin.Cache; import jalview.datamodel.SequenceGroup; import jalview.io.JalviewFileChooser; @@ -40,7 +39,6 @@ import jalview.util.MessageManager; import java.awt.Color; import java.awt.Font; import java.awt.Insets; -import java.awt.event.ActionEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.File; @@ -82,14 +80,10 @@ public class UserDefinedColours extends GUserDefinedColours implements SequenceGroup seqGroup; - List selectedButtons; - ColourSchemeI oldColourScheme; JInternalFrame frame; - JalviewStructureDisplayI structureViewer; - List upperCaseButtons; List lowerCaseButtons; @@ -140,29 +134,7 @@ public class UserDefinedColours extends GUserDefinedColours implements showFrame(); } - public UserDefinedColours(JalviewStructureDisplayI viewer, - ColourSchemeI oldcs) - { - this(); - this.structureViewer = viewer; - - colorChooser.getSelectionModel().addChangeListener(this); - - oldColourScheme = oldcs; - - if (oldColourScheme instanceof UserColourScheme) - { - schemeName.setText(((UserColourScheme) oldColourScheme) - .getSchemeName()); - } - - resetButtonPanel(false); - - showFrame(); - - } - - public UserDefinedColours() + UserDefinedColours() { super(); selectedButtons = new ArrayList(); @@ -509,8 +481,7 @@ public class UserDefinedColours extends GUserDefinedColours implements } /** - * Applies the current colour scheme to the alignment, sequence group or - * structure view. + * Applies the current colour scheme to the alignment or sequence group */ @Override protected void applyButton_actionPerformed() @@ -534,12 +505,14 @@ public class UserDefinedColours extends GUserDefinedColours implements { ap.alignFrame.changeColour(ucs); } - else if (structureViewer != null) - { - structureViewer.setJalviewColourScheme(ucs); - } } + /** + * Constructs an instance of UserColourScheme with the residue colours + * currently set on the buttons on the panel + * + * @return + */ UserColourScheme getSchemeFromButtons() { @@ -595,13 +568,15 @@ public class UserDefinedColours extends GUserDefinedColours implements } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Action on clicking Load scheme button. + *
    + *
  • Open a file chooser to browse for files with extension .jc
  • + *
  • Load in the colour scheme and transfer it to this panel's buttons
  • + *
  • Register the loaded colour scheme
  • + *
*/ @Override - protected void loadbutton_actionPerformed(ActionEvent e) + protected void loadbutton_actionPerformed() { upperCaseButtons = new ArrayList(); lowerCaseButtons = new ArrayList(); @@ -683,13 +658,20 @@ public class UserDefinedColours extends GUserDefinedColours implements } /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! + * Action on pressing the Save button. + *
    + *
  • Check a name has been entered
  • + *
  • Warn if the name already exists, remove any existing scheme of the same + * name if overwriting
  • + *
  • Do the standard file chooser thing to write with extension .jc
  • + *
  • 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
  • + *
  • 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
  • + *
*/ @Override - protected void savebutton_actionPerformed(ActionEvent e) + protected void savebutton_actionPerformed() { String name = schemeName.getText().trim(); if (name.length() < 1) @@ -731,6 +713,16 @@ public class UserDefinedColours extends GUserDefinedColours implements File file = chooser.getSelectedFile(); addNewColourScheme(file.getPath()); saveToFile(file); + + /* + * changes saved - apply to alignment if we are changing + * the currently selected colour scheme + */ + if (oldColourScheme != null + && name.equals(oldColourScheme.getSchemeName())) + { + applyButton_actionPerformed(); + } } } @@ -787,7 +779,8 @@ public class UserDefinedColours extends GUserDefinedColours implements * marshal to file */ JalviewUserColours ucs = new JalviewUserColours(); - ucs.setSchemeName(schemeName.getText()); + String name = schemeName.getText(); + ucs.setSchemeName(name); try { PrintWriter out = new PrintWriter(new OutputStreamWriter( @@ -810,12 +803,11 @@ public class UserDefinedColours extends GUserDefinedColours implements } /** - * On cancel, restores the colour scheme before the dialogue was opened - * - * @param e + * On cancel, restores the colour scheme that was selected before the dialogue + * was opened */ @Override - protected void cancelButton_actionPerformed(ActionEvent e) + protected void cancelButton_actionPerformed() { if (ap != null) { @@ -830,11 +822,6 @@ public class UserDefinedColours extends GUserDefinedColours implements ap.paintAlignment(true); } - if (structureViewer != null) - { - structureViewer.setJalviewColourScheme(oldColourScheme); - } - try { frame.setClosed(true); @@ -843,8 +830,14 @@ public class UserDefinedColours extends GUserDefinedColours implements } } + /** + * Action on selecting or deselecting the Case Sensitive option. When + * selected, separate buttons are shown for lower case residues, and the panel + * is resized to accommodate them. Also, the checkbox for 'apply colour to all + * lower case' is enabled. + */ @Override - public void caseSensitive_actionPerformed(ActionEvent e) + public void caseSensitive_actionPerformed() { boolean selected = caseSensitive.isSelected(); resetButtonPanel(selected); diff --git a/src/jalview/jbgui/GUserDefinedColours.java b/src/jalview/jbgui/GUserDefinedColours.java index aa5319c..c3645a8 100755 --- a/src/jalview/jbgui/GUserDefinedColours.java +++ b/src/jalview/jbgui/GUserDefinedColours.java @@ -137,7 +137,7 @@ public class GUserDefinedColours extends JPanel gridLayout.setRows(5); okButton.setFont(new java.awt.Font("Verdana", 0, 11)); okButton.setText(MessageManager.getString("action.ok")); - okButton.addActionListener(new java.awt.event.ActionListener() + okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) @@ -157,32 +157,32 @@ public class GUserDefinedColours extends JPanel }); loadbutton.setFont(new java.awt.Font("Verdana", 0, 11)); loadbutton.setText(MessageManager.getString("action.load_scheme")); - loadbutton.addActionListener(new java.awt.event.ActionListener() + loadbutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - loadbutton_actionPerformed(e); + loadbutton_actionPerformed(); } }); savebutton.setFont(new java.awt.Font("Verdana", 0, 11)); savebutton.setText(MessageManager.getString("action.save_scheme")); - savebutton.addActionListener(new java.awt.event.ActionListener() + savebutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - savebutton_actionPerformed(e); + savebutton_actionPerformed(); } }); cancelButton.setFont(JvSwingUtils.getLabelFont()); cancelButton.setText(MessageManager.getString("action.cancel")); - cancelButton.addActionListener(new java.awt.event.ActionListener() + cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - cancelButton_actionPerformed(e); + cancelButton_actionPerformed(); } }); this.setBackground(new Color(212, 208, 223)); @@ -218,7 +218,7 @@ public class GUserDefinedColours extends JPanel @Override public void actionPerformed(ActionEvent e) { - caseSensitive_actionPerformed(e); + caseSensitive_actionPerformed(); } }); lcaseColour @@ -282,17 +282,11 @@ public class GUserDefinedColours extends JPanel * @param e * DOCUMENT ME! */ - protected void loadbutton_actionPerformed(ActionEvent e) + protected void loadbutton_actionPerformed() { } - /** - * DOCUMENT ME! - * - * @param e - * DOCUMENT ME! - */ - protected void savebutton_actionPerformed(ActionEvent e) + protected void savebutton_actionPerformed() { } @@ -302,16 +296,16 @@ public class GUserDefinedColours extends JPanel * @param e * DOCUMENT ME! */ - protected void cancelButton_actionPerformed(ActionEvent e) + protected void cancelButton_actionPerformed() { } - public void caseSensitive_actionPerformed(ActionEvent e) + public void caseSensitive_actionPerformed() { } - public void lcaseColour_actionPerformed(ActionEvent e) + public void lcaseColour_actionPerformed() { } diff --git a/src/jalview/schemes/ColourSchemes.java b/src/jalview/schemes/ColourSchemes.java index dc7e403..269811b 100644 --- a/src/jalview/schemes/ColourSchemes.java +++ b/src/jalview/schemes/ColourSchemes.java @@ -15,7 +15,7 @@ public class ColourSchemes private static ColourSchemes instance = new ColourSchemes(); /* - * a map from scheme name to an instance of it + * a map from scheme name (lower-cased) to an instance of it */ private Map schemes; @@ -94,7 +94,10 @@ public class ColourSchemes */ public void removeColourScheme(String name) { - schemes.remove(name); + if (name != null) + { + schemes.remove(name.toLowerCase()); + } } /** @@ -162,14 +165,6 @@ public class ColourSchemes { return false; } - name = name.toLowerCase(); - for (ColourSchemeI scheme : getColourSchemes()) - { - if (name.equals(scheme.getSchemeName().toLowerCase())) - { - return true; - } - } - return false; + return schemes.containsKey(name.toLowerCase()); } } -- 1.7.10.2