chemaxon.jchem.file
Class ProgressWriter

java.lang.Object
  extended bychemaxon.jchem.file.ProgressWriter

public class ProgressWriter
extends java.lang.Object

Class to display the progress of some operation. This class can be used standalone, or as an ancestor for custom progress reporter classes.


Nested Class Summary
static interface ProgressWriter.Logger
          Interface for retreiving messages for events (especially errors) which were suppressed during execution.
 
Field Summary
static int ERROR
          Log level error
static int INFO
          Log level info
protected  long max
          The maximum value -- the higher end of the progress value.
protected  long min
          The minimum value -- the lower end of the progress value.
protected  java.lang.String note
          The additional note that is displayed along with the progress message.
static int WARNING
          Log level warning
 
Constructor Summary
ProgressWriter(java.lang.String note, long min, long max)
          Constructs a object displaying progress and starts monitoring the elapsed time.
 
Method Summary
 void addLogger(ProgressWriter.Logger logger)
          Adds a ProgressWriter.Logger to retreive suppressed (error) messages.
 void calcExpTime()
          Recalculates expected time.
 void close()
          Indicate that the operation is complete.
 java.lang.String getExpTimeString()
          Returns text for displaying the expected remaining time.
 long getMaximum()
          Returns the maximum value -- the higher end of the progress value.
 long getMinimum()
          Returns the minimum value -- the lower end of the progress value.
 java.lang.String getNote()
          Returns the additional note that is displayed along with the progress message.
 long getProgress()
          Return the current value of the monitored progress.
 long getRemainingDays()
          Returns the "days" part of the remaining time.
 long getRemainingHours()
          Returns the "hours" part of the remaining time.
 long getRemainingMinutes()
          Returns the "minutes" part of the remaining time.
 long getRemainingSeconds()
          Returns the "seconds" part of the remaining time.
 boolean isCanceled()
          Indicates, if the progress was canceled.
 void log(int severity, java.lang.String message, java.lang.Throwable t)
          Log a message which needs to be retreived for a "suppressed" event during execution.
 void setCanceled(boolean value)
          Specifies, if the progress was canceled.
 void setMaximum(long m)
          Specifies the maximum value.
 void setMinimum(long m)
          Specifies the minimum value.
 void setNote(java.lang.String note)
          Specifies the additional note that is displayed along with the progress message.
 void setProgress(long nv)
          Indicate the progress of the operation being monitored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR

public static final int ERROR
Log level error

Since:
3.2.8
See Also:
Constant Field Values

WARNING

public static final int WARNING
Log level warning

Since:
3.2.8
See Also:
Constant Field Values

INFO

public static final int INFO
Log level info

Since:
3.2.8
See Also:
Constant Field Values

min

protected long min
The minimum value -- the lower end of the progress value.


max

protected long max
The maximum value -- the higher end of the progress value.


note

protected java.lang.String note
The additional note that is displayed along with the progress message.

Constructor Detail

ProgressWriter

public ProgressWriter(java.lang.String note,
                      long min,
                      long max)
Constructs a object displaying progress and starts monitoring the elapsed time.

Parameters:
note - a short note describing the state of the operation. As the operation progresses, you can call setNote to change the note displayed. This is used, for example, in operations that iterate through a list of files to show the name of the file being processed.
min - the lower bound of the range
max - the upper bound of the range
Method Detail

addLogger

public void addLogger(ProgressWriter.Logger logger)
Adds a ProgressWriter.Logger to retreive suppressed (error) messages.

Parameters:
logger -

log

public void log(int severity,
                java.lang.String message,
                java.lang.Throwable t)
Log a message which needs to be retreived for a "suppressed" event during execution. If there are ProgressWriter.Loggers added to this ProgressWriter instance, the message will be passed to those instances. If there is no ProgressWriter.Logger instance registered, the message is written to the standard error.

Parameters:
severity -
message -
t -

getProgress

public long getProgress()
Return the current value of the monitored progress.


setProgress

public void setProgress(long nv)
Indicate the progress of the operation being monitored. If the specified value is >= the maximum, the progress reporter is closed.

Parameters:
nv - specifies the current value, between the maximum and minimum specified for this component
See Also:
setMinimum(long), setMaximum(long), close()

close

public void close()
Indicate that the operation is complete. This happens automatically when the value set by setProgress is >= max, but it may be called earlier if the operation ends early.


getMinimum

public long getMinimum()
Returns the minimum value -- the lower end of the progress value.

Returns:
represents the minimum value
See Also:
setMinimum(long)

setMinimum

public void setMinimum(long m)
Specifies the minimum value.

Parameters:
m - specifies the minimum value
See Also:
getMinimum()

getMaximum

public long getMaximum()
Returns the maximum value -- the higher end of the progress value.

Returns:
represents the maximum value
See Also:
setMaximum(long)

setMaximum

public void setMaximum(long m)
Specifies the maximum value.

Parameters:
m - specifies the maximum value
See Also:
getMaximum()

setNote

public void setNote(java.lang.String note)
Specifies the additional note that is displayed along with the progress message. Used, for example, to show which file the is currently being copied during a multiple-file copy.

Parameters:
note - a String specifying the note to display
See Also:
getNote()

getNote

public java.lang.String getNote()
Returns the additional note that is displayed along with the progress message.

Returns:
a String specifying the note to display
See Also:
setNote(java.lang.String)

getRemainingSeconds

public long getRemainingSeconds()
Returns the "seconds" part of the remaining time.
Note: Does not recalculate time. Method calcExpTime() should be called before, to udate calculations.

Returns:
number of seconds s, where 0=< s <60

getRemainingMinutes

public long getRemainingMinutes()
Returns the "minutes" part of the remaining time.
Note: Does not recalculate time. Method calcExpTime() should be called before, to udate calculations.

Returns:
number of minutes m, where 0=< m <60

getRemainingHours

public long getRemainingHours()
Returns the "hours" part of the remaining time. Note: Does not recalculate time. Method calcExpTime() should be called before, to udate calculations.

Returns:
number of hours h, where 0=< h <24

getRemainingDays

public long getRemainingDays()
Returns the "days" part of the remaining time. Note: Does not recalculate time. Method calcExpTime() should be called before, to udate calculations.

Returns:
number of hours days left

getExpTimeString

public java.lang.String getExpTimeString()
Returns text for displaying the expected remaining time.
Automatically recalculates expected time.

Returns:
the text representation of remaining time.

calcExpTime

public void calcExpTime()
Recalculates expected time.
This method should be called once, before calling getRemainingSeconds(), getRemainingMinutes(), getRemainingHours() and getRemainingDays().


isCanceled

public boolean isCanceled()
Indicates, if the progress was canceled.

Returns:
true if the progress was canceled

setCanceled

public void setCanceled(boolean value)
Specifies, if the progress was canceled.

Parameters:
value - set to true to cancel the operation