if (value.length() == 7 && value.startsWith("#")) {
// CSS color format (e.g. #000000)
int red = Integer.parseInt(value.substring(1, 3), 16);
int green = Integer.parseInt(value.substring(3, 5), 16);
int blue = Integer.parseInt(value.substring(5, 7), 16);
color = new Color(red, green, blue);
} else if (value.startsWith("rgb")) {
// RGB color format rgb/rgba(255,255,255,0.1)
String[] colors = value.substring(value.indexOf("(") + 1,
value.length() - 1).split(",");
int red = Integer.parseInt(colors[0]);
int green = Integer.parseInt(colors[1]);
int blue = Integer.parseInt(colors[2]);
if (colors.length > 3) {
int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
color = new Color(red, green, blue, alpha);
} else {
color = new Color(red, green, blue);
}
} else if (value.startsWith("hsl")) {
// HSL color format hsl/hsla(100,50%,50%,1.0)
String[] colors = value.substring(value.indexOf("(") + 1,
value.length() - 1).split(",");
int hue = Integer.parseInt(colors[0]);
int saturation = Integer.parseInt(colors[1]
.replace("%", ""));
int lightness = Integer
.parseInt(colors[2].replace("%", ""));
int rgb = Color.HSLtoRGB(hue, saturation, lightness);
if (colors.length > 3) {
int alpha = (int) (Double.parseDouble(colors[3]) * 255d);
color = new Color(rgb);
color.setAlpha(alpha);
} else {
color = new Color(rgb);
}
}
oldValue = value;
fireEvent(new ColorChangeEvent((Component) field.getData(),