public abstract class LongRunningTask extends Object
Importer
and
Exporter
, this general class represents
a task which takes some time to run, may optionally be cancelled and which displays
some sort of progress dialog.
This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.
Constructor and Description |
---|
LongRunningTask() |
LongRunningTask(boolean cancellable,
int delay)
Create a new LongRunningTask
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChanageListener to this task.
|
void |
cancel()
Cancel the current task.
|
abstract float |
getProgress()
Return the progress of this task - a value from 0 (just started) to 1 (complete).
|
boolean |
isCancellable()
Return true if this task can be cancelled before completion by the user.
|
boolean |
isCancelled()
Return true if this task was cancelled before completion by the user.
|
boolean |
isModal()
Indicates whether this task will create modal dialogs by default
|
boolean |
isRunning()
Return true if this task is currently running.
|
void |
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener previously added by
addPropertyChangeListener(java.beans.PropertyChangeListener) |
abstract void |
run()
Run the current task.
|
void |
setCancellable(boolean cancellable)
Set whether this task can be cancelled before completion by the user.
|
void |
setModal(boolean flag)
Sets whether this task will create modal dialogs by default.
|
Thread |
start(JComponent parent,
String title)
Start the task.
|
Thread |
start(JComponent parent,
String title,
boolean modal)
Start the task.
|
public LongRunningTask()
public LongRunningTask(boolean cancellable, int delay)
cancellable
- whether the task is cancellabledelay
- the initial delay before opening the dialogpublic boolean isModal()
public void setModal(boolean flag)
public void addPropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)
addPropertyChangeListener(java.beans.PropertyChangeListener)
public abstract float getProgress()
public boolean isCancellable()
public void setCancellable(boolean cancellable)
cancel()
method can always be called - this method
only affects the state of the "Cancel" buttoncancellable
- whether the task is user-cancellablepublic boolean isCancelled()
public boolean isRunning()
public void cancel()
isCancellable()
public abstract void run() throws Exception
start(javax.swing.JComponent, java.lang.String)
, this method
should typically not be called directly.Exception
public Thread start(JComponent parent, String title)
run()
method is called, and a dialog displayed
which will show the tasks progress as determined by the getProgress()
method.
If the task is cancellable
, a "Cancel" button is displayed
as well, which will call the cancel()
method when clicked on.
The dialog's modal property is the modal property of this task.parent
- the JComponent that the dialog should be displayed relative totitle
- the title of the dialog window - typically something like "Loading".public Thread start(JComponent parent, String title, boolean modal)
run()
method is called, and a dialog displayed
which will show the tasks progress as determined by the getProgress()
method.
If the task is cancellable
, a "Cancel" button is displayed
as well, which will call the cancel()
method when clicked on.parent
- the JComponent that the dialog should be displayed relative totitle
- the title of the dialog window - typically something like "Loading".modal
- whether the task dialog is modal or notCopyright © 2001-2017 Big Faceless Organization