/** * Returns a Color object that corresponds to the value. * * @param value The string representation of the color. This may be a color name or a text * representation of the color's rgb value. * @return The Color object corresponding to the value, or null if not a recognized value. */ public static Color toColor(String value) { return toColor(value, null); }
@Override protected Color _toValue(String text) { return ColorUtil.toColor(text); }
@Override protected void setValue(Object value) { editor.setValue(ColorUtil.toColor((String) value)); updateValue(); }
public void testColorUtil(String testColor, String testRGB) { Color refColor = Color.magenta; String rgb = ColorUtil.getRGBFromName(testColor); assertEquals(rgb, testRGB); String color = ColorUtil.getNameFromRGB(rgb); assertEquals(color.toLowerCase(), testColor.toLowerCase()); Color color1 = ColorUtil.toColor(rgb, refColor); Color color2 = ColorUtil.toColor(color, refColor); assertEquals(color1, color2); Color color3 = ColorUtil.toColor("badvalue", refColor); assertEquals(refColor, color3); }
@Override protected void init(Object target, PropertyInfo propInfo, PropertyGrid propGrid) { super.init(target, propInfo, propGrid); String[] values = propInfo.getConfigValueArray("values"); if (values == null) { //component.setAutoAdd(true); } else { //component.setAutoAdd(false); editor.clear(); for (String choice : values) { String[] color = choice.split("\\:", 2); for (int i = 0; i < color.length; i++) { ColorPickeritem item = new ColorPickeritem(ColorUtil.toColor(color[i])); editor.addChild(item); } } } }