JAL-2588 Check/fix show boxes settings + unit test updates.
[jalview.git] / src / jalview / renderer / ResidueColourFinder.java
index 99f5107..2da7233 100644 (file)
@@ -32,12 +32,32 @@ public class ResidueColourFinder
   {
   }
 
-  public Color getResidueColour(ResidueShaderI shader,
+  /**
+   * Get the colour of a residue in a sequence
+   * 
+   * @param showBoxes
+   *          true if the viewport's Show Boxes setting is true
+   * @param shader
+   *          the viewport's colour scheme
+   * @param allGroups
+   *          all the groups which seq participates in
+   * @param seq
+   *          the sequence containing the residue
+   * @param position
+   *          the position of the residue in the sequence
+   * @param finder
+   *          FeatureColourFinder for the viewport
+   * @return colour of the residue
+   */
+  public Color getResidueColour(boolean showBoxes, ResidueShaderI shader,
           SequenceGroup[] allGroups,
           final SequenceI seq, int position, FeatureColourFinder finder)
   {
-    Color col = getResidueBoxColour(shader, allGroups, seq, position);
+    Color col = getResidueBoxColour(showBoxes, shader, allGroups, seq,
+            position);
 
+    // if there's a FeatureColourFinder we might override the residue colour
+    // here with feature colouring
     if (finder != null)
     {
       col = finder.findFeatureColour(col, seq, position);
@@ -45,27 +65,54 @@ public class ResidueColourFinder
     return col;
   }
 
-  private Color getResidueBoxColour(ResidueShaderI shader,
+  /**
+   * Get the residue colour without accounting for any features
+   * 
+   * @param showBoxes
+   *          true if the viewport's Show Boxes setting is true
+   * @param shader
+   *          the viewport's colour scheme
+   * @param allGroups
+   *          all the groups which seq participates in
+   * @param seq
+   *          the sequence containing the residue
+   * @param i
+   *          the position of the residue in the sequence
+   * @return
+   */
+  protected Color getResidueBoxColour(boolean showBoxes,
+          ResidueShaderI shader,
           SequenceGroup[] allGroups,
           SequenceI seq, int i)
   {
-
-    ResidueShaderI currentShader;
-
     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
             i);
     if (currentSequenceGroup != null)
     {
-      currentShader = currentSequenceGroup.getGroupColourScheme();
+      if (currentSequenceGroup.getDisplayBoxes())
+      {
+        return getBoxColour(currentSequenceGroup.getGroupColourScheme(),
+                seq, i);
+      }
     }
-    else
+    else if (showBoxes)
     {
-      currentShader = shader;
+      return getBoxColour(shader, seq, i);
     }
-
-    return getBoxColour(currentShader, seq, i);
+  
+    return Color.white;
   }
 
+  /**
+   * Search all the groups for a sequence to find the one which a given res
+   * falls into
+   * 
+   * @param allGroups
+   *          all the groups a sequence participates in
+   * @param res
+   *          the residue to search for
+   * @return a sequence group for res, or null if no sequence group applies
+   */
   public SequenceGroup getCurrentSequenceGroup(SequenceGroup[] allGroups,
           int res)
   {
@@ -90,11 +137,11 @@ public class ResidueColourFinder
    * DOCUMENT ME!
    * 
    * @param shader
-   *          DOCUMENT ME!
+   *          the viewport's colour scheme
    * @param seq
-   *          DOCUMENT ME!
+   *          the sequence containing the residue
    * @param i
-   *          DOCUMENT ME!
+   *          the position of the residue in the sequence
    */
   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
   {