Name: eh37734 Date: 02/01/2002
FULL PRODUCT VERSION :
D:\j2sdk1.4.0-beta3\bin>java -version
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
FULL OPERATING SYSTEM VERSION :
Windows 2000 (problem is in Java code, not native)
ADDITIONAL OPERATING SYSTEMS :
All
A DESCRIPTION OF THE PROBLEM :
There is no signature of KeyStroke.getKeyStroke that takes
a key location (e.g., KEY_LOCATION_STANDARD, or
KEY_LOCATION_NUMPAD), so it seems to be impossible to make
a KeyStroke for includion in a key map that pays attention
to location.
Further, the KeyStroke code appears to ignore the location
when finding map entries based on KeyEvents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Since there is no KeyStroke.getKeyStroke method that
accepts a location, it is necessary to construct a KeyEvent
call KeyStroke.getKeyStrokeForEvent on it. The KeyEvent
should specify a KEY_PRESSED event on VK_ENTER with no
modifiers, and a location of KEY_LOCATION_STANDARD.
2. Insert the returned KeyStroke into a map (ActionMap,
InputMap, or DefaultKeyMap).
3. Repeat the #1 and 2 with an identical event, except use
KEY_LOCATION_NUMPAD.
4. Try to find the event in the map with a real KeyEvent
for a key press on the normal and numpad Enter (Return)
keys. Notice that both events find the same Action.
EXPECTED VERSUS ACTUAL BEHAVIOR :
I expected to be able to make two KeyStrokes that are
identical except for location, and to be able to insert
them in a map and find them when I get a matching event,
including matching on location.
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
java.awt.Component c = new java.awt.Label( "fake" );
KeyEvent returnKeyEvent = new KeyEvent(
c, // Component
KeyEvent.KEY_PRESSED, // id
0, // when
0, // modifiers
KeyEvent.VK_ENTER, // keyCode
KeyEvent.CHAR_UNDEFINED, // keyChar
KeyEvent.KEY_LOCATION_STANDARD // location
);
KeyEvent enterKeyEvent = new KeyEvent(
c, // Component
KeyEvent.KEY_PRESSED, // id
0, // when
0, // modifiers
KeyEvent.VK_ENTER, // keyCode
KeyEvent.CHAR_UNDEFINED, // keyChar
KeyEvent.KEY_LOCATION_NUMPAD // location
);
/* I would have preferred to use this:
KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, // keyCode
0, // no modifiers
KeyEvent.KEY_LOCATION_STANDARD // normal keyboard
);
KeyStroke.getKeyStroke(
KeyEvent.VK_ENTER, // keyCode
0, // no modifiers
KeyEvent.KEY_LOCATION_NUMPAD // numpad
);
*/
// then insert in map
// later, find in map with:
KeyStroke k = KeyStroke.getKeyStrokeForEvent(inEvent);
Action a = binding.getAction(k);
// Right now, 'binding' is a Keymap that I got with:
// JTextComponent.addKeymap( "Root Map", null );
// I'm not sure if I'm supposed to be using an ActionMap or InputMap instead of
the DefaultKeymap from JTextComponent.addKeymap
---------- END SOURCE ----------
(Review ID: 138515)
======================================================================