subtle interaction request

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

subtle interaction request

Kenneth Sloan-3
In a Java plugin:

I have an image open...

I want to display a NonBlockingGenericDialog (or, something else that will have the same effect)

BUT...I want the image window to be selected - without user interaction.

The problem is that I want to use the SPACE bar to toggle an overlay on/off - but if the user gets sloppy and
hits the SPACE bar while the dialog window is still on top...it is CANCELed.  Once I display the dialog box,
my program can't do anything.  Catch-22.

Perhaps I simply need to prevent SPACE from invoking the standard action of CANCEL?

Going off to read the documentation, again.

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.

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

Re: subtle interaction request

John Hayes
Dear Kenneth,

Since no one has responded I thought I’d send my 2cents. I’m not sitting in front of the code-base right now, but I believe you can get a reference to the Dialog through the ij.WindowManager class to the Java AWT (java.awt.Window) window by name using WindowManager::getWindow, or WindowManager::getCurrentWindow might work, or WindowManager::getActiveWindow or something similar since Dialogs are Java AWT Windows: https://docs.oracle.com/javase/7/docs/api/java/awt/Dialog.html
and indeed IJ GenericDialogs are as well:
https://imagej.nih.gov/ij/developer/api/ij/gui/GenericDialog.html

Then you should be able to change the focus of the cursor to whatever you want (and certainly not the CANCEL button) I would think. You may need to remove/add ActionListeners to the respective components you are interested in to accommodate your needs though.

I’ll try to play with the actual code tomorrow (eastern American time) if you haven’t come up with a solution by then… please let us know if you or others have solved your needs in the meantime...

All the best,
John

> On Feb 4, 2019, at 5:07 PM, Kenneth Sloan <[hidden email]> wrote:
>
> In a Java plugin:
>
> I have an image open...
>
> I want to display a NonBlockingGenericDialog (or, something else that will have the same effect)
>
> BUT...I want the image window to be selected - without user interaction.
>
> The problem is that I want to use the SPACE bar to toggle an overlay on/off - but if the user gets sloppy and
> hits the SPACE bar while the dialog window is still on top...it is CANCELed.  Once I display the dialog box,
> my program can't do anything.  Catch-22.
>
> Perhaps I simply need to prevent SPACE from invoking the standard action of CANCEL?
>
> Going off to read the documentation, again.
>
> --
> Kenneth Sloan
> [hidden email]
> Vision is the art of seeing what is invisible to others.
>
> --
> 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: subtle interaction request

Wayne Rasband-2
In reply to this post by Kenneth Sloan-3
> On Feb 4, 2019, at 5:07 PM, Kenneth Sloan <[hidden email]> wrote:
>
> In a Java plugin:
>
> I have an image open...
>
> I want to display a NonBlockingGenericDialog (or, something else that will have the same effect)
>
> BUT...I want the image window to be selected - without user interaction.
>
> The problem is that I want to use the SPACE bar to toggle an overlay on/off - but if the user gets sloppy and
> hits the SPACE bar while the dialog window is still on top...it is CANCELed.  Once I display the dialog box,
> my program can't do anything.  Catch-22.

This is a “feature” of the Dialog class, which GenericDialog and NonBlockingGenericDialog extend. Pressing the space bar cancels the dialog if there are no focusable components other than the buttons on the bottom. You can work around this problem by adding at least one focusable component to the dialog.

The following JavaScript code reproduces the problem. Uncomment the second line to work around it.

   gd = new NonBlockingGenericDialog("Dialog");
   //gd.addStringField("","",0);
   gd.addMessage("SPACE = Cancel");
   gd.addMessage("ENTER = OK");
   gd.showDialog();
   if (gd.wasCanceled())
      IJ.log("Cancel");
   if (gd.wasOKed())
      IJ.log("OK”);

-wayne

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

Re: subtle interaction request

Kenneth Sloan-3
Thanks to those who responded.  Wayne's workaround is on point.

I ended up solving the problem a bit differently.

here is my fix (Java snippet):

           ImagePlus ipl = ...;
           while (true)
                    {
                        nbgd = new NonBlockingGenericDialog("Annotate");
                        nbgd.addMessage("SPACE toggles overlay");
                        nbgd.setCancelLabel("Toggle Overlay");
                        nbgd.showDialog();
                        if(nbgd.wasOKed()) break;
                        toggleOverlay(ipl);
                    }
            }

This depends on the fact that "Cancel" is not a reasonable thing to do in this particular case.  If you also
need "Cancel", then Wayne's idea is best.

--
Kenneth Sloan
[hidden email]
Vision is the art of seeing what is invisible to others.





> On Feb 5, 2019, at 09:45, Wayne Rasband <[hidden email]> wrote:
>
>> On Feb 4, 2019, at 5:07 PM, Kenneth Sloan <[hidden email]> wrote:
>>
>> In a Java plugin:
>>
>> I have an image open...
>>
>> I want to display a NonBlockingGenericDialog (or, something else that will have the same effect)
>>
>> BUT...I want the image window to be selected - without user interaction.
>>
>> The problem is that I want to use the SPACE bar to toggle an overlay on/off - but if the user gets sloppy and
>> hits the SPACE bar while the dialog window is still on top...it is CANCELed.  Once I display the dialog box,
>> my program can't do anything.  Catch-22.
>
> This is a “feature” of the Dialog class, which GenericDialog and NonBlockingGenericDialog extend. Pressing the space bar cancels the dialog if there are no focusable components other than the buttons on the bottom. You can work around this problem by adding at least one focusable component to the dialog.
>
> The following JavaScript code reproduces the problem. Uncomment the second line to work around it.
>
>   gd = new NonBlockingGenericDialog("Dialog");
>   //gd.addStringField("","",0);
>   gd.addMessage("SPACE = Cancel");
>   gd.addMessage("ENTER = OK");
>   gd.showDialog();
>   if (gd.wasCanceled())
>      IJ.log("Cancel");
>   if (gd.wasOKed())
>      IJ.log("OK”);
>
> -wayne
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


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