JAL-3719 Format->Colour Gaps option uses Overview gap colour logic pulled up to align...
[jalview.git] / src / jalview / renderer / ResidueColourFinder.java
index 2da7233..7a1b720 100644 (file)
@@ -23,14 +23,25 @@ package jalview.renderer;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.renderer.seqfeatures.FeatureColourFinder;
+import jalview.util.Comparison;
 
 import java.awt.Color;
 
 public class ResidueColourFinder
 {
+  private static final Color BACKGROUND_COLOUR = Color.white;
+
+  protected Color GAP_COLOUR=Color.white; // default colour to use at gaps
+
+  protected Color RESIDUE_COLOUR=BACKGROUND_COLOUR; // default colour to use at residues
+
   public ResidueColourFinder()
   {
   }
+  public ResidueColourFinder(Color gapColour)
+  {
+    GAP_COLOUR = gapColour;
+  }
 
   /**
    * Get the colour of a residue in a sequence
@@ -100,7 +111,7 @@ public class ResidueColourFinder
       return getBoxColour(shader, seq, i);
     }
   
-    return Color.white;
+    return BACKGROUND_COLOUR;
   }
 
   /**
@@ -134,7 +145,7 @@ public class ResidueColourFinder
   }
 
   /**
-   * DOCUMENT ME!
+   * Find the colour for a sequence's position in the alignment 
    * 
    * @param shader
    *          the viewport's colour scheme
@@ -145,11 +156,29 @@ public class ResidueColourFinder
    */
   public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
   {
-    Color resBoxColour = Color.white;
+    Color resBoxColour = RESIDUE_COLOUR;
+    char currentChar = seq.getCharAt(i);
+
+    // In the overview window, gaps are coloured grey, unless the colour scheme
+    // specifies a gap colour, in which case gaps honour the colour scheme
+    // settings
     if (shader.getColourScheme() != null)
     {
-      resBoxColour = shader.findColour(seq.getCharAt(i), i, seq);
+      if (Comparison.isGap(currentChar)
+              && (!shader.getColourScheme().hasGapColour()))
+      {
+        resBoxColour = GAP_COLOUR;
+      }
+      else
+      {
+        resBoxColour = shader.findColour(currentChar, i, seq);
+      }
     }
+    else if (Comparison.isGap(currentChar))
+    {
+      resBoxColour = GAP_COLOUR;
+    }
+
     return resBoxColour;
   }