com.denova.ui
Class SwingWorker

java.lang.Object
  |
  +--com.denova.ui.SwingWorker

public abstract class SwingWorker
extends java.lang.Object

SwingWorker is a class to make using Swing thread safe. * * This is based on what appears to be the last version of * SwingWorker that does not require generics. * Since we still support Java 1.4, this is important. * We've changed the identifiers to largely match the * identifiers used in the Java 6 version of SwingWorker. * Hopefully this will make a later migration to SwingWorker in * Java 6 easier. Don't change anything that makes this * class incompatible with Java 6 SwingWorker unless it's really * necessary. This version also checks for Swing thread * violations using SwingCheckerThread. * * To use this class: *

    *
  1. Create a subclass with a doInBackground() method and a * done() method. *
  2. In doInBackground() you do whatever may take a long time, * but no Swing access. Return a computed value, or null if * there isn't one. *
  3. In done() you can update Swing components. If you want * the return value from doInBackground(), get it with the * get() method. *
  4. Instantiate your SwingWorker. Launch it with execute(). *
* * Last modified: 2008.04.04 * * The rest of these docs are not from DeNova. * *
* * This is the 3rd version of SwingWorker (also known as * SwingWorker 3), an abstract class that you subclass to * perform GUI-related work in a dedicated thread. For * instructions on using this class, see: * * http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html * * Note that the API changed slightly in the 3rd version: * You must now invoke execute() on the SwingWorker after * creating it.


Field Summary
static int DONE
          DONE: immediately after done() is finished.
static int PENDING
          PENDING: when SwingWorker's constructor instantiated.
static int STARTED
          STARTED: immediately before doInBackground() has started.
 
Constructor Summary
SwingWorker()
          Start a thread that will call the doInBackground method * and then exit.
 
Method Summary
abstract  java.lang.Object doInBackground()
          Do time consuming non Swing work in background.
 void done()
          Called on the event dispatching thread, not on the worker thread, * after the doInBackground method has returned.
 void execute()
          Start the worker thread.
 java.lang.Object get()
          Return the value created by the doInBackground method.
 int getState()
          Set the current state of SwingWorker.
protected  java.lang.Object getValue()
          * Get the value produced by the worker thread, or null if * doInBackground isn't finished yet.
 void interrupt()
          Interrupt the doInBackground() thread.
 boolean isDone()
          Determine if SwingWorker is finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PENDING

public static final int PENDING
PENDING: when SwingWorker's constructor instantiated.

See Also:
Constant Field Values

STARTED

public static final int STARTED
STARTED: immediately before doInBackground() has started.

See Also:
Constant Field Values

DONE

public static final int DONE
DONE: immediately after done() is finished.

See Also:
Constant Field Values
Constructor Detail

SwingWorker

public SwingWorker()
Start a thread that will call the doInBackground method * and then exit.

Method Detail

getValue

protected java.lang.Object getValue()
* Get the value produced by the worker thread, or null if * doInBackground isn't finished yet.


doInBackground

public abstract java.lang.Object doInBackground()
Do time consuming non Swing work in background. * Compute the value to be returned by the get method. * Do not access Swing from this method unless the Swing method * is documented in its javadocs as thread safe. * * This method is called on this thread.


done

public void done()
Called on the event dispatching thread, not on the worker thread, * after the doInBackground method has returned. * You can access Swing in this method. Do not do anything that * takes more than a very short time.


getState

public final int getState()
Set the current state of SwingWorker. * * We'd like it to be synchronized, * but that would cause deadlocks.


isDone

public final boolean isDone()
Determine if SwingWorker is finished.


interrupt

public void interrupt()
Interrupt the doInBackground() thread. Call this method * to force the background worker to stop what it's doing. * @deprecated Interrupting Threads causes lockups and races.


get

public java.lang.Object get()
Return the value created by the doInBackground method. * Returns null if either the thread running doInBackground or the current * thread was interrupted before a value was produced. * * @return the value created by the doInBackground method


execute

public void execute()
Start the worker thread. * This method is called on this thread.