|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Monitor the progress of some lengthly operation. This interface makes no
assumption about the output device. It may be the standard output stream
(see ProgressPrinter
implementation),
a window (ProgressWindow
) or mails automatically
sent to some address (ProgressMailer
).
Additionnaly, this interface provides support for non-fatal warning and
exception reports.
All implementations are multi-thread safe, even the Swing implemention. can be invoked from any thread, which never need to be the Swing's thread. This is usefull for performing lenghtly operation in a background thread. Example:
Note: The lineProgressListener p = newProgressPrinter
(); p.setDecription("Loading data"); p.start(); for (int j=0; j<1000; j++) { // ... some process... if ((j & 255) == 0) p.progress(j/10f); } p.complete();
if ((j & 255) == 0)
is used for reducing the amount of calls to progress(float)
(only once every 256 steps).
This is not mandatory, but may speed up the process.
Here is another example showing how to cancel:
Iterator iterator = null;
try{
float size = size();
float position = 0;
progress.started();
for( iterator = iterator(); !progress.isCanceled() && iterator.hasNext(); progress.progress( (position++)/size )){
try {
Feature feature = (Feature) iterator.next();
visitor.visit(feature);
}
catch( Exception erp ){
progress.exceptionOccurred( erp );
}
}
progress.complete();
}
finally {
close( iterator );
}
Note the use of try and catch to report exceptions.
ProgressPrinter
,
ProgressMailer
,
ProgressWindow
,
ProgressMonitor
Method Summary | |
void |
complete()
Notifies this listener that the operation has finished. |
void |
dispose()
Release any resources used by this listener. |
void |
exceptionOccurred(java.lang.Throwable exception)
Reports an exception. |
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. |
void |
setCanceled(boolean cancel)
Indicate that progress should is canceled. |
void |
setDescription(java.lang.String description)
Set the description for the lenghtly operation to be reported. |
void |
started()
Notifies this listener that the operation begins. |
void |
warningOccurred(java.lang.String source,
java.lang.String margin,
java.lang.String warning)
Reports a warning. |
Method Detail |
public java.lang.String getDescription()
public void setDescription(java.lang.String description)
description
- The new description, or if none.public void started()
public void progress(float percent)
public void complete()
public void dispose()
public boolean isCanceled()
public void setCanceled(boolean cancel)
public void warningOccurred(java.lang.String source, java.lang.String margin, java.lang.String warning)
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.public void exceptionOccurred(java.lang.Throwable exception)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |