JAL-3383 removing colour caching (to a separate branch)
[jalview.git] / src / jalview / renderer / OverviewResColourFinder.java
index 94e7c5b..7207dea 100644 (file)
@@ -29,14 +29,6 @@ import java.awt.Color;
 
 public class OverviewResColourFinder extends ResidueColourFinder
 {
-  final int GAP_COLOUR; // default colour to use at gaps
-
-  final int RESIDUE_COLOUR; // default colour to use at residues
-
-  final Color HIDDEN_COLOUR; // colour for hidden regions
-
-  boolean useLegacy = false;
-
   public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
 
   public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
@@ -44,6 +36,18 @@ public class OverviewResColourFinder extends ResidueColourFinder
   public static final Color OVERVIEW_DEFAULT_HIDDEN = Color.darkGray
           .darker();
 
+  final Color gapColour; // colour to use for gaps
+
+  final int gapColourInt;
+
+  final Color residueColour; // colour to use for uncoloured residues
+
+  final int residueColourInt;
+
+  final Color hiddenColour; // colour for hidden regions
+
+  boolean useLegacy = false;
+
   /**
    * Constructor without colour settings (used by applet)
    */
@@ -67,15 +71,23 @@ public class OverviewResColourFinder extends ResidueColourFinder
   {
     if (useLegacyColouring)
     {
-      GAP_COLOUR = Color.white.getRGB();
-      RESIDUE_COLOUR = Color.lightGray.getRGB();
+      gapColour = Color.white;
+      residueColour = Color.lightGray;
     }
     else
     {
-      GAP_COLOUR = gapCol.getRGB();
-      RESIDUE_COLOUR = Color.white.getRGB();
+      gapColour = gapCol;
+      residueColour = Color.WHITE;
     }
-    HIDDEN_COLOUR = hiddenCol;
+    gapColourInt = gapColour.getRGB();
+    residueColourInt = residueColour.getRGB();
+    hiddenColour = hiddenCol;
+  }
+
+  @Override
+  public Color getBoxColour(ResidueShaderI shader, SequenceI seq, int i)
+  {
+    return new Color(getBoxColourInt(shader, seq, i));
   }
 
   public int getBoxColourInt(ResidueShaderI shader, SequenceI seq, int i)
@@ -87,34 +99,49 @@ public class OverviewResColourFinder extends ResidueColourFinder
     boolean isGap = Comparison.isGap(currentChar);
     if (shader.getColourScheme() == null)
     {
-      return (isGap ? GAP_COLOUR : RESIDUE_COLOUR);
+      return (isGap ? gapColourInt : residueColourInt);
     }
-    return (isGap && !shader.getColourScheme().hasGapColour() ? GAP_COLOUR
+    return (isGap && !shader.getColourScheme().hasGapColour() ? gapColourInt
             : shader.findColourInt(currentChar, i, seq));
   }
 
-  public int getResidueColourInt(boolean showBoxes, ResidueShaderI shader,
+  @Override
+  public Color getResidueColour(boolean showBoxes, ResidueShaderI shader,
           SequenceGroup[] allGroups, final SequenceI seq, int i,
           FeatureColourFinder finder)
   {
+    Color col = getResidueBoxColour(showBoxes, shader, allGroups, seq, i);
 
-    int c = seq.getColor(i);
-    if (c != 0)
-    {
-      return c;
-    }
+    // if there's a FeatureColourFinder we might override the residue colour
+    // here with feature colouring
+    col = finder == null || finder.noFeaturesDisplayed() ? col
+            : finder.findFeatureColour(col, seq, i);
+    return col;
+  }
 
-    int col = getResidueBoxColourInt(showBoxes, shader, allGroups, seq,
-            i);
 
+  public int getResidueColourInt(boolean showBoxes, ResidueShaderI shader,
+          SequenceGroup[] allGroups, final SequenceI seq, int i,
+          FeatureColourFinder finder)
+  {
+    int col = getResidueBoxColourInt(showBoxes, shader, allGroups, seq, i);
 
     // if there's a FeatureColourFinder we might override the residue colour
     // here with feature colouring
-    return seq.setColor(i,
-            finder == null || finder.noFeaturesDisplayed() ? col
-            : finder.findFeatureColourInt(col, seq, i));
+    col = finder == null || finder.noFeaturesDisplayed() ? col
+            : finder.findFeatureColourInt(col, seq, i);
+    return col;
+  }
+
+  @Override
+  protected Color getResidueBoxColour(boolean showBoxes,
+          ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
+          int i)
+  {
+    return new Color(
+            getResidueBoxColourInt(showBoxes, shader, allGroups, seq, i));
   }
-  
+
   /**
    * In the overview, the showBoxes setting is ignored, as the overview displays
    * the colours regardless.
@@ -137,6 +164,6 @@ public class OverviewResColourFinder extends ResidueColourFinder
    */
   protected Color getHiddenColour()
   {
-    return HIDDEN_COLOUR;
+    return hiddenColour;
   }
 }