Package org.faceless.pdf2.viewer2.util
Class LongRunningTask
- java.lang.Object
-
- org.faceless.pdf2.viewer2.util.LongRunningTask
-
- Direct Known Subclasses:
Exporter.ExporterTask
,Importer.ImporterTask
public abstract class LongRunningTask extends Object
The superclass forImporter
andExporter
, 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.
- Since:
- 2.10.2
-
-
Constructor Summary
Constructors Constructor Description LongRunningTask()
LongRunningTask(boolean cancellable, int delay)
Create a new LongRunningTask
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 defaultboolean
isRunning()
Return true if this task is currently running.void
removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener previously added byaddPropertyChangeListener(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.
-
-
-
Method Detail
-
isModal
public boolean isModal()
Indicates whether this task will create modal dialogs by default- Since:
- 2.13
-
setModal
public void setModal(boolean flag)
Sets whether this task will create modal dialogs by default.- Since:
- 2.13
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChanageListener to this task. Listeners will be updated on the "state" property of this task, which will move from "running" to either "completed" or "cancelled"- Since:
- 2.11.2
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener previously added byaddPropertyChangeListener(java.beans.PropertyChangeListener)
- Since:
- 2.11.2
-
getProgress
public abstract float getProgress()
Return the progress of this task - a value from 0 (just started) to 1 (complete). A value of NaN means the progress is indeterminate - if this is is the case when the task is started, the progress bar will not be shown.
-
isCancellable
public boolean isCancellable()
Return true if this task can be cancelled before completion by the user.
-
setCancellable
public void setCancellable(boolean cancellable)
Set whether this task can be cancelled before completion by the user. Note that thecancel()
method can always be called - this method only affects the state of the "Cancel" button- Parameters:
cancellable
- whether the task is user-cancellable
-
isCancelled
public boolean isCancelled()
Return true if this task was cancelled before completion by the user.
-
isRunning
public boolean isRunning()
Return true if this task is currently running.
-
cancel
public void cancel()
Cancel the current task. This can be done regardless of the state ofisCancellable()
-
run
public abstract void run() throws Exception
Run the current task. Called bystart(javax.swing.JComponent, java.lang.String)
, this method should typically not be called directly.- Throws:
Exception
-
start
public Thread start(JComponent parent, String title)
Start the task. Therun()
method is called, and a dialog displayed which will show the tasks progress as determined by thegetProgress()
method. If the task iscancellable
, a "Cancel" button is displayed as well, which will call thecancel()
method when clicked on. The dialog's modal property is the modal property of this task.- Parameters:
parent
- the JComponent that the dialog should be displayed relative totitle
- the title of the dialog window - typically something like "Loading".
-
start
public Thread start(JComponent parent, String title, boolean modal)
Start the task. Therun()
method is called, and a dialog displayed which will show the tasks progress as determined by thegetProgress()
method. If the task iscancellable
, a "Cancel" button is displayed as well, which will call thecancel()
method when clicked on.- Parameters:
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 not- Since:
- 2.11.14
-
-