Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright 2012-04-26 Werner Randelshofer
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.monte.media.gui
Class Worker<T>

    java.lang.Object
      org.monte.media.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 can subclass to perform GUI-related work in a dedicated event dispatcher.

This class is similar to SwingWorker but less complex.

Version:
  $Id: Worker.java 134 2011-12-02 16:23:00Z werner $
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.
`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

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

Overview | Package | Class | Tree | Deprecated | Index | Help
| Copyright 2012-04-26 Werner Randelshofer
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD