JAL-1432 updated copyright notices
[jalview.git] / src / jalview / appletgui / UserDefinedColours.java
index 4f1ac38..b245565 100755 (executable)
@@ -1,30 +1,48 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
  * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.appletgui;
 
-import java.util.*;
-
-import java.awt.*;
-import java.awt.event.*;
-
-import jalview.datamodel.*;
-import jalview.schemes.*;
+import jalview.datamodel.SequenceGroup;
+import jalview.schemes.ColourSchemeI;
+import jalview.schemes.GraduatedColor;
+import jalview.schemes.ResidueProperties;
+import jalview.schemes.UserColourScheme;
+
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.GridLayout;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.Rectangle;
+import java.awt.Scrollbar;
+import java.awt.TextField;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.AdjustmentEvent;
+import java.awt.event.AdjustmentListener;
+import java.awt.event.MouseEvent;
+import java.util.Vector;
 
 public class UserDefinedColours extends Panel implements ActionListener,
         AdjustmentListener
@@ -52,7 +70,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
   String originalLabel;
 
-  Color originalColour;
+  Object originalColour;
 
   int R = 0, G = 0, B = 0;
 
@@ -100,18 +118,26 @@ public class UserDefinedColours extends Panel implements ActionListener,
     setTargetColour(fr.colourPanel.getBackground());
     dialog.setVisible(true);
   }
+
   public UserDefinedColours(Component caller, Color col1, Frame alignframe)
   {
     this(caller, col1, alignframe, "Select Colour");
   }
+
   /**
    * Makes a dialog to choose the colour
-   * @param caller - handles events
-   * @param col1 - original colour
-   * @param alignframe - the parent Frame for the dialog
-   * @param title - window title
+   * 
+   * @param caller
+   *          - handles events
+   * @param col1
+   *          - original colour
+   * @param alignframe
+   *          - the parent Frame for the dialog
+   * @param title
+   *          - window title
    */
-  public UserDefinedColours(Component caller, Color col1, Frame alignframe, String title)
+  public UserDefinedColours(Component caller, Color col1, Frame alignframe,
+          String title)
   {
     this.caller = caller;
     originalColour = col1;
@@ -121,10 +147,36 @@ public class UserDefinedColours extends Panel implements ActionListener,
     dialog.setVisible(true);
   }
 
+  /**
+   * feature colour chooser
+   * 
+   * @param caller
+   * @param label
+   * @param colour
+   */
   public UserDefinedColours(Object caller, String label, Color colour)
   {
+    this(caller, label, colour, colour);
+  }
+
+  /**
+   * feature colour chooser when changing style to single color
+   * 
+   * @param me
+   * @param type
+   * @param graduatedColor
+   */
+  public UserDefinedColours(FeatureSettings me, String type,
+          GraduatedColor graduatedColor)
+  {
+    this(me, type, graduatedColor, graduatedColor.getMaxColor());
+  }
+
+  private UserDefinedColours(Object caller, String label, Object ocolour,
+          Color colour)
+  {
     this.caller = caller;
-    originalColour = colour;
+    originalColour = ocolour;
     originalLabel = label;
     init();
     remove(buttonPanel);
@@ -134,8 +186,8 @@ public class UserDefinedColours extends Panel implements ActionListener,
     okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));
     frame.setTitle("User Defined Colours - " + label);
     frame.setSize(420, 200);
-    }
-    
+  }
+
   void setForDialog(String title, Container alignframe)
   {
     init();
@@ -143,13 +195,14 @@ public class UserDefinedColours extends Panel implements ActionListener,
     remove(buttonPanel);
     if (alignframe instanceof Frame)
     {
-      dialog = new Dialog((Frame)alignframe, title, true);
+      dialog = new Dialog((Frame) alignframe, title, true);
     }
-    else {
-//    if (alignframe instanceof JVDialog){
-//      // not 1.1 compatible!
-//      dialog = new Dialog(((JVDialog)alignframe), title, true);
-//    } else {
+    else
+    {
+      // if (alignframe instanceof JVDialog){
+      // // not 1.1 compatible!
+      // dialog = new Dialog(((JVDialog)alignframe), title, true);
+      // } else {
       throw new Error("Unsupported owner for User Colour scheme dialog.");
     }
 
@@ -160,9 +213,10 @@ public class UserDefinedColours extends Panel implements ActionListener,
     int width = 400;
 
     dialog.setBounds(alignframe.getBounds().x
-            + (alignframe.getSize().width - width) / 2, alignframe
-            .getBounds().y
-            + (alignframe.getSize().height - height) / 2, width, height);
+            + (alignframe.getSize().width - width) / 2,
+            alignframe.getBounds().y
+                    + (alignframe.getSize().height - height) / 2, width,
+            height);
 
   }
 
@@ -340,14 +394,14 @@ public class UserDefinedColours extends Panel implements ActionListener,
   {
     final Button button = new Button();
     Color col = Color.white;
-    if (oldColourScheme!=null)
-    {
-    try
-    {
-      col = oldColourScheme.findColour(aa.charAt(0), -1);
-    } catch (Exception ex)
+    if (oldColourScheme != null)
     {
-    }
+      try
+      {
+        col = oldColourScheme.findColour(aa.charAt(0), -1, null);
+      } catch (Exception ex)
+      {
+      }
     }
     button.setBackground(col);
     oldColours.addElement(col);
@@ -406,11 +460,15 @@ public class UserDefinedColours extends Panel implements ActionListener,
       }
       else if (caller instanceof FeatureColourChooser)
       {
-        if (originalLabel.indexOf("inimum")>-1)
+        if (originalLabel.indexOf("inimum") > -1)
         {
-          ((FeatureColourChooser) caller).minColour_actionPerformed(getColor());
-        } else {
-          ((FeatureColourChooser) caller).maxColour_actionPerformed(getColor());
+          ((FeatureColourChooser) caller)
+                  .minColour_actionPerformed(getColor());
+        }
+        else
+        {
+          ((FeatureColourChooser) caller)
+                  .maxColour_actionPerformed(getColor());
         }
       }
 
@@ -467,12 +525,12 @@ public class UserDefinedColours extends Panel implements ActionListener,
         if (originalLabel.equals("Min Colour"))
         {
           ((AnnotationColourChooser) caller)
-                  .minColour_actionPerformed(originalColour);
+                  .minColour_actionPerformed((Color) originalColour);
         }
         else
         {
           ((AnnotationColourChooser) caller)
-                  .maxColour_actionPerformed(originalColour);
+                  .maxColour_actionPerformed((Color) originalColour);
         }
       }
       else if (caller instanceof FeatureRenderer)
@@ -483,11 +541,15 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
       else if (caller instanceof FeatureColourChooser)
       {
-        if (originalLabel.indexOf("inimum")>-1)
+        if (originalLabel.indexOf("inimum") > -1)
+        {
+          ((FeatureColourChooser) caller)
+                  .minColour_actionPerformed((Color) originalColour);
+        }
+        else
         {
-          ((FeatureColourChooser) caller).minColour_actionPerformed(originalColour);
-        } else {
-          ((FeatureColourChooser) caller).maxColour_actionPerformed(originalColour);
+          ((FeatureColourChooser) caller)
+                  .maxColour_actionPerformed((Color) originalColour);
         }
       }
       if (dialog != null)