An abstract superclass that minimizes the effort required to provide
change support for bound and constrained Bean properties.
This class follows the conventions and recommendations as described
in the
Java Bean Specification.
Uses class
ExtendedPropertyChangeSupport
,
to enable the
==
or
#equals
test when
changing values.
TODO: Consider adding a method
#fireChange
that invokes
#firePropertyChange
if and only if
new value != old value
. The background is, that
#firePropertyChange
must fire an event
if
new value==null==old value
.
TODO: Consider renaming this class to AbstractBean. That better describes
what this class is about.
addPropertyChangeListener
public final void addPropertyChangeListener(PropertyChangeListener listener)
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.
- addPropertyChangeListener in interface Observable
listener
- the PropertyChangeListener to be added
addPropertyChangeListener
public final void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
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.
propertyName
- one of the property names listed abovelistener
- the PropertyChangeListener to be added
addVetoableChangeListener
public final void addVetoableChangeListener(String propertyName,
VetoableChangeListener listener)
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.
propertyName
- one of the property names listed abovelistener
- the VetoableChangeListener to be added
addVetoableChangeListener
public final void addVetoableChangeListener(VetoableChangeListener listener)
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.
listener
- the VetoableChangeListener to be added
equals
protected final boolean equals(Object o1,
Object o2)
Checks and answers if the two objects are both null
or equal.
o1
- the first object to compareo2
- the second object to compare
- boolean true if and only if both objects are
null
or equal
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.
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.
fireIndexedPropertyChange
protected final void fireIndexedPropertyChange(String propertyName,
int index,
boolean oldValue,
boolean newValue)
Report a
boolean
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.
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.
fireIndexedPropertyChange
protected final void fireIndexedPropertyChange(String propertyName,
int index,
int oldValue,
int newValue)
Report an
int
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.
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.
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 null
to any registered PropertyChangeListeners.
java.beans.PropertyChangeEvent
firePropertyChange
protected final void firePropertyChange(PropertyChangeEvent event)
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.
event
- describes the property change
firePropertyChange
protected final void firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
firePropertyChange
protected final void firePropertyChange(String propertyName,
Object oldValue,
Object newValue,
boolean checkIdentity)
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.
The boolean parameter specifies whether differences between the old
and new value are tested using
==
or
#equals
.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new valuecheckIdentity
- true to check differences using ==
false to use #equals
.
firePropertyChange
protected final void firePropertyChange(String propertyName,
boolean oldValue,
boolean newValue)
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
firePropertyChange
protected final void firePropertyChange(String propertyName,
double oldValue,
double newValue)
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
firePropertyChange
protected final void firePropertyChange(String propertyName,
float oldValue,
float newValue)
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
firePropertyChange
protected final void firePropertyChange(String propertyName,
int oldValue,
int newValue)
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
firePropertyChange
protected final void firePropertyChange(String propertyName,
long oldValue,
long newValue)
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
fireVetoableChange
protected final void fireVetoableChange(PropertyChangeEvent event)
throws PropertyVetoException
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.
event
- describes the property change
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
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.
propertyName
- the property whose value has changedoldValue
- the property's previous valuenewValue
- the property's new value
getPropertyChangeListeners
public final PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the property change listeners
registered on this component.
- all of this component's
PropertyChangeListener
s
or an empty array if no property change
listeners are currently registered
getPropertyChangeListeners
public final PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
Returns an array of all the listeners which have been associated
with the named property.
propertyName
- the name of the property to lookup listeners
- all of the
PropertyChangeListeners
associated with
the named property or an empty array if no listeners have
been added
getVetoableChangeListeners
public final VetoableChangeListener[] getVetoableChangeListeners()
Returns an array of all the property change listeners
registered on this component.
- all of this component's
VetoableChangeListener
s
or an empty array if no property change
listeners are currently registered
getVetoableChangeListeners
public final VetoableChangeListener[] getVetoableChangeListeners(String propertyName)
Returns an array of all the listeners which have been associated
with the named property.
propertyName
- the name of the property to lookup listeners
- all of the
VetoableChangeListeners
associated with
the named property or an empty array if no listeners have
been added
removePropertyChangeListener
public final void removePropertyChangeListener(PropertyChangeListener listener)
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.
- removePropertyChangeListener in interface Observable
listener
- the PropertyChangeListener to be removed
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.
propertyName
- a valid property namelistener
- the PropertyChangeListener to be removed
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.
propertyName
- a valid property namelistener
- the VetoableChangeListener to be removed
removeVetoableChangeListener
public final void removeVetoableChangeListener(VetoableChangeListener listener)
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.
listener
- the VetoableChangeListener to be removed