java.beans
Class PropertyChangeSupport
java.lang.Object
|
+--java.beans.PropertyChangeSupport
All Implemented Interfaces:
Serializable
PropertyChangeSupport makes it easy to fire property change events and
handle listeners. It allows chaining of listeners, as well as filtering
by property name. In addition, it will serialize only those listeners
which are serializable, ignoring the others without problem. This class
is thread-safe.
Since:Authors:- John Keiser
- Eric Blake <ebb9@email.byu.edu>
PropertyChangeSupport
public PropertyChangeSupport(java.lang.Object source)
Create a PropertyChangeSupport to work with a specific source bean.
Parameters:
Throws:
addPropertyChangeListener
public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a PropertyChangeListener to the list of global listeners. All
property change events will be sent to this listener. The listener add
is not unique: that is, n adds with the same listener will
result in n events being sent to that listener for every
property change. Adding a null listener may cause a NullPointerException
down the road. This method will unwrap a PropertyChangeListenerProxy,
registering the underlying delegate to the named property list.
Parameters:
addPropertyChangeListener
public synchronized void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener l)
Adds a PropertyChangeListener listening on the specified property. Events
will be sent to the listener only if the property name matches. The
listener add is not unique; that is, n adds on a particular
property for a particular listener will result in n events
being sent to that listener when that property is changed. The effect is
cumulative, too; if you are registered to listen to receive events on
all property changes, and then you register on a particular property,
you will receive change events for that property twice. Adding a null
listener may cause a NullPointerException down the road. This method
will unwrap a PropertyChangeListenerProxy, registering the underlying
delegate to the named property list if the names match, and discarding
it otherwise.
Parameters:
Throws:
firePropertyChange
public void firePropertyChange(java.beans.PropertyChangeEvent event)
Fire a PropertyChangeEvent to all the global listeners, and to all the
listeners for the specified property name. This does nothing if old and
new values of the event are equal.
Parameters:
Throws:
firePropertyChange
public void firePropertyChange(java.lang.String propertyName, boolean oldVal, boolean newVal)
Fire a PropertyChangeEvent containing the old and new values of the
property to all the global listeners, and to all the listeners for the
specified property name. This does nothing if old and new are equal.
Parameters:
firePropertyChange
public void firePropertyChange(java.lang.String propertyName, int oldVal, int newVal)
Fire a PropertyChangeEvent containing the old and new values of the
property to all the global listeners, and to all the listeners for the
specified property name. This does nothing if old and new are equal.
Parameters:
firePropertyChange
public void firePropertyChange(java.lang.String propertyName, java.lang.Object oldVal, java.lang.Object newVal)
Fire a PropertyChangeEvent containing the old and new values of the
property to all the global listeners, and to all the listeners for the
specified property name. This does nothing if old and new are non-null
and equal.
Parameters:
getPropertyChangeListeners
public synchronized PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all registered property change listeners. Those that
were registered under a name will be wrapped in a
PropertyChangeListenerProxy
, so you must check whether the
listener is an instance of the proxy class in order to see what name the
real listener is registered under. If there are no registered listeners,
this returns an empty array.
Since:Returns:
- the array of registered listeners
See Also:
getPropertyChangeListeners
public synchronized PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Returns an array of all property change listeners registered under the
given property name. If there are no registered listeners, this returns
an empty array.
Since:Parameters:
Returns:
- the array of registered listeners
Throws:
hasListeners
public synchronized boolean hasListeners(java.lang.String propertyName)
Tell whether the specified property is being listened on or not. This
will only return true
if there are listeners on all
properties or if there is a listener specifically on this property.
Parameters:
Returns:
- whether the property is being listened on
Throws:
removePropertyChangeListener
public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from the list of global listeners. If
any specific properties are being listened on, they must be deregistered
by themselves; this will only remove the general listener to all
properties. If add()
has been called multiple times for a
particular listener, remove()
will have to be called the
same number of times to deregister it. This method will unwrap a
PropertyChangeListenerProxy, removing the underlying delegate from the
named property list.
Parameters:
removePropertyChangeListener
public synchronized void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from listening to a specific property.
If add()
has been called multiple times for a particular
listener on a property, remove()
will have to be called the
same number of times to deregister it. This method will unwrap a
PropertyChangeListenerProxy, removing the underlying delegate from the
named property list if the names match.
Parameters:
Throws: