How-To Progress Monitor

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How-To Progress Monitor

Holger Mappt
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
[hidden email]
https://lists.openstreetmap.org/listinfo/josm-dev
Reply | Threaded
Open this post in threaded view
|

Re: How-To Progress Monitor

Wiktor Niesiobedzki
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 <[hidden email]>:

> 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
> [hidden email]
> https://lists.openstreetmap.org/listinfo/josm-dev

_______________________________________________
josm-dev mailing list
[hidden email]
https://lists.openstreetmap.org/listinfo/josm-dev
Reply | Threaded
Open this post in threaded view
|

Re: How-To Progress Monitor

Holger Mappt
Hi Wiktor,

PleaseWaitRunnable does the trick, thank your for pointing me to it.
Method "cancel" handles the cancel event, I do not need to watch
progressMonitor.isCancelled().

At the end of my task that is now in realRun() I have a
Notification(tr("Message")).show() that triggered some EDT violations,
but I found the GuiHelper.runInEDT() that fixes that.

Thanks,
Holger


Am 22.10.2016 um 18:40 schrieb Wiktor Niesiobedzki:

> 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 <[hidden email]>:
>> 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
>> [hidden email]
>> https://lists.openstreetmap.org/listinfo/josm-dev
>

_______________________________________________
josm-dev mailing list
[hidden email]
https://lists.openstreetmap.org/listinfo/josm-dev