Package com.xinapse.util
Class MonitorWorker
- All Implemented Interfaces:
Runnable
,Future<ExitStatus>
,RunnableFuture<ExitStatus>
- Direct Known Subclasses:
AbstractDynamicWorker
,ContourWorker
,SmootherWorker
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
SwingWorker.isCancelled()
method.-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.SwingWorker
SwingWorker.StateValue
-
Field Summary
Modifier and TypeFieldDescriptionAn error message set when an error occurs.An IndeterminateProgressMonitor which may pop up.A ProgressMonitor which may pop up. -
Constructor Summary
ModifierConstructorDescriptionprotected
MonitorWorker
(Component c, String progName) Creates a new MonitorWorker with a parent component and a program name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Tests whether thisMonitorWorker
has been cancelled.void
checkCancelled
(Integer progress) Tests whether thisMonitorWorker
has been cancelled, and sets the progress through this operation.void
checkCancelled
(String message) Tests whether thisMonitorWorker
has been cancelled.void
checkCancelled
(String message, Integer progress) Tests whether thisMonitorWorker
has been cancelled, and sets the progress through this operation.abstract ExitStatus
Overrides thedoInBackground()
method.void
done()
Overrides thedone()
method.Returns the component from which thisMonitorWorker
was launched.Returns the program name for thisMonitorWorker
.void
Set the action description for the Progress monitor or IndeterminateProgressMonitor.void
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
-
Field Details
-
monitor
A ProgressMonitor which may pop up. -
indeterminateMonitor
An IndeterminateProgressMonitor which may pop up. -
errorMessage
An error message set when an error occurs.
-
-
Constructor Details
-
MonitorWorker
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 Details
-
getComponent
Returns the component from which thisMonitorWorker
was launched.- Returns:
- the component (if non-null) from which this
MonitorWorker
was launched.
-
getProgName
Returns the program name for thisMonitorWorker
.- Returns:
- the program name for this
MonitorWorker
.
-
setAction
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
Set the action description for the Progress monitor or IndeterminateProgressMonitor.- Parameters:
descr
- the action description.
-
checkCancelled
Tests whether thisMonitorWorker
has been cancelled.- Throws:
CancelledException
- if the operation has been cancelled.
-
checkCancelled
Tests whether thisMonitorWorker
has been cancelled.- Parameters:
message
- a message to put to the IndeterminateProgressMonitor.- Throws:
CancelledException
- if the operation has been cancelled.
-
checkCancelled
Tests whether thisMonitorWorker
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
Tests whether thisMonitorWorker
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
Overrides thedoInBackground()
method.- Specified by:
doInBackground
in classSwingWorker<ExitStatus,
Integer> - Returns:
- the
ExitStatus
indicating whether the processing was successful, and if not why not.
-
done
public void done()- Overrides:
done
in classSwingWorker<ExitStatus,
Integer>
-