Class NamedColorProperty
- java.lang.Object
-
- org.openstreetmap.josm.data.preferences.AbstractProperty<T>
-
- org.openstreetmap.josm.data.preferences.AbstractToStringProperty<java.awt.Color>
-
- org.openstreetmap.josm.data.preferences.NamedColorProperty
-
public class NamedColorProperty extends AbstractToStringProperty<java.awt.Color>
A property containing aColor
value with additional information associated to it. The additional information is used to describe the color in theColorPreference
, so it can be recognized and customized by the user.- Since:
- 12987
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.data.preferences.AbstractToStringProperty
AbstractToStringProperty.ChildProperty<T>
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.data.preferences.AbstractProperty
AbstractProperty.InvalidPreferenceValueException, AbstractProperty.ValueChangeEvent<T>, AbstractProperty.ValueChangeListener<T>
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
category
static java.lang.String
COLOR_CATEGORY_GENERAL
static java.lang.String
COLOR_CATEGORY_MAPPAINT
private java.lang.String
name
static java.lang.String
NAMED_COLOR_PREFIX
private java.lang.String
source
-
Fields inherited from class org.openstreetmap.josm.data.preferences.AbstractProperty
defaultValue, key, preferences
-
-
Constructor Summary
Constructors Constructor Description NamedColorProperty(java.lang.String name, java.awt.Color defaultValue)
Construct a newNamedColorProperty
.NamedColorProperty(java.lang.String category, java.lang.String source, java.lang.String name, java.awt.Color defaultValue)
Construct a newNamedColorProperty
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.awt.Color
fromString(java.lang.String string)
Converts the string to an object of the given type.java.awt.Color
get()
Replies the value of this property.java.lang.String
getCategory()
Get the category for this color.FallbackProperty<java.awt.Color>
getChildColor(java.lang.String name)
Return a more specialized color, that will fall back to this color, if not set explicitly.FallbackProperty<java.awt.Color>
getChildColor(java.lang.String category, java.lang.String source, java.lang.String name)
Return a more specialized color, that will fall back to this color, if not set explicitly.private java.util.List<java.lang.String>
getDefaultValuePref()
private static java.lang.String
getKey(java.lang.String category, java.lang.String source, java.lang.String name)
java.lang.String
getName()
Get the color name (a short description of the color).java.lang.String
getSource()
Get the source, i.e. a filename or layer name associated with the color.private static java.awt.Color
getUIColor(java.lang.String uiKey, java.awt.Color defaultValue)
private static java.util.List<java.lang.String>
getValuePref(java.awt.Color color, java.lang.String category, java.lang.String source, java.lang.String name)
boolean
isSet()
Determines if this property is currently set in JOSM preferences.boolean
put(java.awt.Color value)
Sets this property to the specified value.protected void
storeDefaultValue()
Store the default value to the preferences.protected java.lang.String
toString(java.awt.Color color)
Converts the string to an object of the given type.-
Methods inherited from class org.openstreetmap.josm.data.preferences.AbstractToStringProperty
getAsString, getChildProperty, getSpecialized
-
Methods inherited from class org.openstreetmap.josm.data.preferences.AbstractProperty
addListener, addListenerImpl, addWeakListener, cached, equals, getDefaultValue, getKey, getPreferences, hashCode, remove, removeListener, removeListenerImpl
-
-
-
-
Field Detail
-
NAMED_COLOR_PREFIX
public static final java.lang.String NAMED_COLOR_PREFIX
- See Also:
- Constant Field Values
-
COLOR_CATEGORY_GENERAL
public static final java.lang.String COLOR_CATEGORY_GENERAL
- See Also:
- Constant Field Values
-
COLOR_CATEGORY_MAPPAINT
public static final java.lang.String COLOR_CATEGORY_MAPPAINT
- See Also:
- Constant Field Values
-
category
private final java.lang.String category
-
source
private final java.lang.String source
-
name
private final java.lang.String name
-
-
Constructor Detail
-
NamedColorProperty
public NamedColorProperty(java.lang.String category, java.lang.String source, java.lang.String name, java.awt.Color defaultValue)
Construct a newNamedColorProperty
. The priority for getting the color is: 1. a set property, 2.UIManager.getColor(java.lang.Object)
, 3. the givendefaultValue
- Parameters:
category
- a category, can be any identifier, but the following values are recognized by the GUI preferences:COLOR_CATEGORY_GENERAL
andCOLOR_CATEGORY_MAPPAINT
source
- a filename or similar associated with the color, can be null if not applicablename
- a short description of the colordefaultValue
- the default value, can be null
-
NamedColorProperty
public NamedColorProperty(java.lang.String name, java.awt.Color defaultValue)
Construct a newNamedColorProperty
.- Parameters:
name
- a short description of the colordefaultValue
- the default value, can be null
-
-
Method Detail
-
getKey
private static java.lang.String getKey(java.lang.String category, java.lang.String source, java.lang.String name)
-
getUIColor
private static java.awt.Color getUIColor(java.lang.String uiKey, java.awt.Color defaultValue)
-
getDefaultValuePref
private java.util.List<java.lang.String> getDefaultValuePref()
-
storeDefaultValue
protected void storeDefaultValue()
Description copied from class:AbstractProperty
Store the default value to the preferences.- Overrides:
storeDefaultValue
in classAbstractProperty<java.awt.Color>
-
get
public java.awt.Color get()
Description copied from class:AbstractProperty
Replies the value of this property.- Overrides:
get
in classAbstractToStringProperty<java.awt.Color>
- Returns:
- the value of this property
-
isSet
public boolean isSet()
Description copied from class:AbstractProperty
Determines if this property is currently set in JOSM preferences.- Overrides:
isSet
in classAbstractProperty<java.awt.Color>
- Returns:
- true if
getPreferences()
contains this property.
-
getCategory
public java.lang.String getCategory()
Get the category for this color.- Returns:
- the category
-
getSource
public java.lang.String getSource()
Get the source, i.e. a filename or layer name associated with the color. May return null if not applicable.- Returns:
- the source
-
getName
public java.lang.String getName()
Get the color name (a short description of the color).- Returns:
- the color name
-
getValuePref
private static java.util.List<java.lang.String> getValuePref(java.awt.Color color, java.lang.String category, java.lang.String source, java.lang.String name)
-
put
public boolean put(java.awt.Color value)
Description copied from class:AbstractProperty
Sets this property to the specified value.- Overrides:
put
in classAbstractToStringProperty<java.awt.Color>
- Parameters:
value
- The new value of this property- Returns:
- true if something has changed (i.e. value is different than before)
-
getChildColor
public FallbackProperty<java.awt.Color> getChildColor(java.lang.String category, java.lang.String source, java.lang.String name)
Return a more specialized color, that will fall back to this color, if not set explicitly.- Parameters:
category
- the category of the specialized colorsource
- the source of the specialized colorname
- the name of the specialized color- Returns:
- a
FallbackProperty
that will the return the specialized color, if set, but fall back to this property as default value
-
getChildColor
public FallbackProperty<java.awt.Color> getChildColor(java.lang.String name)
Return a more specialized color, that will fall back to this color, if not set explicitly.- Parameters:
name
- the name of the specialized color- Returns:
- a
FallbackProperty
that will the return the specialized color, if set, but fall back to this property as default value
-
fromString
protected java.awt.Color fromString(java.lang.String string)
Description copied from class:AbstractToStringProperty
Converts the string to an object of the given type.- Specified by:
fromString
in classAbstractToStringProperty<java.awt.Color>
- Parameters:
string
- The string- Returns:
- The object.
-
toString
protected java.lang.String toString(java.awt.Color color)
Description copied from class:AbstractToStringProperty
Converts the string to an object of the given type.- Specified by:
toString
in classAbstractToStringProperty<java.awt.Color>
- Parameters:
color
- The object.- Returns:
- The string representing the object
-
-