140 |
} |
} |
141 |
} |
} |
142 |
|
|
143 |
|
/** |
144 |
|
* This flag indicates for which focus traversal key release event we |
145 |
|
* possibly wait, before letting any more KEY_TYPED events through. |
146 |
|
*/ |
147 |
|
private AWTKeyStroke waitForKeyStroke = null; |
148 |
|
|
149 |
/** The {@link java.util.SortedSet} of current {@link |
/** The {@link java.util.SortedSet} of current {@link |
150 |
#EventDelayRequest}s. */ |
#EventDelayRequest}s. */ |
151 |
private SortedSet delayRequests = new TreeSet (); |
private SortedSet delayRequests = new TreeSet (); |
363 |
// the other two key event types for the same key (e.g. if |
// the other two key event types for the same key (e.g. if |
364 |
// KEY_PRESSED TAB is a focus traversal keystroke, we also need to |
// KEY_PRESSED TAB is a focus traversal keystroke, we also need to |
365 |
// consume KEY_RELEASED and KEY_TYPED TAB key events). |
// consume KEY_RELEASED and KEY_TYPED TAB key events). |
366 |
|
// consuming KEY_RELEASED is easy, because their keyCodes matches |
367 |
|
// the KEY_PRESSED event. Consuming the intermediate KEY_TYPED is |
368 |
|
// very difficult because their is no clean way that we can know |
369 |
|
// which KEY_TYPED belongs to a focusTraversalKey and which not. |
370 |
|
// To address this problem we swallow every KEY_TYPE between the |
371 |
|
// KEY_PRESSED event that matches a focusTraversalKey and the |
372 |
|
// corresponding KEY_RELEASED. |
373 |
AWTKeyStroke oppositeKeystroke = AWTKeyStroke.getAWTKeyStroke (e.getKeyCode (), |
AWTKeyStroke oppositeKeystroke = AWTKeyStroke.getAWTKeyStroke (e.getKeyCode (), |
374 |
e.getModifiersEx (), |
e.getModifiersEx (), |
375 |
!(e.id == KeyEvent.KEY_RELEASED)); |
!(e.id == KeyEvent.KEY_RELEASED)); |
376 |
|
|
377 |
|
// Here we check if we are currently waiting for a KEY_RELEASED and |
378 |
|
// swallow all KeyEvents that are to be delivered in between. This |
379 |
|
// should only be the KEY_TYPED events that correspond to the |
380 |
|
// focusTraversalKey's KEY_PRESSED event |
381 |
|
if (waitForKeyStroke != null) |
382 |
|
{ |
383 |
|
if (eventKeystroke.equals(waitForKeyStroke)) |
384 |
|
// release this lock |
385 |
|
waitForKeyStroke = null; |
386 |
|
|
387 |
|
// as long as we are waiting for the KEY_RELEASED, we swallow every |
388 |
|
// KeyEvent, including the KEY_RELEASED |
389 |
|
e.consume(); |
390 |
|
return; |
391 |
|
} |
392 |
|
|
393 |
Set forwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); |
Set forwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS); |
394 |
Set backwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); |
Set backwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS); |
395 |
Set upKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); |
Set upKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS); |
399 |
|
|
400 |
if (forwardKeystrokes.contains (eventKeystroke)) |
if (forwardKeystrokes.contains (eventKeystroke)) |
401 |
{ |
{ |
402 |
|
waitForKeyStroke = oppositeKeystroke; |
403 |
focusNextComponent (comp); |
focusNextComponent (comp); |
404 |
e.consume (); |
e.consume (); |
405 |
} |
} |
406 |
else if (backwardKeystrokes.contains (eventKeystroke)) |
else if (backwardKeystrokes.contains (eventKeystroke)) |
407 |
{ |
{ |
408 |
|
waitForKeyStroke = oppositeKeystroke; |
409 |
focusPreviousComponent (comp); |
focusPreviousComponent (comp); |
410 |
e.consume (); |
e.consume (); |
411 |
} |
} |
412 |
else if (upKeystrokes.contains (eventKeystroke)) |
else if (upKeystrokes.contains (eventKeystroke)) |
413 |
{ |
{ |
414 |
|
waitForKeyStroke = oppositeKeystroke; |
415 |
upFocusCycle (comp); |
upFocusCycle (comp); |
416 |
e.consume (); |
e.consume (); |
417 |
} |
} |
418 |
else if (comp instanceof Container |
else if (comp instanceof Container |
419 |
&& downKeystrokes.contains (eventKeystroke)) |
&& downKeystrokes.contains (eventKeystroke)) |
420 |
{ |
{ |
421 |
|
waitForKeyStroke = oppositeKeystroke; |
422 |
downFocusCycle ((Container) comp); |
downFocusCycle ((Container) comp); |
423 |
e.consume (); |
e.consume (); |
424 |
} |
} |
|
else if (forwardKeystrokes.contains (oppositeKeystroke) |
|
|
|| backwardKeystrokes.contains (oppositeKeystroke) |
|
|
|| upKeystrokes.contains (oppositeKeystroke) |
|
|
|| (comp instanceof Container && |
|
|
downKeystrokes.contains (oppositeKeystroke))) |
|
|
e.consume (); |
|
425 |
} |
} |
426 |
|
|
427 |
protected void enqueueKeyEvents (long after, Component untilFocused) |
protected void enqueueKeyEvents (long after, Component untilFocused) |