public class ObservableProperties extends Objectimplements Serializable
Eventually we might want to ramp this up to rival the ObservableList in terms of synchronized modification safeguards and RecursiveListenerModificationExceptions.
Notes this includes parameterized keys, and it is technically possible to have two keys that use the same name but map to different types.
| Modifier and Type | Class and Description |
|---|---|
static class |
ObservableProperties
This can be used for bounds checking as values are about to be assigned.
|
static class |
ObservableProperties
|
static class |
ObservableProperties
A key for a key/value pair.
|
static class |
ObservableProperties
This throws a NullPointerException if the value is null.
|
static class |
ObservableProperties
This applies bound checking for numeric values.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT
The string "default".
|
static String |
TRANSIENT
The string "transient".
|
| Constructor and Description |
|---|
ObservableProperties()
Create a new ObservableProperties that will accept any group ID.
|
ObservableProperties(ObservableProperties
Clone this ObservableProperties.
|
ObservableProperties(String
Create a new ObservableProperties with a limited set of possible group IDs.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(PropertyChangeListener
Add a PropertyChangeListener for
DEFAULT properties.
|
void |
addListener(String
Add an ActionListener for a key in a given group of properties.
|
void |
addListener(String
Add a ChangeListener for a key in a given group of properties.
|
void |
addListener(String
Add a PropertyChangeListener for a key in a given group of properties.
|
void |
addListener(String
Add a PropertyChangeListener for a given group of properties.
|
ObservableProperties |
beginEdit()
Begin recording an edit that suspends all listeners until
endEdit(Edit) is called.
|
void |
clear()
Clear the DEFAULT group.
|
void |
clear(String
Clear everything in a particular property group.
|
protected void |
clearEventQueue()
Flushes all QueueElements from the eventQueue.
|
void |
endEdit(ObservableProperties
This must be called after
beginEdit() to reactive listeners for this object.
|
<T> T |
get(ObservableProperties
Retrieve a property in the DEFAULT property group.
|
<T> T |
get(String
Return a property from a given property group.
|
SortedSet |
getGroupNames()
|
Map |
getMap()
|
Map |
getMap(boolean prependGroupID, boolean identifyClassNames, String
|
Map |
getMap(String
Return all the properties in a particular category of this ObservableProperties.
|
PropertyChangeListener |
getPropertyListeners()
Return all the PropertyChangeListeners that listen for changes to DEFAULT properties.
|
PropertyChangeListener |
getPropertyListeners(String
Return all the PropertyChangeListeners that listen for changes to a given group of properties.
|
Set |
keys(String
|
void |
removeListener(PropertyChangeListener
Remove a PropertyChangeListener for
DEFAULT properties.
|
void |
removeListener(String
Remove an ActionListener for a given group of properties.
|
void |
removeListener(String
Remove a ChangeListener for a given group of properties.
|
void |
removeListener(String
Remove a PropertyChangeListener for a given group of properties.
|
void |
removeListener(String
Remove a PropertyChangeListener for a given group of properties.
|
<T> T |
set(ObservableProperties
Assign a property to the DEFAULT property group.
|
<T> T |
set(String
Set a property in a given property group.
|
String |
toString()
|
public static final StringDEFAULT
public static final StringTRANSIENT
public ObservableProperties()
public ObservableProperties(ObservablePropertiesp)
public ObservableProperties(String... groupNames)
groupNames - the group IDs this object allows. (If null: then all group IDs are allowed.) If non-null: then attempting to access a group ID not in this set will result in an exception.
public ObservableProperties.Edit beginEdit()
endEdit(Edit) is called.
This is needed when it is dangerous for a listener to get an incomplete picture of the state of this object. For example if you are changing the VALUE key to 5 and the MAXIMUM key to 8, if a listener were notified after the first step and the MAXIMUM value was an older value (such as 3), then it might throw an exception because it assumes the VALUE is always less than the MAXIMUM.
endEdit() when your changes are complete.
public void endEdit(ObservableProperties.Edit endedEdit)
beginEdit() to reactive listeners for this object.
endedEdit - a token created by a call to
beginEdit(). When there are no unresolved edits: all pending PropertyChangeEvents will be flushed.
protected void clearEventQueue()
public StringtoString()
public SortedSet<String > getGroupNames()
public void addListener(PropertyChangeListenerpcl)
DEFAULT properties.
pcl - the listener to add.
public void removeListener(PropertyChangeListenerpcl)
DEFAULT properties.
pcl - the listener to remove.
public void addListener(StringpropertyGroup, PropertyChangeListener pcl)
public void addListener(StringpropertyGroup, ObservableProperties .Key <?> key, PropertyChangeListener pcl)
public void addListener(StringpropertyGroup, ObservableProperties .Key <?> key, ChangeListener changeListener)
public void addListener(StringpropertyGroup, ObservableProperties .Key <?> key, ActionListener actionListener)
public PropertyChangeListener[] getPropertyListeners()
public PropertyChangeListener[] getPropertyListeners(String propertyGroup)
public void removeListener(StringpropertyGroup, ObservableProperties .Key <?> key, ChangeListener changeListener)
propertyGroup - the group this listener belongs to.
key - the key this listener relates to.
changeListener - the listener to remove.
public void removeListener(StringpropertyGroup, ObservableProperties .Key <?> key, ActionListener actionListener)
propertyGroup - the group this listener belongs to.
key - the key this listener relates to.
actionListener - the listener to remove.
public void removeListener(StringpropertyGroup, PropertyChangeListener pcl)
propertyGroup - the group this listener belongs to.
pcl - the listener to remove.
public void removeListener(StringpropertyGroup, ObservableProperties .Key <?> key, PropertyChangeListener pcl)
propertyGroup - the group this listener belongs to.
key - the key this listener relates to.
pcl - the listener to remove.
public <T> T set(StringpropertyGroup, ObservableProperties .Key <T> key, T value)
propertyGroup - the property group to consult. (Recommended values are DEFAULT or TRANSIENT.) This cannot be null. Each ObservableProperties object may be constructed with a finite set of acceptable property groups: if that is the case for this object and this group ID is not part of this set, then an exception is thrown.
key - the key to set.
value - the value to set. If null: then this key is removed.
public <T> T get(StringpropertyGroup, ObservableProperties .Key <T> key)
propertyGroup - the property group to consult. (Recommended values are DEFAULT or TRANSIENT.) This cannot be null. Each ObservableProperties object may be constructed with a finite set of acceptable property groups: if that is the case for this object and this group ID is not part of this set, then an exception is thrown.
key - the key to retrieve.
public Map<String ,Object > getMap()
public Set<ObservableProperties .Key <?>> keys(String propertyGroup)
propertyGroup - the group of keys to return.
public Map<String ,Object > getMap(boolean prependGroupID, boolean identifyClassNames, String ... groupIDs)
prependGroupID - if true, then the groupID will be prepended to all keys. It is highly recommended that this be true, because if this is false and different groups have similar sounding keys: then those groups cannot be safely condensed to a single map and exception will be thrown.
identifyClassNames - if true then keys will be uniquely identified by including their class name.
groupIDs - an optional list of group IDs to poll. If null: then all group IDs are included. For example: you might want to only return the DEFAULT group, at which point it would be safe to pass
false for
prependGroupID.
public <T> T get(ObservableProperties.Key <T> key)
key - the key to get.
public <T> T set(ObservableProperties.Key <T> key, T value)
key - the key to retrieve.
value - the new value of the key
public void clear()
public void clear(StringgroupID)
groupID - the id of the group to clear
public Map<ObservableProperties .Key <?> ,Object > getMap(String groupName)
groupName - the name of the group (such as DEFAULT or TRANSIENT)