unexpected failure of keyboard shortcuts for zoom in a custom StackWindow

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

unexpected failure of keyboard shortcuts for zoom in a custom StackWindow

Mark Bentley
Apologies, but this is a resend of a question that was originally sent
with Reply To status towards the thread 'Fiji Wiki upgrade'. This was an
accident.  Thanks again.

Greetings,

I am experiencing an unexpected failure of the Zoom>In and Zoom>Out
default keyboard mapping as described here,
http://rsb.info.nih.gov/ij/docs/shortcuts.html , when extending a
ij.gui.StackWindow in a Plugin.  Why is it being extended, you ask?  The
plugin features several awt.Button objects added to a Panel that is then
added to the window.  So, the custom StackWindow also implements
ActionListener.  There are two sets of Buttons, each representing a
menu, each menu has a Button designed to switch back to the other menu.  
The code looks something like this...

void actionPerformed(ActionEvent e) {
     if (e.getSource() == currentPanelsSwitchMenuButton) {
         remove(theCurrentPanel);  //remove the panel currently displayed
         add(theOtherPanel); //add the other panel, both panels have
already had the buttons, listeners, etc. added.
         pack();
     }
}

The plugin operates as expected, and the buttons within each menu carry
out their correct functions, including the 'menu switching' mentioned
above, BUT upon switching menus the keyboard shortcuts for zoom stop
working.

Now, AFTER doing a menu switch and thus breaking the zoom shortcuts, the
shortcuts can be restored by manually clicking the magnification tool in
the ImageJ main window.  Once that has been clicked everything is back
to normal; the shortcuts work as they should even when the mag tool is
no longer selected.  BUT a 'menu switch' will break the zoom keys again
until the Magnification tool is manually selected again.  The users of
the plugin switch menus frequently, and this problem is really slowing
them down.

I have already tried including a 'dirty fix' like the one below:

private void fixZoom() {
     String currentTool = IJ.getToolName();
     IJ.setTool(Toolbar.MAGNIFIER);
     IJ.setTool(currentTool);
} /* end fixZoom() */

where fixZoom() is called after pack() in actionPerformed.  Also, just
calling IJ.setTool(Toolbar.MAGNIFIER) and then expecting the user to
select their desired tool afterwards, an even simpler 'half fix,' does
not work.  It seems that the user must actually CLICK ON the mag tool or
CLICK WITH it at least once to restore the keyboard shortcuts.

Any suggestions?

Thank you all,

--
Mark Bentley
[hidden email]

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

Re: unexpected failure of keyboard shortcuts for zoom in a custom StackWindow

Rasband, Wayne (NIH/NIMH) [E]
On Feb 5, 2014, at 11:31 AM, Mark Bentley wrote:

> Greetings,
>
> I am experiencing an unexpected failure of the Zoom>In and Zoom>Out default keyboard mapping as described here, http://rsb.info.nih.gov/ij/docs/shortcuts.html , when extending a ij.gui.StackWindow in a Plugin.

The latest versions of the Panel Window example plugins at

   http://imagej.nih.gov/ij/plugins/panel-window.html

work around this problem be calling requestFocus() on the custom ImageCanvas.

-wayne

> Why is it being extended, you ask?  The plugin features several awt.Button objects added to a Panel that is then added to the window.  So, the custom StackWindow also implements ActionListener.  There are two sets of Buttons, each representing a menu, each menu has a Button designed to switch back to the other menu.  The code looks something like this...
>
> void actionPerformed(ActionEvent e) {
>    if (e.getSource() == currentPanelsSwitchMenuButton) {
>        remove(theCurrentPanel);  //remove the panel currently displayed
>        add(theOtherPanel); //add the other panel, both panels have already had the buttons, listeners, etc. added.
>        pack();
>    }
> }
>
> The plugin operates as expected, and the buttons within each menu carry out their correct functions, including the 'menu switching' mentioned above, BUT upon switching menus the keyboard shortcuts for zoom stop working.
>
> Now, AFTER doing a menu switch and thus breaking the zoom shortcuts, the shortcuts can be restored by manually clicking the magnification tool in the ImageJ main window.  Once that has been clicked everything is back to normal; the shortcuts work as they should even when the mag tool is no longer selected.  BUT a 'menu switch' will break the zoom keys again until the Magnification tool is manually selected again.  The users of the plugin switch menus frequently, and this problem is really slowing them down.
>
> I have already tried including a 'dirty fix' like the one below:
>
> private void fixZoom() {
>    String currentTool = IJ.getToolName();
>    IJ.setTool(Toolbar.MAGNIFIER);
>    IJ.setTool(currentTool);
> } /* end fixZoom() */
>
> where fixZoom() is called after pack() in actionPerformed.  Also, just calling IJ.setTool(Toolbar.MAGNIFIER) and then expecting the user to select their desired tool afterwards, an even simpler 'half fix,' does not work.  It seems that the user must actually CLICK ON the mag tool or CLICK WITH it at least once to restore the keyboard shortcuts.
>
> Any suggestions?

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