more graduated feature support
[jalview.git] / src / jalview / gui / FeatureColourChooser.java
index 993cd2e..55865db 100644 (file)
@@ -87,7 +87,13 @@ public class FeatureColourChooser extends JPanel
     oldcs = fr.featureColours.get(type);
     if (oldcs instanceof GraduatedColor)
     {
-      cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
+      if (((GraduatedColor)oldcs).isAutoScale())
+      {
+        // update the scale
+        cs = new GraduatedColor((GraduatedColor) oldcs, min, max);
+      } else {
+        cs = new GraduatedColor((GraduatedColor) oldcs);
+      }
     } else {
       // promote original color to a graduated color
       Color bl = Color.black;
@@ -108,6 +114,19 @@ public class FeatureColourChooser extends JPanel
     } catch (Exception ex)
     {
     }
+    // update the gui from threshold state
+    thresholdIsMin.setSelected(!cs.isAutoScale());
+    if (cs.getThreshType()!=AnnotationColourGradient.NO_THRESHOLD)
+    {
+      // initialise threshold slider and selector
+      threshold.setSelectedIndex(cs.getThreshType()==AnnotationColourGradient.ABOVE_THRESHOLD ? 1 : 2);
+            slider.setEnabled(true);
+      thresholdValue.setEnabled(true);
+      threshline = new jalview.datamodel.GraphLine(
+                        (max - min) / 2f,
+                        "Threshold", Color.black);
+      
+    }
 
     adjusting = false;
 
@@ -185,9 +204,9 @@ public class FeatureColourChooser extends JPanel
         threshold_actionPerformed(e);
       }
     });
-    threshold.addItem("No Threshold");
-    threshold.addItem("Above Threshold");
-    threshold.addItem("Below Threshold");
+    threshold.addItem("No Threshold"); // index 0
+    threshold.addItem("Above Threshold"); // index 1
+    threshold.addItem("Below Threshold"); // index 2
     jPanel3.setLayout(flowLayout2);
     thresholdValue.addActionListener(new ActionListener()
     {
@@ -354,12 +373,15 @@ public class FeatureColourChooser extends JPanel
     acg.setThreshType(aboveThreshold);
     if (thresholdIsMin.isSelected() && aboveThreshold != AnnotationColourGradient.NO_THRESHOLD)
     {
+      acg.setAutoScaled(false);
       if (aboveThreshold==AnnotationColourGradient.ABOVE_THRESHOLD)
       { 
         acg = new GraduatedColor(acg, threshline.value, max);
       } else { 
         acg = new GraduatedColor(acg, min,threshline.value);
       }
+    } else {
+      acg.setAutoScaled(true);
     }
     
     fr.featureColours.put(type,acg);