JAL-3437 Desktop File...Load Project fails in JalviewJS
[jalview.git] / src / jalview / renderer / OverviewResColourFinder.java
index b606ba3..8206b32 100644 (file)
@@ -22,18 +22,26 @@ package jalview.renderer;
 
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
-import jalview.gui.Preferences;
 import jalview.util.Comparison;
 
 import java.awt.Color;
 
 public class OverviewResColourFinder extends ResidueColourFinder
 {
-  final Color GAP_COLOUR; // default colour to use at gaps
+  public static final Color OVERVIEW_DEFAULT_GAP = Color.lightGray;
 
-  final Color RESIDUE_COLOUR; // default colour to use at residues
+  public static final Color OVERVIEW_DEFAULT_LEGACY_GAP = Color.white;
 
-  final Color HIDDEN_COLOUR; // colour for hidden regions
+  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;
 
@@ -42,8 +50,7 @@ public class OverviewResColourFinder extends ResidueColourFinder
    */
   public OverviewResColourFinder()
   {
-    this(false, Preferences.OVERVIEW_DEFAULT_GAP,
-            Preferences.OVERVIEW_DEFAULT_HIDDEN);
+    this(false, OVERVIEW_DEFAULT_GAP, OVERVIEW_DEFAULT_HIDDEN);
   }
 
   /**
@@ -61,78 +68,59 @@ public class OverviewResColourFinder extends ResidueColourFinder
   {
     if (useLegacyColouring)
     {
-      GAP_COLOUR = Color.white;
-      RESIDUE_COLOUR = Color.lightGray;
-      HIDDEN_COLOUR = hiddenCol;
+      gapColour = Color.white;
+      residueColour = Color.lightGray;
     }
     else
     {
-      GAP_COLOUR = gapCol;
-      RESIDUE_COLOUR = Color.white;
-      HIDDEN_COLOUR = hiddenCol;
+      gapColour = gapCol;
+      residueColour = Color.WHITE;
     }
+    gapColourInt = gapColour.getRGB();
+    hiddenColour = hiddenCol;
   }
 
+  /**
+   * 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)
   {
-    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)
-    {
-      if (Comparison.isGap(currentChar)
-              && (!shader.getColourScheme().hasGapColour()))
-      {
-        resBoxColour = GAP_COLOUR;
-      }
-      else
-      {
-        resBoxColour = shader.findColour(currentChar, i, seq);
-      }
-    }
-    else if (Comparison.isGap(currentChar))
+    boolean isGap = Comparison.isGap(currentChar);
+    if (shader.getColourScheme() == null)
     {
-      resBoxColour = GAP_COLOUR;
+      return (isGap ? gapColour : residueColour);
     }
-
-    return resBoxColour;
+    return (isGap && !shader.getColourScheme().hasGapColour() ? gapColour
+            : shader.findColour(currentChar, i, seq));
   }
 
   /**
-   * {@inheritDoc} In the overview, the showBoxes setting is ignored, as the
-   * overview displays the colours regardless.
+   * 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)
+          ResidueShaderI shader, SequenceGroup[] allGroups, SequenceI seq,
+          int i)
   {
-    ResidueShaderI currentShader;
     SequenceGroup currentSequenceGroup = getCurrentSequenceGroup(allGroups,
             i);
-    if (currentSequenceGroup != null)
-    {
-      currentShader = currentSequenceGroup.getGroupColourScheme();
-    }
-    else
-    {
-      currentShader = shader;
-    }
-
+    ResidueShaderI currentShader = (currentSequenceGroup == null ? shader
+            : currentSequenceGroup.getGroupColourScheme());
     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;
   }
 }