JAL-2438 refactored checks for 'no features displayed'
[jalview.git] / src / jalview / renderer / seqfeatures / FeatureColourFinder.java
index 0c18d39..d4a545b 100644 (file)
@@ -47,6 +47,10 @@ public class FeatureColourFinder
    * transparency, this class provides a dummy 'offscreen' graphics context
    * where multiple feature colours can be overlaid and the combined colour read
    * back.
+   * <p>
+   * This method is not thread-safe when transparency is applied, since a shared
+   * BufferedImage would be used by all threads to hold the composite colour at
+   * a position. Each thread should use a separate instance of this class.
    * 
    * @param defaultColour
    * @param seq
@@ -57,17 +61,11 @@ public class FeatureColourFinder
   public Color findFeatureColour(Color defaultColour, SequenceI seq,
           int column)
   {
-    if (!((FeatureRendererModel) featureRenderer).hasRenderOrder())
+    if (noFeaturesDisplayed())
     {
       return defaultColour;
     }
 
-    FeaturesDisplayedI displayed = featureRenderer.getFeaturesDisplayed();
-    if (displayed == null || displayed.getVisibleFeatureCount() == 0)
-    {
-      return defaultColour; // nothing to see here folks
-    }
-
     Graphics g = null;
 
     /*
@@ -95,4 +93,31 @@ public class FeatureColourFinder
     }
     return c;
   }
+
+  /**
+   * Answers true if feature display is turned off, or there are no features
+   * configured to be visible
+   * 
+   * @return
+   */
+  boolean noFeaturesDisplayed()
+  {
+    if (!featureRenderer.getViewport().isShowSequenceFeatures())
+    {
+      return true;
+    }
+
+    if (!((FeatureRendererModel) featureRenderer).hasRenderOrder())
+    {
+      return true;
+    }
+
+    FeaturesDisplayedI displayed = featureRenderer.getFeaturesDisplayed();
+    if (displayed == null || displayed.getVisibleFeatureCount() == 0)
+    {
+      return true;
+    }
+
+    return false;
+  }
 }