java.lang.Objectjava.beans.PropertyChangeSupport
public class PropertyChangeSupport
This is a utility class that can be used by beans that support bound properties. You can use an instance of this class as a member field of your bean and delegate various work to it. 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.
Constructor Summary | |
---|---|
PropertyChangeSupport
(
Object
sourceBean) Constructs a PropertyChangeSupport object. |
Method Summary | |
---|---|
void |
addPropertyChangeListener
(
PropertyChangeListener
listener) Add a PropertyChangeListener to the listener list. |
void |
addPropertyChangeListener
(
String
propertyName,
PropertyChangeListener
listener) Add a PropertyChangeListener for a specific property. |
void |
fireIndexedPropertyChange
(
String
propertyName, int index, boolean oldValue, boolean newValue) Report a boolean bound indexed property update to any registered listeners. |
void |
fireIndexedPropertyChange
(
String
propertyName, int index, int oldValue, int newValue) Report an int bound indexed property update to any registered listeners. |
void |
fireIndexedPropertyChange
(
String
propertyName, int index,
Object
oldValue,
Object
newValue) Report a bound indexed property update to any registered listeners. |
void |
firePropertyChange
(
PropertyChangeEvent
evt) Fire an existing PropertyChangeEvent to any registered listeners. |
void |
firePropertyChange
(
String
propertyName, boolean oldValue, boolean newValue) Report a boolean bound property update to any registered listeners. |
void |
firePropertyChange
(
String
propertyName, int oldValue, int newValue) Report an int bound property update to any registered listeners. |
void |
firePropertyChange
(
String
propertyName,
Object
oldValue,
Object
newValue) Report a bound property update to any registered listeners. |
PropertyChangeListener [] |
getPropertyChangeListeners
() Returns an array of all the listeners that were added to the PropertyChangeSupport object with addPropertyChangeListener(). |
PropertyChangeListener [] |
getPropertyChangeListeners
(
String
propertyName) Returns an array of all the listeners which have been associated with the named property. |
boolean |
hasListeners
(
String
propertyName) Check if there are any listeners for a specific property, including those registered on all properties. |
void |
removePropertyChangeListener
(
PropertyChangeListener
listener) Remove a PropertyChangeListener from the listener list. |
void |
removePropertyChangeListener
(
String
propertyName,
PropertyChangeListener
listener) Remove a PropertyChangeListener for a specific property. |
Methods inherited from class java.lang. Object |
---|
clone , equals , finalize , getClass , hashCode , notify , notifyAll , toString , wait , wait , wait |
Constructor Detail |
---|
public PropertyChangeSupport(Object sourceBean)
Method Detail |
---|
public void addPropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)
public PropertyChangeListener[] getPropertyChangeListeners()
If some listeners have been added with a named property, then the returned array will be a mixture of PropertyChangeListeners and PropertyChangeListenerProxys. If the calling method is interested in distinguishing the listeners then it must test each element to see if it's a PropertyChangeListenerProxy, perform the cast, and examine the parameter.
PropertyChangeListener[] listeners = bean.getPropertyChangeListeners(); for (int i = 0; i < listeners.length; i++) { if (listeners[i] instanceof PropertyChangeListenerProxy) { PropertyChangeListenerProxy proxy = (PropertyChangeListenerProxy)listeners[i]; if (proxy.getPropertyName().equals("foo")) { // proxy is a PropertyChangeListener which was associated // with the property named "foo" } } }
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
This is merely a convenience wrapper around the more general firePropertyChange method that takes PropertyChangeEvent value.
public void firePropertyChange(String propertyName, int oldValue, int newValue)
This is merely a convenience wrapper around the more general firePropertyChange method that takes Object values.
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)
This is merely a convenience wrapper around the more general firePropertyChange method that takes Object values.
public void firePropertyChange(PropertyChangeEvent evt)
public void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue)
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 method that takes PropertyChangeEvent value.
public void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue)
No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general fireIndexedPropertyChange method which takes Object values.
public void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue)
No event is fired if old and new values are equal.
This is merely a convenience wrapper around the more general fireIndexedPropertyChange method which takes Object values.
public boolean hasListeners(String propertyName)