Class MonitorWorker

All Implemented Interfaces:
Runnable, Future<ExitStatus>, RunnableFuture<ExitStatus>
Direct Known Subclasses:
AbstractDynamicWorker, ContourWorker, SmootherWorker

public abstract class MonitorWorker extends SwingWorker<ExitStatus,Integer>
A class to implement a SwingWorker that can pop up a ProgressMonitor to allow user cancellation. It is up to the MonitorWorker's doInBackground() method to check whether cancellation has occured using either the setMonitorProgress(int progress) method, which throws a CancelledException, or directly with the SwingWorker.isCancelled() method.
  • Field Details

    • monitor

      public ProgressMonitor monitor
      A ProgressMonitor which may pop up.
    • indeterminateMonitor

      public IndeterminateProgressMonitor indeterminateMonitor
      An IndeterminateProgressMonitor which may pop up.
    • errorMessage

      public String errorMessage
      An error message set when an error occurs.
  • Constructor Details

    • MonitorWorker

      protected MonitorWorker(Component c, String progName)
      Creates a new MonitorWorker with a parent component and a program name.
      Parameters:
      c - a Component which may be able to show status messages, if non-null.
      progName - program name for the program that is running this MonitorWorker.
  • Method Details

    • getComponent

      public Component getComponent()
      Returns the component from which this MonitorWorker was launched.
      Returns:
      the component (if non-null) from which this MonitorWorker was launched.
    • getProgName

      public String getProgName()
      Returns the program name for this MonitorWorker.
      Returns:
      the program name for this MonitorWorker.
    • setAction

      public void setAction(String descr, int min, int max)
      Set the action description for the ProgressMonitor.
      Parameters:
      descr - the action description.
      min - the minimum for the ProgressMonitor.
      max - the maximum for the ProgressMonitor.
    • setAction

      public void setAction(String descr)
      Set the action description for the Progress monitor or IndeterminateProgressMonitor.
      Parameters:
      descr - the action description.
    • checkCancelled

      public void checkCancelled() throws CancelledException
      Tests whether this MonitorWorker has been cancelled.
      Throws:
      CancelledException - if the operation has been cancelled.
    • checkCancelled

      public void checkCancelled(String message) throws CancelledException
      Tests whether this MonitorWorker has been cancelled.
      Parameters:
      message - a message to put to the IndeterminateProgressMonitor.
      Throws:
      CancelledException - if the operation has been cancelled.
    • checkCancelled

      public void checkCancelled(Integer progress) throws CancelledException
      Tests whether this MonitorWorker has been cancelled, and sets the progress through this operation.
      Parameters:
      progress - the progress of the ProgressMonitor.
      Throws:
      CancelledException - if the operation has been cancelled.
    • checkCancelled

      public void checkCancelled(String message, Integer progress) throws CancelledException
      Tests whether this MonitorWorker has been cancelled, and sets the progress through this operation.
      Parameters:
      message - a message to put to the IndeterminateProgressMonitor.
      progress - the progress of the ProgressMonitor.
      Throws:
      CancelledException - if the operation has been cancelled.
    • doInBackground

      public abstract ExitStatus doInBackground()
      Overrides the doInBackground() method.
      Specified by:
      doInBackground in class SwingWorker<ExitStatus,Integer>
      Returns:
      the ExitStatus indicating whether the processing was successful, and if not why not.
    • done

      public void done()
      Overrides the done() method. Closes the ProgressMonitor or IndeterminateProgressMonitor.
      Overrides:
      done in class SwingWorker<ExitStatus,Integer>