public void setColorValue(String value) { predefinedColor = null; if (choiceSet != null) { IChoice choice = choiceSet.findChoice(value); if (choice != null) { predefinedColor = choice.getDisplayName(); } } int[] rgbValues = ColorUtil.getRGBs(value); if (rgbValues == null) { setRGB(null); } else { setRGB(new RGB(rgbValues[0], rgbValues[1], rgbValues[2])); } }
/** * Parses the input string to a GRB object. * * @param string The input string. * @return The RGB object represented the string. */ protected RGB parseString(String string) { int colors[] = ColorUtil.getRGBs(string); if (colors != null) return new RGB(colors[0], colors[1], colors[2]); StringTokenizer st = new StringTokenizer(string, " ,()"); // $NON-NLS-1$ if (!st.hasMoreTokens()) return null; int[] rgb = new int[] {0, 0, 0}; int index = 0; while (st.hasMoreTokens()) { try { rgb[index] = Integer.decode(st.nextToken()).intValue(); if (rgb[index] < 0 || rgb[index] > 255) return null; index++; } catch (Exception e) { return null; } } return new RGB(rgb[0], rgb[1], rgb[2]); }