JAL-1420
authordarolmar <darolmar@gmail.com>
Fri, 10 Oct 2014 06:35:44 +0000 (08:35 +0200)
committerdarolmar <darolmar@gmail.com>
Fri, 10 Oct 2014 06:35:44 +0000 (08:35 +0200)
resources/lang/Messages.properties
src/jalview/gui/UserDefinedColours.java

index 47755f3..0a7a0d7 100644 (file)
@@ -1130,4 +1130,6 @@ label.show_group_logo = Show Group Logo
 label.normalise_group_logo = Normalise Group Logo\r
 label.show_histogram = Show Histogram\r
 label.show_logo = Show Logo\r
-label.normalise_logo = Normalise Logo
\ No newline at end of file
+label.normalise_logo = Normalise Logo\r
+label.no_colour_selection_in_scheme = Please, make a colour selection before to apply colour scheme\r
+label.no_colour_selection_warn = Error saving colour scheme
\ No newline at end of file
index 7bf2e6c..37824fe 100755 (executable)
@@ -454,14 +454,26 @@ public class UserDefinedColours extends GUserDefinedColours implements
   @Override
   protected void okButton_actionPerformed(ActionEvent e)
   {
-    applyButton_actionPerformed(null);
-
-    try
-    {
-      frame.setClosed(true);
-    } catch (Exception ex)
-    {
-    }
+               //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)
+                   {
+                   }
+               }
   }
 
   /**
@@ -473,7 +485,18 @@ public class UserDefinedColours extends GUserDefinedColours implements
   @Override
   protected void applyButton_actionPerformed(ActionEvent e)
   {
-    UserColourScheme ucs = getSchemeFromButtons();
+       //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);
+               
+       }
+       UserColourScheme ucs = getSchemeFromButtons();
     ucs.setName(schemeName.getText());
 
     if (seqGroup != null)
@@ -496,10 +519,18 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     Color[] newColours = new Color[24];
 
-    for (int i = 0; i < 24; i++)
-    {
-      JButton button = upperCaseButtons.get(i);
-      newColours[i] = button.getBackground();
+    int length = upperCaseButtons.size();
+    if (length<24){
+       int i = 0;
+       for (JButton btn:upperCaseButtons){
+               newColours[i] = btn.getBackground();
+               i++;
+       }
+    }else{
+       for (int i = 0; i < 24; i++){
+               JButton button = (JButton) upperCaseButtons.get(i);
+               newColours[i] = button.getBackground();
+       }
     }
 
     UserColourScheme ucs = new UserColourScheme(newColours);
@@ -507,10 +538,18 @@ public class UserDefinedColours extends GUserDefinedColours implements
     if (caseSensitive.isSelected())
     {
       newColours = new Color[23];
-      for (int i = 0; i < 23; i++)
-      {
-        JButton button = lowerCaseButtons.get(i);
-        newColours[i] = button.getBackground();
+      length = lowerCaseButtons.size();
+      if (length<23){
+         int i = 0;
+         for (JButton btn:lowerCaseButtons){
+                 newColours[i] = btn.getBackground();
+                 i++;
+         }
+      }else{
+         for (int i = 0; i < 23; i++){
+                 JButton button = (JButton) lowerCaseButtons.get(i);
+                 newColours[i] = button.getBackground();
+         }
       }
       ucs.setLowerCaseColours(newColours);
     }