edit annotation name/description
[jalview.git] / src / jalview / appletgui / UserDefinedColours.java
index b092601..b9c0950 100755 (executable)
@@ -1,6 +1,6 @@
 /*\r
  * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
  *\r
  * This program is free software; you can redistribute it and/or\r
  * modify it under the terms of the GNU General Public License\r
@@ -39,6 +39,10 @@ public class UserDefinedColours
   Frame frame;\r
   MCview.AppletPDBCanvas pdbcanvas;\r
 \r
+  Component caller;\r
+  String originalLabel;\r
+  Color originalColour;\r
+\r
   int R = 0, G = 0, B = 0;\r
 \r
   public ColourSchemeI loadDefaultColours()\r
@@ -70,6 +74,23 @@ public class UserDefinedColours
     init();\r
   }\r
 \r
+  public UserDefinedColours(Component caller,\r
+                            String label,\r
+                            Color colour)\r
+  {\r
+    this.caller = caller;\r
+    originalColour = colour;\r
+    originalLabel = label;\r
+    init();\r
+    remove(buttonPanel);\r
+\r
+    setTargetColour(colour);\r
+\r
+    okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));\r
+    frame.setTitle("User Defined Colours - "+label);\r
+    frame.setSize(420, 200);\r
+  }\r
+\r
   public void actionPerformed(ActionEvent evt)\r
   {\r
     if(evt.getSource()==okButton)\r
@@ -200,10 +221,8 @@ public class UserDefinedColours
     }\r
   }\r
 \r
-  public void colourButtonPressed(MouseEvent e)\r
+  void setTargetColour(Color col)\r
   {\r
-    selectedButton = (Button) e.getSource();\r
-    Color col = selectedButton.getBackground();\r
     R = col.getRed();\r
     G = col.getGreen();\r
     B = col.getBlue();\r
@@ -213,10 +232,15 @@ public class UserDefinedColours
     rText.setText(R + "");\r
     gText.setText(G + "");\r
     bText.setText(B + "");\r
-\r
     colourChanged();\r
   }\r
 \r
+  public void colourButtonPressed(MouseEvent e)\r
+  {\r
+    selectedButton = (Button) e.getSource();\r
+    setTargetColour(selectedButton.getBackground());\r
+  }\r
+\r
   void makeButton(String label, String aa)\r
   {\r
     final Button button = new Button();\r
@@ -224,7 +248,7 @@ public class UserDefinedColours
 \r
     try\r
     {\r
-      col = oldColourScheme.findColour(aa, -1);\r
+      col = oldColourScheme.findColour(aa.charAt(0), -1);\r
     }\r
     catch (Exception ex)\r
     {}\r
@@ -253,6 +277,24 @@ public class UserDefinedColours
 \r
   protected void applyButton_actionPerformed()\r
   {\r
+    if (caller != null)\r
+    {\r
+      if(caller instanceof FeatureSettings)\r
+        ((FeatureSettings)caller).setUserColour\r
+            (originalLabel, new Color(R,G,B));\r
+      else if(caller instanceof AnnotationColourChooser)\r
+      {\r
+        if (originalLabel.equals("Min Colour"))\r
+          ( (AnnotationColourChooser) caller).minColour_actionPerformed\r
+              (new Color(R, G, B));\r
+        else\r
+          ( (AnnotationColourChooser) caller).maxColour_actionPerformed\r
+              (new Color(R, G, B));\r
+      }\r
+      return;\r
+    }\r
+\r
+\r
     Color[] newColours = new Color[24];\r
     for (int i = 0; i < 24; i++)\r
     {\r
@@ -287,6 +329,23 @@ public class UserDefinedColours
 \r
   protected void cancelButton_actionPerformed()\r
   {\r
+    if (caller != null)\r
+    {\r
+      if(caller instanceof FeatureSettings)\r
+        ((FeatureSettings)caller).setUserColour\r
+            (originalLabel, originalColour);\r
+      else if (caller instanceof AnnotationColourChooser)\r
+      {\r
+        if (originalLabel.equals("Min Colour"))\r
+          ( (AnnotationColourChooser) caller).minColour_actionPerformed\r
+              (originalColour);\r
+        else\r
+          ( (AnnotationColourChooser) caller).maxColour_actionPerformed\r
+              (originalColour);\r
+      }\r
+      frame.setVisible(false);\r
+      return;\r
+    }\r
 \r
     Color[] newColours = new Color[24];\r
     for (int i = 0; i < 24; i++)\r
@@ -320,7 +379,7 @@ public class UserDefinedColours
 \r
   protected Panel buttonPanel = new Panel();\r
   protected GridLayout gridLayout = new GridLayout();\r
-  Panel jPanel2 = new Panel();\r
+  Panel okcancelPanel = new Panel();\r
   protected Button okButton = new Button();\r
   protected Button applyButton = new Button();\r
   protected Button cancelButton = new Button();\r
@@ -350,7 +409,7 @@ public class UserDefinedColours
       cancelButton.setLabel("Cancel");\r
       cancelButton.addActionListener(this);\r
       this.setBackground(new Color(212, 208, 223));\r
-      jPanel2.setBounds(new Rectangle(0, 265, 400, 35));\r
+      okcancelPanel.setBounds(new Rectangle(0, 265, 400, 35));\r
       buttonPanel.setBounds(new Rectangle(0, 123, 400, 142));\r
       rScroller.setMaximum(256);\r
       rScroller.setMinimum(0);\r
@@ -396,10 +455,10 @@ public class UserDefinedColours
   bText.addActionListener(this);\r
   target.setBackground(Color.black);\r
       target.setBounds(new Rectangle(229, 26, 134, 79));\r
-      this.add(jPanel2, null);\r
-      jPanel2.add(okButton, null);\r
-      jPanel2.add(applyButton, null);\r
-      jPanel2.add(cancelButton, null);\r
+      this.add(okcancelPanel, null);\r
+      okcancelPanel.add(okButton, null);\r
+      okcancelPanel.add(applyButton, null);\r
+      okcancelPanel.add(cancelButton, null);\r
       this.add(buttonPanel, null);\r
   this.add(target, null);\r
   this.add(gScroller);\r