org.geotools.gui.headless
Class ProgressPrinter

java.lang.Object
  extended byorg.geotools.gui.headless.ProgressPrinter
All Implemented Interfaces:
ProgressListener

public class ProgressPrinter
extends java.lang.Object
implements ProgressListener

Prints progress report of a lengtly operation to an output stream. Progress are reported as percentage on a single line. This class can also prints warning, which is useful for notifications without stoping the lenghtly task.

Since:
2.0
Version:
$Id: ProgressPrinter.java 17672 2006-01-19 00:25:55Z desruisseaux $
Author:
Martin Desruisseaux

Constructor Summary
ProgressPrinter()
          Constructs a new object sending progress reports to the standard output stream.
ProgressPrinter(java.io.PrintWriter out)
          Constructs a new object sending progress reports to the specified stream.
ProgressPrinter(java.io.PrintWriter out, int maxLength)
          Constructs a new object sending progress reports to the specified stream.
 
Method Summary
 void complete()
          Notifies this listener that the operation has finished.
 void dispose()
          Release any resource hold by this object.
 void exceptionOccurred(java.lang.Throwable exception)
          Prints an exception stack trace in a box.
 java.lang.String getDescription()
          Returns the description for the lengthly operation to be reported, or if none.
 boolean isCanceled()
          Is this job canceled?
 void progress(float percent)
          Notifies this listener of progress in the lengthly operation. Progress are reported as a value between 0 and 100 inclusive. Values out of bounds will be clamped.
 void setCanceled(boolean canceled)
          Indicate that progress should is canceled.
 void setDescription(java.lang.String description)
          Set the description for the lenghtly operation to be reported. This method is usually invoked before any progress begins. However, it is legal to invoke this method at any time during the operation, in which case the description display is updated without any change to the percentage accomplished.
 void started()
          Notifies this listener that the operation begins.
 void warningOccurred(java.lang.String source, java.lang.String margin, java.lang.String warning)
          Prints a warning.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgressPrinter

public ProgressPrinter()
Constructs a new object sending progress reports to the standard output stream. The maximal line length is assumed 80 characters.


ProgressPrinter

public ProgressPrinter(java.io.PrintWriter out)
Constructs a new object sending progress reports to the specified stream. The maximal line length is assumed 80 characters.


ProgressPrinter

public ProgressPrinter(java.io.PrintWriter out,
                       int maxLength)
Constructs a new object sending progress reports to the specified stream.

Parameters:
out - The output stream.
maxLength - The maximal line length. This is used by warningOccurred(java.lang.String, java.lang.String, java.lang.String) for splitting longer lines into many lines.
Method Detail

getDescription

public java.lang.String getDescription()
Returns the description for the lengthly operation to be reported, or if none.

Specified by:
getDescription in interface ProgressListener

setDescription

public void setDescription(java.lang.String description)
Set the description for the lenghtly operation to be reported. This method is usually invoked before any progress begins. However, it is legal to invoke this method at any time during the operation, in which case the description display is updated without any change to the percentage accomplished.

Specified by:
setDescription in interface ProgressListener
Parameters:
description - The new description, or if none.

started

public void started()
Notifies this listener that the operation begins.

Specified by:
started in interface ProgressListener

progress

public void progress(float percent)
Notifies this listener of progress in the lengthly operation. Progress are reported as a value between 0 and 100 inclusive. Values out of bounds will be clamped.

Specified by:
progress in interface ProgressListener

complete

public void complete()
Notifies this listener that the operation has finished. The progress indicator will shows 100% or disaspears. If warning messages were pending, they will be printed now.

Specified by:
complete in interface ProgressListener

dispose

public void dispose()
Release any resource hold by this object.

Specified by:
dispose in interface ProgressListener

isCanceled

public boolean isCanceled()
Is this job canceled?

Specified by:
isCanceled in interface ProgressListener

setCanceled

public void setCanceled(boolean canceled)
Indicate that progress should is canceled.

Specified by:
setCanceled in interface ProgressListener

warningOccurred

public void warningOccurred(java.lang.String source,
                            java.lang.String margin,
                            java.lang.String warning)
Prints a warning. The first time this method is invoked, the localized word "WARNING" will be printed in the middle of a box. If a source is specified, it will be printed only if it is not the same one than the source of the last warning. If a marging is specified, it will be printed of the left side of the first line of the warning message.

Specified by:
warningOccurred in interface ProgressListener
Parameters:
source - The source of the warning, or if none. This is typically the filename in process of being parsed.
margin - Text to write on the left side of the warning message, or if none. This is typically the line number where the error occured in the file.
warning - The warning message. If this string is longer than the maximal length specified at construction time (80 characters by default), then it will be splitted in as many lines as needed and indented according the marging width.

exceptionOccurred

public void exceptionOccurred(java.lang.Throwable exception)
Prints an exception stack trace in a box.

Specified by:
exceptionOccurred in interface ProgressListener


Copyright © GeoTools. All Rights Reserved.