A ValueModel that wraps another ValueModel, the subject, and delays changes of the subject's value. Returns the subject's value until a value has been set. The buffered value is not written to the subject until the trigger channel changes to
Boolean.TRUE
. The buffered value can be flushed by changing the trigger channel value to
Boolean.FALSE
. Note that the commit and flush events are performed only if the trigger channel fires a change event. Since a plain ValueHolder fires no property change event if a value is set that has been set before, it is recommended to use a {@link Trigger} insteadand invoke its
#triggerCommit
and
triggerFlush
methods.
The BufferedValueModel has been designed to behave much like its subject when accessing the value. Therefore it throws all exceptions that would arise when accessing the subject directly. Hence, attempts to read or write a value while the subject is null
are always rejected with a NullPointerException
.
This class provides the bound read-write properties subject and triggerChannel for the subject and trigger channel and a bound read-only property buffering for the buffering state.
The BufferedValueModel registers listeners with the subject and trigger channel. It is recommended to remove these listeners by invoking #release
if the subject and trigger channel live much longer than this buffer. After #release
has been called you must not use the BufferedValueModel instance any longer. As an alternative you may use event listener lists in subjects and trigger channels that are based on WeakReference
s.
If the subject value changes while this model is in buffering state this change won't show through as this model's new value. If you want to update the value whenever the subject value changes, register a listener with the subject value and flush this model's trigger.
Constraints: The subject is of type Object
, the trigger channel value of type Boolean
.
@author Karsten Lentzsch
@version $Revision: 1.14 $
@see ValueModel
@see ValueModel#getValue()
@see ValueModel#setValue(Object) Copyright (c) 2002-2005 JGoodies Karsten Lentzsch. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: o Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. o Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. o Neither the name of JGoodies Karsten Lentzsch nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.