ucar.unidata.beans
Class AbstractProperty

java.lang.Object
  extended by ucar.unidata.beans.AbstractProperty
All Implemented Interfaces:
Property
Direct Known Subclasses:
NonVetoableProperty, VetoableProperty

public abstract class AbstractProperty
extends Object
implements Property

Provides support for JavaBean properties -- both vetoable and non-vetoable. This implementation conserves memory by allocating storage for property change listeners only when the first property change listener is added).

Version:
$Id: AbstractProperty.java,v 1.11 2005/05/13 18:28:22 jeffmc Exp $
Author:
Steven R. Emmerson

Constructor Summary
protected AbstractProperty(Object sourceBean, String name)
          Constructs an instance.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener.
abstract  void addVetoableChangeListener(VetoableChangeListener listener)
          Adds a VetoableChangeListener.
 void clearValue()
          This clears the current and previous value without notifying listeners
 String getName()
          Gets the name of the property.
 Object getSourceBean()
          Gets the source bean of the property.
 Object getValue()
          Gets the property value.
 boolean isReporting()
          Indicates if the property is reporting changes.
abstract  boolean isVetoable()
          Indicates if changes to this property can be vetoed.
 void notifyListeners()
          Reports changes to the Property.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener.
abstract  void removeVetoableChangeListener(VetoableChangeListener listener)
          Removes a VetoableChangeListener.
protected  void setCurrentValue(Object newValue)
          Sets the current value.
 void setReporting(boolean reportChanges)
          Enables or disables the reporting of property changes.
abstract  void setValue(Object newValue)
          Sets the property value.
abstract  void setValueAndNotifyListeners(Object newValue)
          Sets the property value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractProperty

protected AbstractProperty(Object sourceBean,
                           String name)
Constructs an instance.

Parameters:
sourceBean - The source bean of the property.
name - The name of the property.
Method Detail

getSourceBean

public final Object getSourceBean()
Gets the source bean of the property.

Specified by:
getSourceBean in interface Property
Returns:
The source bean of the property.

getName

public final String getName()
Gets the name of the property.

Specified by:
getName in interface Property
Returns:
The name of the property.

getValue

public Object getValue()
Gets the property value.

Specified by:
getValue in interface Property
Returns:
The property value, which is not a copy.

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener.

Specified by:
addPropertyChangeListener in interface Property
Parameters:
listener - The PropertyChangeListener to add.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener.

Specified by:
removePropertyChangeListener in interface Property
Parameters:
listener - The PropertyChangeListener to remove.

addVetoableChangeListener

public abstract void addVetoableChangeListener(VetoableChangeListener listener)
                                        throws UnsupportedOperationException
Adds a VetoableChangeListener.

Specified by:
addVetoableChangeListener in interface Property
Parameters:
listener - The VetoableChangeListener to add.
Throws:
UnsupportedOperationException - This operation is unsupported for this type of Property.

removeVetoableChangeListener

public abstract void removeVetoableChangeListener(VetoableChangeListener listener)
Removes a VetoableChangeListener.

Specified by:
removeVetoableChangeListener in interface Property
Parameters:
listener - The VetoableChangeListener to remove.

isVetoable

public abstract boolean isVetoable()
Indicates if changes to this property can be vetoed.

Specified by:
isVetoable in interface Property
Returns:
True if and only if changes to this property can be vetoed. NB: a VetoableProperty with no registered VetoableChangeListener-s will still return true.

setValueAndNotifyListeners

public abstract void setValueAndNotifyListeners(Object newValue)
                                         throws PropertyVetoException
Sets the property value. Will notify any listeners if and only if isReporting() is true. Will always notify any, registered, VetoableChangeListener-s.

Specified by:
setValueAndNotifyListeners in interface Property
Parameters:
newValue - The new property value.
Throws:
PropertyVetoException - A registered VetoableChangeListener objected to the change. The change was not committed.

setValue

public abstract void setValue(Object newValue)
                       throws PropertyVetoException
Sets the property value. Will not notify any PropertyChangeListener-s but will notify all VetoableChangeListener-s.

Specified by:
setValue in interface Property
Parameters:
newValue - The new property value.
Throws:
PropertyVetoException - A registered VetoableChangeListener objected to the change. The change was not committed.

setCurrentValue

protected final void setCurrentValue(Object newValue)
Sets the current value. This is the only way to set the value.

Parameters:
newValue - The new property value.

setReporting

public final void setReporting(boolean reportChanges)
Enables or disables the reporting of property changes.

Specified by:
setReporting in interface Property
Parameters:
reportChanges - Whether to enable or disable property change reporting.

isReporting

public final boolean isReporting()
Indicates if the property is reporting changes.

Specified by:
isReporting in interface Property
Returns:
_more_

notifyListeners

public final void notifyListeners()
Reports changes to the Property. Changes are only actually reported if isReporting() is true and the current value of the property is not equal to the previously-reported value.

Specified by:
notifyListeners in interface Property

clearValue

public void clearValue()
This clears the current and previous value without notifying listeners

Specified by:
clearValue in interface Property