Thursday, August 5, 2010

PreferenceConverter

I was wondering how to save colors or non int/double/boolean/string values into rcp preferences. As usual it is very easy if you know the tool to use. :)

So from Color -> Preference

IPreferenceStore store = ...
Color red = Display.getDefault().getSystemColor(SWT.COLOR_RED);
PreferenceConverter.setDefault(store, "COLOR_KEY", red.getRGB());


And back: Preference -> Color

RGB colorRgb = PreferenceConverter.getColor(store, "COLOR_KEY");
Color red = new Color( Display.getDefault(), colorRgb);


Same applies for example for Fonts or Rectangle and other nice things.

No comments: