1 package jalview.renderer.seqfeatures;
3 import jalview.api.FeatureRenderer;
4 import jalview.api.FeaturesDisplayedI;
5 import jalview.datamodel.SequenceI;
6 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
9 import java.awt.Graphics;
10 import java.awt.image.BufferedImage;
13 * A helper class to find feature colour using an associated FeatureRenderer
18 public class FeatureColourFinder
21 * the class we delegate feature finding to
23 private FeatureRenderer featureRenderer;
26 * a 1-pixel image on which features can be drawn, for the case where
27 * transparency allows 'see-through' of multiple feature colours
29 private BufferedImage offscreenImage;
36 public FeatureColourFinder(FeatureRenderer fr)
39 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
43 * Answers the feature colour to show for the given sequence and column
44 * position. This delegates to the FeatureRenderer to find the colour, which
45 * will depend on feature location, visibility, ordering, colour scheme, and
46 * whether or not transparency is applied. For feature rendering with
47 * transparency, this class provides a dummy 'offscreen' graphics context
48 * where multiple feature colours can be overlaid and the combined colour read
51 * This method is not thread-safe when transparency is applied, since a shared
52 * BufferedImage would be used by all threads to hold the composite colour at
53 * a position. Each thread should use a separate instance of this class.
55 * @param defaultColour
58 * alignment column position (base zero)
61 public Color findFeatureColour(Color defaultColour, SequenceI seq,
64 if (noFeaturesDisplayed())
72 * if transparency applies, provide a notional 1x1 graphics context
73 * that has been primed with the default colour
75 if (featureRenderer.getTransparency() != 1f)
77 g = offscreenImage.getGraphics();
78 if (defaultColour != null)
80 offscreenImage.setRGB(0, 0, defaultColour.getRGB());
84 Color c = featureRenderer.findFeatureColour(seq, column, g);
92 c = new Color(offscreenImage.getRGB(0, 0));
98 * Answers true if feature display is turned off, or there are no features
99 * configured to be visible
103 boolean noFeaturesDisplayed()
105 if (featureRenderer == null
106 || !featureRenderer.getViewport().isShowSequenceFeatures())
111 if (!((FeatureRendererModel) featureRenderer).hasRenderOrder())
116 FeaturesDisplayedI displayed = featureRenderer.getFeaturesDisplayed();
117 if (displayed == null || displayed.getVisibleFeatureCount() == 0)