Class AbstractProperty<T>
- java.lang.Object
-
- org.openstreetmap.josm.data.preferences.AbstractProperty<T>
-
- Type Parameters:
T
- The type of object accessed by this property
- Direct Known Subclasses:
AbstractToStringProperty
,CachedProperty
,CachingProperty
,FallbackProperty
,ListProperty
public abstract class AbstractProperty<T> extends java.lang.Object
Captures the common functionality of preference properties
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractProperty.InvalidPreferenceValueException
An exception that is thrown if a preference value is invalid.private class
AbstractProperty.PreferenceChangedListenerAdapter
static class
AbstractProperty.ValueChangeEvent<T>
An event that is triggered if the value of a property changes.static interface
AbstractProperty.ValueChangeListener<T>
A listener that listens to changes in the properties value.private class
AbstractProperty.WeakPreferenceAdapter
This class wraps the ValueChangeListener in a ListenableWeakReference that automatically removes itself if the listener is garbage collected.
-
Field Summary
Fields Modifier and Type Field Description protected T
defaultValue
protected java.lang.String
key
protected IPreferences
preferences
The preferences object this property is for.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractProperty(java.lang.String key, T defaultValue)
Constructs a newAbstractProperty
.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addListener(AbstractProperty.ValueChangeListener<? super T> listener)
Adds a listener that listens only for changes to this preference key.protected void
addListenerImpl(PreferenceChangedListener adapter)
void
addWeakListener(AbstractProperty.ValueChangeListener<? super T> listener)
Adds a weak listener that listens only for changes to this preference key.CachingProperty<T>
cached()
Creates a newCachingProperty
instance for this property.boolean
equals(java.lang.Object obj)
abstract T
get()
Replies the value of this property.T
getDefaultValue()
Replies the default value of this property.java.lang.String
getKey()
Replies the property key.protected IPreferences
getPreferences()
Gets the preferences used for this property.int
hashCode()
boolean
isSet()
Determines if this property is currently set in JOSM preferences.abstract boolean
put(T value)
Sets this property to the specified value.void
remove()
Removes this property from JOSM preferences (i.e replace it by its default value).void
removeListener(AbstractProperty.ValueChangeListener<? super T> listener)
Removes a listener that listens only for changes to this preference key.protected void
removeListenerImpl(PreferenceChangedListener adapter)
protected void
storeDefaultValue()
Store the default value to the preferences.
-
-
-
Field Detail
-
preferences
protected final IPreferences preferences
The preferences object this property is for.
-
key
protected final java.lang.String key
-
defaultValue
protected final T defaultValue
-
-
Constructor Detail
-
AbstractProperty
protected AbstractProperty(java.lang.String key, T defaultValue)
Constructs a newAbstractProperty
.- Parameters:
key
- The property keydefaultValue
- The default value- Since:
- 5464
-
-
Method Detail
-
storeDefaultValue
protected void storeDefaultValue()
Store the default value to the preferences.
-
getKey
public java.lang.String getKey()
Replies the property key.- Returns:
- The property key
-
isSet
public boolean isSet()
Determines if this property is currently set in JOSM preferences.- Returns:
- true if
getPreferences()
contains this property.
-
getDefaultValue
public T getDefaultValue()
Replies the default value of this property.- Returns:
- The default value of this property
-
remove
public void remove()
Removes this property from JOSM preferences (i.e replace it by its default value).
-
get
public abstract T get()
Replies the value of this property.- Returns:
- the value of this property
- Since:
- 5464
-
put
public abstract boolean put(T value)
Sets this property to the specified value.- Parameters:
value
- The new value of this property- Returns:
- true if something has changed (i.e. value is different than before)
- Since:
- 5464
-
getPreferences
protected IPreferences getPreferences()
Gets the preferences used for this property.- Returns:
- The preferences for this property.
- Since:
- 12999
-
cached
public CachingProperty<T> cached()
Creates a newCachingProperty
instance for this property.- Returns:
- The new caching property instance.
- Since:
- 12983
-
addListener
public void addListener(AbstractProperty.ValueChangeListener<? super T> listener)
Adds a listener that listens only for changes to this preference key.- Parameters:
listener
- The listener to add.- Since:
- 10824
-
addListenerImpl
protected void addListenerImpl(PreferenceChangedListener adapter)
-
addWeakListener
public void addWeakListener(AbstractProperty.ValueChangeListener<? super T> listener)
Adds a weak listener that listens only for changes to this preference key.- Parameters:
listener
- The listener to add.- Since:
- 10824
-
removeListener
public void removeListener(AbstractProperty.ValueChangeListener<? super T> listener)
Removes a listener that listens only for changes to this preference key.- Parameters:
listener
- The listener to add.- Since:
- 10824
-
removeListenerImpl
protected void removeListenerImpl(PreferenceChangedListener adapter)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-