net.sf.doolin.gui.monitor
Class TaskMonitor<T,V>

java.lang.Object
  extended by net.sf.doolin.gui.monitor.TaskMonitor<T,V>
Type Parameters:
T - the result type returned by the Task doInBackground and get methods
V - the type used for carrying out intermediate results by this Task publish and process methods
All Implemented Interfaces:
PropertyChangeListener, EventListener, TaskListener<T,V>

public class TaskMonitor<T,V>
extends Object
implements TaskListener<T,V>, PropertyChangeListener

Monitor that displays a progress dialog for a Task.

Author:
Damien Coraboeuf

Constructor Summary
TaskMonitor(Task<T,V> task, JComponent component, String title, Object messageList, int maximum)
          Constructor
 
Method Summary
protected  JDialog createDialog()
          Creates the dialog
 boolean isCancelled()
          Returns the cancellation state
 void onNoteChanged(Task<T,V> task, String note)
          This method is called when the task publishes a new note for the task monitor.
 void propertyChange(PropertyChangeEvent evt)
           
 void setCancellable(boolean cancellable)
          Sets if the task can be cancelled or not
 void setInitialNote(String note)
          Sets the initial note message for the progress dialog
 void setMaximum(int max)
          Updates the maximum number of steps of the progress bar
 T start()
          Starts the task
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskMonitor

public TaskMonitor(Task<T,V> task,
                   JComponent component,
                   String title,
                   Object messageList,
                   int maximum)
Constructor

Parameters:
task - Task to run
component - Parent component for the progress dialog
title - Title for the dialog
messageList - List of message, as specified in JOptionPane
maximum - Maximum of steps for the progress bar. If set to 0, the progress bar is set indeterminate.
Method Detail

isCancelled

public boolean isCancelled()
Returns the cancellation state

Returns:
true if the task has been cancelled.

onNoteChanged

public void onNoteChanged(Task<T,V> task,
                          String note)
Description copied from interface: TaskListener
This method is called when the task publishes a new note for the task monitor.

Specified by:
onNoteChanged in interface TaskListener<T,V>
Parameters:
task - Task
note - Note

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

setCancellable

public void setCancellable(boolean cancellable)
Sets if the task can be cancelled or not

Parameters:
cancellable - Cancellable state

setInitialNote

public void setInitialNote(String note)
Sets the initial note message for the progress dialog

Parameters:
note - Note message

setMaximum

public void setMaximum(int max)
Updates the maximum number of steps of the progress bar

Parameters:
max - Number of steps

start

public T start()
        throws TaskException
Starts the task

Returns:
Result of the task
Throws:
TaskException - If the task throws an exception during its execution

createDialog

protected JDialog createDialog()
Creates the dialog

Returns:
Created dialog


Copyright © 2011. All Rights Reserved.