Wait for user / NonBlockingGenericDialog

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Wait for user / NonBlockingGenericDialog

Influenza
Hy everyone,

I have a Problem with my PlugIn that has been solved in different ways yet, but all of the solutions don't work for me.

I want the User after opening an Image to make a point selection and I want the PlugIn to wait until that has happend.

If I do something like:

        ...IJ.setTool("point");
        nbgd=new NonBlockingGenericDialog("Fixpoint required!");
        nbgd.addMessage("For further please tag fixpoint and enter OK afterwards");
        nbgd.showDialog();
        rm.runCommand("Add");...

The Plugin continues and the Manager shows up empty with the dialog displayed. But the Dialog such as ImageJ itselve can't be quit anymore.

Then I read about the WaitForUser Dialog. Doing:

        ...IJ.setTool("point");
        new WaitForUserDialog("...","...");
        rm.runCommand("Add");...

the same happens with the difference that no message is displayed in the dialog. Here I read about solving the problem by outsourcing the Dialog in a new Thread:

        ...IJ.setTool("point");
        wfUser("...","...");
        rm.runCommand("Add");...

        public void wfUser(final String title, final String message){
       
               
  Thread waitDialog = new Thread(new Runnable() {
                         public void run() {
                                 new WaitForUserDialog(title,message).show();
                        }
                });
        waitDialog.start();

        }

but the Plugin still don't waits until the user made the selection.
I'm glad for every hint or solution!

Thanks & best regards
Steve
Reply | Threaded
Open this post in threaded view
|

Re: Wait for user / NonBlockingGenericDialog

Michael Schmid
Hi Steven,

it is not enough to create a WaitForUserDialog, you have to show it:

  waitForUserDialog = new WaitForUserDialog(title, text);
  waitForUserDialog.show();
then the program flow is stopped until the user closes the dialog.
Afterwards, you may use
  if (waitForUserDialog.escPressed())
to see whether the user has pressed ESC.

This will not work in the Event Queue:  The code must not be called from a MouseEvent, KeyEvent, etc.  In such a case, you would need a separate thread.

Michael
________________________________________________________________
On Oct 22, 2013, at 18:21, Influenza wrote:

> Hy everyone,
>
> I have a Problem with my PlugIn that has been solved in different ways yet,
> but all of the solutions don't work for me.
>
> I want the User after opening an Image to make a point selection and I want
> the PlugIn to wait until that has happend.
>
> If I do something like:
>
> ...IJ.setTool("point");
> nbgd=new NonBlockingGenericDialog("Fixpoint required!");
> nbgd.addMessage("For further please tag fixpoint and enter OK afterwards");
> nbgd.showDialog();
> rm.runCommand("Add");...
>
> The Plugin continues and the Manager shows up empty with the dialog
> displayed. But the Dialog such as ImageJ itselve can't be quit anymore.
>
> Then I read about the WaitForUser Dialog. Doing:
>
> ...IJ.setTool("point");
> new WaitForUserDialog("...","...");
> rm.runCommand("Add");...
>
> the same happens with the difference that no message is displayed in the
> dialog. Here I read about solving the problem by outsourcing the Dialog in a
> new Thread:
>
> ...IJ.setTool("point");
> wfUser("...","...");
> rm.runCommand("Add");...
>
> public void wfUser(final String title, final String message){
>
>
> Thread waitDialog = new Thread(new Runnable() {
> public void run() {
> new WaitForUserDialog(title,message).show();
> }
> });
> waitDialog.start();
>
> }
>
> but the Plugin still don't waits until the user made the selection.
> I'm glad for every hint or solution!
>
> Thanks & best regards
> Steve
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Wait-for-user-NonBlockingGenericDialog-tp5005270.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Wait for user / NonBlockingGenericDialog

Influenza
Hi Michael!

Thanks for your respond, but I of course added the x.show(); Method in my Plugin I just forgot to post it within my example code. The problem stays the same!
Reply | Threaded
Open this post in threaded view
|

Re: Wait for user / NonBlockingGenericDialog

Michael Schmid
Hi Steven,

here is an example for how to use the WaitForUser Dialog.
It works well in my case; the "dialog finished" message appears after I click OK.

import ij.IJ;
import ij.plugin.PlugIn;
import ij.gui.*;

public class WaitForUserTest implements PlugIn {

    public void run(String arg) {
        IJ.setTool("point");
        WaitForUserDialog wfd = new WaitForUserDialog("Test",
                "Select the point and press OK when done");
        wfd.show();
        IJ.log("dialog finished");
    }
}

As I said, it won't work in the message queue, so you must not call the WaitForUserDialog from any of the MouseListener, KeyListener, DialogListener etc, callbacks such as keyPressed, mouseDragged, dialogItemChanged, ...

Michael
________________________________________________________________
On Oct 25, 2013, at 16:46, Influenza wrote:

> Hi Michael!
>
> Thanks for your respond, but I of course added the x.show(); Method in my
> Plugin I just forgot to post it within my example code. The problem stays
> the same!

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html