org.expasy.jpl.commons.base.task
Class TerminalProgressBar

java.lang.Object
  extended by org.expasy.jpl.commons.base.task.TerminalProgressBar
All Implemented Interfaces:
ProgressBar

public final class TerminalProgressBar
extends Object
implements ProgressBar

A simple terminal progress bar.

Description

A progress bar typically communicates the progress of some work by displaying its percentage of completion and possibly a textual display of this percentage.

A progression bar has 2 modes of execution. Depending on the a priori knowledge of the total steps, we have a Determinate mode or an Indeterminate mode.

The terminal progression bar is constituted of 2 parts:

  1. the current processed step (over all steps) found in the Left Margin (LM)
  2. the Progression Bar (PB) itself
Note that each LM and PB space lengths together with the length of the roaming segment in indeterminate mode are configurable. It is even possible to set the refreshing period of progression bar in this last mode.

Indeterminate Mode

   LM      PB
 < -- >< -------- >
    0  [=====     ]
    1  [ =====    ]
    2  [  =====   ]
    3  [   =====  ]
    4  [    ===== ]
    5  [     =====]
    6  [    ===== ]
    7  [   =====  ]
   ...
 

Determinate Mode

   LM      PB
 < -- >< -------- >
  0/10 [          ]
  1/10 [=         ]
  2/10 [==        ]
  3/10 [===       ]
  4/10 [====      ]
  5/10 [=====     ]
  6/10 [======    ]
  7/10 [=======   ]
  8/10 [========  ]
  9/10 [========= ]
 10/10 [==========]
 

Version:
1.0
Author:
nikitin

Method Summary
static TerminalProgressBar indeterminate()
           
 boolean isIndeterminate()
          Return true if indeterminate
static TerminalProgressBar newInstance(int minimum, int maximum)
           
 void setBarLength(int length)
          Set the progress bar length.
 void setDoneMessage(String message)
           
 void setIncompleteMessage(String message)
           
 void setIndeterminate(boolean bool)
          Sets the indeterminate property of the progress bar which determines whether the progress bar is in determinate or indeterminate mode.
 void setLeftMarginLength(int length)
          Set the left margin length (with completion infos).
 void setMaximum(int maximum)
          Sets the progress bar's minimum value to n
 void setMinimum(int minimum)
          Sets the progress bar's maximum value to n
 void setPrintStream(PrintStream ps)
          Set the print stream for bar display.
 void setRefreshBarPeriod(int period)
          Set the period of bar animation refresh while the bar is in indeterminate mode.
 void setSegmentLength(int length)
          Set the length of segment constantly animated in indeterminate mode.
 void setTaskName(String name)
          Set the task name (displayed in left margin)
 void setValue(int completed)
          Sets the progress bar's current value to n
 void start()
          Initialize progress bar (mandatory to restart bar in Indeterminate mode)
 void stop()
          Interrupt the task (mandatory to complete Inderminate mode)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static TerminalProgressBar newInstance(int minimum,
                                              int maximum)

indeterminate

public static TerminalProgressBar indeterminate()

setTaskName

public void setTaskName(String name)
Description copied from interface: ProgressBar
Set the task name (displayed in left margin)

Specified by:
setTaskName in interface ProgressBar

setLeftMarginLength

public void setLeftMarginLength(int length)
Set the left margin length (with completion infos).

Parameters:
length - the left margin length.

setBarLength

public void setBarLength(int length)
Set the progress bar length.

Parameters:
length - the given length.

setRefreshBarPeriod

public void setRefreshBarPeriod(int period)
Set the period of bar animation refresh while the bar is in indeterminate mode.

Parameters:
period - the period of refresh for cursor animation.

setSegmentLength

public void setSegmentLength(int length)
Set the length of segment constantly animated in indeterminate mode.

Parameters:
length - the given length (> 0 and < bar len).

setPrintStream

public void setPrintStream(PrintStream ps)
Set the print stream for bar display.

Parameters:
ps - the output stream.

setMinimum

public final void setMinimum(int minimum)
Description copied from interface: ProgressBar
Sets the progress bar's maximum value to n

Specified by:
setMinimum in interface ProgressBar

setMaximum

public final void setMaximum(int maximum)
Description copied from interface: ProgressBar
Sets the progress bar's minimum value to n

Specified by:
setMaximum in interface ProgressBar

setDoneMessage

public void setDoneMessage(String message)

setIncompleteMessage

public void setIncompleteMessage(String message)

setIndeterminate

public void setIndeterminate(boolean bool)
Description copied from interface: ProgressBar
Sets the indeterminate property of the progress bar which determines whether the progress bar is in determinate or indeterminate mode.

Specified by:
setIndeterminate in interface ProgressBar

start

public void start()
Initialize progress bar (mandatory to restart bar in Indeterminate mode)


stop

public void stop()
Interrupt the task (mandatory to complete Inderminate mode)

Note 1

If you want to restart another progression, you will have to call start() first.


setValue

public void setValue(int completed)
Description copied from interface: ProgressBar
Sets the progress bar's current value to n

Specified by:
setValue in interface ProgressBar

isIndeterminate

public final boolean isIndeterminate()
Description copied from interface: ProgressBar
Return true if indeterminate

Specified by:
isIndeterminate in interface ProgressBar


Copyright (c) 2012 Swiss Institute of Bioinformatics. All rights reserved.