From: gmungoc Date: Fri, 6 Jan 2017 14:10:44 +0000 (+0000) Subject: JAL-2360 findColour() with no args removed from ColourSchemeI X-Git-Tag: Release_2_10_3b1~357^2~16^2~1 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;ds=sidebyside;h=dfd021096780038aa9389ed96f6ce938244f95c4;p=jalview.git JAL-2360 findColour() with no args removed from ColourSchemeI --- diff --git a/src/jalview/io/AnnotationFile.java b/src/jalview/io/AnnotationFile.java index 2af3fcd..ae34f6b 100755 --- a/src/jalview/io/AnnotationFile.java +++ b/src/jalview/io/AnnotationFile.java @@ -32,7 +32,6 @@ import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; import jalview.schemes.ColourSchemeI; import jalview.schemes.ColourSchemeProperty; -import jalview.schemes.UserColourScheme; import jalview.util.ColorUtils; import java.awt.Color; @@ -1677,9 +1676,8 @@ public class AnnotationFile } else if (key.equalsIgnoreCase("idColour")) { - // consider warning if colour doesn't resolve to a real colour - def = new UserColourScheme(value); - sg.setIdColour(def.findColour()); + Color idColour = ColorUtils.parseColourString(value); + sg.setIdColour(idColour == null ? Color.black : idColour); } else if (key.equalsIgnoreCase("hide")) { diff --git a/src/jalview/schemes/ColourSchemeI.java b/src/jalview/schemes/ColourSchemeI.java index 372b569..64248c5 100755 --- a/src/jalview/schemes/ColourSchemeI.java +++ b/src/jalview/schemes/ColourSchemeI.java @@ -32,14 +32,6 @@ import java.util.Map; public interface ColourSchemeI { /** - * Returns the fixed colour for the colour scheme. For use when the colour - * does not vary. - * - * @return - */ - Color findColour(); - - /** * Returns the colour for the given character. For use when the colour depends * only on the symbol. * diff --git a/src/jalview/schemes/FeatureColour.java b/src/jalview/schemes/FeatureColour.java index 70897de..dbe4901 100644 --- a/src/jalview/schemes/FeatureColour.java +++ b/src/jalview/schemes/FeatureColour.java @@ -213,9 +213,9 @@ public class FeatureColour implements FeatureColourI FeatureColour featureColour; try { - featureColour = new FeatureColour( - new UserColourScheme(mincol).findColour(), - new UserColourScheme(maxcol).findColour(), min, max); + Color minColour = ColorUtils.parseColourString(mincol); + Color maxColour = ColorUtils.parseColourString(maxcol); + featureColour = new FeatureColour(minColour, maxColour, min, max); featureColour.setColourByLabel(labelColour); featureColour.setAutoScaled(autoScaled); // add in any additional parameters @@ -307,6 +307,14 @@ public class FeatureColour implements FeatureColourI */ public FeatureColour(Color low, Color high, float min, float max) { + if (low == null) + { + low = Color.white; + } + if (high == null) + { + high = Color.black; + } graduatedColour = true; colour = null; minColour = low; diff --git a/src/jalview/schemes/ResidueColourScheme.java b/src/jalview/schemes/ResidueColourScheme.java index 7dbcced..217786a 100755 --- a/src/jalview/schemes/ResidueColourScheme.java +++ b/src/jalview/schemes/ResidueColourScheme.java @@ -112,17 +112,6 @@ public abstract class ResidueColourScheme implements ColourSchemeI } /** - * Returns the colour for symbol 'A'. Intended for use in a 'fixed colour' - * colour scheme (for example a feature colour). - */ - @Override - public Color findColour() - { - // TODO delete this method in favour of ColorUtils.parseColourString()? - return findColour('A'); - } - - /** * Find a colour without an index in a sequence */ @Override diff --git a/src/jalview/util/ColorUtils.java b/src/jalview/util/ColorUtils.java index 55db824..d7829df 100644 --- a/src/jalview/util/ColorUtils.java +++ b/src/jalview/util/ColorUtils.java @@ -256,11 +256,15 @@ public class ColorUtils */ public static Color createColourFromName(String name) { + if (name == null) + { + return Color.white; + } int lsize = name.length(); int start = 0; int end = lsize / 3; - int rgbOffset = Math.abs(name.hashCode() % 10) * 15; + int rgbOffset = Math.abs(name.hashCode() % 10) * 15; // 0-135 /* * red: first third diff --git a/test/jalview/util/ColorUtilsTest.java b/test/jalview/util/ColorUtilsTest.java index 77eab16..d267ebc 100644 --- a/test/jalview/util/ColorUtilsTest.java +++ b/test/jalview/util/ColorUtilsTest.java @@ -224,4 +224,21 @@ public class ColorUtilsTest assertNull(ColorUtils.getAWTColorFromName("")); assertNull(ColorUtils.getAWTColorFromName(null)); } + + @Test(groups = "Functional") + public void testCreateColourFromName() + { + assertEquals(Color.white, ColorUtils.createColourFromName(null)); + assertEquals(new Color(20, 20, 20), ColorUtils.createColourFromName("")); + assertEquals(new Color(123, 211, 122), + ColorUtils.createColourFromName("hello world")); + assertEquals(new Color(27, 147, 112), + ColorUtils.createColourFromName("HELLO WORLD")); + /* + * the algorithm makes the same values for r,g,b if + * the string consists of 3 repeating substrings + */ + assertEquals(new Color(184, 184, 184), + ColorUtils.createColourFromName("HELLO HELLO HELLO ")); + } }