JAL-2438 clarify code and javadoc, reinstate updateFeatures() check
[jalview.git] / src / jalview / renderer / seqfeatures / FeatureColourFinder.java
index 5055ed5..0c18d39 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.renderer.seqfeatures;
 
+import jalview.api.FeatureRenderer;
 import jalview.api.FeaturesDisplayedI;
 import jalview.datamodel.SequenceI;
 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
@@ -19,7 +20,7 @@ public class FeatureColourFinder
   /*
    * the class we delegate feature finding to
    */
-  private jalview.api.FeatureRenderer featureRenderer;
+  private FeatureRenderer featureRenderer;
 
   /*
    * a 1-pixel image on which features can be drawn, for the case where
@@ -32,7 +33,7 @@ public class FeatureColourFinder
    * 
    * @param fr
    */
-  public FeatureColourFinder(jalview.api.FeatureRenderer fr)
+  public FeatureColourFinder(FeatureRenderer fr)
   {
     featureRenderer = fr;
     offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
@@ -41,14 +42,16 @@ public class FeatureColourFinder
   /**
    * Answers the feature colour to show for the given sequence and column
    * position. This delegates to the FeatureRenderer to find the colour, which
-   * will depend on feature location, visibility, ordering, and whether or not
-   * transparency is applied. For feature rendering with transparency, this
-   * class provides a dummy 'offscreen' graphics context where multiple feature
-   * colours can be overlaid and the combined colour read back.
+   * will depend on feature location, visibility, ordering, colour scheme, and
+   * whether or not transparency is applied. For feature rendering with
+   * transparency, this class provides a dummy 'offscreen' graphics context
+   * where multiple feature colours can be overlaid and the combined colour read
+   * back.
    * 
    * @param defaultColour
    * @param seq
    * @param column
+   *          alignment column position (base zero)
    * @return
    */
   public Color findFeatureColour(Color defaultColour, SequenceI seq,
@@ -65,15 +68,31 @@ public class FeatureColourFinder
       return defaultColour; // nothing to see here folks
     }
 
-    Graphics g = featureRenderer.getTransparency() == 1f ? null
-            : offscreenImage.getGraphics();
+    Graphics g = null;
 
-    Color c = featureRenderer.findFeatureColour(defaultColour, seq, column,
-            g);
-    if (c != null && g != null)
+    /*
+     * if transparency applies, provide a notional 1x1 graphics context 
+     * that has been primed with the default colour
+     */
+    if (featureRenderer.getTransparency() != 1f)
+    {
+      g = offscreenImage.getGraphics();
+      if (defaultColour != null)
+      {
+        offscreenImage.setRGB(0, 0, defaultColour.getRGB());
+      }
+    }
+
+    Color c = featureRenderer.findFeatureColour(seq, column, g);
+    if (c == null)
+    {
+      return defaultColour;
+    }
+
+    if (g != null)
     {
       c = new Color(offscreenImage.getRGB(0, 0));
     }
-    return c == null ? defaultColour : c;
+    return c;
   }
 }