1 package jalview.renderer.seqfeatures;
3 import jalview.api.FeaturesDisplayedI;
4 import jalview.datamodel.SequenceI;
5 import jalview.viewmodel.seqfeatures.FeatureRendererModel;
8 import java.awt.Graphics;
9 import java.awt.image.BufferedImage;
12 * A helper class to find feature colour using an associated FeatureRenderer
17 public class FeatureColourFinder
20 * the class we delegate feature finding to
22 private jalview.api.FeatureRenderer featureRenderer;
25 * a 1-pixel image on which features can be drawn, for the case where
26 * transparency allows 'see-through' of multiple feature colours
28 private BufferedImage offscreenImage;
35 public FeatureColourFinder(jalview.api.FeatureRenderer fr)
38 offscreenImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
42 * Answers the feature colour to show for the given sequence and column
43 * position. This delegates to the FeatureRenderer to find the colour, which
44 * will depend on feature location, visibility, ordering, and whether or not
45 * transparency is applied. For feature rendering with transparency, this
46 * class provides a dummy 'offscreen' graphics context where multiple feature
47 * colours can be overlaid and the combined colour read back.
49 * @param defaultColour
54 public Color findFeatureColour(Color defaultColour, SequenceI seq,
57 if (!((FeatureRendererModel) featureRenderer).hasRenderOrder())
62 FeaturesDisplayedI displayed = featureRenderer.getFeaturesDisplayed();
63 if (displayed == null || displayed.getVisibleFeatureCount() == 0)
65 return defaultColour; // nothing to see here folks
68 Graphics g = featureRenderer.getTransparency() == 1f ? null
69 : offscreenImage.getGraphics();
71 Color c = featureRenderer.findFeatureColour(seq, column, g);
72 if (c != null && g != null)
74 c = new Color(offscreenImage.getRGB(0, 0));
76 return c == null ? defaultColour : c;