JAL-2630 first pass groovy colour scheme (with slight refactoring)
[jalview.git] / src / jalview / schemes / ResidueColourScheme.java
index 92de7ac..7dbcced 100755 (executable)
@@ -134,24 +134,46 @@ public abstract class ResidueColourScheme implements ColourSchemeI
   @Override
   public Color findColour(char c, int j, SequenceI seq)
   {
-    Color currentColour;
+    Color colour = Color.white;
 
-    if (colors != null && symbolIndex != null && (threshold == 0)
-            || aboveThreshold(c, j))
+    if (colors != null && symbolIndex != null)
     {
-      currentColour = colors[symbolIndex[c]];
+      colour = colors[symbolIndex[c]];
     }
-    else
+    colour = adjustColour(c, j, colour);
+
+    return colour;
+  }
+
+  /**
+   * Adjusts colour by applying thresholding or conservation shading, if in
+   * force. That is
+   * <ul>
+   * <li>if there is a threshold set for colouring, and the residue doesn't
+   * match the consensus (or a joint consensus) residue, or the consensus score
+   * is not above the threshold, then the colour is set to white</li>
+   * <li>if conservation colouring is selected, the colour is faded by an amount
+   * depending on the conservation score for the column, and the conservation
+   * colour threshold</li>
+   * </ul>
+   * 
+   * @param symbol
+   * @param column
+   * @param colour
+   * @return
+   */
+  protected Color adjustColour(char symbol, int column, Color colour)
+  {
+    if (!aboveThreshold(symbol, column))
     {
-      currentColour = Color.white;
+      colour = Color.white;
     }
 
     if (conservationColouring)
     {
-      currentColour = applyConservation(currentColour, j);
+      colour = applyConservation(colour, column);
     }
-
-    return currentColour;
+    return colour;
   }
 
   /**
@@ -195,6 +217,10 @@ public abstract class ResidueColourScheme implements ColourSchemeI
    */
   public boolean aboveThreshold(char residue, int column)
   {
+    if (threshold == 0)
+    {
+      return true;
+    }
     if ('a' <= residue && residue <= 'z')
     {
       // TO UPPERCASE !!!
@@ -409,4 +435,14 @@ public abstract class ResidueColourScheme implements ColourSchemeI
   {
     return false;
   }
+
+  /**
+   * Default method returns true. Override this to return false in colour
+   * schemes that are not determined solely by the sequence symbol.
+   */
+  @Override
+  public boolean isSimple()
+  {
+    return true;
+  }
 }