|
@@ -36,38 +36,30 @@ import javax.swing.JButton;
|
36
|
36
|
*/
|
37
|
37
|
public class DialogKeyListener implements KeyEventDispatcher {
|
38
|
38
|
|
39
|
|
- /** Repeat delay to prevent rapid firing of the events. */
|
40
|
|
- private static final int REPEAT_DELAY = 250;
|
41
|
|
- /** Last key press. */
|
42
|
|
- private long lastKeyPress = System.currentTimeMillis();
|
43
|
|
-
|
44
|
39
|
/** {@inheritDoc} */
|
45
|
40
|
@Override
|
46
|
41
|
public boolean dispatchKeyEvent(final KeyEvent e) {
|
47
|
|
- if (e.getID() == e.KEY_RELEASED) {
|
48
|
|
- if (lastKeyPress + REPEAT_DELAY <= System.currentTimeMillis()) {
|
49
|
|
- if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
|
50
|
|
- getFocusedWindow() instanceof StandardDialog) {
|
51
|
|
- final StandardDialog dialog = (StandardDialog) KeyboardFocusManager.
|
52
|
|
- getCurrentKeyboardFocusManager().getFocusedWindow();
|
53
|
|
- if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == UIUtilities.
|
54
|
|
- getCtrlMask()) {
|
55
|
|
- dialog.ctrlEnterPressed();
|
56
|
|
- }
|
57
|
|
- if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() != UIUtilities.
|
58
|
|
- getCtrlMask()) {
|
59
|
|
- if (dialog.getFocusOwner() instanceof JButton) {
|
60
|
|
- dialog.executeAction(
|
61
|
|
- ((JButton) dialog.getFocusOwner()));
|
62
|
|
- } else {
|
63
|
|
- return dialog.enterPressed();
|
64
|
|
- }
|
65
|
|
- }
|
66
|
|
- if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
67
|
|
- return dialog.escapePressed();
|
|
42
|
+ if (e.getID() == KeyEvent.KEY_RELEASED) {
|
|
43
|
+ if (KeyboardFocusManager.getCurrentKeyboardFocusManager().
|
|
44
|
+ getFocusedWindow() instanceof StandardDialog) {
|
|
45
|
+ final StandardDialog dialog = (StandardDialog) KeyboardFocusManager.
|
|
46
|
+ getCurrentKeyboardFocusManager().getFocusedWindow();
|
|
47
|
+ if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() == UIUtilities.
|
|
48
|
+ getCtrlMask()) {
|
|
49
|
+ dialog.ctrlEnterPressed();
|
|
50
|
+ }
|
|
51
|
+ if (e.getKeyCode() == KeyEvent.VK_ENTER && e.getModifiers() != UIUtilities.
|
|
52
|
+ getCtrlMask()) {
|
|
53
|
+ if (dialog.getFocusOwner() instanceof JButton) {
|
|
54
|
+ dialog.executeAction(
|
|
55
|
+ ((JButton) dialog.getFocusOwner()));
|
|
56
|
+ } else {
|
|
57
|
+ return dialog.enterPressed();
|
68
|
58
|
}
|
69
|
59
|
}
|
70
|
|
- lastKeyPress = System.currentTimeMillis();
|
|
60
|
+ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
|
61
|
+ return dialog.escapePressed();
|
|
62
|
+ }
|
71
|
63
|
}
|
72
|
64
|
}
|
73
|
65
|
return false;
|