added graduated colourscheme support for feature file
[jalview.git] / src / jalview / schemes / GraduatedColor.java
index 25681c4..b134968 100644 (file)
@@ -25,6 +25,10 @@ public class GraduatedColor
    */
   boolean tolow=false;
   /**
+   * when false, min/max range has been manually set so should not be dynamically adjusted.
+   */
+  boolean autoScale = true;
+  /**
    * construct a graduatedColor object from simple parameters
    * @param low
    * @param high
@@ -64,6 +68,7 @@ public class GraduatedColor
     tolow = oldcs.tolow;
     thresholdState = oldcs.thresholdState;
     thrsh = oldcs.thrsh;
+    autoScale = oldcs.autoScale;
   }
   /**
    * make a new gradient from an old one with a different scale range
@@ -74,16 +79,7 @@ public class GraduatedColor
   public GraduatedColor(GraduatedColor oldcs, float min, float max)
   {
     this(oldcs);
-    if (max<min)
-    {
-      base = max;
-      range = min-max;
-      tolow=true;
-    } else {
-      base = min;
-      range = max-min;
-      tolow=false;
-    }
+    updateBounds(min, max);
   }
   public Color getMinColor()
   {
@@ -145,6 +141,9 @@ public class GraduatedColor
   {
     thrsh = value;
   }
+  public float getThresh() {
+    return thrsh;
+  }
   public void setThreshType(int aboveThreshold)
   {
     thresholdState = aboveThreshold;
@@ -153,4 +152,38 @@ public class GraduatedColor
   {
     return thresholdState;
   }
+  public float getMax()
+  {
+    // regenerate the original values passed in to the constructor
+    return (tolow) ? base : (base + range);
+  }
+  public float getMin()
+  {
+    // regenerate the original value passed in to the constructor
+    return (tolow) ? (base+range) : base;
+  }
+  public boolean isAutoScale()
+  {
+    return autoScale;
+  }
+  public void setAutoScaled(boolean autoscale) {
+    autoScale = autoscale;
+  }
+  /**
+   * update the base and range appropriatly for the given minmax range  
+   * @param a float[] {min,max} array containing minmax range for the associated score values
+   */
+  public void updateBounds(float min,float max) 
+  {
+    if (max<min)
+    {
+      base = max;
+      range = min-max;
+      tolow=true;
+    } else {
+      base = min;
+      range = max-min;
+      tolow=false;
+    }
+  }
 }