net.pacbell.jfai.toh.util
Class BufferedValue

java.lang.Object
  extended by net.pacbell.jfai.toh.util.BufferedValue
All Implemented Interfaces:
IChangeStatus

public class BufferedValue
extends Object
implements IChangeStatus

An instance represents an arbitrary value which can be in a changed or unchanged state. Value,bufferedValue and changed are bound bean properties . The value's state becomes changed by calling setValue(). The new value is buffered until the change is accepted with apply(). While the value is changed, getValue() answers the buffered value. The new value can be undone using cancel(). Both apply() and cancel() move the value's state back to unchanged. forceValue() unconditionally forces the value and the buffered value, and clears the changed status.

Author:
Jürgen Failenschmid

Field Summary
static String PROPERTY_BUFFERED_VALUE
          Name of bound property: buffered value.
static String PROPERTY_CHANGED
          Name of bound property: value has changed.
static String PROPERTY_VALUE
          Name of bound property: original value.
 
Constructor Summary
BufferedValue()
          Creates an instance without a value object.
BufferedValue(Object value)
          Creates a buffer for the given value object.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds the given listener to be notified of events for all bound properties.
 void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Adds the given listener to be notified of events for the given named property.
 void apply()
          Applies a pending value change.
 void cancel()
          Cancels a pending value change.
 void forceValue(Object newValue)
          Forces the value of the receiver without triggering a value property event.
 Object getBufferedValue()
          Gets the buffered value.
 Object getValue()
          Answers the value.
 boolean hasListeners(String propertyName)
          Checks if there are any listeners for changes to the given property.
 boolean isChanged()
          Checks for pending changes.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes the given listener so that it will no longer be notified of events for any bound property.
 void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
          Removes the given listener so that it will no longer be notified of events for the given named property.
 void setValue(Object newValue)
          Put a new value into the buffer and mark the receiver changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_BUFFERED_VALUE

public static final String PROPERTY_BUFFERED_VALUE
Name of bound property: buffered value.

See Also:
Constant Field Values

PROPERTY_CHANGED

public static final String PROPERTY_CHANGED
Name of bound property: value has changed.

See Also:
Constant Field Values

PROPERTY_VALUE

public static final String PROPERTY_VALUE
Name of bound property: original value.

See Also:
Constant Field Values
Constructor Detail

BufferedValue

public BufferedValue()
Creates an instance without a value object.


BufferedValue

public BufferedValue(Object value)
Creates a buffer for the given value object.

Parameters:
value - an object
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds the given listener to be notified of events for all bound properties.

Parameters:
listener - a listener

addPropertyChangeListener

public void addPropertyChangeListener(String propertyName,
                                      PropertyChangeListener listener)
Adds the given listener to be notified of events for the given named property.

Parameters:
propertyName - a string
listener - a listener

apply

public void apply()
Applies a pending value change. This has no effect if the value status is "unchanged". Triggers property events value and changed as needed.


cancel

public void cancel()
Cancels a pending value change. This has no effect if there isn't a changed state. Triggers property events bufferedValue and changed as needed.


forceValue

public void forceValue(Object newValue)
Forces the value of the receiver without triggering a value property event. bufferedValue and changed property events are triggered as needed.

Parameters:
newValue - new value object

getBufferedValue

public Object getBufferedValue()
Gets the buffered value.

Returns:
the buffered value

getValue

public Object getValue()
Answers the value.

Returns:
the buffered value of the receiver if the state is changed, otherwise answers the value of the receiver.

hasListeners

public boolean hasListeners(String propertyName)
Checks if there are any listeners for changes to the given property.

Parameters:
propertyName - a string
Returns:
Are there any listeners interested in the named property?

isChanged

public boolean isChanged()
Checks for pending changes.

Specified by:
isChanged in interface IChangeStatus
Returns:
Is a change of the value pending?
See Also:
IChangeStatus.isChanged()

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes the given listener so that it will no longer be notified of events for any bound property.

Parameters:
listener - a listener

removePropertyChangeListener

public void removePropertyChangeListener(String propertyName,
                                         PropertyChangeListener listener)
Removes the given listener so that it will no longer be notified of events for the given named property.

Parameters:
propertyName - a string
listener - a listener

setValue

public void setValue(Object newValue)
Put a new value into the buffer and mark the receiver changed. This triggers property events bufferedValue and changed as needed. This method has no effect if the current value is equal to the specified new value. The current and new values are compared using equals().

Parameters:
newValue - the new value