uk.org.ogsadai.client.databrowser
Class DBProgressModel

java.lang.Object
  |
  +--java.util.Observable
        |
        +--uk.org.ogsadai.client.databrowser.DBProgressModel

public class DBProgressModel
extends java.util.Observable

Observable progress model for monitoring progress of a task. Notifies observers of the state of the progess of tasks. In this case the observer is the DBProgressView which displays the state of the progress.

The model should be instantiated and then call method startTask at the start of a long running task, status at stages within the task and finishTask on completion. The task itself should be executed in a GUIThread thread to keep the GUI responsive.

For tasks of known length the status can be set in two ways. If the subtask number is specified in the status method call then the progress view is told the subtask value. This should be used for tasks with many subtasks or where the status is set in a loop, eg:

startTask("Parsing document", 10000); ... for (int i ...) if (i%100==0) status("Parsing line", i) ... finishTask();

If the subtask number is not specified for a task of known length then it should be incremented by DBProgressView.

Version:
$Revision: 1.3 $
Author:
Paul J Graham, EPCC
See Also:
DBProgressView

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
          Copyright statement
static int FINISHED
           
static int INDETERMINATE
           
private  int mNumberOfTasks
           
private  DBProgressView mProgressView
           
private  int mSubtask
           
private  java.lang.String mTaskname
           
private static java.lang.String NO_SUBTASKNAME
           
private static java.lang.String NO_TASKNAME
           
static int STARTED
           
 
Fields inherited from class java.util.Observable
 
Constructor Summary
DBProgressModel(javax.swing.JDialog dialog)
          Construct the progress model to be displayed over a parent JDialog.
DBProgressModel(javax.swing.JFrame frame)
          Construct the progress model to be displayed over a parent JFrame.
 
Method Summary
 void finishTask()
          Finish the task
 int getNumberOfTasks()
           
 int getSubTask()
           
 java.lang.String getTaskname()
           
private  void setSubTask(int subtask)
          Set the current subtask number
 void startTask(java.lang.String taskname)
          Start a task of unspecified length.
 void startTask(java.lang.String taskname, int numberOfTasks)
          Start a task of specified length
 void status(java.lang.String message)
          Report the current status of the task.
 void status(java.lang.String message, int subtask)
          Report the current status of the task and the number of the subtask.
private  void updateObservers(java.lang.Object obj)
          Update the observers of the progess model.
private  void updateStatus(java.lang.String message, int subtask)
          Sends the observers the current status of the task.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
Copyright statement

See Also:
Constant Field Values

INDETERMINATE

public static final int INDETERMINATE
See Also:
Constant Field Values

STARTED

public static final int STARTED
See Also:
Constant Field Values

FINISHED

public static final int FINISHED
See Also:
Constant Field Values

NO_TASKNAME

private static final java.lang.String NO_TASKNAME
See Also:
Constant Field Values

NO_SUBTASKNAME

private static final java.lang.String NO_SUBTASKNAME
See Also:
Constant Field Values

mProgressView

private DBProgressView mProgressView

mSubtask

private int mSubtask

mTaskname

private java.lang.String mTaskname

mNumberOfTasks

private int mNumberOfTasks
Constructor Detail

DBProgressModel

public DBProgressModel(javax.swing.JFrame frame)
Construct the progress model to be displayed over a parent JFrame.

Parameters:
frame - The parent GUI

DBProgressModel

public DBProgressModel(javax.swing.JDialog dialog)
Construct the progress model to be displayed over a parent JDialog.

Parameters:
dialog -
Method Detail

updateObservers

private void updateObservers(java.lang.Object obj)
Update the observers of the progess model.

Parameters:
obj - The updated value

startTask

public void startTask(java.lang.String taskname)
Start a task of unspecified length.

Parameters:
taskname - The name of the task

startTask

public void startTask(java.lang.String taskname,
                      int numberOfTasks)
Start a task of specified length

Parameters:
taskname - The name of the task
numberOfTasks - The length of the task

status

public void status(java.lang.String message)
Report the current status of the task. Subtask number not specified so is incremented here.

Parameters:
message - The status report

status

public void status(java.lang.String message,
                   int subtask)
Report the current status of the task and the number of the subtask.

Parameters:
message -
subtask -

updateStatus

private void updateStatus(java.lang.String message,
                          int subtask)
Sends the observers the current status of the task.

Parameters:
message -
subtask -

finishTask

public void finishTask()
Finish the task


getTaskname

public java.lang.String getTaskname()
Returns:
The name of the current task

getNumberOfTasks

public int getNumberOfTasks()
Returns:
The number of subtasks in the current task

setSubTask

private void setSubTask(int subtask)
Set the current subtask number

Parameters:
subtask - The number of the current subtask

getSubTask

public int getSubTask()
Returns:
The number of the current subtask