How-To Progress Monitor

Wiktor Niesiobedzki osm at vink.pl
Sat Oct 22 16:40:56 UTC 2016


Hi,

I guess that you may find
org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction
helpful. This is the class that downloads WMS along GPX track. Let me
give you a short guide around the code:

PrecacheWmsTask is the class that is executed in background. The task
is submitted to background thread for execution as:
Main.worker.execute(task);

It means that task is executed in one shared background thread across JOSM.

PrecacheWmsTask.realRun method implements, what needs to be done in background.

To implement user friendly Progress Monitor you can do as follow:
use: progressMonitor.setTicksCount(int) to set how many units of work
(ex. images) you have at the begging of realRun()
and then, when unit of work is done, use progressMonitor.worked(1) to
notify, that one unit is already done (ex. one image is processed)

You should also watch progressMonitor.isCancelled() to shut down your
background work if user cancels it.

I guess this has helped you.

Cheers,

Wiktor


2016-10-22 17:07 GMT+02:00 Holger Mappt <holgerosm at gmx.net>:
> Hi,
>
> I'm writing a plugin that processes a number of images after a menu item was
> selected.  What is the right way to do that in a way that doesn't block the
> GUI with an indication of the progress?  I guess I have to run some kind of
> task that updates the progress after every image.  Then some GUI component
> displays a progress bar (with an optional cancel button).  I implemented
> something that is based on javax.swing.ProgressMonitor and
> javax.swing.SwingWorker according to the code sample from the Java tutorial
> (https://docs.oracle.com/javase/tutorial/uiswing/examples/components/ProgressMonitorDemoProject/src/components/ProgressMonitorDemo.java),
> but it's not working.  The progress window opens after the 101st image and
> then blocks the execution of the task.
>
> What is the recommended JOSM way to do that?  Is there a good example where
> I can learn from?  JOSM has a ProgressMonitor interface and some classes
> that implement it, but there is no documentation and the plugins I looked at
> are quite complex with an endless chain of subroutines.  Any help is
> appreciated.
>
> Thanks,
> Holger
>
> _______________________________________________
> josm-dev mailing list
> josm-dev at openstreetmap.org
> https://lists.openstreetmap.org/listinfo/josm-dev



More information about the josm-dev mailing list