From: gmungoc Date: Mon, 4 Mar 2019 10:54:27 +0000 (+0000) Subject: Merge branch 'bug/JAL-3120restoreFeatureColour' into merge/JAL-3120 X-Git-Tag: Release_2_11_0~17^2~80 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=3c8a25936a2d805e7e3d7ab82f83b13135406d18;hp=09d3b755d9b00f5c3acb44049aedd49361dc0690 Merge branch 'bug/JAL-3120restoreFeatureColour' into merge/JAL-3120 Conflicts: src/jalview/gui/Jalview2XML.java test/jalview/io/Jalview2xmlTests.java --- diff --git a/src/jalview/appletgui/FeatureColourChooser.java b/src/jalview/appletgui/FeatureColourChooser.java index d9eae11..5569ab0 100644 --- a/src/jalview/appletgui/FeatureColourChooser.java +++ b/src/jalview/appletgui/FeatureColourChooser.java @@ -134,7 +134,8 @@ public class FeatureColourChooser extends Panel implements ActionListener, if (oldcs.isGraduatedColour()) { threshline.value = oldcs.getThreshold(); - cs = new FeatureColour((FeatureColour) oldcs, min, max); + cs = new FeatureColour(oldcs.getColour(), oldcs.getMinColour(), + oldcs.getMaxColour(), oldcs.getNoColour(), min, max); } else { @@ -145,7 +146,8 @@ public class FeatureColourChooser extends Panel implements ActionListener, bl = oldcs.getColour(); } // original colour becomes the maximum colour - cs = new FeatureColour(Color.white, bl, mm[0], mm[1]); + cs = new FeatureColour(bl, Color.white, bl, Color.white, mm[0], + mm[1]); } minColour.setBackground(cs.getMinColour()); maxColour.setBackground(cs.getMaxColour()); @@ -411,8 +413,9 @@ public class FeatureColourChooser extends Panel implements ActionListener, slider.setEnabled(true); thresholdValue.setEnabled(true); - FeatureColour acg = new FeatureColour(minColour.getBackground(), - maxColour.getBackground(), min, max); + Color minc = minColour.getBackground(); + Color maxc = maxColour.getBackground(); + FeatureColour acg = new FeatureColour(maxc, minc, maxc, minc, min, max); acg.setColourByLabel(colourFromLabel.getState()); maxColour.setEnabled(!colourFromLabel.getState()); @@ -448,11 +451,15 @@ public class FeatureColourChooser extends Panel implements ActionListener, { if (thresholdOption == AnnotationColourGradient.ABOVE_THRESHOLD) { - acg = new FeatureColour(acg, threshline.value, max); + acg = new FeatureColour(acg.getColour(), acg.getMinColour(), + acg.getMaxColour(), acg.getNoColour(), threshline.value, + max); } else { - acg = new FeatureColour(acg, min, threshline.value); + acg = new FeatureColour(acg.getColour(), acg.getMinColour(), + acg.getMaxColour(), acg.getNoColour(), min, + threshline.value); } } diff --git a/src/jalview/gui/FeatureTypeSettings.java b/src/jalview/gui/FeatureTypeSettings.java index 58bbbe8..82e826f 100644 --- a/src/jalview/gui/FeatureTypeSettings.java +++ b/src/jalview/gui/FeatureTypeSettings.java @@ -562,13 +562,20 @@ public class FeatureTypeSettings extends JalviewDialog maxColour.setBorder(new LineBorder(Color.black)); /* - * default max colour to last plain colour; - * make min colour a pale version of max colour + * if not set, default max colour to last plain colour, + * and make min colour a pale version of max colour */ - FeatureColourI fc = fr.getFeatureColours().get(featureType); - Color bg = fc.getColour() == null ? Color.BLACK : fc.getColour(); - maxColour.setBackground(bg); - minColour.setBackground(ColorUtils.bleachColour(bg, 0.9f)); + Color max = originalColour.getMaxColour(); + if (max == null) + { + max = originalColour.getColour(); + minColour.setBackground(ColorUtils.bleachColour(max, 0.9f)); + } + else + { + maxColour.setBackground(max); + minColour.setBackground(originalColour.getMinColour()); + } noValueCombo = new JComboBox<>(); noValueCombo.addItem(MessageManager.getString("label.no_colour")); @@ -747,16 +754,16 @@ public class FeatureTypeSettings extends JalviewDialog singleColour.setFont(JvSwingUtils.getLabelFont()); singleColour.setBorder(BorderFactory.createLineBorder(Color.black)); singleColour.setPreferredSize(new Dimension(40, 20)); - if (originalColour.isGraduatedColour()) - { - singleColour.setBackground(originalColour.getMaxColour()); - singleColour.setForeground(originalColour.getMaxColour()); - } - else - { + // if (originalColour.isGraduatedColour()) + // { + // singleColour.setBackground(originalColour.getMaxColour()); + // singleColour.setForeground(originalColour.getMaxColour()); + // } + // else + // { singleColour.setBackground(originalColour.getColour()); singleColour.setForeground(originalColour.getColour()); - } + // } singleColour.addMouseListener(new MouseAdapter() { @Override @@ -881,42 +888,9 @@ public class FeatureTypeSettings extends JalviewDialog private FeatureColourI makeColourFromInputs() { /* - * easiest case - a single colour + * min-max range is to (or from) threshold value if + * 'threshold is min/max' is selected */ - if (simpleColour.isSelected()) - { - return new FeatureColour(singleColour.getBackground()); - } - - /* - * next easiest case - colour by Label, or attribute text - */ - if (byCategory.isSelected()) - { - Color c = singleColour.getBackground(); - FeatureColourI fc = new FeatureColour(c); - fc.setColourByLabel(true); - String byWhat = (String) colourByTextCombo.getSelectedItem(); - if (!LABEL_18N.equals(byWhat)) - { - fc.setAttributeName( - FeatureMatcher.fromAttributeDisplayName(byWhat)); - } - return fc; - } - - /* - * remaining case - graduated colour by score, or attribute value - */ - Color noColour = null; - if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION) - { - noColour = minColour.getBackground(); - } - else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION) - { - noColour = maxColour.getBackground(); - } float thresh = 0f; try @@ -926,11 +900,6 @@ public class FeatureTypeSettings extends JalviewDialog { // invalid inputs are already handled on entry } - - /* - * min-max range is to (or from) threshold value if - * 'threshold is min/max' is selected - */ float minValue = min; float maxValue = max; final int thresholdOption = threshold.getSelectedIndex(); @@ -944,14 +913,50 @@ public class FeatureTypeSettings extends JalviewDialog { maxValue = thresh; } + Color noColour = null; + if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION) + { + noColour = minColour.getBackground(); + } + else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION) + { + noColour = maxColour.getBackground(); + } + + /* + * construct a colour that 'remembers' all the options, including + * those not currently selected + */ + FeatureColourI fc = new FeatureColour(singleColour.getBackground(), + minColour.getBackground(), maxColour.getBackground(), noColour, + minValue, maxValue); + + /* + * easiest case - a single colour + */ + if (simpleColour.isSelected()) + { + ((FeatureColour) fc).setGraduatedColour(false); + return fc; + } /* - * make the graduated colour + * next easiest case - colour by Label, or attribute text */ - FeatureColourI fc = new FeatureColour(minColour.getBackground(), - maxColour.getBackground(), noColour, minValue, maxValue); + if (byCategory.isSelected()) + { + fc.setColourByLabel(true); + String byWhat = (String) colourByTextCombo.getSelectedItem(); + if (!LABEL_18N.equals(byWhat)) + { + fc.setAttributeName( + FeatureMatcher.fromAttributeDisplayName(byWhat)); + } + return fc; + } /* + * remaining case - graduated colour by score, or attribute value; * set attribute to colour by if selected */ String byWhat = (String) colourByRangeCombo.getSelectedItem(); diff --git a/src/jalview/project/Jalview2XML.java b/src/jalview/project/Jalview2XML.java index f772cf5..53e9a83 100644 --- a/src/jalview/project/Jalview2XML.java +++ b/src/jalview/project/Jalview2XML.java @@ -5067,7 +5067,8 @@ public class Jalview2XML float min = safeFloat(safeFloat(setting.getMin())); float max = setting.getMax() == null ? 1f : setting.getMax().floatValue(); - FeatureColourI gc = new FeatureColour(minColour, maxColour, + FeatureColourI gc = new FeatureColour(maxColour, minColour, + maxColour, noValueColour, min, max); if (setting.getAttributeName().size() > 0) { @@ -6562,7 +6563,7 @@ public class Jalview2XML noValueColour = maxcol; } - colour = new FeatureColour(mincol, maxcol, noValueColour, + colour = new FeatureColour(maxcol, mincol, maxcol, noValueColour, safeFloat(colourModel.getMin()), safeFloat(colourModel.getMax())); final List attributeName = colourModel.getAttributeName(); diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index f34478c..c73e32b 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -358,8 +358,8 @@ public class FeatureColour implements FeatureColourI Color maxColour = ColorUtils.parseColourString(maxcol); Color noColour = noValueColour.equals(NO_VALUE_MAX) ? maxColour : (noValueColour.equals(NO_VALUE_NONE) ? null : minColour); - featureColour = new FeatureColour(minColour, maxColour, noColour, min, - max); + featureColour = new FeatureColour(maxColour, minColour, maxColour, + noColour, min, max); featureColour.setColourByLabel(minColour == null); featureColour.setAutoScaled(autoScaled); if (byAttribute) @@ -429,36 +429,25 @@ public class FeatureColour implements FeatureColourI } /** - * Constructor given a simple colour + * Constructor given a simple colour. This also 'primes' a graduated colour + * range, where the maximum colour is the given simple colour, and the minimum + * colour a paler shade of it. This is for convenience when switching from a + * simple colour to a graduated colour scheme. * * @param c */ public FeatureColour(Color c) { - minColour = Color.WHITE; - maxColour = Color.BLACK; - noColour = DEFAULT_NO_COLOUR; - minRed = 0f; - minGreen = 0f; - minBlue = 0f; - deltaRed = 0f; - deltaGreen = 0f; - deltaBlue = 0f; - colour = c; - } + /* + * set max colour to the simple colour, min colour to a paler shade of it + */ + this(c, c == null ? Color.white : ColorUtils.bleachColour(c, 0.9f), + c == null ? Color.black : c, DEFAULT_NO_COLOUR, 0, 0); - /** - * Constructor given a colour range and a score range, defaulting 'no value - * colour' to be the same as minimum colour - * - * @param low - * @param high - * @param min - * @param max - */ - public FeatureColour(Color low, Color high, float min, float max) - { - this(low, high, low, min, max); + /* + * but enforce simple colour for now! + */ + setGraduatedColour(false); } /** @@ -491,29 +480,23 @@ public class FeatureColour implements FeatureColourI } /** - * Copy constructor with new min/max ranges - * - * @param fc - * @param min - * @param max - */ - public FeatureColour(FeatureColour fc, float min, float max) - { - this(fc); - updateBounds(min, max); - } - - /** - * Constructor for a graduated colour + * Constructor that sets both simple and graduated colour values. This allows + * alternative colour schemes to be 'preserved' while switching between them + * to explore their effects on the visualisation. + *

+ * This sets the colour scheme to 'graduated' by default. Override this if + * wanted by calling setGraduatedColour(false) for a simple + * colour, or setColourByLabel(true) for colour by label. * + * @param myColour * @param low * @param high * @param noValueColour * @param min * @param max */ - public FeatureColour(Color low, Color high, Color noValueColour, - float min, float max) + public FeatureColour(Color myColour, Color low, Color high, + Color noValueColour, float min, float max) { if (low == null) { @@ -523,10 +506,10 @@ public class FeatureColour implements FeatureColourI { high = Color.black; } - graduatedColour = true; - colour = null; + colour = myColour; minColour = low; maxColour = high; + setGraduatedColour(true); noColour = noValueColour; threshold = Float.NaN; isHighToLow = min >= max; @@ -558,7 +541,7 @@ public class FeatureColour implements FeatureColourI * Sets the 'graduated colour' flag. If true, also sets 'colour by label' to * false. */ - void setGraduatedColour(boolean b) + public void setGraduatedColour(boolean b) { graduatedColour = b; if (b) @@ -833,9 +816,20 @@ public class FeatureColour implements FeatureColourI sb.append(BAR).append(Format.getHexString(getMinColour())) .append(BAR); sb.append(Format.getHexString(getMaxColour())).append(BAR); - String noValue = minColour.equals(noColour) ? NO_VALUE_MIN - : (maxColour.equals(noColour) ? NO_VALUE_MAX - : NO_VALUE_NONE); + + /* + * 'no value' colour should be null, min or max colour; + * if none of these, coerce to minColour + */ + String noValue = NO_VALUE_MIN; + if (maxColour.equals(noColour)) + { + noValue = NO_VALUE_MAX; + } + if (noColour == null) + { + noValue = NO_VALUE_NONE; + } sb.append(noValue).append(BAR); if (!isAutoScaled()) { diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index 335529c..78c6da2 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -118,7 +118,10 @@ public class ConsensusThread extends AlignCalcWorker protected void eraseConsensus(int aWidth) { AlignmentAnnotation consensus = getConsensusAnnotation(); - consensus.annotations = new Annotation[aWidth]; + if (consensus != null) + { + consensus.annotations = new Annotation[aWidth]; + } AlignmentAnnotation gap = getGapAnnotation(); if (gap != null) { diff --git a/src/jalview/ws/jws2/AADisorderClient.java b/src/jalview/ws/jws2/AADisorderClient.java index 9a2316c..a1b8e7a 100644 --- a/src/jalview/ws/jws2/AADisorderClient.java +++ b/src/jalview/ws/jws2/AADisorderClient.java @@ -344,8 +344,9 @@ public class AADisorderClient extends JabawsCalcWorker { // set graduated color as fading to white for minimum, and // autoscaling to values on alignment - FeatureColourI ggc = new FeatureColour(Color.white, - gc.getColour(), Float.MIN_VALUE, Float.MAX_VALUE); + FeatureColourI ggc = new FeatureColour(gc.getColour(), + Color.white, gc.getColour(), Color.white, + Float.MIN_VALUE, Float.MAX_VALUE); ggc.setAutoScaled(true); fr.setColour(ft, ggc); } diff --git a/test/jalview/controller/AlignViewControllerTest.java b/test/jalview/controller/AlignViewControllerTest.java index efee93b..68b0b57 100644 --- a/test/jalview/controller/AlignViewControllerTest.java +++ b/test/jalview/controller/AlignViewControllerTest.java @@ -147,7 +147,8 @@ public class AlignViewControllerTest * seq1 feature in columns 4-6 is hidden * seq2 feature in columns 6-7 is shown */ - FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f); + FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null, + 0f, 10f); fc.setAboveThreshold(true); fc.setThreshold(5f); af.getFeatureRenderer().setColour("Metal", fc); diff --git a/test/jalview/gui/AlignFrameTest.java b/test/jalview/gui/AlignFrameTest.java index f13a877..454ff61 100644 --- a/test/jalview/gui/AlignFrameTest.java +++ b/test/jalview/gui/AlignFrameTest.java @@ -119,7 +119,8 @@ public class AlignFrameTest * seq1 feature in columns 1-5 is hidden * seq2 feature in columns 6-10 is shown */ - FeatureColourI fc = new FeatureColour(Color.red, Color.blue, 0f, 10f); + FeatureColourI fc = new FeatureColour(null, Color.red, Color.blue, null, + 0f, 10f); fc.setAboveThreshold(true); fc.setThreshold(5f); alignFrame.getFeatureRenderer().setColour("Metal", fc); diff --git a/test/jalview/gui/FeatureSettingsTest.java b/test/jalview/gui/FeatureSettingsTest.java index 6ddebf8..29c3e56 100644 --- a/test/jalview/gui/FeatureSettingsTest.java +++ b/test/jalview/gui/FeatureSettingsTest.java @@ -60,8 +60,8 @@ public class FeatureSettingsTest fr.setColour("type2", byLabel); // type3: by score above threshold - FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1, - 10); + FeatureColourI byScore = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byScore.setAboveThreshold(true); byScore.setThreshold(2f); fr.setColour("type3", byScore); @@ -73,8 +73,8 @@ public class FeatureSettingsTest fr.setColour("type4", byAF); // type5: by attribute CSQ:PolyPhen below threshold - FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE, - 1, 10); + FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byPolyPhen.setBelowThreshold(true); byPolyPhen.setThreshold(3f); byPolyPhen.setAttributeName("CSQ", "PolyPhen"); diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index 3632cc7..77c18db 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -779,7 +779,7 @@ public class FeaturesFileTest /* * now threshold to Score > 1.1 - should exclude sf2 */ - FeatureColourI fc = new FeatureColour(Color.white, Color.BLACK, + FeatureColourI fc = new FeatureColour(null, Color.white, Color.BLACK, Color.white, 0f, 2f); fc.setAboveThreshold(true); fc.setThreshold(1.1f); @@ -855,7 +855,7 @@ public class FeaturesFileTest * now threshold to Score > 1.1 - should exclude sf2 * (and there should be no empty STARTGROUP/ENDGROUP output) */ - FeatureColourI fc = new FeatureColour(Color.white, Color.BLACK, + FeatureColourI fc = new FeatureColour(null, Color.white, Color.BLACK, Color.white, 0f, 2f); fc.setAboveThreshold(true); fc.setThreshold(1.1f); diff --git a/test/jalview/io/SequenceAnnotationReportTest.java b/test/jalview/io/SequenceAnnotationReportTest.java index 87e35c7..cf3c7e5 100644 --- a/test/jalview/io/SequenceAnnotationReportTest.java +++ b/test/jalview/io/SequenceAnnotationReportTest.java @@ -37,11 +37,11 @@ import jalview.viewmodel.seqfeatures.FeatureRendererModel; import java.awt.Color; import java.util.Map; -import junit.extensions.PA; - import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import junit.extensions.PA; + public class SequenceAnnotationReportTest { @@ -158,7 +158,8 @@ public class SequenceAnnotationReportTest /* * then with colour by an attribute the feature lacks */ - FeatureColourI fc = new FeatureColour(Color.white, Color.black, 5, 10); + FeatureColourI fc = new FeatureColour(null, Color.white, Color.black, + null, 5, 10); fc.setAttributeName("Pfam"); fr.setColour("METAL", fc); sb.setLength(0); @@ -187,7 +188,8 @@ public class SequenceAnnotationReportTest FeatureRendererModel fr = new FeatureRenderer(null); Map minmax = fr.getMinMax(); - FeatureColourI fc = new FeatureColour(Color.white, Color.blue, 12, 22); + FeatureColourI fc = new FeatureColour(null, Color.white, Color.blue, + null, 12, 22); fc.setAttributeName("clinical_significance"); fr.setColour("METAL", fc); minmax.put("METAL", new float[][] { { 0f, 1f }, null }); @@ -328,7 +330,8 @@ public class SequenceAnnotationReportTest // with showDbRefs = true, colour Variant features by clinical_significance sb.setLength(0); - FeatureColourI fc = new FeatureColour(Color.green, Color.pink, 2, 3); + FeatureColourI fc = new FeatureColour(null, Color.green, Color.pink, + null, 2, 3); fc.setAttributeName("clinical_significance"); fr.setColour("Variant", fc); sar.createSequenceAnnotationReport(sb, seq, true, true, fr); diff --git a/test/jalview/project/Jalview2xmlTests.java b/test/jalview/project/Jalview2xmlTests.java index d6df39a..afc445e 100644 --- a/test/jalview/project/Jalview2xmlTests.java +++ b/test/jalview/project/Jalview2xmlTests.java @@ -930,8 +930,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase fr.setColour("type2", byLabel); // type3: by score above threshold - FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1, - 10); + FeatureColourI byScore = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byScore.setAboveThreshold(true); byScore.setThreshold(2f); fr.setColour("type3", byScore); @@ -943,8 +943,8 @@ public class Jalview2xmlTests extends Jalview2xmlBase fr.setColour("type4", byAF); // type5: by attribute CSQ:PolyPhen below threshold - FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE, - 1, 10); + FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byPolyPhen.setBelowThreshold(true); byPolyPhen.setThreshold(3f); byPolyPhen.setAttributeName("CSQ", "PolyPhen"); diff --git a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java index d8b905e..af7c2ed 100644 --- a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java @@ -323,7 +323,7 @@ public class FeatureColourFinderTest */ Color min = new Color(100, 50, 150); Color max = new Color(200, 0, 100); - FeatureColourI fc = new FeatureColour(min, max, 0, 10); + FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10); fr.setColour("kd", fc); fr.featuresAdded(); av.setShowSequenceFeatures(true); @@ -493,7 +493,7 @@ public class FeatureColourFinderTest */ Color min = new Color(100, 50, 150); Color max = new Color(200, 0, 100); - FeatureColourI fc = new FeatureColour(min, max, 0, 10); + FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10); fc.setAboveThreshold(true); fc.setThreshold(5f); fr.setColour(kdFeature, fc); diff --git a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java index a0fb498..723f3b8 100644 --- a/test/jalview/renderer/seqfeatures/FeatureRendererTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureRendererTest.java @@ -285,8 +285,8 @@ public class FeatureRendererTest * give "Type3" features a graduated colour scheme * - first with no threshold */ - FeatureColourI gc = new FeatureColour(Color.yellow, Color.red, null, 0f, - 10f); + FeatureColourI gc = new FeatureColour(Color.green, Color.yellow, + Color.red, null, 0f, 10f); fr.getFeatureColours().put("Type3", gc); features = fr.findFeaturesAtColumn(seq, 8); assertTrue(features.contains(sf4)); @@ -428,8 +428,8 @@ public class FeatureRendererTest * graduated colour by score, no threshold, no score * */ - FeatureColourI gc = new FeatureColour(Color.yellow, Color.red, - Color.green, 1f, 11f); + FeatureColourI gc = new FeatureColour(Color.red, Color.yellow, + Color.red, Color.green, 1f, 11f); fr.getFeatureColours().put("Cath", gc); assertEquals(fr.getColour(sf1), Color.green); @@ -453,7 +453,8 @@ public class FeatureRendererTest * threshold is min-max; now score 6 is 1/6 of the way from 5 to 11 * or from yellow(255, 255, 0) to red(255, 0, 0) */ - gc = new FeatureColour(Color.yellow, Color.red, Color.green, 5f, 11f); + gc = new FeatureColour(Color.red, Color.yellow, Color.red, Color.green, + 5f, 11f); fr.getFeatureColours().put("Cath", gc); gc.setAutoScaled(false); // this does little other than save a checkbox setting! assertEquals(fr.getColour(sf2), new Color(255, 213, 0)); @@ -476,7 +477,8 @@ public class FeatureRendererTest * colour by feature attribute value * first with no value held */ - gc = new FeatureColour(Color.yellow, Color.red, Color.green, 1f, 11f); + gc = new FeatureColour(Color.red, Color.yellow, Color.red, Color.green, + 1f, 11f); fr.getFeatureColours().put("Cath", gc); gc.setAttributeName("AF"); assertEquals(fr.getColour(sf2), Color.green); @@ -574,7 +576,7 @@ public class FeatureRendererTest /* * feature score outwith colour threshold (score > 2) */ - FeatureColourI fc = new FeatureColour(Color.white, Color.black, + FeatureColourI fc = new FeatureColour(null, Color.white, Color.black, Color.white, 0, 10); fc.setAboveThreshold(true); fc.setThreshold(2f); diff --git a/test/jalview/schemes/FeatureColourTest.java b/test/jalview/schemes/FeatureColourTest.java index 6ccce85..8f7ac7c 100644 --- a/test/jalview/schemes/FeatureColourTest.java +++ b/test/jalview/schemes/FeatureColourTest.java @@ -38,8 +38,6 @@ import java.awt.Color; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; -import junit.extensions.PA; - public class FeatureColourTest { @@ -51,6 +49,30 @@ public class FeatureColourTest } @Test(groups = { "Functional" }) + public void testConstructors() + { + FeatureColourI fc = new FeatureColour(); + assertNull(fc.getColour()); + assertTrue(fc.isSimpleColour()); + assertFalse(fc.isColourByLabel()); + assertFalse(fc.isGraduatedColour()); + assertFalse(fc.isColourByAttribute()); + assertEquals(Color.white, fc.getMinColour()); + assertEquals(Color.black, fc.getMaxColour()); + + fc = new FeatureColour(Color.RED); + assertEquals(Color.red, fc.getColour()); + assertTrue(fc.isSimpleColour()); + assertFalse(fc.isColourByLabel()); + assertFalse(fc.isGraduatedColour()); + assertFalse(fc.isColourByAttribute()); + assertEquals(ColorUtils.bleachColour(Color.RED, 0.9f), + fc.getMinColour()); + assertEquals(Color.RED, fc.getMaxColour()); + + } + + @Test(groups = { "Functional" }) public void testCopyConstructor() { /* @@ -67,7 +89,8 @@ public class FeatureColourTest /* * min-max colour */ - fc = new FeatureColour(Color.gray, Color.black, 10f, 20f); + fc = new FeatureColour(null, Color.gray, Color.black, Color.gray, 10f, + 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc1 = new FeatureColour(fc); @@ -86,12 +109,14 @@ public class FeatureColourTest /* * min-max-noValue colour */ - fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); + fc = new FeatureColour(Color.red, Color.gray, Color.black, Color.green, + 10f, 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc1 = new FeatureColour(fc); assertTrue(fc1.isGraduatedColour()); assertFalse(fc1.isColourByLabel()); + assertFalse(fc1.isSimpleColour()); assertFalse(fc1.isColourByAttribute()); assertNull(fc1.getAttributeName()); assertTrue(fc1.isAboveThreshold()); @@ -99,6 +124,7 @@ public class FeatureColourTest assertEquals(Color.gray, fc1.getMinColour()); assertEquals(Color.black, fc1.getMaxColour()); assertEquals(Color.green, fc1.getNoColour()); + assertEquals(Color.red, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); @@ -128,7 +154,8 @@ public class FeatureColourTest /* * colour by attribute (value) */ - fc = new FeatureColour(Color.gray, Color.black, Color.green, 10f, 20f); + fc = new FeatureColour(Color.yellow, Color.gray, Color.black, + Color.green, 10f, 20f); fc.setAboveThreshold(true); fc.setThreshold(12f); fc.setAttributeName("AF"); @@ -136,104 +163,19 @@ public class FeatureColourTest assertTrue(fc1.isGraduatedColour()); assertFalse(fc1.isColourByLabel()); assertTrue(fc1.isColourByAttribute()); + assertFalse(fc1.isSimpleColour()); assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); assertTrue(fc1.isAboveThreshold()); assertEquals(12f, fc1.getThreshold()); assertEquals(Color.gray, fc1.getMinColour()); assertEquals(Color.black, fc1.getMaxColour()); assertEquals(Color.green, fc1.getNoColour()); + assertEquals(Color.yellow, fc1.getColour()); assertEquals(10f, fc1.getMin()); assertEquals(20f, fc1.getMax()); } @Test(groups = { "Functional" }) - public void testCopyConstructor_minMax() - { - /* - * graduated colour - */ - FeatureColour fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); - assertTrue(fc.isGraduatedColour()); - assertFalse(fc.isColourByLabel()); - assertFalse(fc.isColourByAttribute()); - assertNull(fc.getAttributeName()); - assertEquals(1f, fc.getMin()); - assertEquals(5f, fc.getMax()); - - /* - * update min-max bounds - */ - FeatureColour fc1 = new FeatureColour(fc, 2f, 6f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(2f, fc1.getMin()); - assertEquals(6f, fc1.getMax()); - assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * update min-max bounds - high to low - */ - fc1 = new FeatureColour(fc, 23f, 16f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(23f, fc1.getMin()); - assertEquals(16f, fc1.getMax()); - assertTrue((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * graduated colour by attribute - */ - fc1.setAttributeName("AF"); - fc1 = new FeatureColour(fc1, 13f, 36f); - assertTrue(fc1.isGraduatedColour()); - assertFalse(fc1.isColourByLabel()); - assertTrue(fc1.isColourByAttribute()); - assertArrayEquals(new String[] { "AF" }, fc1.getAttributeName()); - assertEquals(13f, fc1.getMin()); - assertEquals(36f, fc1.getMax()); - assertFalse((boolean) PA.getValue(fc1, "isHighToLow")); - - /* - * colour by label - */ - fc = new FeatureColour(Color.BLUE, Color.RED, 1f, 5f); - fc.setColourByLabel(true); - assertFalse(fc.isGraduatedColour()); - assertTrue(fc.isColourByLabel()); - assertFalse(fc.isColourByAttribute()); - assertNull(fc.getAttributeName()); - assertEquals(1f, fc.getMin()); - assertEquals(5f, fc.getMax()); - - /* - * update min-max bounds - */ - fc1 = new FeatureColour(fc, 2f, 6f); - assertFalse(fc1.isGraduatedColour()); - assertTrue(fc1.isColourByLabel()); - assertFalse(fc1.isColourByAttribute()); - assertNull(fc1.getAttributeName()); - assertEquals(2f, fc1.getMin()); - assertEquals(6f, fc1.getMax()); - - /* - * colour by attribute text - */ - fc1.setAttributeName("AC"); - fc1 = new FeatureColour(fc1, 13f, 36f); - assertFalse(fc1.isGraduatedColour()); - assertTrue(fc1.isColourByLabel()); - assertTrue(fc1.isColourByAttribute()); - assertArrayEquals(new String[] { "AC" }, fc1.getAttributeName()); - assertEquals(13f, fc1.getMin()); - assertEquals(36f, fc1.getMax()); - } - - @Test(groups = { "Functional" }) public void testGetColor_simpleColour() { FeatureColour fc = new FeatureColour(Color.RED); @@ -260,7 +202,8 @@ public class FeatureColourTest * score 0 to 100 * gray(128, 128, 128) to red(255, 0, 0) */ - FeatureColour fc = new FeatureColour(Color.GRAY, Color.RED, 0f, 100f); + FeatureColour fc = new FeatureColour(null, Color.GRAY, Color.RED, null, + 0f, 100f); // feature score is 75 which is 3/4 of the way from GRAY to RED SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 75f, null); @@ -276,8 +219,8 @@ public class FeatureColourTest public void testGetColor_aboveBelowThreshold() { // gradient from [50, 150] from WHITE(255, 255, 255) to BLACK(0, 0, 0) - FeatureColour fc = new FeatureColour(Color.WHITE, Color.BLACK, 50f, - 150f); + FeatureColour fc = new FeatureColour(null, Color.WHITE, Color.BLACK, + Color.white, 50f, 150f); SequenceFeature sf = new SequenceFeature("type", "desc", 0, 20, 70f, null); @@ -371,7 +314,8 @@ public class FeatureColourTest * graduated colour by score, no threshold * - default constructor sets noValueColor = minColor */ - fc = new FeatureColour(Color.GREEN, Color.RED, 12f, 25f); + fc = new FeatureColour(null, Color.GREEN, Color.RED, Color.GREEN, 12f, + 25f); String greenHex = Format.getHexString(Color.GREEN); String expected = String.format( "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, @@ -381,7 +325,8 @@ public class FeatureColourTest /* * graduated colour by score, no threshold, no value gets min colour */ - fc = new FeatureColour(Color.GREEN, Color.RED, Color.GREEN, 12f, 25f); + fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.GREEN, + 12f, 25f); expected = String.format( "domain\tscore|%s|%s|noValueMin|abso|12.0|25.0|none", greenHex, redHex); @@ -390,7 +335,8 @@ public class FeatureColourTest /* * graduated colour by score, no threshold, no value gets max colour */ - fc = new FeatureColour(Color.GREEN, Color.RED, Color.RED, 12f, 25f); + fc = new FeatureColour(Color.RED, Color.GREEN, Color.RED, Color.RED, + 12f, 25f); expected = String.format( "domain\tscore|%s|%s|noValueMax|abso|12.0|25.0|none", greenHex, redHex); @@ -687,8 +633,9 @@ public class FeatureColourTest * graduated colour based on attribute value for AF * given a min-max range of 0-100 */ - FeatureColour fc = new FeatureColour(new Color(50, 100, 150), - new Color(150, 200, 250), Color.yellow, 0f, 100f); + FeatureColour fc = new FeatureColour(Color.white, + new Color(50, 100, 150), new Color(150, 200, 250), Color.yellow, + 0f, 100f); String attName = "AF"; fc.setAttributeName(attName); @@ -721,7 +668,8 @@ public class FeatureColourTest assertFalse(fc.isOutwithThreshold(null)); assertFalse(fc.isOutwithThreshold(sf)); - fc = new FeatureColour(Color.white, Color.black, Color.green, 0f, 10f); + fc = new FeatureColour(null, Color.white, Color.black, Color.green, 0f, + 10f); assertFalse(fc.isOutwithThreshold(sf)); // no threshold fc.setAboveThreshold(true);