diff --git a/uk/ac/sanger/artemis/plot/LineAttributes.java b/uk/ac/sanger/artemis/plot/LineAttributes.java index 13d400854bc27bb06b0291c88347891d1cf596b4..a04f29ca86bb83167391383290eedb20c709969e 100644 --- a/uk/ac/sanger/artemis/plot/LineAttributes.java +++ b/uk/ac/sanger/artemis/plot/LineAttributes.java @@ -163,6 +163,33 @@ public class LineAttributes return lines; } + /** + * From a string representation of a colour return the + * corresponding <code>Color</code>. + * @param colourStr the string to parse + * @return + */ + public static Color parse(String colourStr) + { + if(colourStr.indexOf(":") > -1) + { + String colourStrs[] = colourStr.split(":"); + return new Color(Integer.parseInt(colourStrs[0]), + Integer.parseInt(colourStrs[1]), + Integer.parseInt(colourStrs[2])); + } + + if ( colourStr.startsWith("#") ) + colourStr = colourStr.substring(1); + + colourStr = colourStr.toLowerCase(); + if (colourStr.length() > 6) + throw new NumberFormatException("not a 24 bit representation of the color"); + + Color color = new Color( Integer.parseInt( colourStr , 16 ) ); + return color; + } + /** * Utility used by uk.ac.sanger.artemis.components.Plot * @param numPlots