From 616c019f37a4adb252ec733841dafeee4cc61fab Mon Sep 17 00:00:00 2001 From: tjc <tjc@ee4ac58c-ac51-4696-9907-e4b3aa274f04> Date: Tue, 7 Jul 2009 14:36:56 +0000 Subject: [PATCH] add parse() to parse a string representation of a color git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@11330 ee4ac58c-ac51-4696-9907-e4b3aa274f04 --- uk/ac/sanger/artemis/plot/LineAttributes.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/uk/ac/sanger/artemis/plot/LineAttributes.java b/uk/ac/sanger/artemis/plot/LineAttributes.java index 13d400854..a04f29ca8 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 -- GitLab