JAL-2055 prototype alternate feature colouring based on
[jalview.git] / src / jalview / schemes / GraduatedColor.java
index 665a78b..f629d09 100644 (file)
@@ -1,23 +1,26 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * Jalview is free software: you can redistribute it and/or
  * modify it under the terms of the GNU General Public License 
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
  *  
  * Jalview is distributed in the hope that it will be useful, but 
  * WITHOUT ANY WARRANTY; without even the implied warranty 
  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
 package jalview.schemes;
 
+import jalview.api.FeatureColourI;
 import jalview.datamodel.SequenceFeature;
 
 import java.awt.Color;
@@ -31,6 +34,11 @@ import java.awt.Color;
  */
 public class GraduatedColor
 {
+  private static final Color[] colours = new Color[] { Color.blue,
+      Color.red };
+
+  private static int colourModulus = 0;
+
   int thresholdState = AnnotationColourGradient.NO_THRESHOLD; // or
                                                               // ABOVE_THRESHOLD
                                                               // or
@@ -101,6 +109,7 @@ public class GraduatedColor
     thrsh = oldcs.thrsh;
     autoScale = oldcs.autoScale;
     colourByLabel = oldcs.colourByLabel;
+    colourAlternately = oldcs.colourAlternately;
   }
 
   /**
@@ -116,6 +125,11 @@ public class GraduatedColor
     updateBounds(min, max);
   }
 
+  public GraduatedColor(FeatureColourI col)
+  {
+    setColourByLabel(col.isColourByLabel());
+  }
+
   public Color getMinColor()
   {
     return new Color(lr, lg, lb);
@@ -143,7 +157,7 @@ public class GraduatedColor
   public boolean isColored(SequenceFeature feature)
   {
     float val = feature.getScore();
-    if (val == Float.NaN)
+    if (Float.isNaN(val))
     {
       return true;
     }
@@ -151,7 +165,7 @@ public class GraduatedColor
     {
       return true;
     }
-    if (this.thrsh == Float.NaN)
+    if (Float.isNaN(this.thrsh))
     {
       return true;
     }
@@ -174,6 +188,8 @@ public class GraduatedColor
 
   private boolean colourByLabel = false;
 
+  private boolean colourAlternately = false;
+
   /**
    * 
    * @return true if colourByLabel style is set
@@ -204,12 +220,18 @@ public class GraduatedColor
       }
       return ucs.createColourFromName(feature.getDescription());
     }
+    if (colourAlternately)
+    {
+      int minOrMax = feature.getFeatureNumber() % 2;
+      return minOrMax == 0 ? new Color(lr, lg, lb) : new Color(lr + dr, lg
+              + dg, lb + db);
+    }
     if (range == 0.0)
     {
       return getMaxColor();
     }
     float scr = feature.getScore();
-    if (scr == Float.NaN)
+    if (Float.isNaN(scr))
     {
       return getMinColor();
     }
@@ -293,4 +315,14 @@ public class GraduatedColor
       tolow = false;
     }
   }
+
+  public boolean isColourAlternately()
+  {
+    return colourAlternately;
+  }
+
+  public void setColourAlternately(boolean colourAlternately)
+  {
+    this.colourAlternately = colourAlternately;
+  }
 }