com.townleyenterprises.swing
Class AbstractMonitoredTask

java.lang.Object
  extended bycom.townleyenterprises.swing.AbstractMonitoredTask
All Implemented Interfaces:
MonitoredTask

public abstract class AbstractMonitoredTask
extends java.lang.Object
implements MonitoredTask

This is an implementation of the MonitoredTask interface which requires only that a single method be implemneted.

Since:
2.1
Version:
$Id: AbstractMonitoredTask.java,v 1.6 2004/07/28 10:33:59 atownley Exp $
Author:
Andrew S. Townley

Constructor Summary
AbstractMonitoredTask()
           
 
Method Summary
 void addTaskListener(TaskListener listener)
          This method is used to register a new task listener.
protected  void fireTaskAborted()
          This method is used to fire the task aborted event.
protected  void fireTaskCompleted()
          This method is used to fire the task completed event.
protected  void fireTaskStarted()
          This method is used to fire the task started event.
 int getCurrentProgress()
          This method returns the current progress of the task.
 java.lang.Throwable getError()
          This method is used to return a reference to the throwable encountered during the performing of the task.
 java.lang.String getStatus()
          This method is used to return the last status message associated with the task.
 int getTaskLength()
          This method returns the length of the current task.
 java.util.List getTaskListeners()
          This method is used to return the list of task listeners.
 boolean hasError()
          This method returns true if the task encountered any errors.
protected  void initialize()
          This method can be overridden to add extra initialization prior to the iterations performed by the thread.
 boolean isComplete()
          This method returns true if the task has completed.
protected abstract  int performWork(boolean stop)
          This method is the actual re-entrant method that is called for each chunk of work that should be done.
 void removeTaskListener(TaskListener listener)
          This method is used to remove a specific listener.
 void requestStop()
          This method is used to request that the task be stopped.
protected  void setComplete(boolean val)
          This method is used to indicate that the task is complete and should be stopped.
protected  void setError(java.lang.Throwable error)
          This method is used to set the error encountered by the task.
protected  void setProgress(int progress)
          This method is used to set the progress of the current task.
protected  void setStatus(java.lang.String s)
          This method is used to set the status text
protected  void setTaskLength(int length)
          This method is used to set the length of the task.
 boolean shouldStop()
          This method returns true if the task has received a request to be cancelled.
 void start()
          This method is used to start the task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractMonitoredTask

public AbstractMonitoredTask()
Method Detail

shouldStop

public boolean shouldStop()
This method returns true if the task has received a request to be cancelled.

Specified by:
shouldStop in interface MonitoredTask
Returns:
true if should stop; false otherwise

isComplete

public boolean isComplete()
This method returns true if the task has completed.

Specified by:
isComplete in interface MonitoredTask
Returns:
true if done; false if not

hasError

public boolean hasError()
This method returns true if the task encountered any errors.

Specified by:
hasError in interface MonitoredTask
Returns:
true if errors; false if no

getTaskLength

public int getTaskLength()
This method returns the length of the current task.

Specified by:
getTaskLength in interface MonitoredTask
Returns:
an integer indicating the length of the task

getError

public java.lang.Throwable getError()
This method is used to return a reference to the throwable encountered during the performing of the task.

Specified by:
getError in interface MonitoredTask
Returns:
the Throwable

getCurrentProgress

public int getCurrentProgress()
This method returns the current progress of the task. In cases where the current progress is unknown, this method can indicate this state by returning a value < 0.

Specified by:
getCurrentProgress in interface MonitoredTask
Returns:
positive integer < the task length or -1 if unknown

getStatus

public java.lang.String getStatus()
This method is used to return the last status message associated with the task. Useful for tasks that perform a number of steps.

Specified by:
getStatus in interface MonitoredTask
Returns:
the message

start

public final void start()
This method is used to start the task.

Specified by:
start in interface MonitoredTask

requestStop

public void requestStop()
This method is used to request that the task be stopped.

Specified by:
requestStop in interface MonitoredTask

addTaskListener

public void addTaskListener(TaskListener listener)
This method is used to register a new task listener.

Specified by:
addTaskListener in interface MonitoredTask
Parameters:
listener - the listener to add

getTaskListeners

public java.util.List getTaskListeners()
This method is used to return the list of task listeners.

Specified by:
getTaskListeners in interface MonitoredTask
Returns:
the list of listeners

removeTaskListener

public void removeTaskListener(TaskListener listener)
This method is used to remove a specific listener.

Specified by:
removeTaskListener in interface MonitoredTask
Parameters:
listener - the listener to remove

initialize

protected void initialize()
This method can be overridden to add extra initialization prior to the iterations performed by the thread.


performWork

protected abstract int performWork(boolean stop)
This method is the actual re-entrant method that is called for each chunk of work that should be done. This method should not take a long time to return and should make calls to the protected methods to update status.

Parameters:
stop - indicates that the task should stop
Returns:
the current amount of progress made this iteration

setComplete

protected void setComplete(boolean val)
This method is used to indicate that the task is complete and should be stopped.

Parameters:
val - true to indicate task is finished

setError

protected void setError(java.lang.Throwable error)
This method is used to set the error encountered by the task.

Parameters:
error - the throwable

setProgress

protected void setProgress(int progress)
This method is used to set the progress of the current task.

Parameters:
progress - the new value

setTaskLength

protected void setTaskLength(int length)
This method is used to set the length of the task.


setStatus

protected void setStatus(java.lang.String s)
This method is used to set the status text


fireTaskStarted

protected void fireTaskStarted()
This method is used to fire the task started event.


fireTaskAborted

protected void fireTaskAborted()
This method is used to fire the task aborted event.


fireTaskCompleted

protected void fireTaskCompleted()
This method is used to fire the task completed event.



Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.