JAL-1702 corrected check for 'no colours selected'
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 23 Apr 2015 10:44:50 +0000 (11:44 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 23 Apr 2015 10:44:50 +0000 (11:44 +0100)
src/jalview/gui/UserDefinedColours.java

index c5562c6..a907187 100755 (executable)
  */
 package jalview.gui;
 
-import jalview.api.structures.JalviewStructureDisplayI;
-import jalview.datamodel.SequenceGroup;
-import jalview.io.JalviewFileChooser;
-import jalview.jbgui.GUserDefinedColours;
-import jalview.schemes.ColourSchemeI;
-import jalview.schemes.ResidueProperties;
-import jalview.schemes.UserColourScheme;
-import jalview.util.ColorUtils;
-import jalview.util.MessageManager;
-
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
@@ -50,6 +40,16 @@ import javax.swing.JOptionPane;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
+import jalview.api.structures.JalviewStructureDisplayI;
+import jalview.datamodel.SequenceGroup;
+import jalview.io.JalviewFileChooser;
+import jalview.jbgui.GUserDefinedColours;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
+import jalview.util.ColorUtils;
+import jalview.util.MessageManager;
+
 /**
  * This panel allows the user to assign colours to Amino Acid residue codes, and
  * save the colour scheme.
@@ -454,26 +454,40 @@ public class UserDefinedColours extends GUserDefinedColours implements
   @Override
   protected void okButton_actionPerformed(ActionEvent e)
   {
-               //Check if the user have done any selection
-               boolean showWarning = (upperCaseButtons==null) ||
-                                       ((upperCaseButtons!=null) && (upperCaseButtons.size()==0)) ||
-                                       (lowerCaseButtons==null) ||
-                                       ((lowerCaseButtons!=null) && (lowerCaseButtons.size()==0));
-               if (showWarning){
-               JOptionPane.showMessageDialog(Desktop.desktop,
-                       MessageManager.getString("label.no_colour_selection_in_scheme"),MessageManager.getString("label.no_colour_selection_warn"),
-                       JOptionPane.WARNING_MESSAGE);
-                       
-               }else{
-                   applyButton_actionPerformed(null);
-               
-                   try
-                   {
-                     frame.setClosed(true);
-                   } catch (Exception ex)
-                   {
-                   }
-               }
+    if (isNoSelectionMade())
+    {
+      JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
+              .getString("label.no_colour_selection_in_scheme"),
+              MessageManager.getString("label.no_colour_selection_warn"),
+              JOptionPane.WARNING_MESSAGE);
+    }
+    else
+    {
+      applyButton_actionPerformed(null);
+
+      try
+      {
+        frame.setClosed(true);
+      } catch (Exception ex)
+      {
+      }
+    }
+  }
+
+  /**
+   * Returns true if the user has not made any colour selection (including if
+   * 'case-sensitive' selected and no lower-case colour chosen).
+   * 
+   * @return
+   */
+  protected boolean isNoSelectionMade()
+  {
+    final boolean noUpperCaseSelected = upperCaseButtons == null
+            || upperCaseButtons.isEmpty();
+    final boolean noLowerCaseSelected = caseSensitive.isSelected()
+            && (lowerCaseButtons == null || lowerCaseButtons.isEmpty());
+    final boolean noSelectionMade = noUpperCaseSelected || noLowerCaseSelected;
+    return noSelectionMade;
   }
 
   /**
@@ -485,12 +499,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
   @Override
   protected void applyButton_actionPerformed(ActionEvent e)
   {
-       //Check if the user have done any selection
-       boolean showWarning = (upperCaseButtons==null) ||
-                               ((upperCaseButtons!=null) && (upperCaseButtons.size()==0)) ||
-                               (lowerCaseButtons==null) ||
-                               ((lowerCaseButtons!=null) && (lowerCaseButtons.size()==0));
-       if (showWarning){
+    if (isNoSelectionMade())
+    {
         JOptionPane.showMessageDialog(Desktop.desktop,
                 MessageManager.getString("label.no_colour_selection_in_scheme"),MessageManager.getString("label.no_colour_selection_warn"),
                 JOptionPane.WARNING_MESSAGE);
@@ -700,7 +710,7 @@ public class UserDefinedColours extends GUserDefinedColours implements
         name = jucs.getColour(i).getName();
         if (ResidueProperties.aa3Hash.containsKey(name))
         {
-          index = ((Integer) ResidueProperties.aa3Hash.get(name))
+          index = ResidueProperties.aa3Hash.get(name)
                   .intValue();
         }
         else