Class LongRunningTask

  • Direct Known Subclasses:
    Exporter.ExporterTask, Importer.ImporterTask

    public abstract class LongRunningTask
    extends Object
    The superclass for 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.

    Since:
    2.10.2
    • Constructor Detail

      • LongRunningTask

        public LongRunningTask()
      • LongRunningTask

        public LongRunningTask​(boolean cancellable,
                               int delay)
        Create a new LongRunningTask
        Parameters:
        cancellable - whether the task is cancellable
        delay - the initial delay before opening the dialog
    • 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
      • 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 the cancel() 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 of isCancellable()
      • start

        public Thread start​(JComponent parent,
                            String title)
        Start the task. The 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.
        Parameters:
        parent - the JComponent that the dialog should be displayed relative to
        title - the title of the dialog window - typically something like "Loading".
      • start

        public Thread start​(JComponent parent,
                            String title,
                            boolean modal)
        Start the task. The 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.
        Parameters:
        parent - the JComponent that the dialog should be displayed relative to
        title - the title of the dialog window - typically something like "Loading".
        modal - whether the task dialog is modal or not
        Since:
        2.11.14