if (poss != -1 && pose != -1) {
value = value.substring(poss + 1, pose);
try {
String[] args = value.split(",");
if (args.length != 3) {
throw new PropertyException(
"Invalid number of arguments: rgb(" + value + ")");
}
float red = 0.0f, green = 0.0f, blue = 0.0f;
String str = args[0].trim();
if (str.endsWith("%")) {
red = Float.parseFloat(str.substring(0,
str.length() - 1)) / 100f;
} else {
red = Float.parseFloat(str) / 255f;
}
str = args[1].trim();
if (str.endsWith("%")) {
green = Float.parseFloat(str.substring(0,
str.length() - 1)) / 100f;
} else {
green = Float.parseFloat(str) / 255f;
}
str = args[2].trim();
if (str.endsWith("%")) {
blue = Float.parseFloat(str.substring(0,
str.length() - 1)) / 100f;
} else {
blue = Float.parseFloat(str) / 255f;
}
if ((red < 0.0 || red > 1.0)
|| (green < 0.0 || green > 1.0)
|| (blue < 0.0 || blue > 1.0)) {
throw new PropertyException("Color values out of range");
}
parsedColor = new Color(red, green, blue);
} catch (PropertyException pe) {
//simply re-throw
throw pe;
} catch (Exception e) {
//wrap in a PropertyException
throw new PropertyException(e);
}
} else {
throw new PropertyException("Unknown color format: " + value
+ ". Must be rgb(r,g,b)");
}
return parsedColor;
}