public static Color parseColour(String col) {
if (col == null) return null;
if (col.equals("black")) return Color.black;
else if (col.equals("blue")) return Color.blue;
else if (col.equals("cyan")) return Color.cyan;
else if (col.equals("darkGray")) return Color.darkGray;
else if (col.equals("gray")) return Color.gray;
else if (col.equals("green")) return Color.green;
else if (col.equals("lightGray")) return Color.lightGray;
else if (col.equals("magenta")) return Color.magenta;
else if (col.equals("orange")) return Color.orange;
else if (col.equals("pink")) return Color.pink;
else if (col.equals("red")) return Color.red;
else if (col.equals("white")) return Color.white;
else if (col.equals("yellow")) return Color.yellow;
Color c = Color.getColor(col);
if (c != null) return c;
if (col.startsWith("#")) {
col = col.substring(1);
}
if (col.length() != 6) return null;
try {
int r = Integer.parseInt(col.substring(0,2),16);
int g = Integer.parseInt(col.substring(2,4),16);
int b = Integer.parseInt(col.substring(4,6),16);
return new Color(r,g,b);
}
catch (NumberFormatException nfe) {
return null;
}
}
|