com.xinapse.util
Class MonitorWorker

java.lang.Object
  extended by javax.swing.SwingWorker<ExitStatus,java.lang.Integer>
      extended by com.xinapse.util.MonitorWorker
All Implemented Interfaces:
java.lang.Runnable, java.util.concurrent.Future<ExitStatus>, java.util.concurrent.RunnableFuture<ExitStatus>
Direct Known Subclasses:
AbstractDynamicWorker, ContourWorker, SmootherWorker

public abstract class MonitorWorker
extends javax.swing.SwingWorker<ExitStatus,java.lang.Integer>

A class to implement a SwingWorker that can pop up a ProgressMonitor to allow user cancellation. It is up to the MonitorWorker's doInBackground method to check whether cancellation has occured using either the setMonitorProgress(int progress) method, which throws a CancelledException, or directly with the isCancelled() method.


Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.SwingWorker
javax.swing.SwingWorker.StateValue
 
Field Summary
 java.lang.String errorMessage
          An error message set when an error occurs.
 IndeterminateProgressMonitor indeterminateMonitor
          An IndeterminateProgressMonitor which may pop up.
 javax.swing.ProgressMonitor monitor
          A ProgressMonitor which may pop up.
 
Constructor Summary
protected MonitorWorker(java.awt.Component c, java.lang.String progName)
          Creates a new MonitorWorker with a parent component and a program name.
 
Method Summary
 void checkCancelled()
          Tests whether this CancellableWorker has been cancelled.
 void checkCancelled(java.lang.Integer progress)
          Tests whether this CancellableWorker has been cancelled, and sets the progress through this operation.
 void checkCancelled(java.lang.String message)
          Tests whether this CancellableWorker has been cancelled.
 void checkCancelled(java.lang.String message, java.lang.Integer progress)
          Tests whether this CancellableWorker has been cancelled, and sets the progress through this operation.
abstract  ExitStatus doInBackground()
          Overrides the doInBackground() method.
 void done()
          Overrides the done() method.
 java.awt.Component getComponent()
          Returns the component from which this MonitorWorker was launched.
 java.lang.String getProgName()
          Returns the program name for this MonitorWorker.
 void setAction(java.lang.String descr)
          Set the action description for the Progress monitor or IndeterminateProgressMonitor.
 void setAction(java.lang.String descr, int min, int max)
          Set the action description for the ProgressMonitor.
 
Methods inherited from class javax.swing.SwingWorker
addPropertyChangeListener, cancel, execute, firePropertyChange, get, get, getProgress, getPropertyChangeSupport, getState, isCancelled, isDone, process, publish, removePropertyChangeListener, run, setProgress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

monitor

public javax.swing.ProgressMonitor monitor
A ProgressMonitor which may pop up.


indeterminateMonitor

public IndeterminateProgressMonitor indeterminateMonitor
An IndeterminateProgressMonitor which may pop up.


errorMessage

public java.lang.String errorMessage
An error message set when an error occurs.

Constructor Detail

MonitorWorker

protected MonitorWorker(java.awt.Component c,
                        java.lang.String progName)
Creates a new MonitorWorker with a parent component and a program name.

Parameters:
c - a Component which may be able to show status messages, if non-null.
progName - program name for the program that is running this MonitorWorker.
Method Detail

getComponent

public java.awt.Component getComponent()
Returns the component from which this MonitorWorker was launched.

Returns:
the component (if non-null) from which this MonitorWorker was launched.

getProgName

public java.lang.String getProgName()
Returns the program name for this MonitorWorker.

Returns:
the program name for this MonitorWorker.

setAction

public void setAction(java.lang.String descr,
                      int min,
                      int max)
Set the action description for the ProgressMonitor.

Parameters:
descr - the action description.
min - the minimum for the ProgressMonitor.
max - the maximum for the ProgressMonitor.

setAction

public void setAction(java.lang.String descr)
Set the action description for the Progress monitor or IndeterminateProgressMonitor.

Parameters:
descr - the action description.

checkCancelled

public void checkCancelled()
                    throws CancelledException
Tests whether this CancellableWorker has been cancelled.

Throws:
CancelledException - if the operation has been cancelled.

checkCancelled

public void checkCancelled(java.lang.String message)
                    throws CancelledException
Tests whether this CancellableWorker has been cancelled.

Parameters:
message - a message to put to the IndeterminateProgressMonitor.
Throws:
CancelledException - if the operation has been cancelled.

checkCancelled

public void checkCancelled(java.lang.Integer progress)
                    throws CancelledException
Tests whether this CancellableWorker has been cancelled, and sets the progress through this operation.

Parameters:
progress - the progress of the ProgressMonitor.
Throws:
CancelledException - if the operation has been cancelled.

checkCancelled

public void checkCancelled(java.lang.String message,
                           java.lang.Integer progress)
                    throws CancelledException
Tests whether this CancellableWorker has been cancelled, and sets the progress through this operation.

Parameters:
message - a message to put to the IndeterminateProgressMonitor.
progress - the progress of the ProgressMonitor.
Throws:
CancelledException - if the operation has been cancelled.

doInBackground

public abstract ExitStatus doInBackground()
Overrides the doInBackground() method.

Specified by:
doInBackground in class javax.swing.SwingWorker<ExitStatus,java.lang.Integer>
Returns:
the ExitStatus indicating whether the processing was successful, and if not why not.

done

public void done()
Overrides the done() method. Closes the ProgressMonitor or IndeterminateProgressMonitor.

Overrides:
done in class javax.swing.SwingWorker<ExitStatus,java.lang.Integer>


Copyright 2006-2011 Xinapse Systems Limited. All Rights Reserved.