This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 31004 - Menu mnemonics from lowercase letters do not work
Summary: Menu mnemonics from lowercase letters do not work
Status: VERIFIED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Window System (show other bugs)
Version: 3.x
Hardware: PC Linux
: P2 blocker (vote)
Assignee: _ mihmax
URL:
Keywords: A11Y
Depends on:
Blocks: 26640
  Show dependency tree
 
Reported: 2003-02-12 17:15 UTC by Jesse Glick
Modified: 2008-12-22 20:50 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2003-02-12 17:15:30 UTC
[dev feb 11, MDI, Linux, JDK 1.4.1_01] Alt-R does
not work to post the Versioning menu. Generally,
create a new menu named "He&llo". Alt-L does not
post it. Rename it "&O Hello". Alt-O does work to
post it.

Suspect a problem in recently committed
org.openide.awt.Mnemonics. Note that
setLocalizedText2 creates a local var "ch" of type
char. It then calls setMnemonic and *implicitly
casts it* to int (already bad style).
AbstractButton.setMnemonic (and
JLabel.setDisplayedMnemonic) have two forms. One
(apparently deprecated though no @deprecated)
takes a char and I am guessing is case-insensitive.

The other - the one Mnemonics calls - takes an
int. (1) This is case-sensitive according to its
documentation. (2) It is supposed to be a keycode!
There is no necessary relation to a Unicode
character. It so happens that KeyEvent defines
VK_A .. VK_Z and VK0 .. VK9 to be their ASCII
equivalents; this is not true of lowercase letters
(which of course have the same keycode for
purposes of mnemonics), nor for arbitrary other
characters.

In other words, Mnemonics.setMnemonic(Object,int)
is written completely incorrectly. I am not sure
offhand what needs to be done to fix it; you need
to somehow take a Unicode char and translate it
into the keycode which somehow might press to
generate it, ignoring some modifiers like Shift.
Source code for AbstractButton.setMnemonic(char)
is of little use, since that only handles [A-Za-z]
correctly, and I presume [0-9] too though that is
not documented.

However it seems that this method is only ever
called with a char in the Latin range [A-Za-z0-9].
In that case the patch is simple: change the
signature of Mnemonics.setMnemonic(Object,int) to
be setMnemonic(Object,char). That should cause the
older overload of AB.sM and JL.sDM to be called,
which both correctly handle lowercase Latin
letters (as well as uppercase Latin letters and
apparently also Arabic digits and (char)0 for no
mnemonic). Please try this one-line patch and see
if it helps.
Comment 1 _ mihmax 2003-02-12 19:51:19 UTC
I suppose you are right - calling setMnemonic(int) is bad, 
I'll use setMnemonic(char) instead.
Or, maybe, I should cut&paste a-z -> A-Z translation from 
setMnemonic(char) and call "not-obsolete" setMnemonic(int)?

I'm also curious, what characters may be used as mnemonic 
other than [a-z,A-Z,0-9], maybe -,=,\,`,[,],;,',,,.,/
on some of them ([];',./` there're Russian letters).
Comment 2 Jesse Glick 2003-02-12 20:22:19 UTC
Re. calling setMnemonic(char) vs. copying logic to translate [a-z] - I
guess it doesn't make much difference.

Re. other mnemonicable characters - don't know. I have only ever heard
of alphanumerics as mnemonics. Since that is all the JRE supports,
probably that is all we need to support too (besides your work - the
special support for e.g. Alt-F posting an underlined Cyrillic phi).
Comment 3 _ mihmax 2003-02-12 20:45:33 UTC
Well, my final decision is not to copy [a-z] -> [A-Z] 
logic inside Mnemonics.java, 
but still I'd like to make some extensions to 
Mnemonics.java (no limit to improve ;-)):

KeyEvent.VK_AMPERSAND!=(int)'&' !!!, 
hence I'll need to setup a table in Mnemonics.properties 
to convert '&' to KeyEvent.VK_AMPERSAND, and not just 
(int) it, i.e.
MNEMONIC_&=150

I'll make a thorough test before commiting.
Comment 4 Jesse Glick 2003-02-12 20:55:23 UTC
OK. Does anyone actually use '&' as a mnemonic? (Alt-Shift-7 on a US
keyboard?) Just curious.
Comment 5 _ mihmax 2003-02-12 21:58:49 UTC
OK, wrong example ;-)
VK_BACK_QUOTE != (int)'`'
i.e.: MNEMONIC_`=192

Actually, I don't think that anybody will use ` as a 
mnemonics in English, but who knows...

But there's a Russian character 'jo' (rarely used) on it, 
so 
MNEMONIC_\u0401=` would be wrong, the correct is 
MNEMONIC_\u0401=192
Comment 6 _ mihmax 2003-02-12 22:20:43 UTC
One more example:
# public static final int VK_QUOTE 222 
MNEMONIC_\'=222
Comment 7 _ mihmax 2003-02-12 22:56:58 UTC
done

Checking in 
openide/src/org/openide/awt/Mnemonics.properties;
new revision: 1.2; previous revision: 1.1

Checking in openide/src/org/openide/awt/Mnemonics.java;
new revision: 1.2; previous revision: 1.1
Comment 8 _ mihmax 2003-02-12 23:02:02 UTC
Jesse, please verify,
especially in English locale ;-)
Comment 9 Jesse Glick 2003-02-13 17:05:31 UTC
Alt-R works now.

Also I confirmed that ' and ` can work as mnemonics, for whatever
that's worth.
Comment 10 _ mihmax 2003-02-13 17:23:11 UTC
More rewrite (now using setMnemonic(int) istead of 
setMnemonic(char)).

Also under JDK1.3 when someone wants to set, e.g. `, as 
mnemonic a character that has a keycode different from a 
char itself,
there's a conflict: appending (<Keycode>) shows some 
character, which is, hmm, a strange one ;-) (there's no 
such char on the keyboard), because <Keycode> is not a 
character at all.

So, some mess is appended, but Alt+` will work.

Under JDK1.4 everything is OK, but this is a A11Y issue on 
1.3, so setting ` as mnemonic is HIGHLY not recommended, 
though possible.
Comment 11 _ mihmax 2003-02-13 17:36:58 UTC
Checking in openide/src/org/openide/awt/Mnemonics.java;
new revision: 1.3; previous revision: 1.2

done, I hope ;-)