|
@@ -57,7 +57,15 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
|
57
|
57
|
/** {@inheritDoc} */
|
58
|
58
|
@Override
|
59
|
59
|
protected void addUpHandler() {
|
60
|
|
- ((JTextComponent) target).getActionMap().put("upArrow", new AbstractAction() {
|
|
60
|
+ final JTextComponent localTarget;
|
|
61
|
+ if (target instanceof JTextComponent) {
|
|
62
|
+ localTarget = (JTextComponent) target;
|
|
63
|
+ } else if (target instanceof SwingInputField) {
|
|
64
|
+ localTarget = ((SwingInputField) target).getTextField();
|
|
65
|
+ } else {
|
|
66
|
+ throw new RuntimeException("Unsupported component: " + target.getClass());
|
|
67
|
+ }
|
|
68
|
+ localTarget.getActionMap().put("upArrow", new AbstractAction() {
|
61
|
69
|
|
62
|
70
|
/**
|
63
|
71
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -72,14 +80,22 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
|
72
|
80
|
doBufferUp();
|
73
|
81
|
}
|
74
|
82
|
});
|
75
|
|
- ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
|
83
|
+ localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
76
|
84
|
put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "upArrow");
|
77
|
85
|
}
|
78
|
86
|
|
79
|
87
|
/** {@inheritDoc} */
|
80
|
88
|
@Override
|
81
|
89
|
protected void addDownHandler() {
|
82
|
|
- ((JTextComponent) target).getActionMap().put("downArrow", new AbstractAction() {
|
|
90
|
+ final JTextComponent localTarget;
|
|
91
|
+ if (target instanceof JTextComponent) {
|
|
92
|
+ localTarget = (JTextComponent) target;
|
|
93
|
+ } else if (target instanceof SwingInputField) {
|
|
94
|
+ localTarget = ((SwingInputField) target).getTextField();
|
|
95
|
+ } else {
|
|
96
|
+ throw new RuntimeException("Unsupported component: " + target.getClass());
|
|
97
|
+ }
|
|
98
|
+ localTarget.getActionMap().put("downArrow", new AbstractAction() {
|
83
|
99
|
|
84
|
100
|
/**
|
85
|
101
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -94,14 +110,22 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
|
94
|
110
|
doBufferDown();
|
95
|
111
|
}
|
96
|
112
|
});
|
97
|
|
- ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
|
113
|
+ localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
98
|
114
|
put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "downArrow");
|
99
|
115
|
}
|
100
|
116
|
|
101
|
117
|
/** {@inheritDoc} */
|
102
|
118
|
@Override
|
103
|
119
|
protected void addTabHandler() {
|
104
|
|
- ((JTextComponent) target).getActionMap().put("tabPressed", new AbstractAction() {
|
|
120
|
+ final JTextComponent localTarget;
|
|
121
|
+ if (target instanceof JTextComponent) {
|
|
122
|
+ localTarget = (JTextComponent) target;
|
|
123
|
+ } else if (target instanceof SwingInputField) {
|
|
124
|
+ localTarget = ((SwingInputField) target).getTextField();
|
|
125
|
+ } else {
|
|
126
|
+ throw new RuntimeException("Unsupported component: " + target.getClass());
|
|
127
|
+ }
|
|
128
|
+ localTarget.getActionMap().put("tabPressed", new AbstractAction() {
|
105
|
129
|
|
106
|
130
|
/**
|
107
|
131
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -116,14 +140,22 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
|
116
|
140
|
doTabCompletion();
|
117
|
141
|
}
|
118
|
142
|
});
|
119
|
|
- ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
|
143
|
+ localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
120
|
144
|
put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), "tabPressed");
|
121
|
145
|
}
|
122
|
146
|
|
123
|
147
|
/** {@inheritDoc} */
|
124
|
148
|
@Override
|
125
|
149
|
protected void addEnterHandler() {
|
126
|
|
- ((JTextComponent) target).getActionMap().put("enterButton", new AbstractAction() {
|
|
150
|
+ final JTextComponent localTarget;
|
|
151
|
+ if (target instanceof JTextComponent) {
|
|
152
|
+ localTarget = (JTextComponent) target;
|
|
153
|
+ } else if (target instanceof SwingInputField) {
|
|
154
|
+ localTarget = ((SwingInputField) target).getTextField();
|
|
155
|
+ } else {
|
|
156
|
+ throw new RuntimeException("Unsupported component: " + target.getClass());
|
|
157
|
+ }
|
|
158
|
+ localTarget.getActionMap().put("enterButton", new AbstractAction() {
|
127
|
159
|
|
128
|
160
|
/**
|
129
|
161
|
* A version number for this class. It should be changed whenever the class
|
|
@@ -138,7 +170,7 @@ public class SwingInputHandler extends InputHandler implements KeyListener {
|
138
|
170
|
enterPressed(target.getText());
|
139
|
171
|
}
|
140
|
172
|
});
|
141
|
|
- ((JTextComponent) target).getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
|
173
|
+ localTarget.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).
|
142
|
174
|
put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enterButton");
|
143
|
175
|
}
|
144
|
176
|
|