From: gmungoc Date: Tue, 14 Mar 2017 15:07:19 +0000 (+0000) Subject: JAL-2438 unit test, fixes, Javadoc updates X-Git-Tag: Release_2_10_2~3^2~161 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=846f3f1ad573cad309d41356af68887a4a3348eb JAL-2438 unit test, fixes, Javadoc updates --- diff --git a/src/jalview/api/FeatureRenderer.java b/src/jalview/api/FeatureRenderer.java index 3565488..839119d 100644 --- a/src/jalview/api/FeatureRenderer.java +++ b/src/jalview/api/FeatureRenderer.java @@ -38,17 +38,24 @@ public interface FeatureRenderer { /** - * compute the perceived colour for a given column position in sequenceI, - * taking transparency and feature visibility into account. + * Returns the combined feature colour for a given sequence and column + * position, taking into account feature colour schemes, ordering, feature and + * feature group visibility, and transparency. Returns null if there is no + * visible feature at the position. + *

+ * The Graphics argument is optional and may be null if no transparency is + * applied. With feature transparency, visible features are written to the + * graphics context and the composite colour can be read off. + *

+ * This is provided for use by Structure Viewers and the Overview Window to + * get the feature colour of the rendered sequence. * - * @param sequenceI - * - sequence providing features - * @param r - * - column position + * @param sequence + * @param column * @param g * @return */ - Color findFeatureColour(SequenceI sequenceI, int r, Graphics g); + Color findFeatureColour(SequenceI sequence, int column, Graphics g); /** * trigger the feature discovery process for a newly created feature renderer. diff --git a/src/jalview/renderer/seqfeatures/FeatureColourFinder.java b/src/jalview/renderer/seqfeatures/FeatureColourFinder.java index 761f418..9a1ecf9 100644 --- a/src/jalview/renderer/seqfeatures/FeatureColourFinder.java +++ b/src/jalview/renderer/seqfeatures/FeatureColourFinder.java @@ -67,10 +67,20 @@ public class FeatureColourFinder return defaultColour; // nothing to see here folks } - Graphics g = featureRenderer.getTransparency() == 1f ? null - : offscreenImage.getGraphics(); + Graphics g = null; + + /* + * if transparency applies, get colours drawn to a 1x1 pixel + * graphics context that has been primed with the default colour + */ + if (featureRenderer.getTransparency() != 1f) + { + g = offscreenImage.getGraphics(); + offscreenImage.setRGB(0, 0, defaultColour.getRGB()); + } Color c = featureRenderer.findFeatureColour(seq, column, g); + if (c != null && g != null) { c = new Color(offscreenImage.getRGB(0, 0)); diff --git a/src/jalview/renderer/seqfeatures/FeatureRenderer.java b/src/jalview/renderer/seqfeatures/FeatureRenderer.java index f826a88..49b98a5 100644 --- a/src/jalview/renderer/seqfeatures/FeatureRenderer.java +++ b/src/jalview/renderer/seqfeatures/FeatureRenderer.java @@ -210,12 +210,7 @@ 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 seq - * @param column - * @return + * {@inheritDoc} */ @Override public Color findFeatureColour(SequenceI seq, int column, Graphics g) @@ -271,15 +266,17 @@ public class FeatureRenderer extends FeatureRendererModel /** * 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 diff --git a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java index 6074e85..127b6c2 100644 --- a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java @@ -327,10 +327,12 @@ public class FeatureColourFinderTest /* * the FeatureSettings transparency slider has range 0-70 which * corresponds to a transparency value of 1 - 0.3 + * A value of 0.4 gives a combination of + * 0.4 * red(255, 0, 0) + 0.6 * cyan(0, 255, 255) = (102, 153, 153) */ - fr.setTransparency(0.5f); - Color c = finder.findFeatureColour(Color.blue, seq, 10); - assertEquals(c, new Color(85, 170, 0)); + fr.setTransparency(0.4f); + Color c = finder.findFeatureColour(Color.cyan, seq, 10); + assertEquals(c, new Color(102, 153, 153)); } @Test(groups = "Functional") @@ -349,30 +351,37 @@ public class FeatureColourFinderTest av.setShowSequenceFeatures(true); /* - * Domain (green(0, 255, 0)) rendered above Metal (red(255, 0, 0)) + * Domain (green) rendered above Metal (red) above background (cyan) + * 1) 0.6 * red(255, 0, 0) + 0.4 * cyan(0, 255, 255) = (153, 102, 102) + * 2) 0.6* green(0, 255, 0) + 0.4 * (153, 102, 102) = (61, 194, 41) rounded */ - fr.setTransparency(0.5f); - Color c = finder.findFeatureColour(Color.blue, seq, 10); - assertEquals(c, new Color(85, 170, 0)); + fr.setTransparency(0.6f); + Color c = finder.findFeatureColour(Color.cyan, seq, 10); + assertEquals(c, new Color(61, 194, 41)); /* * now promote Metal above Domain * - currently no way other than mimicking reordering of * table in Feature Settings + * Metal (red) rendered above Domain (green) above background (cyan) + * 1) 0.6 * green(0, 255, 0) + 0.4 * cyan(0, 255, 255) = (0, 255, 102) + * 2) 0.6* red(255, 0, 0) + 0.4 * (0, 255, 102) = (153, 102, 41) rounded */ Object[][] data = new Object[2][]; data[0] = new Object[] { "Metal", red, true }; data[1] = new Object[] { "Domain", green, true }; fr.setFeaturePriority(data); - c = finder.findFeatureColour(Color.blue, seq, 10); - assertEquals(c, new Color(153, 102, 0)); + c = finder.findFeatureColour(Color.cyan, seq, 10); + assertEquals(c, new Color(153, 102, 41)); /* * ..and turn off display of Metal + * Domain (green) above background (pink) + * 0.6 * green(0, 255, 0) + 0.4 * pink(255, 175, 175) = (102, 223, 70) */ data[0][2] = false; fr.setFeaturePriority(data); - c = finder.findFeatureColour(Color.blue, seq, 10); - assertEquals(c, Color.green); + c = finder.findFeatureColour(Color.pink, seq, 10); + assertEquals(c, new Color(102, 223, 70)); } }