org.geotools.gui.headless
Class ProgressPrinter

Object
  extended by ProgressPrinter
All Implemented Interfaces:
ProgressListener

public class ProgressPrinter
extends 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
Author:
Martin Desruisseaux (PMO, IRD)
Module:

Constructor Summary
ProgressPrinter()
          Constructs a new object sending progress reports to the standard output stream.
ProgressPrinter(PrintWriter out)
          Constructs a new object sending progress reports to the specified stream.
ProgressPrinter(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()
          Releases any resource hold by this object.
 void exceptionOccurred(Throwable exception)
          Prints an exception stack trace in a box.
 String getDescription()
          
 float getProgress()
          Returns the current progress as a percent completed.
 InternationalString getTask()
           
 boolean isCanceled()
          
 void progress(float percent)
          
 void setCanceled(boolean canceled)
          
 void setDescription(String description)
          
 void setTask(InternationalString task)
           
 void started()
          
 void warningOccurred(String source, String margin, String warning)
          Prints a warning.
 
Methods inherited from class 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(PrintWriter out)
Constructs a new object sending progress reports to the specified stream. The maximal line length is assumed 80 characters.


ProgressPrinter

public ProgressPrinter(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 String getDescription()

Specified by:
getDescription in interface ProgressListener

setDescription

public void setDescription(String description)

Specified by:
setDescription in interface ProgressListener

started

public void started()

Specified by:
started in interface ProgressListener

progress

public void progress(float percent)

Specified by:
progress in interface ProgressListener

getProgress

public float getProgress()
Returns the current progress as a percent completed.

Specified by:
getProgress 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()
Releases any resource hold by this object.

Specified by:
dispose in interface ProgressListener

isCanceled

public boolean isCanceled()

Specified by:
isCanceled in interface ProgressListener

setCanceled

public void setCanceled(boolean canceled)

Specified by:
setCanceled in interface ProgressListener

warningOccurred

public void warningOccurred(String source,
                            String margin,
                            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 null 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 null if none. This is typically the line number where the error occured in the source 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(Throwable exception)
Prints an exception stack trace in a box.

Specified by:
exceptionOccurred in interface ProgressListener

setTask

public void setTask(InternationalString task)
Specified by:
setTask in interface ProgressListener

getTask

public InternationalString getTask()
Specified by:
getTask in interface ProgressListener


Copyright © 1996-2009 Geotools. All Rights Reserved.