Package org.eclipse.jface.preference
Class PreferenceConverter
- java.lang.Object
-
- org.eclipse.jface.preference.PreferenceConverter
-
public class PreferenceConverter extends Object
A utility class for dealing with preferences whose values are common SWT objects (color, points, rectangles, and font data). The static methods on this class handle the conversion between the SWT objects and their string representations.Usage:
IPreferenceStore store = ...; PreferenceConverter.setValue(store, "bg", new RGB(127,127,127)); ... RBG bgColor = PreferenceConverter.getValue(store, "bg");
This class contains static methods and fields only and cannot be instantiated.
Note: touching this class has the side effect of creating a display (static initializer).- Restriction:
- This class is not intended to be instantiated by clients.
-
-
Field Summary
Fields Modifier and Type Field Description static RGB
COLOR_DEFAULT_DEFAULT
The default-default value for color preferences (black,RGB(0,0,0)
).static FontData[]
FONTDATA_ARRAY_DEFAULT_DEFAULT
Deprecated.this is not thread-safe and may contain invalid data at startup.static FontData
FONTDATA_DEFAULT_DEFAULT
Deprecated.this is not thread-safe and may contain invalid data at startup.static Point
POINT_DEFAULT_DEFAULT
The default-default value for point preferences (the origin,(0,0)
).static Rectangle
RECTANGLE_DEFAULT_DEFAULT
The default-default value for rectangle preferences (the empty rectangle(0,0,0,0)
).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FontData[]
basicGetFontData(String value)
Helper method to construct aFontData
from the given string.static RGB
getColor(IPreferenceStore store, String name)
Returns the current value of the color-valued preference with the given name in the given preference store.static RGB
getDefaultColor(IPreferenceStore store, String name)
Returns the default value for the color-valued preference with the given name in the given preference store.static FontData
getDefaultFontData(IPreferenceStore store, String name)
Returns a single default value for the font-valued preference with the given name in the given preference store.static FontData[]
getDefaultFontDataArray(IPreferenceStore store, String name)
Returns the default value array for the font-valued preference with the given name in the given preference store.static Point
getDefaultPoint(IPreferenceStore store, String name)
Returns the default value for the point-valued preference with the given name in the given preference store.static Rectangle
getDefaultRectangle(IPreferenceStore store, String name)
Returns the default value for the rectangle-valued preference with the given name in the given preference store.static FontData
getFontData(IPreferenceStore store, String name)
Returns the current value of the first entry of the font-valued preference with the given name in the given preference store.static FontData[]
getFontDataArray(IPreferenceStore store, String name)
Returns the current value of the font-valued preference with the given name in the given preference store.static FontData[]
getFontDataArrayDefaultDefault()
The default-default value forFontData[]
preferences.static Point
getPoint(IPreferenceStore store, String name)
Returns the current value of the point-valued preference with the given name in the given preference store.static Rectangle
getRectangle(IPreferenceStore store, String name)
Returns the current value of the rectangle-valued preference with the given name in the given preference store.static String
getStoredRepresentation(FontData[] fontData)
Returns the stored representation of the given array of FontData objects.static void
putValue(IPreferenceStore store, String name, FontData[] value)
Sets the current value of the preference with the given name in the given preference store.static FontData[]
readFontData(String fontDataValue)
Reads the supplied string and returns its corresponding FontData.static void
setDefault(IPreferenceStore store, String name, FontData value)
Sets the default value of the preference with the given name in the given preference store.static void
setDefault(IPreferenceStore store, String name, FontData[] value)
Sets the default value of the preference with the given name in the given preference store.static void
setDefault(IPreferenceStore store, String name, Point value)
Sets the default value of the preference with the given name in the given preference store.static void
setDefault(IPreferenceStore store, String name, Rectangle value)
Sets the default value of the preference with the given name in the given preference store.static void
setDefault(IPreferenceStore store, String name, RGB value)
Sets the default value of the preference with the given name in the given preference store.static void
setValue(IPreferenceStore store, String name, FontData value)
Sets the current value of the preference with the given name in the given preference store.static void
setValue(IPreferenceStore store, String name, FontData[] value)
Sets the current value of the preference with the given name in the given preference store.static void
setValue(IPreferenceStore store, String name, Point value)
Sets the current value of the preference with the given name in the given preference store.static void
setValue(IPreferenceStore store, String name, Rectangle value)
Sets the current value of the preference with the given name in the given preference store.static void
setValue(IPreferenceStore store, String name, RGB value)
Sets the current value of the preference with the given name in the given preference store.
-
-
-
Field Detail
-
POINT_DEFAULT_DEFAULT
public static final Point POINT_DEFAULT_DEFAULT
The default-default value for point preferences (the origin,(0,0)
).
-
RECTANGLE_DEFAULT_DEFAULT
public static final Rectangle RECTANGLE_DEFAULT_DEFAULT
The default-default value for rectangle preferences (the empty rectangle(0,0,0,0)
).
-
COLOR_DEFAULT_DEFAULT
public static final RGB COLOR_DEFAULT_DEFAULT
The default-default value for color preferences (black,RGB(0,0,0)
).
-
FONTDATA_ARRAY_DEFAULT_DEFAULT
@Deprecated public static FontData[] FONTDATA_ARRAY_DEFAULT_DEFAULT
Deprecated.this is not thread-safe and may contain invalid data at startup. CallgetFontDataArrayDefaultDefault()
from the UI thread instead.The default-default value forFontData[]
preferences. Read-only.
-
FONTDATA_DEFAULT_DEFAULT
@Deprecated public static FontData FONTDATA_DEFAULT_DEFAULT
Deprecated.this is not thread-safe and may contain invalid data at startup. CallgetFontDataArrayDefaultDefault()
} from the UI thread instead.The default-default value forFontData
preferences. Read-only.
-
-
Method Detail
-
basicGetFontData
public static FontData[] basicGetFontData(String value)
Helper method to construct aFontData
from the given string. String is in the form FontData;FontData; in order that multiple FontDatas can be defined.- Parameters:
value
- the identifier for the font- Returns:
- FontData[]
- Since:
- 3.0
-
readFontData
public static FontData[] readFontData(String fontDataValue)
Reads the supplied string and returns its corresponding FontData. If it cannot be read then the default FontData will be returned.- Parameters:
fontDataValue
- the string value for the font data- Returns:
- the font data
-
getColor
public static RGB getColor(IPreferenceStore store, String name)
Returns the current value of the color-valued preference with the given name in the given preference store. Returns the default-default value (COLOR_DEFAULT_DEFAULT
) if there is no preference with the given name, or if the current value cannot be treated as a color.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the color-valued preference
-
getDefaultColor
public static RGB getDefaultColor(IPreferenceStore store, String name)
Returns the default value for the color-valued preference with the given name in the given preference store. Returns the default-default value (COLOR_DEFAULT_DEFAULT
) is no default preference with the given name, or if the default value cannot be treated as a color.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the default value of the preference
-
getDefaultFontDataArray
public static FontData[] getDefaultFontDataArray(IPreferenceStore store, String name)
Returns the default value array for the font-valued preference with the given name in the given preference store. Returns the default-default value (FONTDATA_ARRAY_DEFAULT_DEFAULT
) is no default preference with the given name, or if the default value cannot be treated as font data.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the default value of the preference
-
getDefaultFontData
public static FontData getDefaultFontData(IPreferenceStore store, String name)
Returns a single default value for the font-valued preference with the given name in the given preference store. Returns the default-default value (FONTDATA_DEFAULT_DEFAULT
) is no default preference with the given name, or if the default value cannot be treated as font data. This method is provided for backwards compatibility. It is recommended thatgetDefaultFontDataArray
is used instead.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the default value of the preference
-
getDefaultPoint
public static Point getDefaultPoint(IPreferenceStore store, String name)
Returns the default value for the point-valued preference with the given name in the given preference store. Returns the default-default value (POINT_DEFAULT_DEFAULT
) is no default preference with the given name, or if the default value cannot be treated as a point.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the default value of the preference
-
getDefaultRectangle
public static Rectangle getDefaultRectangle(IPreferenceStore store, String name)
Returns the default value for the rectangle-valued preference with the given name in the given preference store. Returns the default-default value (RECTANGLE_DEFAULT_DEFAULT
) is no default preference with the given name, or if the default value cannot be treated as a rectangle.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the default value of the preference
-
getFontDataArray
public static FontData[] getFontDataArray(IPreferenceStore store, String name)
Returns the current value of the font-valued preference with the given name in the given preference store. Returns the default-default value (FONTDATA_ARRAY_DEFAULT_DEFAULT
) if there is no preference with the given name, or if the current value cannot be treated as font data.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the font-valued preference
-
getFontDataArrayDefaultDefault
public static FontData[] getFontDataArrayDefaultDefault()
The default-default value forFontData[]
preferences. Must be called from the UI thread.- Returns:
- the default-default value for
FontData[]
preferences. - Since:
- 3.12
-
getFontData
public static FontData getFontData(IPreferenceStore store, String name)
Returns the current value of the first entry of the font-valued preference with the given name in the given preference store. Returns the default-default value (FONTDATA_ARRAY_DEFAULT_DEFAULT
) if there is no preference with the given name, or if the current value cannot be treated as font data. This API is provided for backwards compatibility. It is recommended thatgetFontDataArray
is used instead.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the font-valued preference
-
getPoint
public static Point getPoint(IPreferenceStore store, String name)
Returns the current value of the point-valued preference with the given name in the given preference store. Returns the default-default value (POINT_DEFAULT_DEFAULT
) if there is no preference with the given name, or if the current value cannot be treated as a point.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the point-valued preference
-
getRectangle
public static Rectangle getRectangle(IPreferenceStore store, String name)
Returns the current value of the rectangle-valued preference with the given name in the given preference store. Returns the default-default value (RECTANGLE_DEFAULT_DEFAULT
) if there is no preference with the given name, or if the current value cannot be treated as a rectangle.- Parameters:
store
- the preference storename
- the name of the preference- Returns:
- the rectangle-valued preference
-
setDefault
public static void setDefault(IPreferenceStore store, String name, FontData value)
Sets the default value of the preference with the given name in the given preference store. As FontDatas are stored as arrays this method is only provided for backwards compatibility. UsesetDefault(IPreferenceStore, String, FontData[])
instead.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new default value of the preference
-
setDefault
public static void setDefault(IPreferenceStore store, String name, FontData[] value)
Sets the default value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new default value of the preference
-
setDefault
public static void setDefault(IPreferenceStore store, String name, Point value)
Sets the default value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new default value of the preference
-
setDefault
public static void setDefault(IPreferenceStore store, String name, Rectangle value)
Sets the default value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new default value of the preference
-
setDefault
public static void setDefault(IPreferenceStore store, String name, RGB value)
Sets the default value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new default value of the preference
-
setValue
public static void setValue(IPreferenceStore store, String name, FontData value)
Sets the current value of the preference with the given name in the given preference store.Included for backwards compatibility. This method is equivalent to
setValue(store, name, new FontData[]{value})
.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new current value of the preference
-
setValue
public static void setValue(IPreferenceStore store, String name, FontData[] value)
Sets the current value of the preference with the given name in the given preference store. This method also sets the corresponding key in the JFace font registry to the value and fires a property change event to listeners on the preference store.Note that this API does not update any other settings that may be dependant upon it. Only the value in the preference store and in the font registry is updated.
- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new current value of the preference- See Also:
putValue(IPreferenceStore, String, FontData[])
-
putValue
public static void putValue(IPreferenceStore store, String name, FontData[] value)
Sets the current value of the preference with the given name in the given preference store. This method does not update the font registry or fire a property change event.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new current value of the preference- See Also:
setValue(IPreferenceStore, String, FontData[])
-
getStoredRepresentation
public static String getStoredRepresentation(FontData[] fontData)
Returns the stored representation of the given array of FontData objects. The stored representation has the form FontData;FontData; Only includes the non-null entries.- Parameters:
fontData
- the array of FontData objects- Returns:
- the stored representation of the FontData objects
- Since:
- 3.0
-
setValue
public static void setValue(IPreferenceStore store, String name, Point value)
Sets the current value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new current value of the preference
-
setValue
public static void setValue(IPreferenceStore store, String name, Rectangle value)
Sets the current value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new current value of the preference
-
setValue
public static void setValue(IPreferenceStore store, String name, RGB value)
Sets the current value of the preference with the given name in the given preference store.- Parameters:
store
- the preference storename
- the name of the preferencevalue
- the new current value of the preference
-
-