Side of Software
Wizard Library 1.6

sos.wizard
Class AbstractTask

java.lang.Object
  |
  +--sos.wizard.AbstractModel
        |
        +--sos.wizard.AbstractTask
All Implemented Interfaces:
javax.swing.ComboBoxModel, javax.swing.ListModel, Model, java.lang.Runnable, Task

public abstract class AbstractTask
extends AbstractModel
implements Task

A partial implementation of the Task interface. A subclass need only implement run. The run method should invoke setProgress whenever it makes progress toward completing the task.

If a subclass wishes to be interruptible, it should override isInterruptible to return true, and it should periodically invoke shouldAbort. If shouldAbort returns true, it should gracefully unwind and return.

This class handles the notification of progress listeners, the notification of subtask listeners, the setting and retrieving of the progress, and the suspending and resuming of the execution.

Since:
1.0

Constructor Summary
AbstractTask()
          Creates an AbstractTask with no name.
AbstractTask(java.lang.String name)
          Creates an AbstractTask with the specified name.
 
Method Summary
 void addListDataListener(javax.swing.event.ListDataListener l)
          Adds a listener to the list that's notified each time a change to the data model occurs.
 void addProgressListener(ProgressListener listener)
          Registers the specified listener to get notified when this task's progress changes.
protected  void fireProgressChange(double newProgressValue)
          Notifies progress listeners that this task's progress has changed to newProgressValue.
protected  void fireSubTasksAdded(int index0, int index1)
          Notifies all listeners that there are additional sub-tasks need to complete this task.
protected  void fireSubTasksChanged(int index0, int index1)
          Notifies all listeners that the sub-tasks have changed or that the current sub-task has changed.
protected  void fireSubTasksRemoved(int index0, int index1)
          Notifies all listeners that some sub-tasks are no longer needed to complete this task.
 java.lang.Object getElementAt(int index)
          Returns the value at the specified index.
 java.lang.String getName()
          Returns the (localized) name of this task.
 double getProgress()
          Returns a number between 0 and 100 that estimates this task's percentage complete.
 java.lang.Object getSelectedItem()
          Returns the selected item
 int getSize()
          Returns the length of the list.
 boolean isInterruptible()
          Returns true if this task can be interrupted.
 boolean isPaused()
          Returns true is this task is paused.
 void pause()
          Pauses this task.
 void removeListDataListener(javax.swing.event.ListDataListener l)
          Removes a listener from the list that's notified each time a change to the data model occurs.
 void removeProgressListener(ProgressListener listener)
          Unregisters the specified listener for getting notified when this task's progress changes.
 void resume()
          Resumes this task if it is paused.
 void setName(java.lang.String name)
          Sets this task's name.
 void setProgress(double progress)
          Sets this task's progress and notifies progress listeners.
 void setSelectedItem(java.lang.Object anItem)
          Set the selected item.
protected  boolean shouldAbort()
          Returns true if this task should abort.
 
Methods inherited from class sos.wizard.AbstractModel
addPropertyChangeListener, addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, removePropertyChangeListener, removePropertyChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sos.wizard.Task
run
 
Methods inherited from interface sos.wizard.Model
addPropertyChangeListener, addPropertyChangeListener, removePropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

AbstractTask

public AbstractTask()
Creates an AbstractTask with no name.

See Also:
AbstractTask(String)

AbstractTask

public AbstractTask(java.lang.String name)
Creates an AbstractTask with the specified name.

Parameters:
name - name of this task
Method Detail

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener l)
Adds a listener to the list that's notified each time a change to the data model occurs.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
l - the ListDataListener to be added

addProgressListener

public void addProgressListener(ProgressListener listener)
Description copied from interface: Task
Registers the specified listener to get notified when this task's progress changes.

Specified by:
addProgressListener in interface Task
Parameters:
listener - object wishing to get notified

fireSubTasksChanged

protected void fireSubTasksChanged(int index0,
                                   int index1)
Notifies all listeners that the sub-tasks have changed or that the current sub-task has changed. To indicate the latter, pass in -1 for both index0 and index1.

Parameters:
index0 - start index of the change
index1 - end index (inclusive) of the change
See Also:
fireSubTasksAdded(int, int)

fireSubTasksAdded

protected void fireSubTasksAdded(int index0,
                                 int index1)
Notifies all listeners that there are additional sub-tasks need to complete this task.

Parameters:
index0 - start index of the change
index1 - end index (inclusive) of the change
See Also:
fireSubTasksChanged(int, int)

fireSubTasksRemoved

protected void fireSubTasksRemoved(int index0,
                                   int index1)
Notifies all listeners that some sub-tasks are no longer needed to complete this task.

Parameters:
index0 - start index of the change
index1 - end index (inclusive) of the change
See Also:
fireSubTasksChanged(int, int)

fireProgressChange

protected void fireProgressChange(double newProgressValue)
Notifies progress listeners that this task's progress has changed to newProgressValue.

Parameters:
newProgressValue - a number between 0 and 100 indicating this task's progress (as a percentage)

getElementAt

public java.lang.Object getElementAt(int index)
Returns the value at the specified index.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - the requested index
Returns:
the value at index

getName

public java.lang.String getName()
Description copied from interface: Task
Returns the (localized) name of this task.

Specified by:
getName in interface Task
Returns:
this task's name

getProgress

public double getProgress()
Description copied from interface: Task
Returns a number between 0 and 100 that estimates this task's percentage complete.

Specified by:
getProgress in interface Task
Returns:
the amount of progress this task has made

getSelectedItem

public java.lang.Object getSelectedItem()
Returns the selected item

Specified by:
getSelectedItem in interface javax.swing.ComboBoxModel
Returns:
The selected item or null if there is no selection

getSize

public int getSize()
Returns the length of the list.

Specified by:
getSize in interface javax.swing.ListModel
Returns:
the length of the list

isInterruptible

public boolean isInterruptible()
Description copied from interface: Task
Returns true if this task can be interrupted.

Specified by:
isInterruptible in interface Task
Returns:
true if this task can be interrupted

isPaused

public boolean isPaused()
Description copied from interface: Task
Returns true is this task is paused.

Specified by:
isPaused in interface Task
Returns:
true is this task is paused.


pause

public void pause()
Description copied from interface: Task
Pauses this task. If it is already paused, then this method has no effect.

Specified by:
pause in interface Task
See Also:
Task.resume(), Task.isInterruptible()

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener l)
Removes a listener from the list that's notified each time a change to the data model occurs.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
l - the ListDataListener to be removed

removeProgressListener

public void removeProgressListener(ProgressListener listener)
Description copied from interface: Task
Unregisters the specified listener for getting notified when this task's progress changes.

Specified by:
removeProgressListener in interface Task
Parameters:
listener - object that no longer wishes to be notified

resume

public void resume()
Description copied from interface: Task
Resumes this task if it is paused. If it is not paused, then this method has no effect.

Specified by:
resume in interface Task
See Also:
Task.pause(), Task.isInterruptible()

setName

public void setName(java.lang.String name)
Sets this task's name.

Parameters:
name - name of this task

setProgress

public void setProgress(double progress)
Sets this task's progress and notifies progress listeners.

Parameters:
progress - this task's current progress, as a percentage between 0.0 and 100.0, inclusive
See Also:
getProgress()

setSelectedItem

public void setSelectedItem(java.lang.Object anItem)
Set the selected item. The implementation of this method should notify all registered ListDataListeners that the contents have changed.

Specified by:
setSelectedItem in interface javax.swing.ComboBoxModel
Parameters:
anItem - the list object to select or null to clear the selection

shouldAbort

protected boolean shouldAbort()
Returns true if this task should abort. If this task is paused, then this method blocks until it is resumed.

Returns:
true if this task should abort

Side of Software
Wizard Library 1.6

Copyright 2004-07 Side of Software (SOS). All rights reserved.