Skip to content

Most visited

Recently visited

navigation
Added in API level 3

PropertyChangeSupport

public class PropertyChangeSupport
extends Object implements Serializable

java.lang.Object
   ↳ java.beans.PropertyChangeSupport


Manages a list of listeners to be notified when a property changes. Listeners subscribe to be notified of all property changes, or of changes to a single named property.

This class is thread safe. No locking is necessary when subscribing or unsubscribing listeners, or when publishing events. Callers should be careful when publishing events because listeners may not be thread safe.

Summary

Public constructors

PropertyChangeSupport(Object sourceBean)

Creates a new instance that uses the source bean as source for any event.

Public methods

void addPropertyChangeListener(PropertyChangeListener listener)

Subscribes listener to change notifications for all properties.

void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)

Subscribes listener to change notifications for the property named propertyName.

void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue)

Fires a property change of an integer property with the given name.

void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue)

Fires an IndexedPropertyChangeEvent with the given name, old value, new value and index.

void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue)

Fires a property change of a boolean property with the given name.

void firePropertyChange(String propertyName, int oldValue, int newValue)

Fires a property change of an integer property with the given name.

void firePropertyChange(String propertyName, boolean oldValue, boolean newValue)

Fires a property change of a boolean property with the given name.

void firePropertyChange(PropertyChangeEvent event)

Publishes a property change event to all listeners of that property.

void firePropertyChange(String propertyName, Object oldValue, Object newValue)

Fires a PropertyChangeEvent with the given name, old value and new value.

PropertyChangeListener[] getPropertyChangeListeners()

Returns all subscribers.

PropertyChangeListener[] getPropertyChangeListeners(String propertyName)

Returns the subscribers to be notified when propertyName changes.

boolean hasListeners(String propertyName)

Returns true if there are listeners registered to the property with the given name.

void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)

Unsubscribes listener from change notifications for the property named propertyName.

void removePropertyChangeListener(PropertyChangeListener listener)

Unsubscribes listener from change notifications for all properties.

Inherited methods

From class java.lang.Object

Public constructors

PropertyChangeSupport

Added in API level 3
PropertyChangeSupport (Object sourceBean)

Creates a new instance that uses the source bean as source for any event.

Parameters
sourceBean Object: the bean used as source for all events.

Public methods

addPropertyChangeListener

Added in API level 3
void addPropertyChangeListener (PropertyChangeListener listener)

Subscribes listener to change notifications for all properties. If the listener is already subscribed, it will receive an additional notification. If the listener is null, this method silently does nothing.

Parameters
listener PropertyChangeListener

addPropertyChangeListener

Added in API level 3
void addPropertyChangeListener (String propertyName, 
                PropertyChangeListener listener)

Subscribes listener to change notifications for the property named propertyName. If the listener is already subscribed, it will receive an additional notification when the property changes. If the property name or listener is null, this method silently does nothing.

Parameters
propertyName String
listener PropertyChangeListener

fireIndexedPropertyChange

Added in API level 3
void fireIndexedPropertyChange (String propertyName, 
                int index, 
                int oldValue, 
                int newValue)

Fires a property change of an integer property with the given name. If the old value and the new value are not null and equal the event will not be fired.

Parameters
propertyName String: the property name
index int: the index of the changed property
oldValue int: the old value
newValue int: the new value

fireIndexedPropertyChange

Added in API level 3
void fireIndexedPropertyChange (String propertyName, 
                int index, 
                Object oldValue, 
                Object newValue)

Fires an IndexedPropertyChangeEvent with the given name, old value, new value and index. As source the bean used to initialize this instance is used. If the old value and the new value are not null and equal the event will not be fired.

Parameters
propertyName String: the name of the property
index int: the index
oldValue Object: the old value of the property
newValue Object: the new value of the property

fireIndexedPropertyChange

Added in API level 3
void fireIndexedPropertyChange (String propertyName, 
                int index, 
                boolean oldValue, 
                boolean newValue)

Fires a property change of a boolean property with the given name. If the old value and the new value are not null and equal the event will not be fired.

Parameters
propertyName String: the property name
index int: the index of the changed property
oldValue boolean: the old value
newValue boolean: the new value

firePropertyChange

Added in API level 3
void firePropertyChange (String propertyName, 
                int oldValue, 
                int newValue)

Fires a property change of an integer property with the given name. If the old value and the new value are not null and equal the event will not be fired.

Parameters
propertyName String: the property name
oldValue int: the old value
newValue int: the new value

firePropertyChange

Added in API level 3
void firePropertyChange (String propertyName, 
                boolean oldValue, 
                boolean newValue)

Fires a property change of a boolean property with the given name. If the old value and the new value are not null and equal the event will not be fired.

Parameters
propertyName String: the property name
oldValue boolean: the old value
newValue boolean: the new value

firePropertyChange

Added in API level 3
void firePropertyChange (PropertyChangeEvent event)

Publishes a property change event to all listeners of that property. If the event's old and new values are equal (but non-null), no event will be published.

Parameters
event PropertyChangeEvent

firePropertyChange

Added in API level 3
void firePropertyChange (String propertyName, 
                Object oldValue, 
                Object newValue)

Fires a PropertyChangeEvent with the given name, old value and new value. As source the bean used to initialize this instance is used. If the old value and the new value are not null and equal the event will not be fired.

Parameters
propertyName String: the name of the property
oldValue Object: the old value of the property
newValue Object: the new value of the property

getPropertyChangeListeners

Added in API level 3
PropertyChangeListener[] getPropertyChangeListeners ()

Returns all subscribers. This includes both listeners subscribed to all property changes and listeners subscribed to a single property.

Returns
PropertyChangeListener[]

getPropertyChangeListeners

Added in API level 3
PropertyChangeListener[] getPropertyChangeListeners (String propertyName)

Returns the subscribers to be notified when propertyName changes. This includes both listeners subscribed to all property changes and listeners subscribed to the named property only.

Parameters
propertyName String
Returns
PropertyChangeListener[]

hasListeners

Added in API level 3
boolean hasListeners (String propertyName)

Returns true if there are listeners registered to the property with the given name.

Parameters
propertyName String: the name of the property
Returns
boolean true if there are listeners registered to that property, false otherwise.

removePropertyChangeListener

Added in API level 3
void removePropertyChangeListener (String propertyName, 
                PropertyChangeListener listener)

Unsubscribes listener from change notifications for the property named propertyName. If multiple subscriptions exist for listener, it will receive one fewer notifications when the property changes. If the property name or listener is null or not subscribed, this method silently does nothing.

Parameters
propertyName String
listener PropertyChangeListener

removePropertyChangeListener

Added in API level 3
void removePropertyChangeListener (PropertyChangeListener listener)

Unsubscribes listener from change notifications for all properties. If the listener has multiple subscriptions, it will receive one fewer notification when properties change. If the property name or listener is null or not subscribed, this method silently does nothing.

Parameters
listener PropertyChangeListener
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.