public static Color colorFromString(String rgbString) { if (rgbString != null && rgbString.trim().length() > 0) { Color col = JFaceResources.getColorRegistry().get(rgbString); try { if (col == null) { RGB rgb = StringConverter.asRGB(rgbString); JFaceResources.getColorRegistry().put(rgbString, rgb); col = JFaceResources.getColorRegistry().get(rgbString); } } catch (DataFormatException e) { log.error("Corrupt color value: " + rgbString, e); } return col; } return null; }
public void createColorProperty(Composite cmp, final String prop, String name, final IPreferenceStore store) { new Label(cmp, SWT.NONE).setText(name); final ColorSelector colorSelector = new ColorSelector(cmp); colorSelector.addListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { properties.put(prop, StringConverter.asString(colorSelector.getColorValue())); save(store); } }); try { colorSelector.setColorValue(StringConverter.asRGB(properties.get(prop))); } catch (DataFormatException e) { e.printStackTrace(); } }
@Override public Object convert(Object fromObject) { if (fromObject instanceof String) { try { return StringConverter.asInt(fromObject.toString()); } catch(DataFormatException e) { } } else if (fromObject instanceof Integer) { return StringConverter.asString((Integer)fromObject); } else if(fromObject == null) return null; throw new IllegalArgumentException(fromObject.getClass() + " type cannot be converted by " + getClass()); }
private RGB parseRgb(String rgbString) { RGB rgb = null; if (rgbString != null) { if (rgbString.equalsIgnoreCase("null")) { rgb = NULL; } else { try { rgb = ColorUtils.parseRGB(rgbString); } catch (DataFormatException x) { LogUtil.error(x); } } } return rgb; }
/** * Create a Color instance using the String created by {@link ColorPersistor#asColor(String)} */ public static Color asColor(String colorAsString) { try { return GUIHelper.getColor(StringConverter.asRGB(colorAsString)); } catch (DataFormatException e) { return DEFAULT_COLOR; } }
protected Color getNamedColor(String name) { Color color = fNamedColorTable.get(name); if (color == null || color.isDisposed()) { String colorCode = preferences != null ? preferences.getString(name) : ""; if (colorCode.length() == 0) { if (name.equals("RED")) { color = getColor(new RGB(255, 0, 0)); } else if (name.equals("BLACK")) { color = getColor(new RGB(0, 0, 0)); } else if (name.equals("WHITE")) { color = getColor(new RGB(255, 255, 255)); } else { Log.log("Unknown color:" + name); color = getColor(new RGB(255, 0, 0)); } } else { try { RGB rgb = StringConverter.asRGB(colorCode); color = new Color(Display.getCurrent(), rgb); fNamedColorTable.put(name, color); } catch (DataFormatException e) { // Data conversion failure, maybe someone edited our prefs by hand Log.log(e); color = getColor(new RGB(255, 50, 0)); } } } return color; }