this.green = Integer.parseInt(value.substring(3, 5), 16)
/ 255f;
this.blue = Integer.parseInt(value.substring(5), 16)
/ 255f;
} else {
throw new PropertyException("Unknown color format: "
+ value + ". Must be #RGB or #RRGGBB");
}
} catch (NumberFormatException e) {
throw new PropertyException("Unknown color format: " + value
+ ". Must be #RGB or #RRGGBB");
}
} else if (value.startsWith("rgb(")) {
int poss = value.indexOf("(");
int pose = value.indexOf(")");
if (poss != -1 && pose != -1) {
value = value.substring(poss + 1, pose);
StringTokenizer st = new StringTokenizer(value, ",");
try {
if (st.hasMoreTokens()) {
String str = st.nextToken().trim();
if (str.endsWith("%")) {
this.red = Float.parseFloat(str.substring(0, str
.length() - 1)) / 100.0f;
} else {
this.red = Float.parseFloat(str) / 255f;
}
}
if (st.hasMoreTokens()) {
String str = st.nextToken().trim();
if (str.endsWith("%")) {
this.green = Float.parseFloat(str.substring(0, str
.length() - 1)) / 100.0f;
} else {
this.green = Float.parseFloat(str) / 255f;
}
}
if (st.hasMoreTokens()) {
String str = st.nextToken().trim();
if (str.endsWith("%")) {
this.blue = Float.parseFloat(str.substring(0, str
.length() - 1)) / 100.0f;
} else {
this.blue = Float.parseFloat(str) / 255f;
}
}
} catch (Exception e) {
throw new PropertyException(
"Arguments to rgb() must be [0..255] or [0%..100%]");
}
} else {
throw new PropertyException("Unknown color format: " + value
+ ". Must be rgb(r,g,b)");
}
} else if (value.startsWith("url(")) {
throw new PropertyException(
"Colors starting with url( are not yet supported!");
} else {
if (value.startsWith("system-color(")) {
int poss = value.indexOf("(");
int pose = value.indexOf(")");
if (poss != -1 && pose != -1) {
value = value.substring(poss + 1, pose);
} else {
throw new PropertyException("Unknown color format: "
+ value + ". Must be system-color(x)");
}
}
if (value.toLowerCase().equals("transparent")) {
this.red = 0;
this.green = 0;
this.blue = 0;
this.alpha = 0;
} else {
boolean found = false;
for (int count = 0; count < NAMES.length; count++) {
if (value.toLowerCase().equals(NAMES[count])) {
this.red = VALUES[count][0] / 255f;
this.green = VALUES[count][1] / 255f;
this.blue = VALUES[count][2] / 255f;
found = true;
break;
}
}
if (!found) {
throw new PropertyException("Unknown color name: " + value);
}
}
}
if ((this.red < 0.0 || this.red > 1.0)
|| (this.green < 0.0 || this.green > 1.0)
|| (this.blue < 0.0 || this.blue > 1.0)
|| (this.alpha < 0.0 || this.alpha > 1.0)) {
throw new PropertyException("Color values out of range");
}
}