import jalview.datamodel.SequenceI;
import jalview.schemes.ColourSchemeI;
import jalview.schemes.ColourSchemeProperty;
-import jalview.schemes.UserColourScheme;
import jalview.util.ColorUtils;
import java.awt.Color;
}
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"))
{
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.
*
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
*/
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;
}
/**
- * 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
*/
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
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 "));
+ }
}