JAL-3437 Desktop File...Load Project fails in JalviewJS
[jalview.git] / src / jalview / renderer / OverviewResColourFinder.java
index a98f3b3..8206b32 100644 (file)
@@ -22,21 +22,12 @@ 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 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 +35,16 @@ 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; // RGB value of gapColour
+
+  final Color residueColour; // colour to use for uncoloured residues
+
+  final Color hiddenColour; // colour for hidden regions
+
+  boolean useLegacy = false;
+
   /**
    * Constructor without colour settings (used by applet)
    */
@@ -67,108 +68,59 @@ 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();
+    hiddenColour = hiddenCol;
   }
 
-  @Override
   /**
-   * for Test suite only.
+   * Overrides the method to return the currently configured Overview colours
+   * for gaps, or residues with no colour scheme set. A custom colour scheme
+   * which specifies a colour for gaps overrides the normal gap colour.
    */
+  @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)
-  {
     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
     boolean isGap = Comparison.isGap(currentChar);
     if (shader.getColourScheme() == null)
     {
-      return (isGap ? GAP_COLOUR : RESIDUE_COLOUR);
-    }
-    return (isGap && !shader.getColourScheme().hasGapColour() ? GAP_COLOUR
-            : shader.findColourInt(currentChar, i, seq));
-  }
-
-  /**
-   * For test suite only.
-   */
-  @Override
-  public Color getResidueColour(boolean showBoxes, ResidueShaderI shader,
-          SequenceGroup[] allGroups, final SequenceI seq, int i,
-          FeatureColourFinder finder)
-  {
-    return new Color(getResidueColourInt(showBoxes, shader, allGroups, seq,
-            i, finder));
-  }
-
-
-  public int getResidueColourInt(boolean showBoxes, ResidueShaderI shader,
-          SequenceGroup[] allGroups, final SequenceI seq, int i,
-          FeatureColourFinder finder)
-  {
-
-    int c = seq.getColor(i);
-    if (c != 0)
-    {
-      return c;
+      return (isGap ? gapColour : residueColour);
     }
-
-    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));
+    return (isGap && !shader.getColourScheme().hasGapColour() ? gapColour
+            : shader.findColour(currentChar, i, seq));
   }
 
   /**
-   * For test suite only.
+   * In the overview, the showBoxes setting is ignored, as the overview displays
+   * the colours regardless
    */
   @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.
-   */
-  protected int getResidueBoxColourInt(boolean showBoxes,
-          ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
-          int i)
-  {
     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
             i);
     ResidueShaderI currentShader = (currentSequenceGroup == null ? shader
             : currentSequenceGroup.getGroupColourScheme());
-    return getBoxColourInt(currentShader, seq, i);
+    return getBoxColour(currentShader, seq, i);
   }
 
   /**
-   * Supply hidden colour
+   * Returns the coloured configured for hidden regions in the Overview
    * 
-   * @return colour of hidden regions
+   * @return
    */
   protected Color getHiddenColour()
   {
-    return HIDDEN_COLOUR;
+    return hiddenColour;
   }
 }