Generating correct Macintosh menu accelerator key

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Generating correct Macintosh menu accelerator key

Russell Bjork
Is there any way to get the GUI editor to generate code for menu shortcuts
that works correctly on Mac OS?  I'm not talking about getting NetBeans
to work correctly, but about getting the software it produces to work
correctly when using its GUI form creation tools.

To be specific, when the accelerator property of a JMenuItem is set using the
KeyStrokeEditor, one has to specify whether to use Ctrl, Alt, Shift, or some
combination together with the specified key.  For most platforms, the
correct answer for common functions (e.g. New, Open, Save) is
Ctrl; but for Macs it's Meta, which isn't an option.  Even if it were, checking this
would produce software that was Mac-specific, rather than cross-platform.

It turns out that the elegant way to handle this is to use 
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() to calculate the
correct mask.  This will return CTRL_MASK on most platforms, but 
META_MASK on Macs; thus, the mask will be correct for the platform
the software is running on, and the same software will work correctly
on Mac and non-Mac platforms without modification. 
It would be really nice if this were one of the check boxes.  (Available
in possible conjunction with another option - e.g. Shift - for
certain cases).

Is there a neat, clean way to get the code generator to generate this code,
or does one have to do it manually by using the Form Connection editor
instead?  That's painful, to say the least.   I ask this question because it seems
that NetBeans itself does handle menu shortcuts correctly - and if NetBeans
builds itself, then someone in the project has either found a way to do this,
or has been doing a fair amount of work.   (Alas, I can't find the place in the
source code where NetBeans' menus are created to see how this is being done)

Thanks for any help.

Russell C. Bjork

Professor of Computer Science

Gordon College

255 Grapevine Rd

Wenham, MA 01984     (978) 927-2306 x4377  russell.bjork@gordon.edu