JHotDraw 7.4.1

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 604 2010-01-09 12:00:29Z rawcoder $
Author:
Werner Randelshofer

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.
 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
 

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.


getError

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


start

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


Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.