popup menu toggles between graduated colour and single colour feature style
authorjprocter <Jim Procter>
Thu, 29 Apr 2010 08:51:30 +0000 (08:51 +0000)
committerjprocter <Jim Procter>
Thu, 29 Apr 2010 08:51:30 +0000 (08:51 +0000)
src/jalview/appletgui/FeatureSettings.java
src/jalview/appletgui/UserDefinedColours.java

index 7f59de5..d20d864 100755 (executable)
@@ -161,6 +161,7 @@ public class FeatureSettings extends Panel implements ItemListener,
           int x, int y)
   {
     final String type = check.type;
+    final Object typeCol = fr.getFeatureStyle(type);
     java.awt.PopupMenu men = new PopupMenu("Settings for " + type);
     java.awt.MenuItem scr = new MenuItem("Sort by Score");
     men.add(scr);
@@ -206,16 +207,26 @@ public class FeatureSettings extends Panel implements ItemListener,
       {
         // graduated colourschemes for those where minmax exists for the
         // positional features
-        MenuItem mxcol = new MenuItem("Graduated Colour");
+        MenuItem mxcol = new MenuItem(
+                (typeCol instanceof Color) ? "Graduated Colour"
+                        : "Single Colour");
         men.add(mxcol);
         mxcol.addActionListener(new ActionListener()
         {
 
           public void actionPerformed(ActionEvent e)
           {
-            new FeatureColourChooser(me, type);
-            // write back the current colour object to update the table
-            check.updateColor(fr.getFeatureStyle(type));
+            if (typeCol instanceof Color)
+            {
+              new FeatureColourChooser(me, type);
+              // write back the current colour object to update the table
+              check.updateColor(fr.getFeatureStyle(type));
+            }
+            else
+            {
+              new UserDefinedColours(me, check.type,
+                      ((GraduatedColor) typeCol));
+            }
           }
 
         });
@@ -555,12 +566,23 @@ public class FeatureSettings extends Panel implements ItemListener,
     }
   }
 
-  public void setUserColour(String feature, Color col)
+  public void setUserColour(String feature, Object originalColour)
   {
-    fr.setColour(feature, col);
+    if (originalColour instanceof Color
+            || originalColour instanceof GraduatedColor)
+    {
+      fr.setColour(feature, originalColour);
+    }
+    else
+    {
+      throw new Error(
+              "Implementation error: Unsupported feature colour object.");
+    }
     refreshTable();
   }
-  public void refreshTable() {
+
+  public void refreshTable()
+  {
     featurePanel.removeAll();
     resetTable(false);
     ap.paintAlignment(true);
@@ -581,8 +603,7 @@ public class FeatureSettings extends Panel implements ItemListener,
     {
       this.popupSort(check, fr.minmax, evt.getX(), evt.getY());
     }
-    if (fr.featureLinks != null
-            && fr.featureLinks.containsKey(check.type))
+    if (fr.featureLinks != null && fr.featureLinks.containsKey(check.type))
     {
       if (evt.getX() > check.stringWidth + 20)
       {
@@ -604,7 +625,9 @@ public class FeatureSettings extends Panel implements ItemListener,
       if (fcol instanceof Color)
       {
         new UserDefinedColours(this, check.type, (Color) fcol);
-      } else {
+      }
+      else
+      {
         new FeatureColourChooser(this, check.type);
         // write back the current colour object to update the table
         check.updateColor(fr.getFeatureStyle(check.type));
@@ -626,6 +649,7 @@ public class FeatureSettings extends Panel implements ItemListener,
   class MyCheckbox extends Checkbox
   {
     public String type;
+
     public int stringWidth;
 
     boolean hasLink;
@@ -657,14 +681,19 @@ public class FeatureSettings extends Panel implements ItemListener,
       else
       {
         String vlabel = type;
-        if (gcol.getThreshType()!=AnnotationColourGradient.NO_THRESHOLD)
+        if (gcol.getThreshType() != AnnotationColourGradient.NO_THRESHOLD)
         {
-          vlabel += " "+((gcol.getThreshType()==AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)" : "(<)");
+          vlabel += " "
+                  + ((gcol.getThreshType() == AnnotationColourGradient.ABOVE_THRESHOLD) ? "(>)"
+                          : "(<)");
         }
-        if (gcol.isColourByLabel()) {
+        if (gcol.isColourByLabel())
+        {
           setBackground(Color.white);
           vlabel += " (by Label)";
-        } else {
+        }
+        else
+        {
           setBackground(gcol.getMinColor());
         }
         this.setLabel(vlabel);
@@ -684,7 +713,7 @@ public class FeatureSettings extends Panel implements ItemListener,
     public MyCheckbox(String type, boolean selected, boolean b,
             Object featureStyle)
     {
-      this(type,selected,b);
+      this(type, selected, b);
       updateColor(featureStyle);
     }
 
@@ -696,24 +725,25 @@ public class FeatureSettings extends Panel implements ItemListener,
         if (gcol.isColourByLabel())
         {
           g.setColor(Color.white);
-          g.fillRect(d.width/2, 0,d.width/2, d.height);
-          /*g.setColor(Color.black); 
-          Font f=g.getFont().deriveFont(9);
-          g.setFont(f);
-
-          // g.setFont(g.getFont().deriveFont(
-          // AffineTransform.getScaleInstance(
-          // width/g.getFontMetrics().stringWidth("Label"),
-          // height/g.getFontMetrics().getHeight())));
-          g.drawString("Label", width/2, 0); */
+          g.fillRect(d.width / 2, 0, d.width / 2, d.height);
+          /*
+           * g.setColor(Color.black); Font f=g.getFont().deriveFont(9);
+           * g.setFont(f);
+           * 
+           * // g.setFont(g.getFont().deriveFont( //
+           * AffineTransform.getScaleInstance( //
+           * width/g.getFontMetrics().stringWidth("Label"), //
+           * height/g.getFontMetrics().getHeight()))); g.drawString("Label",
+           * width/2, 0);
+           */
 
         }
         else
         {
           Color maxCol = gcol.getMaxColor();
           g.setColor(maxCol);
-          g.fillRect(d.width/2, 0,d.width/2, d.height);
-          
+          g.fillRect(d.width / 2, 0, d.width / 2, d.height);
+
         }
       }
 
index 4f1ac38..23a290f 100755 (executable)
@@ -52,7 +52,7 @@ public class UserDefinedColours extends Panel implements ActionListener,
 
   String originalLabel;
 
-  Color originalColour;
+  Object originalColour;
 
   int R = 0, G = 0, B = 0;
 
@@ -100,18 +100,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 +129,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 +168,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 +177,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.");
     }
 
@@ -340,14 +375,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);
+      } catch (Exception ex)
+      {
+      }
     }
     button.setBackground(col);
     oldColours.addElement(col);
@@ -406,11 +441,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 +506,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 +522,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)