Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jgoodies.binding.extras
Class DelayedValueModel  view DelayedValueModel download DelayedValueModel.java

java.lang.Object
  extended byAbstractValueModel
      extended bycom.jgoodies.binding.extras.DelayedValueModel

public final class DelayedValueModel
extends AbstractValueModel

A ValueModel that deferres value changes for a specified delay. Useful to coalesce frequent changes. For example if a heavy computation shall be performed only for a "stable" selection after a series of quick selection changes.

Wraps a given subject ValueModel and returns the subject value or the value to be set as this model's value. Observes subject value changes and forwards them to listeners of this model. If a value is set to this model, a Swing Timer is used to delay the value commit to the subject. A previously started timer - if any - will be stopped before.

Version:
$Revision: 1.2 $

Nested Class Summary
private  class DelayedValueModel.SubjectValueChangeHandler
           
private  class DelayedValueModel.ValueCommitListener
           
 
Field Summary
private  java.lang.Object pendingValue
          Holds the most recent pending value.
private  ValueModel subject
          Refers to the underlying subject ValueModel.
private  javax.swing.Timer timer
          The Timer used to perform the delayed commit.
 
Constructor Summary
DelayedValueModel(ValueModel subject, int delay)
          Constructs a DelayedValueModel for the given subject ValueModel and the specified Timer delay in milliseconds.
 
Method Summary
 java.lang.Object getValue()
          Returns the subject's value or in case of a pending commit, the pending new value.
private  boolean hasPendingChange()
           
 void setValue(java.lang.Object newValue)
          Sets the given new value after this model's delay.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subject

private final ValueModel subject
Refers to the underlying subject ValueModel.


timer

private final javax.swing.Timer timer
The Timer used to perform the delayed commit.


pendingValue

private java.lang.Object pendingValue
Holds the most recent pending value. It is updated evertime #setValue is invoked.

Constructor Detail

DelayedValueModel

public DelayedValueModel(ValueModel subject,
                         int delay)
Constructs a DelayedValueModel for the given subject ValueModel and the specified Timer delay in milliseconds.

Method Detail

getValue

public java.lang.Object getValue()
Returns the subject's value or in case of a pending commit, the pending new value.


setValue

public void setValue(java.lang.Object newValue)
Sets the given new value after this model's delay. Does nothing if the new value and the latest pending value are the same.


hasPendingChange

private boolean hasPendingChange()