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, colour scheme, and
45 * whether or not transparency is applied. For feature rendering with
46 * transparency, this class provides a dummy 'offscreen' graphics context
47 * where multiple feature colours can be overlaid and the combined colour read
50 * @param defaultColour
53 * alignment column position (base zero)
56 public Color findFeatureColour(Color defaultColour, SequenceI seq,
59 if (!((FeatureRendererModel) featureRenderer).hasRenderOrder())
64 FeaturesDisplayedI displayed = featureRenderer.getFeaturesDisplayed();
65 if (displayed == null || displayed.getVisibleFeatureCount() == 0)
67 return defaultColour; // nothing to see here folks
73 * if transparency applies, get colours drawn to a 1x1 pixel
74 * graphics context that has been primed with the default colour
76 if (featureRenderer.getTransparency() != 1f)
78 g = offscreenImage.getGraphics();
79 offscreenImage.setRGB(0, 0, defaultColour.getRGB());
82 Color c = featureRenderer.findFeatureColour(seq, column, g);
84 if (c != null && g != null)
86 c = new Color(offscreenImage.getRGB(0, 0));
88 return c == null ? defaultColour : c;