com.xmlmind.util
Class SimpleProgressMonitor

java.lang.Object
  extended by com.xmlmind.util.SimpleProgressMonitor
All Implemented Interfaces:
ProgressMonitor

public final class SimpleProgressMonitor
extends java.lang.Object
implements ProgressMonitor

A simple ProgressMonitor printing error and warning messages on System.err and other messages (info, verbose, debug) on System.out.

This ProgressMonitor is used to implement command-line utilities.


Field Summary
 int messageLevel
          All messages having a type larger than messageLevel are not printed by this monitor.
 
Constructor Summary
SimpleProgressMonitor()
          Equivalent to this(Console.MessageType.INFO).
SimpleProgressMonitor(Console.MessageType messageLevel)
          Constructs a simple ProgressMonitor.
 
Method Summary
 boolean message(java.lang.String message, Console.MessageType messageType)
          Invoked by the lengthy task to give this monitor information about the step being executed.
 void start()
          Invoked by the lengthy task to inform this monitor that the execution of the task has started.
 boolean step(int step)
          Invoked by the lengthy task to inform this monitor each time a new step is about to be executed.
 boolean stepCount(int stepCount)
          Invoked by the lengthy task to inform this monitor about the total numbers of steps comprising the task.
 void stop()
          Invoked by the lengthy task to inform this monitor that the execution of the task has stopped, whatever the reason (success, canceled, error).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageLevel

public final int messageLevel
All messages having a type larger than messageLevel are not printed by this monitor.

Constructor Detail

SimpleProgressMonitor

public SimpleProgressMonitor()
Equivalent to this(Console.MessageType.INFO).


SimpleProgressMonitor

public SimpleProgressMonitor(Console.MessageType messageLevel)
Constructs a simple ProgressMonitor.

Parameters:
messageLevel - all messages having a type larger than messageLevel will not be printed by this monitor
Method Detail

start

public void start()
Description copied from interface: ProgressMonitor
Invoked by the lengthy task to inform this monitor that the execution of the task has started.

This method is guaranteed to be invoked once before any other method.

Specified by:
start in interface ProgressMonitor

message

public boolean message(java.lang.String message,
                       Console.MessageType messageType)
Description copied from interface: ProgressMonitor
Invoked by the lengthy task to give this monitor information about the step being executed.

This method may be invoked any number of times (including 0), at any time, between ProgressMonitor.start() and ProgressMonitor.stop().

Specified by:
message in interface ProgressMonitor
Parameters:
message - message containing information about the step being executed
messageType - type of message. May be null which is equivalent to INFO.
Returns:
false if this monitor wants to cancel the lengthy task; true otherwise

stepCount

public boolean stepCount(int stepCount)
Description copied from interface: ProgressMonitor
Invoked by the lengthy task to inform this monitor about the total numbers of steps comprising the task.

This method is guaranteed to be invoked once before any invocation of ProgressMonitor.step(int). Therefore the simplest sequence of invocations is:

start
stepCount
step
step
...
step
stop

Note that in the above example, ProgressMonitor.message(java.lang.String, com.xmlmind.util.Console.MessageType) is never invoked.

Specified by:
stepCount in interface ProgressMonitor
Parameters:
stepCount - total numbers of steps comprising the lengthy task. This number is computed once for all. A negative value means that this number cannot be determined.
Returns:
false if this monitor wants to cancel the lengthy task; true otherwise

step

public boolean step(int step)
Description copied from interface: ProgressMonitor
Invoked by the lengthy task to inform this monitor each time a new step is about to be executed.

Specified by:
step in interface ProgressMonitor
Parameters:
step - current step. First step is step 0. Last step is step stepCount-1, when stepCount is strictly positive.
Returns:
false if this monitor wants to cancel the lengthy task; true otherwise

stop

public void stop()
Description copied from interface: ProgressMonitor
Invoked by the lengthy task to inform this monitor that the execution of the task has stopped, whatever the reason (success, canceled, error).

This method is guaranteed to be invoked once when ProgressMonitor.start() has also been invoked. No other method will be invoked after that.

Specified by:
stop in interface ProgressMonitor