Class TaskMonitor
- java.lang.Object
-
- org.jdesktop.application.AbstractBean
-
- org.jdesktop.application.TaskMonitor
-
public class TaskMonitor extends AbstractBean
This class is intended to serve as the model for GUI components, like status bars, that display the state of an application's background tasks.TaskMonitorprovides an overview of all the ApplicationContext's Tasks, as well as the state of a singleforegroundTask.The value of
getTasks()is a list of all of theTaskswhose state is notDONEfor all of the ApplicationContext'sTaskServices. In other words: all of the ApplicationContext's background tasks that haven't finished executing. Each time a new TaskService Task is executed it's added to the list; when the Task finishes it's removed. Each time the list changesPropertyChangeListenersare fired. Applications that wish to create a detailed visualization of all Tasks should monitor the TaskMonitor"tasks"property.Users are often only interested in the status of a single foreground task, typically the one associated with GUI element they're working with, or with the most recent command they've issued. The TaskMonitor's PropertyChangeListener is notified each time a property of the
foregroundTaskchanges. Additionally the TaskMonitor fires synthetic PropertyChangeEvents for properties named "pending", "started", and "done" when the corresponding Taskstateproperty changes occur.TaskMonitor manages a queue of new Tasks. The foregroundTask is automatically set to the first new Task, and when that Task finishes, the next Task in the queue, and so on. Applications can set the foregroundTask explicitly, to better reflect what the user is doing. For example, a tabbed browsing GUI that launched one Task per tab might set the foreground Task each time the user selected a tab. To prevent the foregroundTask property from (ever) being reset automatically, one must set
autoUpdateForegroundTaskto false.This class is not thread-safe. All of its methods must be called on the event dispatching thread (EDT) and all of its listeners will run on the EDT.
-
-
Constructor Summary
Constructors Constructor Description TaskMonitor(ApplicationContext context)Construct a TaskMonitor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleangetAutoUpdateForegroundTask()True if theforegroundTaskproperty should be automatically reset to the oldest Task in the queue when it finishes running.TaskgetForegroundTask()Indicates theTaskwhose status the ApplicationContext's GUI wants to be displayed, typically in the main window's status bar.java.util.List<Task>getTasks()All of the Application Tasks whosestateis notDONE.voidsetAutoUpdateForegroundTask(boolean autoUpdateForegroundTask)True if theforegroundTaskproperty should be automatically reset to the oldest Task in the queue when it finishes running.voidsetForegroundTask(Task foregroundTask)The TaskMonitor's PropertyChangeListeners are fired each time any property of the theforegroundTaskchanges.-
Methods inherited from class org.jdesktop.application.AbstractBean
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
TaskMonitor
public TaskMonitor(ApplicationContext context)
Construct a TaskMonitor.
-
-
Method Detail
-
setForegroundTask
public void setForegroundTask(Task foregroundTask)
The TaskMonitor's PropertyChangeListeners are fired each time any property of the theforegroundTaskchanges. By default this property is set to the first Task to be executed and then, when that Task finishes, reset to the next most recently executed Task. If theautoUpdateForegroundTaskis false, then the foregroundTask property is not reset automatically.- Parameters:
foregroundTask- the task whose properties are reflected by this class- See Also:
setAutoUpdateForegroundTask(boolean),getForegroundTask()
-
getForegroundTask
public Task getForegroundTask()
Indicates theTaskwhose status the ApplicationContext's GUI wants to be displayed, typically in the main window's status bar.- Returns:
- the value of the foregroundTask property.
- See Also:
setForegroundTask(org.jdesktop.application.Task)
-
getAutoUpdateForegroundTask
public boolean getAutoUpdateForegroundTask()
True if theforegroundTaskproperty should be automatically reset to the oldest Task in the queue when it finishes running.This property is true by default.
- Returns:
- true if the foregroundTask should be set automatically.
- See Also:
setAutoUpdateForegroundTask(boolean),setForegroundTask(org.jdesktop.application.Task)
-
setAutoUpdateForegroundTask
public void setAutoUpdateForegroundTask(boolean autoUpdateForegroundTask)
True if theforegroundTaskproperty should be automatically reset to the oldest Task in the queue when it finishes running. An application that wants explicit control over the Task being monitored can set this property to false.This property is true by default.
- Parameters:
autoUpdateForegroundTask- true if the foregroundTask should be set automatically- See Also:
getAutoUpdateForegroundTask()
-
getTasks
public java.util.List<Task> getTasks()
All of the Application Tasks whosestateis notDONE.Each time the list of Tasks changes, a PropertyChangeEvent for the property named "tasks" is fired. Applications that want to monitor all background Tasks should monitor the tasks property.
- Returns:
- a list of all Tasks that aren't
DONE
-
-