Class Bean
- All Implemented Interfaces:
ObservableBean
,ObservableBean2
,Serializable
- Direct Known Subclasses:
AbstractUnitConverter
This class uses the standard PropertyChangeSupport
to notify registered listeners about
changes. Subclasses can use different change support implementations by overriding
createPropertyChangeSupport
, for example to ensure that notifications are sent in the
Event dispatch thread, or to compare old and new values with ==
not equals
.
- Author:
- Karsten Lentzsch
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PropertyChangeSupport
If anyPropertyChangeListeners
have been registered, thechangeSupport
field describes them. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds a PropertyChangeListener to the listener list.final void
addPropertyChangeListener
(String propertyName, PropertyChangeListener listener) Adds a PropertyChangeListener to the listener list for a specific property.final void
Adds a VetoableChangeListener to the listener list.final void
addVetoableChangeListener
(String propertyName, VetoableChangeListener listener) Adds a VetoableChangeListener to the listener list for a specific property.protected PropertyChangeSupport
Creates and returns a PropertyChangeSupport for the given bean.protected final void
fireIndexedPropertyChange
(String propertyName, int index, boolean oldValue, boolean newValue) Report aboolean
bound indexed property update to any registered listeners.protected final void
fireIndexedPropertyChange
(String propertyName, int index, int oldValue, int newValue) Report anint
bound indexed property update to any registered listeners.protected final void
fireIndexedPropertyChange
(String propertyName, int index, Object oldValue, Object newValue) Report a bound indexed property update to any registered listeners.protected final void
Indicates that an arbitrary set of bound properties have changed.protected final void
General support for reporting bound property changes.protected final void
firePropertyChange
(String propertyName, boolean oldValue, boolean newValue) Support for reporting bound property changes for boolean properties.protected final void
firePropertyChange
(String propertyName, double oldValue, double newValue) Support for reporting bound property changes for integer properties.protected final void
firePropertyChange
(String propertyName, float oldValue, float newValue) Support for reporting bound property changes for integer properties.protected final void
firePropertyChange
(String propertyName, int oldValue, int newValue) Support for reporting bound property changes for integer properties.protected final void
firePropertyChange
(String propertyName, long oldValue, long newValue) Support for reporting bound property changes for integer properties.protected final void
firePropertyChange
(String propertyName, Object oldValue, Object newValue) Support for reporting bound property changes for Object properties.protected final void
General support for reporting constrained property changes.protected final void
fireVetoableChange
(String propertyName, boolean oldValue, boolean newValue) Support for reporting changes for constrained boolean properties.protected final void
fireVetoableChange
(String propertyName, double oldValue, double newValue) Support for reporting changes for constrained integer properties.protected final void
fireVetoableChange
(String propertyName, float oldValue, float newValue) Support for reporting changes for constrained integer properties.protected final void
fireVetoableChange
(String propertyName, int oldValue, int newValue) Support for reporting changes for constrained integer properties.protected final void
fireVetoableChange
(String propertyName, long oldValue, long newValue) Support for reporting changes for constrained integer properties.protected final void
fireVetoableChange
(String propertyName, Object oldValue, Object newValue) Support for reporting changes for constrained Object properties.final PropertyChangeListener[]
Returns an array of all the property change listeners registered on this component.final PropertyChangeListener[]
getPropertyChangeListeners
(String propertyName) Returns an array of all the listeners which have been associated with the named property.final VetoableChangeListener[]
Returns an array of all the property change listeners registered on this component.final VetoableChangeListener[]
getVetoableChangeListeners
(String propertyName) Returns an array of all the listeners which have been associated with the named property.final void
Removes a PropertyChangeListener from the listener list.final void
removePropertyChangeListener
(String propertyName, PropertyChangeListener listener) Removes a PropertyChangeListener from the listener list for a specific property.final void
Removes a VetoableChangeListener from the listener list.final void
removeVetoableChangeListener
(String propertyName, VetoableChangeListener listener) Removes a VetoableChangeListener from the listener list for a specific property.
-
Field Details
-
changeSupport
If anyPropertyChangeListeners
have been registered, thechangeSupport
field describes them.
-
-
Constructor Details
-
Bean
public Bean()
-
-
Method Details
-
addPropertyChangeListener
Adds a PropertyChangeListener to the listener list. The listener is registered for all bound properties of this class.If listener is
null
, no exception is thrown and no action is performed.- Specified by:
addPropertyChangeListener
in interfaceObservableBean
- Parameters:
listener
- the PropertyChangeListener to be added- See Also:
-
removePropertyChangeListener
Removes a PropertyChangeListener from the listener list. This method should be used to remove PropertyChangeListeners that were registered for all bound properties of this class.If listener is
null
, no exception is thrown and no action is performed.- Specified by:
removePropertyChangeListener
in interfaceObservableBean
- Parameters:
listener
- the PropertyChangeListener to be removed- See Also:
-
addPropertyChangeListener
Adds a PropertyChangeListener to the listener list for a specific property. The specified property may be user-defined.Note that if this Model is inheriting a bound property, then no event will be fired in response to a change in the inherited property.
If listener is
null
, no exception is thrown and no action is performed.- Specified by:
addPropertyChangeListener
in interfaceObservableBean2
- Parameters:
propertyName
- one of the property names listed abovelistener
- the PropertyChangeListener to be added- See Also:
-
removePropertyChangeListener
public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) Removes a PropertyChangeListener from the listener list for a specific property. This method should be used to remove PropertyChangeListeners that were registered for a specific bound property.If listener is
null
, no exception is thrown and no action is performed.- Specified by:
removePropertyChangeListener
in interfaceObservableBean2
- Parameters:
propertyName
- a valid property namelistener
- the PropertyChangeListener to be removed- See Also:
-
addVetoableChangeListener
Adds a VetoableChangeListener to the listener list. The listener is registered for all bound properties of this class.If listener is
null
, no exception is thrown and no action is performed.- Parameters:
listener
- the VetoableChangeListener to be added- See Also:
-
removeVetoableChangeListener
Removes a VetoableChangeListener from the listener list. This method should be used to remove VetoableChangeListeners that were registered for all bound properties of this class.If listener is
null
, no exception is thrown and no action is performed.- Parameters:
listener
- the VetoableChangeListener to be removed- See Also:
-
addVetoableChangeListener
Adds a VetoableChangeListener to the listener list for a specific property. The specified property may be user-defined.Note that if this Model is inheriting a bound property, then no event will be fired in response to a change in the inherited property.
If listener is
null
, no exception is thrown and no action is performed.- Parameters:
propertyName
- one of the property names listed abovelistener
- the VetoableChangeListener to be added- See Also:
-
removeVetoableChangeListener
public final void removeVetoableChangeListener(String propertyName, VetoableChangeListener listener) Removes a VetoableChangeListener from the listener list for a specific property. This method should be used to remove VetoableChangeListeners that were registered for a specific bound property.If listener is
null
, no exception is thrown and no action is performed.- Parameters:
propertyName
- a valid property namelistener
- the VetoableChangeListener to be removed- See Also:
-
getPropertyChangeListeners
Returns an array of all the property change listeners registered on this component.- Specified by:
getPropertyChangeListeners
in interfaceObservableBean2
- Returns:
- all of this component's
PropertyChangeListener
s or an empty array if no property change listeners are currently registered - See Also:
-
getPropertyChangeListeners
Returns an array of all the listeners which have been associated with the named property.- Specified by:
getPropertyChangeListeners
in interfaceObservableBean2
- Parameters:
propertyName
- the name of the property to lookup listeners- Returns:
- all of the
PropertyChangeListeners
associated with the named property or an empty array if no listeners have been added - See Also:
-
getVetoableChangeListeners
Returns an array of all the property change listeners registered on this component.- Returns:
- all of this component's
VetoableChangeListener
s or an empty array if no property change listeners are currently registered - See Also:
-
getVetoableChangeListeners
Returns an array of all the listeners which have been associated with the named property.- Parameters:
propertyName
- the name of the property to lookup listeners- Returns:
- all of the
VetoableChangeListeners
associated with the named property or an empty array if no listeners have been added - See Also:
-
createPropertyChangeSupport
Creates and returns a PropertyChangeSupport for the given bean. Invoked by the first call toaddPropertyChangeListener(java.beans.PropertyChangeListener)
when lazily creating the sole change support instance used throughout this bean.This default implementation creates a
PropertyChangeSupport
. Subclasses may override to return other change support implementations. For example to ensure that listeners are notified in the Event dispatch thread (EDT change support). The JGoodies Binding uses an extended change support that allows to configure whether the old and new value are compared with==
orequals
.- Parameters:
bean
- the bean to create a change support for- Returns:
- the new change support
-
firePropertyChange
General support for reporting bound property changes. Sends the given PropertyChangeEvent to any registered PropertyChangeListener.Most bean setters will invoke the fireXXX methods that get a property name and the old and new value. However some frameworks and setters may prefer to use this general method. Also, this method allows to fire IndexedPropertyChangeEvents that have been introduced in Java 5.
- Parameters:
event
- describes the property change- Since:
- 1.3
-
firePropertyChange
Support for reporting bound property changes for Object properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
-
firePropertyChange
Support for reporting bound property changes for boolean properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
-
firePropertyChange
Support for reporting bound property changes for integer properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
-
firePropertyChange
Support for reporting bound property changes for integer properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
-
firePropertyChange
Support for reporting bound property changes for integer properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
-
firePropertyChange
Support for reporting bound property changes for integer properties. This method can be called when a bound property has changed and it will send the appropriate PropertyChangeEvent to any registered PropertyChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
-
fireMultiplePropertiesChanged
protected final void fireMultiplePropertiesChanged()Indicates that an arbitrary set of bound properties have changed. Sends a PropertyChangeEvent with property name, old and new value set tonull
to any registered PropertyChangeListeners.- Since:
- 1.0.3
- See Also:
-
fireIndexedPropertyChange
protected final void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) Report a bound indexed property update to any registered listeners.No event is fired if old and new values are equal and non-null.
- Parameters:
propertyName
- The programmatic name of the property that was changed.index
- index of the property element that was changed.oldValue
- The old value of the property.newValue
- The new value of the property.- Since:
- 2.0
-
fireIndexedPropertyChange
protected final void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue) Report anint
bound indexed property update to any registered listeners.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 method which takes Object values.
- Parameters:
propertyName
- The programmatic name of the property that was changed.index
- index of the property element that was changed.oldValue
- The old value of the property.newValue
- The new value of the property.- Since:
- 2.0
-
fireIndexedPropertyChange
protected final void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue) Report aboolean
bound indexed property update to any registered listeners.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 method which takes Object values.
- Parameters:
propertyName
- The programmatic name of the property that was changed.index
- index of the property element that was changed.oldValue
- The old value of the property.newValue
- The new value of the property.- Since:
- 2.0
-
fireVetoableChange
General support for reporting constrained property changes. Sends the given PropertyChangeEvent to any registered PropertyChangeListener.Most bean setters will invoke the fireXXX methods that get a property name and the old and new value. However some frameworks and setters may prefer to use this general method. Also, this method allows to fire IndexedPropertyChangeEvents that have been introduced in Java 5.
- Parameters:
event
- describes the property change- Throws:
PropertyVetoException
- if a constrained property change is rejected- Since:
- 1.3
-
fireVetoableChange
protected final void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws PropertyVetoException Support for reporting changes for constrained Object properties. This method can be called before a constrained property will be changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value- Throws:
PropertyVetoException
- if a constrained property change is rejected
-
fireVetoableChange
protected final void fireVetoableChange(String propertyName, boolean oldValue, boolean newValue) throws PropertyVetoException Support for reporting changes for constrained boolean properties. This method can be called before a constrained property will be changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value- Throws:
PropertyVetoException
- if a constrained property change is rejected
-
fireVetoableChange
protected final void fireVetoableChange(String propertyName, double oldValue, double newValue) throws PropertyVetoException Support for reporting changes for constrained integer properties. This method can be called before a constrained property will be changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value- Throws:
PropertyVetoException
- if a constrained property change is rejected
-
fireVetoableChange
protected final void fireVetoableChange(String propertyName, int oldValue, int newValue) throws PropertyVetoException Support for reporting changes for constrained integer properties. This method can be called before a constrained property will be changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value- Throws:
PropertyVetoException
- if a constrained property change is rejected
-
fireVetoableChange
protected final void fireVetoableChange(String propertyName, float oldValue, float newValue) throws PropertyVetoException Support for reporting changes for constrained integer properties. This method can be called before a constrained property will be changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value- Throws:
PropertyVetoException
- if a constrained property change is rejected
-
fireVetoableChange
protected final void fireVetoableChange(String propertyName, long oldValue, long newValue) throws PropertyVetoException Support for reporting changes for constrained integer properties. This method can be called before a constrained property will be changed and it will send the appropriate PropertyChangeEvent to any registered VetoableChangeListeners.- Parameters:
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value- Throws:
PropertyVetoException
- if a constrained property change is rejected
-