Class TaskControlPanel<R>

Type Parameters:
R - task result type
All Implemented Interfaces:
TaskListener<R>, ImageObserver, MenuContainer, Serializable, Accessible

public class TaskControlPanel<R> extends JPanel implements TaskListener<R>
Compact Swing controls for a one-shot TaskHandle.

The panel presents Start and Cancel buttons, a determinate or indeterminate progress bar, status text, and elapsed worker time. It is intentionally smaller than SimulationControlPanel: a one-shot task has no meaningful pause, resume, or repeated-step controls.

Threading

TaskHandle listener callbacks are delivered on Swing's EDT, so this panel updates its components directly. A Swing timer updates elapsed time four times per second while work is active. Binding and unbinding should also be performed on the EDT, as with ordinary Swing component configuration.

Lifecycle

A panel may be constructed unbound and later attached with bind(TaskHandle), or constructed with a handle. Rebinding first unregisters the panel from its previous handle. Unbinding does not cancel the task; task ownership remains with application code.

See Also:
  • Constructor Details

    • TaskControlPanel

      public TaskControlPanel()
      Creates an unbound task control panel.
    • TaskControlPanel

      public TaskControlPanel(TaskHandle<R> handle)
      Creates and binds a task control panel.
      Parameters:
      handle - handle to control
      Throws:
      NullPointerException - if handle is null
  • Method Details

    • bind

      public final void bind(TaskHandle<R> newHandle)
      Binds this panel to a task handle, replacing any previous binding. Binding does not start the task.
      Parameters:
      newHandle - handle to control
      Throws:
      NullPointerException - if newHandle is null
    • unbind

      public final void unbind()
      Removes the current listener binding without stopping or cancelling work.
    • getTaskHandle

      public final TaskHandle<R> getTaskHandle()
      Returns:
      currently bound handle, or null
    • getStartButton

      public final JButton getStartButton()
      Returns:
      Start button, for application-specific presentation or automation
    • getCancelButton

      public final JButton getCancelButton()
      Returns:
      Cancel button, for application-specific presentation or automation
    • getProgressBar

      public final JProgressBar getProgressBar()
      Returns:
      progress component displayed by this panel
    • getStatusLabel

      public final JLabel getStatusLabel()
      Returns:
      status label displayed by this panel
    • getElapsedLabel

      public final JLabel getElapsedLabel()
      Returns:
      elapsed-time label displayed by this panel
    • onStarted

      public void onStarted(TaskHandle<R> taskHandle)
      Description copied from interface: TaskListener
      Called when execution begins. @param handle originating handle
      Specified by:
      onStarted in interface TaskListener<R>
    • onProgress

      public void onProgress(TaskHandle<R> taskHandle, ProgressInfo progress)
      Description copied from interface: TaskListener
      Called for a coalesced progress update.
      Specified by:
      onProgress in interface TaskListener<R>
      Parameters:
      taskHandle - originating handle
      progress - latest progress value
    • onMessage

      public void onMessage(TaskHandle<R> taskHandle, String message)
      Description copied from interface: TaskListener
      Called for a coalesced status message.
      Specified by:
      onMessage in interface TaskListener<R>
      Parameters:
      taskHandle - originating handle
      message - latest message
    • onCompleted

      public void onCompleted(TaskHandle<R> taskHandle, CompletionStatus status, Throwable error)
      Description copied from interface: TaskListener
      Called exactly once for every terminal outcome, after the corresponding outcome-specific callback above.
      Specified by:
      onCompleted in interface TaskListener<R>
      Parameters:
      taskHandle - originating handle
      status - terminal outcome
      error - failure, or null for a non-failure outcome