some process... if ((j & 255) == 0) p.progress(j/10f); } p.complete();
Note: The line
if ((j & 255) == 0)
is used for reducing the amount of calls to {@link #progress} (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.
@since 2.0
@source $URL$
@version $Id$
@author Martin Desruisseaux (PMO, IRD)
@see org.geotools.gui.headless.ProgressPrinter
@see org.geotools.gui.headless.ProgressMailer
@see org.geotools.gui.swing.ProgressWindow
@see javax.swing.ProgressMonitor
@deprecated Please use org.opengis.util.ProgressListener