org.jhotdraw.gui
Class Worker<T>

java.lang.Object
  extended by org.jhotdraw.gui.Worker<T>
All Implemented Interfaces:
java.lang.Runnable

public abstract class Worker<T>
extends java.lang.Object
implements java.lang.Runnable

This is an abstract class that you subclass to perform GUI-related work in a dedicated event dispatcher.

This class is similar to SwingWorker but less complex.

Version:
$Id: Worker.java 557 2009-09-06 16:12:08Z rawcoder $
Author:
Werner Randelshofer

Field Summary
private  java.lang.Throwable error
           
private  T value
           
 
Constructor Summary
Worker()
           
 
Method Summary
protected abstract  T construct()
          Compute the value to be returned by the get method.
protected  void done(T value)
          Called on the event dispatching thread (not on the worker thread) after the construct method has returned without throwing an error.
protected  void failed(java.lang.Throwable error)
          Called on the event dispatching thread (not on the worker thread) after the construct method has thrown an error.
protected  void finished()
          Called on the event dispatching thread (not on the worker thread) after the construct method has finished and after done() or failed() has been invoked.
protected  java.lang.Throwable getError()
          Get the error produced by the worker thread, or null if it hasn't thrown one.
protected  T getValue()
          Get the value produced by the worker thread, or null if it hasn't been constructed yet.
 void run()
          Calls #construct on the current thread and invokes #done on the AWT event dispatcher thread.
private  void setError(java.lang.Throwable x)
          Set the error thrown by constrct.
private  void setValue(T x)
          Set the value produced by construct.
 void start()
          Starts the Worker on an internal worker thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

value

private T value

error

private java.lang.Throwable error
Constructor Detail

Worker

public Worker()
Method Detail

run

public final void run()
Calls #construct on the current thread and invokes #done on the AWT event dispatcher thread.

Specified by:
run in interface java.lang.Runnable

construct

protected abstract T construct()
                        throws java.lang.Exception
Compute the value to be returned by the get method.

Throws:
java.lang.Exception

done

protected void done(T value)
Called on the event dispatching thread (not on the worker thread) after the construct method has returned without throwing an error.

The default implementation does nothing. Subclasses may override this method to perform done actions on the Event Dispatch Thread.

Parameters:
value - The return value of the construct method.

failed

protected void failed(java.lang.Throwable error)
Called on the event dispatching thread (not on the worker thread) after the construct method has thrown an error.

The default implementation prints a stack trace. Subclasses may override this method to perform failure actions on the Event Dispatch Thread.

Parameters:
error - The error thrown by construct.

finished

protected void finished()
Called on the event dispatching thread (not on the worker thread) after the construct method has finished and after done() or failed() has been invoked.

The default implementation does nothing. Subclasses may override this method to perform completion actions on the Event Dispatch Thread.


getValue

protected T getValue()
Get the value produced by the worker thread, or null if it hasn't been constructed yet.


setValue

private void setValue(T x)
Set the value produced by construct.


getError

protected java.lang.Throwable getError()
Get the error produced by the worker thread, or null if it hasn't thrown one.


setError

private void setError(java.lang.Throwable x)
Set the error thrown by constrct.


start

public void start()
Starts the Worker on an internal worker thread.