|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jdesktop.application.AbstractBean
org.jdesktop.application.Application
examples.ActionExample4
public class ActionExample4
An @Action that executes a background Task.
This example demonstates the use of a background Task.
If an @Action returns a Task, it's executed
on a worker thread, and monitored by the application framework.
When executed, the ListFilesTask Task class
recursively lists all of the files beginning with some root, and
publishes the files it finds, 10 at a time. A
private subclass of ListFilesTask overrides the Task.process method to update a JList's ListModel with the new
files:
private class DoListFiles extends ListFilesTask {
public DoListFiles(File root) {
super(root);
listModel.clear();
}
@Override protected void process(List<File> files) {
if (!isCancelled()) {
listModel.addAll(files);
}
}
}
The example's go @Action, keeps a reference to the
DoListFiles background Task
so that the stop @Action can cancel it:
private Task doListFiles = null;
@Action public Task go() {
stop(); // maybe cancel pending Task
doListFiles = new DoListFiles(getRootFile());
setStopEnabled(true);
return doListFiles;
}
@Action(enabledProperty = "stopEnabled") public void stop() {
if ((doListFiles != null) && (doListFiles.cancel(true))) {
setStopEnabled(false);
}
}
The Action's resources are initialized from a
ResourceBundle, as with ActionExample2.
Additionally, the ListFilesTask's title and
description properties are initialized from the
resources/ListFilesTask.properties ResourceBundle:
ListFilesTask.title = List Files
ListFilesTask.description = List all of the files accessible from some root directory
ListFilesTask.directoryMessage = Listing files in {0}
The directoryMessage resource is used by ListFilesTask
to format a message each time a new directory is listed.
Action,
Task| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class org.jdesktop.application.Application |
|---|
Application.ExitListener |
| Constructor Summary | |
|---|---|
ActionExample4()
|
|
| Method Summary | |
|---|---|
Task |
go()
The go @Action. |
boolean |
isStopEnabled()
|
static void |
main(java.lang.String[] args)
|
void |
setStopEnabled(boolean stopEnabled)
|
protected void |
startup()
Responsible for starting the application; for creating and showing the initial GUI. |
void |
stop()
The stop @Action. |
| Methods inherited from class org.jdesktop.application.Application |
|---|
addExitListener, end, exit, exit, getContext, getExitListeners, getInstance, getInstance, hide, initialize, launch, quit, ready, removeExitListener, show, shutdown |
| Methods inherited from class org.jdesktop.application.AbstractBean |
|---|
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ActionExample4()
| Method Detail |
|---|
@Action public Task go()
go @Action.
Cancel the pending DoListFiles Task and then return a new one. We add a PropertyChangeListener to the new Task so that we can monitor its "message" property.
stop()@Action(enabledProperty="stopEnabled") public void stop()
stop @Action.
Cancel the pending DoListFiles Task, if there is one.
go()public boolean isStopEnabled()
public void setStopEnabled(boolean stopEnabled)
protected void startup()
Application
This method is called by the static launch method,
subclasses must override it. It runs on the event dispatching
thread.
startup in class ApplicationApplication.launch(java.lang.Class, java.lang.String[]) ,
Application.initialize(java.lang.String[]),
Application.shutdown()public static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||