Class PrintStreamProgressMonitor
- java.lang.Object
-
- org.hortonmachine.gears.libs.monitor.PrintStreamProgressMonitor
-
- All Implemented Interfaces:
IHMProgressMonitor
public class PrintStreamProgressMonitor extends Object implements IHMProgressMonitor
A progress monitor for printstream based applications, i.e. console or commandline.This implements both
IHMProgressMonitorandIProgressMonitorin order to be used also in the part of the code that needs to stay clean of rcp code.- Author:
- Andrea Antonello (www.hydrologis.com)
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancancelledprotected PrintStreamerrStreamprotected intlastPercentageprotected PrintStreamoutStreamprotected intrunningWorkprotected StringtaskNameprotected inttotalWork-
Fields inherited from interface org.hortonmachine.gears.libs.monitor.IHMProgressMonitor
UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description PrintStreamProgressMonitor()PrintStreamProgressMonitor(PrintStream outStream, PrintStream errorStream)PrintStreamProgressMonitor(String prefix, PrintStream outStream, PrintStream errorStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tadapt(Class<T> adaptee)Adapts the monitor to a given class.voidbeginTask(String name)voidbeginTask(String name, int totalWork)Notifies that the main task is beginning.voiddone()Notifies that the work is done; that is, either the main task is completed or the user canceled it.voiderrorMessage(String message)Sends out an error message.voidexceptionThrown(String message)Method to be called in case of exception.PrintStreamgetPrintStream()voidinternalWorked(double work)Internal method to handle scaling correctly.booleanisCanceled()Returns whether cancellation of current operation has been requested.voidmessage(String message)Sends out a message.voidonModuleExit()Method to call on module finalization.voidsetCanceled(boolean cancelled)Sets the cancel state to the given value.voidsetTaskName(String name)Sets the task name to the given value.voidsubTask(String name)Notifies that a subtask of the main task is beginning.voidworked(int work)Notifies that a given number of work unit of the main task has been completed.
-
-
-
Field Detail
-
cancelled
protected boolean cancelled
-
outStream
protected final PrintStream outStream
-
errStream
protected final PrintStream errStream
-
taskName
protected String taskName
-
totalWork
protected int totalWork
-
runningWork
protected int runningWork
-
lastPercentage
protected int lastPercentage
-
-
Constructor Detail
-
PrintStreamProgressMonitor
public PrintStreamProgressMonitor()
-
PrintStreamProgressMonitor
public PrintStreamProgressMonitor(PrintStream outStream, PrintStream errorStream)
-
PrintStreamProgressMonitor
public PrintStreamProgressMonitor(String prefix, PrintStream outStream, PrintStream errorStream)
-
-
Method Detail
-
beginTask
public void beginTask(String name, int totalWork)
Description copied from interface:IHMProgressMonitorNotifies that the main task is beginning.- Specified by:
beginTaskin interfaceIHMProgressMonitor
-
beginTask
public void beginTask(String name)
-
done
public void done()
Description copied from interface:IHMProgressMonitorNotifies that the work is done; that is, either the main task is completed or the user canceled it.- Specified by:
donein interfaceIHMProgressMonitor
-
internalWorked
public void internalWorked(double work)
Description copied from interface:IHMProgressMonitorInternal method to handle scaling correctly.- Specified by:
internalWorkedin interfaceIHMProgressMonitor
-
isCanceled
public boolean isCanceled()
Description copied from interface:IHMProgressMonitorReturns whether cancellation of current operation has been requested.- Specified by:
isCanceledin interfaceIHMProgressMonitor- Returns:
-
setCanceled
public void setCanceled(boolean cancelled)
Description copied from interface:IHMProgressMonitorSets the cancel state to the given value.- Specified by:
setCanceledin interfaceIHMProgressMonitor
-
setTaskName
public void setTaskName(String name)
Description copied from interface:IHMProgressMonitorSets the task name to the given value.- Specified by:
setTaskNamein interfaceIHMProgressMonitor
-
subTask
public void subTask(String name)
Description copied from interface:IHMProgressMonitorNotifies that a subtask of the main task is beginning.- Specified by:
subTaskin interfaceIHMProgressMonitor
-
worked
public void worked(int work)
Description copied from interface:IHMProgressMonitorNotifies that a given number of work unit of the main task has been completed.- Specified by:
workedin interfaceIHMProgressMonitor
-
getPrintStream
public PrintStream getPrintStream()
-
adapt
public <T> T adapt(Class<T> adaptee)
Description copied from interface:IHMProgressMonitorAdapts the monitor to a given class.- Specified by:
adaptin interfaceIHMProgressMonitor- Parameters:
adaptee- the class to which to adapt to.- Returns:
- the adapted object or null, if it is not assignable.
-
errorMessage
public void errorMessage(String message)
Description copied from interface:IHMProgressMonitorSends out an error message.- Specified by:
errorMessagein interfaceIHMProgressMonitor- Parameters:
message- the error message to send out.
-
message
public void message(String message)
Description copied from interface:IHMProgressMonitorSends out a message.- Specified by:
messagein interfaceIHMProgressMonitor- Parameters:
message- the message to send out.
-
exceptionThrown
public void exceptionThrown(String message)
Description copied from interface:IHMProgressMonitorMethod to be called in case of exception.- Specified by:
exceptionThrownin interfaceIHMProgressMonitor- Parameters:
message- the error message to send out.
-
onModuleExit
public void onModuleExit()
Description copied from interface:IHMProgressMonitorMethod to call on module finalization.- Specified by:
onModuleExitin interfaceIHMProgressMonitor
-
-