Keeps original threshold value
authoramwaterhouse <Andrew Waterhouse>
Fri, 24 Feb 2006 11:45:36 +0000 (11:45 +0000)
committeramwaterhouse <Andrew Waterhouse>
Fri, 24 Feb 2006 11:45:36 +0000 (11:45 +0000)
src/jalview/gui/AnnotationColourChooser.java

index 49e835d..d49a4b6 100755 (executable)
@@ -36,6 +36,7 @@ public class AnnotationColourChooser
   ColourSchemeI oldcs;\r
   Hashtable oldgroupColours;\r
   jalview.datamodel.AlignmentAnnotation currentAnnotation;\r
+  boolean adjusting = false;\r
 \r
   public AnnotationColourChooser(AlignViewport av, AlignmentPanel ap)\r
   {\r
@@ -56,7 +57,7 @@ public class AnnotationColourChooser
     frame = new JInternalFrame();\r
     frame.setContentPane(this);\r
     frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
-    Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145, false);\r
+    Desktop.addInternalFrame(frame, "Colour by Annotation", 480, 145);\r
 \r
     try\r
     {\r
@@ -69,8 +70,11 @@ public class AnnotationColourChooser
     {\r
       public void stateChanged(ChangeEvent evt)\r
       {\r
-        thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");\r
-        valueChanged();\r
+        if(!adjusting)\r
+        {\r
+          thresholdValue.setText( ( (float) slider.getValue() / 1000f) + "");\r
+          valueChanged();\r
+        }\r
       }\r
     });\r
 \r
@@ -89,6 +93,7 @@ public class AnnotationColourChooser
       maxColour.setBackground(Color.red);\r
     }\r
 \r
+    adjusting = true;\r
     for (int i = 0; i < av.alignment.getAlignmentAnnotation().length; i++)\r
     {\r
       if (av.alignment.getAlignmentAnnotation()[i].graph > 0)\r
@@ -99,6 +104,10 @@ public class AnnotationColourChooser
     threshold.addItem("Above Threshold");\r
     threshold.addItem("Below Threshold");\r
 \r
+    adjusting = false;\r
+\r
+    changeColour();\r
+\r
   }\r
 \r
   public AnnotationColourChooser()\r
@@ -181,10 +190,12 @@ public class AnnotationColourChooser
         thresholdValue_actionPerformed(e);\r
       }\r
     });\r
+    slider.setPaintLabels(false);\r
     slider.setPaintTicks(true);\r
     slider.setBackground(Color.white);\r
     slider.setEnabled(false);\r
     slider.setOpaque(false);\r
+    slider.setPreferredSize(new Dimension(150, 32));\r
     thresholdValue.setEnabled(false);\r
     thresholdValue.setColumns(10);\r
     jPanel3.setBackground(Color.white);\r
@@ -253,7 +264,7 @@ public class AnnotationColourChooser
   void changeColour()\r
   {\r
     // Check if combobox is still adjusting\r
-    if (threshold.getSelectedIndex() == -1)\r
+    if (adjusting)\r
       return;\r
 \r
     // We removed the non-graph annotations when filling the combobox\r
@@ -278,9 +289,11 @@ public class AnnotationColourChooser
     else if (threshold.getSelectedItem().equals("Below Threshold"))\r
       aboveThreshold = AnnotationColourGradient.BELOW_THRESHOLD;\r
 \r
+    slider.setEnabled(true);\r
+    thresholdValue.setEnabled(true);\r
+\r
     if (aboveThreshold == AnnotationColourGradient.NO_THRESHOLD)\r
     {\r
-      currentAnnotation.threshold = null;\r
       slider.setEnabled(false);\r
       thresholdValue.setEnabled(false);\r
       thresholdValue.setText("");\r
@@ -293,6 +306,11 @@ public class AnnotationColourChooser
                                         currentAnnotation.graphMin) / 2f,\r
                                       "Threshold",\r
                                       Color.black));\r
+    }\r
+\r
+    if(aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)\r
+    {\r
+      adjusting = true;\r
       float range = currentAnnotation.graphMax * 1000 -\r
           currentAnnotation.graphMin * 1000;\r
 \r
@@ -304,6 +322,7 @@ public class AnnotationColourChooser
       slider.setMinorTickSpacing( (int) (range / 100f));\r
       slider.setEnabled(true);\r
       thresholdValue.setEnabled(true);\r
+      adjusting = false;\r
     }\r
 \r
     AnnotationColourGradient acg = null;\r
@@ -396,8 +415,6 @@ public class AnnotationColourChooser
 \r
   public void annotations_actionPerformed(ActionEvent e)\r
   {\r
-    if(currentAnnotation!=null)\r
-      currentAnnotation.threshold = null;\r
     changeColour();\r
   }\r
 \r
@@ -419,6 +436,12 @@ public class AnnotationColourChooser
 \r
   public void valueChanged()\r
   {\r
+    if (currentColours.isSelected()\r
+        && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))\r
+    {\r
+      changeColour();\r
+    }\r
+\r
     currentAnnotation.threshold.value = (float)slider.getValue()/1000f;\r
     ap.repaint();\r
   }\r