PropertyChangeEvents to them. You can use an instance of this class
as a member field of your bean and delegate these types of work to it.
The PropertyChangeListener can be registered for all properties
or for a property specified by name.
Here is an example of PropertyChangeSupport usage that follows
the rules and recommendations laid out in the JavaBeans specification:
public class MyBean {
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener listener) {
this.pcs.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
this.pcs.removePropertyChangeListener(listener);
}
private String value;
public String getValue() {
return this.value;
}
public void setValue(String newValue) {
String oldValue = this.value;
this.value = newValue;
this.pcs.firePropertyChange("value", oldValue, newValue);
}
[...]
}
A PropertyChangeSupport instance is thread-safe.
This class is serializable. When it is serialized it will save (and restore) any listeners that are themselves serializable. Any non-serializable listeners will be skipped during serialization.
VetoableChangeSupport
| Modifier and Type | Class and Description |
|---|---|
| private static class | PropertyChangeSupport.
This is a |
| Modifier and Type | Field and Description |
|---|---|
| private PropertyChangeSupport. | |
| private static final ObjectStreamField[] | |
| private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability. |
| private Object | source
The object to be provided as the "source" for any generated events. |
| Access | Constructor and Description |
|---|---|
| public | PropertyChangeSupport(Object
The bean to be given as the source for any events. sourceBean)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public void | addPropertyChangeListener(PropertyChangeListener
The PropertyChangeListener to be added listener)Add a PropertyChangeListener to the listener list. |
| public void | addPropertyChangeListener(String
The name of the property to listen on. propertyName, PropertyChangeListener The PropertyChangeListener to be added listener)Add a PropertyChangeListener for a specific property. |
| private static void | |
| public void | fireIndexedPropertyChange(String
the programmatic name of the property that was changed propertyName, int the index of the property element that was changed index, Object the old value of the property oldValue, Object the new value of the property newValue)Reports a bound indexed property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public void | fireIndexedPropertyChange(String
the programmatic name of the property that was changed propertyName, int the index of the property element that was changed index, int the old value of the property oldValue, int the new value of the property newValue)Reports an integer bound indexed property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public void | fireIndexedPropertyChange(String
the programmatic name of the property that was changed propertyName, int the index of the property element that was changed index, boolean the old value of the property oldValue, boolean the new value of the property newValue)Reports a boolean bound indexed property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public void | firePropertyChange(String
the programmatic name of the property that was changed propertyName, Object the old value of the property oldValue, Object the new value of the property newValue)Reports a bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public void | firePropertyChange(String
the programmatic name of the property that was changed propertyName, int the old value of the property oldValue, int the new value of the property newValue)Reports an integer bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public void | firePropertyChange(String
the programmatic name of the property that was changed propertyName, boolean the old value of the property oldValue, boolean the new value of the property newValue)Reports a boolean bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public void | firePropertyChange(PropertyChangeEvent
the event)PropertyChangeEvent to be firedFires a property change event to listeners that have been registered to track updates of all properties or a property with the specified name. |
| public PropertyChangeListener[] | Returns: all of thePropertyChangeListeners added or an
empty array if no listeners have been addedReturns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener(). |
| public PropertyChangeListener[] | Returns: all of thePropertyChangeListeners associated with
the named property. If no such listeners have been added,
or if propertyName is null, an empty array is
returned.The name of the property being listened to propertyName)Returns an array of all the listeners which have been associated with the named property. |
| public boolean | Returns: true if there are one or more listeners for the given propertythe property name. propertyName)Check if there are any listeners for a specific property, including those registered on all properties. |
| private void | |
| public void | removePropertyChangeListener(PropertyChangeListener
The PropertyChangeListener to be removed listener)Remove a PropertyChangeListener from the listener list. |
| public void | removePropertyChangeListener(String
The name of the property that was listened on. propertyName, PropertyChangeListener The PropertyChangeListener to be removed listener)Remove a PropertyChangeListener for a specific property. |
| private void | writeObject(ObjectOutputStream
the s)ObjectOutputStream to writeWrites serializable fields to stream. |
| map | back to summary |
|---|---|
| private PropertyChangeSupport. | |
| serialPersistentFields | back to summary |
|---|---|
| private static final ObjectStreamField[] serialPersistentFields
| |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Use serialVersionUID from JDK 1.1 for interoperability. | |
| source | back to summary |
|---|---|
| private Object source The object to be provided as the "source" for any generated events. | |
| PropertyChangeSupport | back to summary |
|---|---|
| public PropertyChangeSupport(Object sourceBean) Constructs a
| |
| addPropertyChangeListener | back to summary |
|---|---|
| public void addPropertyChangeListener(PropertyChangeListener listener) Add a PropertyChangeListener to the listener list.
The listener is registered for all properties.
The same listener object may be added more than once, and will be called
as many times as it is added.
If
| |
| addPropertyChangeListener | back to summary |
|---|---|
| public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) Add a PropertyChangeListener for a specific property. The listener
will be invoked only when a call on firePropertyChange names that
specific property.
The same listener object may be added more than once. For each
property, the listener will be invoked the number of times it was added
for that property.
If
| |
| fire | back to summary |
|---|---|
| private static void fire(PropertyChangeListener[] listeners, PropertyChangeEvent event) | |
| fireIndexedPropertyChange | back to summary |
|---|---|
| public void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) Reports a bound indexed property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal and non-null.
This is merely a convenience wrapper around the more general
| |
| fireIndexedPropertyChange | back to summary |
|---|---|
| public void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue) Reports an integer bound indexed property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
| |
| fireIndexedPropertyChange | back to summary |
|---|---|
| public void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue) Reports a boolean bound indexed property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
| |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, Object oldValue, Object newValue) Reports a bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal and non-null.
This is merely a convenience wrapper around the more general
| |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, int oldValue, int newValue) Reports an integer bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
| |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) Reports a boolean bound property update to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general
| |
| firePropertyChange | back to summary |
|---|---|
| public void firePropertyChange(PropertyChangeEvent event) Fires a property change event to listeners that have been registered to track updates of all properties or a property with the specified name. No event is fired if the given event's old and new values are equal and non-null.
| |
| getPropertyChangeListeners | back to summary |
|---|---|
| public PropertyChangeListener[] getPropertyChangeListeners() Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener().
If some listeners have been added with a named property, then
the returned array will be a mixture of PropertyChangeListeners
and
| |
| getPropertyChangeListeners | back to summary |
|---|---|
| public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) Returns an array of all the listeners which have been associated with the named property.
| |
| hasListeners | back to summary |
|---|---|
| public boolean hasListeners(String propertyName) Check if there are any listeners for a specific property, including
those registered on all properties. If
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException Reads the
| |
| removePropertyChangeListener | back to summary |
|---|---|
| public void removePropertyChangeListener(PropertyChangeListener listener) Remove a PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.
If
| |
| removePropertyChangeListener | back to summary |
|---|---|
| public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) Remove a PropertyChangeListener for a specific property.
If
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream s) throws IOException Writes serializable fields to stream.
| |
ChangeListenerMap implementation
that works with PropertyChangeListener objects.
| Modifier and Type | Field and Description |
|---|---|
| private static final PropertyChangeListener[] |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public PropertyChangeListener | extract(PropertyChangeListener listener)
Implements abstract java. Extracts a real listener from the proxy listener. |
| protected PropertyChangeListener[] | Returns: an array with specified lengththe array length length)Implements abstract java. Creates an array of |
| protected PropertyChangeListener | Returns: aPropertyChangeListenerProxy objectthe name of the property to listen on name, PropertyChangeListener the listener to process events listener)Implements abstract java. Creates a |
| EMPTY | back to summary |
|---|---|
| private static final PropertyChangeListener[] EMPTY | |
| PropertyChangeListenerMap | back to summary |
|---|---|
| private PropertyChangeListenerMap() | |
| extract | back to summary |
|---|---|
| public PropertyChangeListener extract(PropertyChangeListener listener) Implements abstract java. Doc from java. Extracts a real listener from the proxy listener. It is necessary because default proxy class is not serializable.
| |
| newArray | back to summary |
|---|---|
| protected PropertyChangeListener[] newArray(int length) Implements abstract java. Creates an array of
| |
| newProxy | back to summary |
|---|---|
| protected PropertyChangeListener newProxy(String name, PropertyChangeListener listener) Implements abstract java. Creates a
| |