com.taco.swinger
Class SwingCompute

java.lang.Object
  extended by com.taco.swinger.SwingCompute
All Implemented Interfaces:
java.lang.Runnable

public abstract class SwingCompute
extends java.lang.Object
implements java.lang.Runnable

A class that computes a value in the event-dispatch thread, whether the caller is running in the event-dispatch thread or not.


Field Summary
protected  java.lang.Object _result
          The result of compute().
protected  java.lang.Throwable _savedException
          The exception thrown by the last invocation of _compute(), if any.
 
Constructor Summary
SwingCompute()
           
 
Method Summary
protected abstract  java.lang.Object _compute()
          Run in the event-dispatch thread, and return whatever result should be returned by get().
 void clear()
          Clear the previously computed result.
 java.lang.Object get()
          Return the value in computed in the event-dispatch thread by _compute().
 java.lang.Throwable getSavedException()
          Return the exception thrown by _compute() the last time this instance was run.
 boolean hasRun()
          Return true if this instance has finished running already.
 void run()
          Call _compute(), but do not throw any exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_result

protected java.lang.Object _result
The result of compute().


_savedException

protected java.lang.Throwable _savedException
The exception thrown by the last invocation of _compute(), if any.

Constructor Detail

SwingCompute

public SwingCompute()
Method Detail

get

public final java.lang.Object get()
Return the value in computed in the event-dispatch thread by _compute(). The caller may or may not be running in the event-dispatch thread itself.


run

public final void run()
Call _compute(), but do not throw any exceptions. Instead, save any exception in _savedException. Also save the result of _compute() in _result.

Specified by:
run in interface java.lang.Runnable

getSavedException

public final java.lang.Throwable getSavedException()
Return the exception thrown by _compute() the last time this instance was run. If the instance has never been run, or no exception was thrown, return null.


hasRun

public boolean hasRun()
Return true if this instance has finished running already.


clear

public void clear()
Clear the previously computed result. After this method is called, hasRun() will return false.


_compute

protected abstract java.lang.Object _compute()
                                      throws java.lang.Exception
Run in the event-dispatch thread, and return whatever result should be returned by get(). Throw any exception desired; it will be caught by the caller.

Throws:
java.lang.Exception