JAL-2438 clarify code and javadoc, reinstate updateFeatures() check
[jalview.git] / src / jalview / renderer / seqfeatures / FeatureRenderer.java
index de3b201..02cfd05 100644 (file)
@@ -31,7 +31,6 @@ import java.awt.Color;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
-import java.awt.image.BufferedImage;
 
 public class FeatureRenderer extends FeatureRendererModel
 {
@@ -40,8 +39,6 @@ public class FeatureRenderer extends FeatureRendererModel
 
   protected SequenceI lastSeq;
 
-  BufferedImage offscreenImage;
-
   private volatile SequenceFeature[] lastSequenceFeatures;
 
   int sfSize;
@@ -213,21 +210,14 @@ public class FeatureRenderer extends FeatureRendererModel
   }
 
   /**
-   * This is used by Structure Viewers and the Overview Window to get the
-   * feature colour of the rendered sequence
-   * 
-   * @param defaultColour
-   * @param seq
-   * @param column
-   * @return
+   * {@inheritDoc}
    */
   @Override
-  public Color findFeatureColour(Color defaultColour, SequenceI seq,
-          int column, Graphics g)
+  public Color findFeatureColour(SequenceI seq, int column, Graphics g)
   {
     if (!av.isShowSequenceFeatures())
     {
-      return defaultColour;
+      return null;
     }
 
     SequenceFeature[] sequenceFeatures = seq.getSequenceFeatures();
@@ -254,7 +244,7 @@ public class FeatureRenderer extends FeatureRendererModel
 
     if (lastSequenceFeatures == null || sfSize == 0)
     {
-      return defaultColour;
+      return null;
     }
 
     if (Comparison.isGap(lastSeq.getCharAt(column)))
@@ -265,26 +255,35 @@ public class FeatureRenderer extends FeatureRendererModel
     Color renderedColour = null;
     if (transparency == 1.0f)
     {
+      /*
+       * simple case - just find the topmost rendered visible feature colour
+       */
       renderedColour = findFeatureColour(seq, seq.findPosition(column));
     }
     else
     {
+      /*
+       * transparency case - draw all visible features in render order to
+       * build up a composite colour on the graphics context
+       */
       renderedColour = drawSequence(g, lastSeq, column, column, 0, true);
     }
-    return renderedColour == null ? defaultColour : renderedColour;
+    return renderedColour;
   }
 
   /**
    * Draws the sequence features on the graphics context, or just determines the
-   * colour that would be drawn (if flag offscreenrender is true).
+   * colour that would be drawn (if flag colourOnly is true). Returns the last
+   * colour drawn (which may not be the effective colour if transparency
+   * applies), or null if no feature is drawn in the range given.
    * 
    * @param g
    *          the graphics context to draw on (may be null if colourOnly==true)
    * @param seq
    * @param start
-   *          start column (or sequence position in offscreenrender mode)
+   *          start column
    * @param end
-   *          end column (not used in offscreenrender mode)
+   *          end column
    * @param y1
    *          vertical offset at which to draw on the graphics
    * @param colourOnly
@@ -325,10 +324,7 @@ public class FeatureRenderer extends FeatureRendererModel
     Color drawnColour = null;
 
     /*
-     * iterate over features in ordering of their rendering;
-     * if drawing a range of columns, use render order to ensure last is on top
-     * if drawing a single column (as in findFeatureColour), with no 
-     * transparency, work backwards to find the topmost rendered feature colour
+     * iterate over features in ordering of their rendering (last is on top)
      */
     for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
     {
@@ -348,15 +344,18 @@ public class FeatureRenderer extends FeatureRendererModel
           continue;
         }
 
+        /*
+         * a feature type may be flagged as shown but the group 
+         * an instance of it belongs to may be hidden
+         */
         if (featureGroupNotShown(sequenceFeature))
         {
           continue;
         }
 
         /*
-         * check feature overlaps the visible part of the alignment, 
-         * unless doing offscreenRender (to the Overview window or a 
-         * structure viewer) which is not limited 
+         * check feature overlaps the target range
+         * TODO: efficient retrieval of features overlapping a range
          */
         if (sequenceFeature.getBegin() > endPos
                 || sequenceFeature.getEnd() < startPos)
@@ -415,13 +414,8 @@ public class FeatureRenderer extends FeatureRendererModel
     if (transparency != 1.0f && g != null)
     {
       /*
-       * get colour as rendered including transparency
-       * and reset transparency
+       * reset transparency
        */
-      if (offscreenImage != null && drawnColour != null)
-      {
-        drawnColour = new Color(offscreenImage.getRGB(0, 0));
-      }
       Graphics2D g2 = (Graphics2D) g;
       g2.setComposite(NO_TRANSPARENCY);
     }
@@ -477,7 +471,10 @@ public class FeatureRenderer extends FeatureRendererModel
       return null;
     }
   
-    // updateFeatures();
+    /*
+     * check for new feature added while processing
+     */
+    updateFeatures();
 
     /*
      * inspect features in reverse renderOrder (the last in the array is 
@@ -504,6 +501,10 @@ public class FeatureRenderer extends FeatureRendererModel
           continue;
         }
 
+        /*
+         * check the column position is within the feature range
+         * (or is one of the two contact positions for a contact feature)
+         */
         boolean featureIsAtPosition = sequenceFeature.begin <= pos
                 && sequenceFeature.end >= pos;
         if (sequenceFeature.isContactFeature())