org.springframework.richclient.util
Class SwingWorker

java.lang.Object
  extended by EDU.oswego.cs.dl.util.concurrent.FutureResult
      extended by org.springframework.richclient.util.SwingWorker
All Implemented Interfaces:
Runnable

public abstract class SwingWorker
extends EDU.oswego.cs.dl.util.concurrent.FutureResult
implements Runnable

An abstract class that you subclass to perform GUI-related work in a dedicated thread.

This class was adapted from the SwingWorker class presented in "Using a Swing Worker Thread" in the Swing Connection archives http://java.sun.com/products/jfc/tsc/archive/archive.html

This version of SwingWorker extends FutureResult and implements Runnable. Timeouts are supported.


Field Summary
protected  Thread thread
          Worker thread.
 
Fields inherited from class EDU.oswego.cs.dl.util.concurrent.FutureResult
exception_, ready_, value_
 
Constructor Summary
SwingWorker()
           
 
Method Summary
 void clear()
          Clears the worker thread variable and the FutureResult state, allowing this SwingWorker to be reused.
protected abstract  Object construct()
          Computes the value to be returned by the get method.
protected  void finished()
          Called on the event dispatching thread (not on the worker thread) after the construct method has returned.
protected  Object getFinishedResult()
           
protected  Throwable getTargetException()
           
 long getTimeout()
          Override to return a timeout period, in milliseconds.
 void interrupt()
          Stops the worker and sets the exception to InterruptedException.
 void run()
          Calls the construct method to compute the result, and then invokes the finished method on the event dispatch thread.
 void start()
          Starts the worker thread.
 
Methods inherited from class EDU.oswego.cs.dl.util.concurrent.FutureResult
doGet, get, getException, isReady, peek, set, setException, setter, timedGet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

thread

protected Thread thread
Worker thread.

Constructor Detail

SwingWorker

public SwingWorker()
Method Detail

construct

protected abstract Object construct()
                             throws Exception
Computes the value to be returned by the get method.

Throws:
Exception

finished

protected void finished()
Called on the event dispatching thread (not on the worker thread) after the construct method has returned.


getFinishedResult

protected Object getFinishedResult()

getTargetException

protected Throwable getTargetException()

getTimeout

public long getTimeout()
Override to return a timeout period, in milliseconds. The timeout is the maximum time to wait for the worker to complete. There is no time limit if the timeout is 0 (default).


run

public void run()
Calls the construct method to compute the result, and then invokes the finished method on the event dispatch thread.

Specified by:
run in interface Runnable

start

public void start()
Starts the worker thread.


interrupt

public void interrupt()
Stops the worker and sets the exception to InterruptedException.


clear

public void clear()
Clears the worker thread variable and the FutureResult state, allowing this SwingWorker to be reused. This is not particularly recommended and must be done only when you know that the worker thread is finished and that no other object is depending on the properties of this SwingWorker.

Overrides:
clear in class EDU.oswego.cs.dl.util.concurrent.FutureResult


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.