Index: java/awt/DefaultKeyboardFocusManager.java =================================================================== RCS file: /cvsroot/classpath/classpath/java/awt/DefaultKeyboardFocusManager.java,v retrieving revision 1.11 diff -u -r1.11 DefaultKeyboardFocusManager.java --- java/awt/DefaultKeyboardFocusManager.java 7 Nov 2004 00:42:13 -0000 1.11 +++ java/awt/DefaultKeyboardFocusManager.java 20 May 2005 19:17:55 -0000 @@ -140,6 +140,12 @@ } } + /** + * This flag indicates for which focus traversal key release event we + * possibly wait, bevor letting any more KEY_TYPED events through. + */ + private AWTKeyStroke waitForKeyStroke = null; + /** The address@hidden java.util.SortedSet} of current address@hidden #EventDelayRequest}s. */ private SortedSet delayRequests = new TreeSet (); @@ -357,10 +363,33 @@ // the other two key event types for the same key (e.g. if // KEY_PRESSED TAB is a focus traversal keystroke, we also need to // consume KEY_RELEASED and KEY_TYPED TAB key events). + // consuming KEY_RELEASED is easy, because their keyCodes matches + // the KEY_PRESSED event. Consuming the intermediate KEY_TYPED is + // very difficult because their is no clean way that we can know + // which KEY_TYPED belongs to a focusTraversalKey and which not. + // To address this problem we swallow every KEY_TYPE between the + // KEY_PRESSED event that matches a focusTraversalKey and the + // corresponding KEY_RELEASED. AWTKeyStroke oppositeKeystroke = AWTKeyStroke.getAWTKeyStroke (e.getKeyCode (), e.getModifiersEx (), !(e.id == KeyEvent.KEY_RELEASED)); + // Here we check if we are currently waiting for a KEY_PRESSED and + // swallow all KeyEvents that are to be delivered in between. This + // should only be the KEY_TYPED events that correspond to the + // focusTraversalKey's KEY_PRESSED event + if (waitForKeyStroke != null) + { + if (eventKeystroke.equals(waitForKeyStroke)) + // release this lock + waitForKeyStroke = null; + + // as long as we are waiting for the KEY_RELEASED, we swallow every + // KeyEvent, including the KEY_RELEASED + e.consume(); + return; + } + Set forwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); Set backwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); Set upKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); @@ -370,31 +399,29 @@ if (forwardKeystrokes.contains (eventKeystroke)) { + waitForKeyStroke = oppositeKeystroke; focusNextComponent (comp); e.consume (); } else if (backwardKeystrokes.contains (eventKeystroke)) { + waitForKeyStroke = oppositeKeystroke; focusPreviousComponent (comp); e.consume (); } else if (upKeystrokes.contains (eventKeystroke)) { + waitForKeyStroke = oppositeKeystroke; upFocusCycle (comp); e.consume (); } else if (comp instanceof Container && downKeystrokes.contains (eventKeystroke)) { + waitForKeyStroke = oppositeKeystroke; downFocusCycle ((Container) comp); e.consume (); } - else if (forwardKeystrokes.contains (oppositeKeystroke) - || backwardKeystrokes.contains (oppositeKeystroke) - || upKeystrokes.contains (oppositeKeystroke) - || (comp instanceof Container && - downKeystrokes.contains (oppositeKeystroke))) - e.consume (); } protected void enqueueKeyEvents (long after, Component untilFocused)