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 classAbstractProperty.InvalidPreferenceValueExceptionAn exception that is thrown if a preference value is invalid.private classAbstractProperty.PreferenceChangedListenerAdapterstatic classAbstractProperty.ValueChangeEvent<T>An event that is triggered if the value of a property changes.static interfaceAbstractProperty.ValueChangeListener<T>A listener that listens to changes in the properties value.private classAbstractProperty.WeakPreferenceAdapterThis 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 TdefaultValueprotected java.lang.Stringkeyprotected IPreferencespreferencesThe preferences object this property is for.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractProperty(java.lang.String key, T defaultValue)Constructs a newAbstractProperty.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(AbstractProperty.ValueChangeListener<? super T> listener)Adds a listener that listens only for changes to this preference key.protected voidaddListenerImpl(PreferenceChangedListener adapter)voidaddWeakListener(AbstractProperty.ValueChangeListener<? super T> listener)Adds a weak listener that listens only for changes to this preference key.CachingProperty<T>cached()Creates a newCachingPropertyinstance for this property.booleanequals(java.lang.Object obj)abstract Tget()Replies the value of this property.TgetDefaultValue()Replies the default value of this property.java.lang.StringgetKey()Replies the property key.protected IPreferencesgetPreferences()Gets the preferences used for this property.inthashCode()booleanisSet()Determines if this property is currently set in JOSM preferences.abstract booleanput(T value)Sets this property to the specified value.voidremove()Removes this property from JOSM preferences (i.e replace it by its default value).voidremoveListener(AbstractProperty.ValueChangeListener<? super T> listener)Removes a listener that listens only for changes to this preference key.protected voidremoveListenerImpl(PreferenceChangedListener adapter)protected voidstoreDefaultValue()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 newCachingPropertyinstance 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:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-