JAL-2055 removed stub first version of colours
[jalview.git] / src / jalview / schemes / GraduatedColor.java
index 037b6ca..e6aced3 100644 (file)
@@ -1,22 +1,26 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
- * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * 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;
@@ -100,6 +104,7 @@ public class GraduatedColor
     thrsh = oldcs.thrsh;
     autoScale = oldcs.autoScale;
     colourByLabel = oldcs.colourByLabel;
+    colourAlternately = oldcs.colourAlternately;
   }
 
   /**
@@ -115,6 +120,11 @@ public class GraduatedColor
     updateBounds(min, max);
   }
 
+  public GraduatedColor(FeatureColourI col)
+  {
+    setColourByLabel(col.isColourByLabel());
+  }
+
   public Color getMinColor()
   {
     return new Color(lr, lg, lb);
@@ -142,7 +152,7 @@ public class GraduatedColor
   public boolean isColored(SequenceFeature feature)
   {
     float val = feature.getScore();
-    if (val == Float.NaN)
+    if (Float.isNaN(val))
     {
       return true;
     }
@@ -150,7 +160,7 @@ public class GraduatedColor
     {
       return true;
     }
-    if (this.thrsh == Float.NaN)
+    if (Float.isNaN(this.thrsh))
     {
       return true;
     }
@@ -173,6 +183,8 @@ public class GraduatedColor
 
   private boolean colourByLabel = false;
 
+  private boolean colourAlternately = false;
+
   /**
    * 
    * @return true if colourByLabel style is set
@@ -203,12 +215,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();
     }
@@ -292,4 +310,14 @@ public class GraduatedColor
       tolow = false;
     }
   }
+
+  public boolean isColourAlternately()
+  {
+    return colourAlternately;
+  }
+
+  public void setColourAlternately(boolean colourAlternately)
+  {
+    this.colourAlternately = colourAlternately;
+  }
 }