Colour above or below threshold
authoramwaterhouse <Andrew Waterhouse>
Wed, 8 Feb 2006 15:22:23 +0000 (15:22 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 8 Feb 2006 15:22:23 +0000 (15:22 +0000)
src/jalview/gui/AnnotationColourChooser.java
src/jalview/schemes/AnnotationColourGradient.java

index c3e30fb..06040a6 100755 (executable)
@@ -69,6 +69,10 @@ public class AnnotationColourChooser
         annotations.addItem(av.alignment.getAlignmentAnnotation()[i].label);\r
     }\r
 \r
+    threshold.addItem("No Threshold");\r
+    threshold.addItem("Above Threshold");\r
+    threshold.addItem("Below Threshold");\r
+\r
   }\r
 \r
   public AnnotationColourChooser()\r
@@ -107,19 +111,6 @@ public class AnnotationColourChooser
         maxColour_actionPerformed(e);\r
       }\r
     });\r
-    thresholdCheck.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));\r
-    thresholdCheck.setOpaque(false);\r
-    thresholdCheck.setHorizontalTextPosition(SwingConstants.LEADING);\r
-    thresholdCheck.setSelectedIcon(null);\r
-    thresholdCheck.setText("Above Threshold");\r
-    thresholdCheck.setBounds(new Rectangle(329, 6, 126, 23));\r
-    thresholdCheck.addActionListener(new ActionListener()\r
-    {\r
-      public void actionPerformed(ActionEvent e)\r
-      {\r
-        thresholdCheck_actionPerformed(e);\r
-      }\r
-    });\r
     ok.setOpaque(false);\r
     ok.setText("OK");\r
     ok.addActionListener(new ActionListener()\r
@@ -150,12 +141,20 @@ public class AnnotationColourChooser
     });\r
     jPanel1.setBackground(Color.white);\r
     jPanel2.setBackground(Color.white);\r
+    threshold.setBounds(new Rectangle(328, 6, 125, 22));\r
+    threshold.addActionListener(new ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        threshold_actionPerformed(e);\r
+      }\r
+    });\r
     jPanel1.add(ok);\r
     jPanel1.add(cancel);\r
     jPanel2.add(annotations);\r
     jPanel2.add(minColour);\r
     jPanel2.add(maxColour);\r
-    jPanel2.add(thresholdCheck);\r
+    jPanel2.add(threshold);\r
     this.add(jPanel1, java.awt.BorderLayout.SOUTH);\r
     this.add(jPanel2, java.awt.BorderLayout.CENTER);\r
   }\r
@@ -163,13 +162,12 @@ public class AnnotationColourChooser
   JComboBox annotations = new JComboBox();\r
   JButton minColour = new JButton();\r
   JButton maxColour = new JButton();\r
-  JCheckBox thresholdCheck = new JCheckBox();\r
   JButton ok = new JButton();\r
   JButton cancel = new JButton();\r
   JPanel jPanel1 = new JPanel();\r
   JPanel jPanel2 = new JPanel();\r
   BorderLayout borderLayout1 = new BorderLayout();\r
-\r
+  JComboBox threshold = new JComboBox();\r
 \r
   public void minColour_actionPerformed(ActionEvent e)\r
   {\r
@@ -195,6 +193,10 @@ public class AnnotationColourChooser
 \r
   void changeColour()\r
   {\r
+    // Check if combobox is still adjusting\r
+    if(threshold.getSelectedIndex()==-1)\r
+          return;\r
+\r
     // We removed the non-graph annotations when filling the combobox\r
     // so allow for them again here\r
     int nograph = 0, graph = -1;\r
@@ -212,16 +214,26 @@ public class AnnotationColourChooser
     jalview.datamodel.AlignmentAnnotation aa\r
         = av.alignment.getAlignmentAnnotation()[graph+nograph];\r
 \r
-    AnnotationColourGradient acg = new AnnotationColourGradient(aa,\r
-     minColour.getBackground(),\r
-     maxColour.getBackground(),\r
-     thresholdCheck.isSelected());\r
 \r
-   if(thresholdCheck.isSelected() && aa.graphLines==null)\r
+    int aboveThreshold = -1;\r
+    if(threshold.getSelectedItem().equals("Above Threshold"))\r
+      aboveThreshold = AnnotationColourGradient.ABOVE_THRESHOLD;\r
+    else if(threshold.getSelectedItem().equals("Below Threshold"))\r
+      aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;\r
+\r
+    if(aboveThreshold!=AnnotationColourGradient.NO_THRESHOLD && aa.graphLines==null)\r
    {\r
      aa.addGraphLine(new jalview.datamodel.GraphLine((aa.graphMax-aa.graphMin)/2f, "Threshold", Color.black));\r
    }\r
 \r
+    AnnotationColourGradient acg = new AnnotationColourGradient(aa,\r
+     minColour.getBackground(),\r
+     maxColour.getBackground(),\r
+     aboveThreshold );\r
+\r
+\r
+\r
+\r
    av.setGlobalColourScheme(acg);\r
    ap.repaint();\r
 \r
@@ -253,4 +265,9 @@ public class AnnotationColourChooser
     changeColour();\r
   }\r
 \r
+  public void threshold_actionPerformed(ActionEvent e)\r
+  {\r
+    changeColour();\r
+  }\r
+\r
 }\r
index bc44559..5825612 100755 (executable)
@@ -24,8 +24,14 @@ import jalview.datamodel.*;
 \r
 public class AnnotationColourGradient extends ResidueColourScheme\r
 {\r
+    public static int NO_THRESHOLD = -1;\r
+    public static int BELOW_THRESHOLD = 0;\r
+    public static int ABOVE_THRESHOLD = 1;\r
+\r
     AlignmentAnnotation annotation;\r
-    boolean aboveAnnotationThreshold = false;\r
+    int aboveAnnotationThreshold = -1;\r
+\r
+    GraphLine annotationThreshold;\r
 \r
     float r1, g1, b1, rr, gg, bb, dr, dg, db;\r
     float range;\r
@@ -34,12 +40,15 @@ public class AnnotationColourGradient extends ResidueColourScheme
      * Creates a new AnnotationColourGradient object.\r
      */\r
     public AnnotationColourGradient(AlignmentAnnotation annotation,\r
-        Color minColour, Color maxColour, boolean aboveThreshold)\r
+        Color minColour, Color maxColour, int aboveThreshold)\r
     {\r
       this.annotation = annotation;\r
 \r
       aboveAnnotationThreshold = aboveThreshold;\r
 \r
+      if(aboveThreshold!=NO_THRESHOLD && annotation.graphLines!=null)\r
+        annotationThreshold = annotation.getGraphLine(0);\r
+\r
       r1 = minColour.getRed();\r
       g1 = minColour.getGreen();\r
       b1 = minColour.getBlue();\r
@@ -91,8 +100,9 @@ public class AnnotationColourGradient extends ResidueColourScheme
             currentColour = Color.white;\r
           else\r
           {\r
-            if(!aboveAnnotationThreshold || (annotation.graphLines!=null\r
-               && annotation.annotations[j].value>=annotation.getGraphLine(0).value))\r
+            if(  aboveAnnotationThreshold==NO_THRESHOLD\r
+               || (annotationThreshold!=null && aboveAnnotationThreshold==ABOVE_THRESHOLD && annotation.annotations[j].value>=annotationThreshold.value)\r
+               || (annotationThreshold!=null && aboveAnnotationThreshold==BELOW_THRESHOLD && annotation.annotations[j].value<=annotationThreshold.value))\r
             {\r
                 dr = rr *\r
                      ((annotation.annotations[j].value-annotation.graphMin) / range )\r