Formatting
[jalview.git] / src / jalview / appletgui / UserDefinedColours.java
index 6544993..af08b75 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) 2007 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
@@ -38,9 +38,10 @@ public class UserDefinedColours
   ColourSchemeI oldColourScheme;\r
   Frame frame;\r
   MCview.AppletPDBCanvas pdbcanvas;\r
-  FeatureSettings featureSettings;\r
-  String feature;\r
-  Color originalFeatureCol;\r
+\r
+  Component caller;\r
+  String originalLabel;\r
+  Color originalColour;\r
 \r
   int R = 0, G = 0, B = 0;\r
 \r
@@ -73,47 +74,66 @@ public class UserDefinedColours
     init();\r
   }\r
 \r
-  public UserDefinedColours(FeatureSettings featureSettings,\r
-                            String feature,\r
-                            Color col)\r
+  public UserDefinedColours(Component caller,\r
+                            String label,\r
+                            Color colour)\r
   {\r
-    this.featureSettings = featureSettings;\r
-    this.feature = feature;\r
+    this.caller = caller;\r
+    originalColour = colour;\r
+    originalLabel = label;\r
     init();\r
     remove(buttonPanel);\r
-    originalFeatureCol = col;\r
-    setTargetColour(col);\r
+\r
+    setTargetColour(colour);\r
 \r
     okcancelPanel.setBounds(new Rectangle(0, 113, 400, 35));\r
-    frame.setTitle("User Defined Colours - "+feature);\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
-     okButton_actionPerformed();\r
-   else if(evt.getSource()==applyButton)\r
+    if (evt.getSource() == okButton)\r
+    {\r
+      okButton_actionPerformed();\r
+    }\r
+    else if (evt.getSource() == applyButton)\r
+    {\r
       applyButton_actionPerformed();\r
-   else if(evt.getSource()==cancelButton)\r
-     cancelButton_actionPerformed();\r
-   else if(evt.getSource()==rText)\r
-     rText_actionPerformed();\r
-   else if (evt.getSource() == gText)\r
-     gText_actionPerformed();\r
-   else if (evt.getSource() == bText)\r
-     bText_actionPerformed();\r
-}\r
+    }\r
+    else if (evt.getSource() == cancelButton)\r
+    {\r
+      cancelButton_actionPerformed();\r
+    }\r
+    else if (evt.getSource() == rText)\r
+    {\r
+      rText_actionPerformed();\r
+    }\r
+    else if (evt.getSource() == gText)\r
+    {\r
+      gText_actionPerformed();\r
+    }\r
+    else if (evt.getSource() == bText)\r
+    {\r
+      bText_actionPerformed();\r
+    }\r
+  }\r
 \r
   public void adjustmentValueChanged(AdjustmentEvent evt)\r
   {\r
-    if(evt.getSource()==rScroller)\r
-    rScroller_adjustmentValueChanged();\r
-  else if(evt.getSource()==gScroller)\r
-    gScroller_adjustmentValueChanged();\r
-  else if(evt.getSource()==bScroller)\r
-    bScroller_adjustmentValueChanged();\r
-}\r
+    if (evt.getSource() == rScroller)\r
+    {\r
+      rScroller_adjustmentValueChanged();\r
+    }\r
+    else if (evt.getSource() == gScroller)\r
+    {\r
+      gScroller_adjustmentValueChanged();\r
+    }\r
+    else if (evt.getSource() == bScroller)\r
+    {\r
+      bScroller_adjustmentValueChanged();\r
+    }\r
+  }\r
 \r
   void init()\r
   {\r
@@ -147,6 +167,7 @@ public class UserDefinedColours
 \r
     validate();\r
   }\r
+\r
   protected void rText_actionPerformed()\r
   {\r
     try\r
@@ -246,7 +267,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
@@ -275,9 +296,26 @@ public class UserDefinedColours
 \r
   protected void applyButton_actionPerformed()\r
   {\r
-    if (featureSettings != null)\r
+    if (caller != null)\r
     {\r
-      featureSettings.setUserColour(feature, new Color(R,G,B));\r
+      if (caller instanceof FeatureSettings)\r
+      {\r
+        ( (FeatureSettings) caller).setUserColour\r
+            (originalLabel, new Color(R, G, B));\r
+      }\r
+      else if (caller instanceof AnnotationColourChooser)\r
+      {\r
+        if (originalLabel.equals("Min Colour"))\r
+        {\r
+          ( (AnnotationColourChooser) caller).minColour_actionPerformed\r
+              (new Color(R, G, B));\r
+        }\r
+        else\r
+        {\r
+          ( (AnnotationColourChooser) caller).maxColour_actionPerformed\r
+              (new Color(R, G, B));\r
+        }\r
+      }\r
       return;\r
     }\r
 \r
@@ -289,10 +327,12 @@ public class UserDefinedColours
     }\r
 \r
     UserColourScheme ucs = new UserColourScheme(newColours);\r
-    if(ap!=null)\r
+    if (ap != null)\r
+    {\r
       ucs.setThreshold(0, ap.av.getIgnoreGapsConsensus());\r
+    }\r
 \r
-    if(ap!=null)\r
+    if (ap != null)\r
     {\r
       if (seqGroup != null)\r
       {\r
@@ -305,19 +345,35 @@ public class UserDefinedColours
       ap.seqPanel.seqCanvas.img = null;\r
       ap.repaint();\r
     }\r
-    else if(pdbcanvas!=null)\r
+    else if (pdbcanvas != null)\r
     {\r
       pdbcanvas.pdb.setColours(ucs);\r
       pdbcanvas.updateSeqColours();\r
     }\r
   }\r
 \r
-\r
   protected void cancelButton_actionPerformed()\r
   {\r
-    if(featureSettings!=null)\r
+    if (caller != null)\r
     {\r
-      featureSettings.setUserColour(feature, originalFeatureCol);\r
+      if (caller instanceof FeatureSettings)\r
+      {\r
+        ( (FeatureSettings) caller).setUserColour\r
+            (originalLabel, originalColour);\r
+      }\r
+      else if (caller instanceof AnnotationColourChooser)\r
+      {\r
+        if (originalLabel.equals("Min Colour"))\r
+        {\r
+          ( (AnnotationColourChooser) caller).minColour_actionPerformed\r
+              (originalColour);\r
+        }\r
+        else\r
+        {\r
+          ( (AnnotationColourChooser) caller).maxColour_actionPerformed\r
+              (originalColour);\r
+        }\r
+      }\r
       frame.setVisible(false);\r
       return;\r
     }\r
@@ -331,7 +387,7 @@ public class UserDefinedColours
 \r
     UserColourScheme ucs = new UserColourScheme(newColours);\r
 \r
-   if(ap!=null)\r
+    if (ap != null)\r
     {\r
       if (seqGroup != null)\r
       {\r
@@ -343,7 +399,7 @@ public class UserDefinedColours
       }\r
       ap.repaint();\r
     }\r
-    else if(pdbcanvas!=null)\r
+    else if (pdbcanvas != null)\r
     {\r
       pdbcanvas.pdb.setColours(ucs);\r
     }\r
@@ -351,7 +407,6 @@ public class UserDefinedColours
     frame.setVisible(false);\r
   }\r
 \r
-\r
   protected Panel buttonPanel = new Panel();\r
   protected GridLayout gridLayout = new GridLayout();\r
   Panel okcancelPanel = new Panel();\r
@@ -369,82 +424,84 @@ public class UserDefinedColours
   protected TextField bText = new TextField();\r
   protected Panel target = new Panel();\r
 \r
-  private void jbInit() throws Exception {\r
-      this.setLayout(null);\r
-      buttonPanel.setLayout(gridLayout);\r
-      gridLayout.setColumns(6);\r
-      gridLayout.setRows(4);\r
-      okButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
-      okButton.setLabel("OK");\r
-      okButton.addActionListener(this);\r
-      applyButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
-      applyButton.setLabel("Apply");\r
-      applyButton.addActionListener(this);\r
-      cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
-      cancelButton.setLabel("Cancel");\r
-      cancelButton.addActionListener(this);\r
-      this.setBackground(new Color(212, 208, 223));\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
-      rScroller.setOrientation(0);\r
-      rScroller.setUnitIncrement(1);\r
-  rScroller.setVisibleAmount(1);\r
-  rScroller.setBounds(new Rectangle(36, 27, 119, 19));\r
-  rScroller.addAdjustmentListener(this);\r
-  label1.setAlignment(Label.RIGHT);\r
-  label1.setText("R");\r
-  label1.setBounds(new Rectangle(19, 30, 16, 15));\r
-  rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
-  rText.setText("0        ");\r
-  rText.setBounds(new Rectangle(156, 27, 53, 19));\r
-  rText.addActionListener(this);\r
-  label4.setAlignment(Label.RIGHT);\r
-  label4.setText("G");\r
-  label4.setBounds(new Rectangle(15, 56, 20, 15));\r
-  gScroller.setMaximum(256);\r
-      gScroller.setMinimum(0);\r
-      gScroller.setOrientation(0);\r
-      gScroller.setUnitIncrement(1);\r
-  gScroller.setVisibleAmount(1);\r
-  gScroller.setBounds(new Rectangle(35, 52, 120, 20));\r
-  gScroller.addAdjustmentListener(this);\r
-  gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
-  gText.setText("0        ");\r
-  gText.setBounds(new Rectangle(156, 52, 53, 20));\r
-  gText.addActionListener(this);\r
-  label5.setAlignment(Label.RIGHT);\r
-  label5.setText("B");\r
-  label5.setBounds(new Rectangle(14, 82, 20, 15));\r
-  bScroller.setMaximum(256);\r
-      bScroller.setMinimum(0);\r
-      bScroller.setOrientation(0);\r
-      bScroller.setUnitIncrement(1);\r
-  bScroller.setVisibleAmount(1);\r
-  bScroller.setBounds(new Rectangle(35, 78, 120, 20));\r
-  bScroller.addAdjustmentListener(this);\r
-  bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
-  bText.setText("0        ");\r
-  bText.setBounds(new Rectangle(157, 78, 52, 20));\r
-  bText.addActionListener(this);\r
-  target.setBackground(Color.black);\r
-      target.setBounds(new Rectangle(229, 26, 134, 79));\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
-  this.add(rScroller);\r
-  this.add(bScroller);\r
-  this.add(label5);\r
-  this.add(label4);\r
-  this.add(label1);\r
-  this.add(gText);\r
-  this.add(rText);\r
-  this.add(bText);\r
-}\r
+  private void jbInit()\r
+      throws Exception\r
+  {\r
+    this.setLayout(null);\r
+    buttonPanel.setLayout(gridLayout);\r
+    gridLayout.setColumns(6);\r
+    gridLayout.setRows(4);\r
+    okButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+    okButton.setLabel("OK");\r
+    okButton.addActionListener(this);\r
+    applyButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+    applyButton.setLabel("Apply");\r
+    applyButton.addActionListener(this);\r
+    cancelButton.setFont(new java.awt.Font("Verdana", 0, 11));\r
+    cancelButton.setLabel("Cancel");\r
+    cancelButton.addActionListener(this);\r
+    this.setBackground(new Color(212, 208, 223));\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
+    rScroller.setOrientation(0);\r
+    rScroller.setUnitIncrement(1);\r
+    rScroller.setVisibleAmount(1);\r
+    rScroller.setBounds(new Rectangle(36, 27, 119, 19));\r
+    rScroller.addAdjustmentListener(this);\r
+    label1.setAlignment(Label.RIGHT);\r
+    label1.setText("R");\r
+    label1.setBounds(new Rectangle(19, 30, 16, 15));\r
+    rText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+    rText.setText("0        ");\r
+    rText.setBounds(new Rectangle(156, 27, 53, 19));\r
+    rText.addActionListener(this);\r
+    label4.setAlignment(Label.RIGHT);\r
+    label4.setText("G");\r
+    label4.setBounds(new Rectangle(15, 56, 20, 15));\r
+    gScroller.setMaximum(256);\r
+    gScroller.setMinimum(0);\r
+    gScroller.setOrientation(0);\r
+    gScroller.setUnitIncrement(1);\r
+    gScroller.setVisibleAmount(1);\r
+    gScroller.setBounds(new Rectangle(35, 52, 120, 20));\r
+    gScroller.addAdjustmentListener(this);\r
+    gText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+    gText.setText("0        ");\r
+    gText.setBounds(new Rectangle(156, 52, 53, 20));\r
+    gText.addActionListener(this);\r
+    label5.setAlignment(Label.RIGHT);\r
+    label5.setText("B");\r
+    label5.setBounds(new Rectangle(14, 82, 20, 15));\r
+    bScroller.setMaximum(256);\r
+    bScroller.setMinimum(0);\r
+    bScroller.setOrientation(0);\r
+    bScroller.setUnitIncrement(1);\r
+    bScroller.setVisibleAmount(1);\r
+    bScroller.setBounds(new Rectangle(35, 78, 120, 20));\r
+    bScroller.addAdjustmentListener(this);\r
+    bText.setFont(new java.awt.Font("Dialog", Font.PLAIN, 10));\r
+    bText.setText("0        ");\r
+    bText.setBounds(new Rectangle(157, 78, 52, 20));\r
+    bText.addActionListener(this);\r
+    target.setBackground(Color.black);\r
+    target.setBounds(new Rectangle(229, 26, 134, 79));\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
+    this.add(rScroller);\r
+    this.add(bScroller);\r
+    this.add(label5);\r
+    this.add(label4);\r
+    this.add(label1);\r
+    this.add(gText);\r
+    this.add(rText);\r
+    this.add(bText);\r
+  }\r
 \r
 }\r