Package ucar.ui.widget
Class ProgressMonitor
- java.lang.Object
-
- ucar.ui.widget.ProgressMonitor
-
public class ProgressMonitor extends Object
This wraps a javax.swing.ProgressMonitor, which allows tasks to be canceled. This class adds extra behavior to javax.swing.ProgressMonitor:- Pass in the ProgressMonitorTask you want to monitor.
- Throws an actionEvent (on the AWT event thread) when the task is done.
- If an error, pops up an error message.
- Get status: success/failed/cancel when task is done.
Example: AddDatasetTask task = new AddDatasetTask(datasets); ProgressMonitor pm = new ProgressMonitor(task); pm.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("success")) { doGoodStuff(); } } }); pm.start( this, "Add Datasets", datasets.size()); (or) AddDatasetTask task = new AddDatasetTask(datasets); ProgressMonitor pm = new ProgressMonitor(task, () -> doGoodStuff()); pm.start( this, "Add Datasets", datasets.size());
-
-
Constructor Summary
Constructors Constructor Description ProgressMonitor(ProgressMonitorTask task)
ProgressMonitor(ProgressMonitorTask task, ActionListener successListener)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActionListener(ActionListener l)
Add listener: action event sent when task is done.ProgressMonitorTask
getTask()
void
removeActionListener(ActionListener l)
void
start(Component top, String taskName, int progressMaxCount)
Call this from awt event thread.
-
-
-
Constructor Detail
-
ProgressMonitor
public ProgressMonitor(ProgressMonitorTask task)
-
ProgressMonitor
public ProgressMonitor(ProgressMonitorTask task, ActionListener successListener)
-
-
Method Detail
-
getTask
public ProgressMonitorTask getTask()
-
addActionListener
public void addActionListener(ActionListener l)
Add listener: action event sent when task is done. event.getActionCommand() =- "success"
- "error"
- "cancel"
- "done" if done, but success/error/cancel not set
-
removeActionListener
public void removeActionListener(ActionListener l)
-
start
public void start(Component top, String taskName, int progressMaxCount)
Call this from awt event thread. The task is run in a background thread.- Parameters:
top
- put ProgressMonitor on top of this component (may be null)taskName
- display name of taskprogressMaxCount
- maximum number of Progress indicator
-
-