org.geotoolkit.gui.headless
Class ProgressPrinter

Object
  extended by ProgressController
      extended by ProgressPrinter
All Implemented Interfaces:
EventListener, ProcessListener, Localized

@ThreadSafe
public class ProgressPrinter
extends ProgressController

Prints progress report of a lengthly 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 stopping the lengthly task.

Since:
1.0
Version:
3.19
Author:
Martin Desruisseaux (MPO, IRD, Geomatys)
Module:
display/geotk-widgets-swing (download)    View source code for this class

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 completed()
          Notifies this listener that the operation has finished.
 void exceptionOccurred(Throwable exception)
          Prints an exception stack trace in a box.
 void setProgress(float percent)
          Notifies this controller of progress in the lengthly operation.
 void started()
          Notifies this controller that the operation begins.
 void warningOccurred(String source, String margin, String warning)
          Prints a warning.
 
Methods inherited from class ProgressController
cancel, completed, failed, getLocale, getProgress, getTask, isCanceled, progressing, setTask, started
 
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 to be 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.

Parameters:
out - The output stream.

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

started

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

Specified by:
started in class ProgressController

setProgress

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

Overrides:
setProgress in class ProgressController
Parameters:
percent - The progress as a value between 0 and 100 inclusive.

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 margin is specified, it will be printed of the left side of the first line of the warning message.

Specified by:
warningOccurred in class ProgressController
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 occurred 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 margin width.

exceptionOccurred

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

Specified by:
exceptionOccurred in class ProgressController
Parameters:
exception - The exception to report.

completed

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

Specified by:
completed in class ProgressController


Copyright © 2009-2012 Geotoolkit.org. All Rights Reserved.