40
40
import java .awt .*;
41
41
import java .awt .event .ActionEvent ;
42
42
import java .awt .event .ActionListener ;
43
+ import java .awt .event .KeyAdapter ;
44
+ import java .awt .event .KeyEvent ;
43
45
import java .util .Hashtable ;
44
46
import java .util .concurrent .CountDownLatch ;
45
47
@@ -92,6 +94,32 @@ void createTree() {
92
94
super .createUI (panel , "AccessibleActionsTest" );
93
95
}
94
96
97
+ private void createEditableTextArea () {
98
+ AccessibleComponentTest .INSTRUCTIONS = "INSTRUCTIONS:\n "
99
+ + "Check a11y show context menu in editable JTextArea.\n \n "
100
+ + "Turn screen reader on and press Tab to move to the text area\n "
101
+ + "Perform the VO action \" Open a shortcut menu\" (VO+Shift+m)\n \n "
102
+ + "If the menu appears tab further and press PASS, otherwise press FAIL." ;
103
+
104
+ JTextArea textArea = new MyTextArea ("some text to edit" );
105
+ JLabel label = new JLabel (textArea .getText ().length () + " chars" );
106
+ label .setLabelFor (textArea );
107
+ textArea .setEditable (true );
108
+ textArea .addKeyListener (new KeyAdapter () {
109
+ @ Override
110
+ public void keyReleased (KeyEvent e ) {
111
+ label .setText (String .valueOf (textArea .getText ().length ()) + " chars" );
112
+ }
113
+ });
114
+
115
+ JPanel panel = new JPanel ();
116
+ panel .setLayout (new FlowLayout ());
117
+ panel .add (textArea );
118
+ panel .add (label );
119
+ exceptionString = "Editable text area test failed!" ;
120
+ super .createUI (panel , "AccessibleTextTest" );
121
+ }
122
+
95
123
public static void main (String [] args ) throws Exception {
96
124
AccessibleActionsTest test = new AccessibleActionsTest ();
97
125
@@ -110,6 +138,14 @@ public static void main(String[] args) throws Exception {
110
138
if (!testResult ) {
111
139
throw new RuntimeException (a11yTest .exceptionString );
112
140
}
141
+
142
+ countDownLatch = test .createCountDownLatch ();
143
+ SwingUtilities .invokeLater (test ::createEditableTextArea );
144
+ countDownLatch .await ();
145
+
146
+ if (!testResult ) {
147
+ throw new RuntimeException (a11yTest .exceptionString );
148
+ }
113
149
}
114
150
115
151
private class AccessibleActionsTestFrame extends JPanel {
@@ -167,17 +203,70 @@ public boolean doAccessibleAction(int i) {
167
203
}
168
204
}
169
205
170
- private static JPopupMenu createPopup () {
171
- JPopupMenu popup = new JPopupMenu ("MENU" );
172
- popup .add ("One" );
173
- popup .add ("Two" );
174
- popup .add ("Three" );
175
- return popup ;
176
- }
206
+
177
207
178
208
private static void changeText (JLabel label , String text ) {
179
209
label .setText (text );
180
210
}
181
211
182
212
}
213
+
214
+ private static class MyTextArea extends JTextArea {
215
+
216
+ public MyTextArea (String some_text_to_edit ) {
217
+ }
218
+
219
+ @ Override
220
+ public AccessibleContext getAccessibleContext () {
221
+ if (accessibleContext == null ) {
222
+ accessibleContext = new MyAccessibleJTextArea ();
223
+ }
224
+ return accessibleContext ;
225
+ }
226
+
227
+ private class MyAccessibleJTextArea extends JTextArea .AccessibleJTextArea {
228
+ @ Override
229
+ public AccessibleAction getAccessibleAction () {
230
+ return new AccessibleAction () {
231
+ @ Override
232
+ public int getAccessibleActionCount () {
233
+ AccessibleAction aa = MyAccessibleJTextArea .super .getAccessibleAction ();
234
+ if (aa == null ) {
235
+ return 1 ;
236
+ }
237
+ int count = aa .getAccessibleActionCount ();
238
+ return aa .getAccessibleActionCount () + 1 ;
239
+ }
240
+
241
+ @ Override
242
+ public String getAccessibleActionDescription (int i ) {
243
+ AccessibleAction aa = MyAccessibleJTextArea .super .getAccessibleAction ();
244
+ if ((aa != null ) && (i >= 0 ) && (i < aa .getAccessibleActionCount ())) {
245
+ return aa .getAccessibleActionDescription (i );
246
+ }
247
+ return AccessibleAction .TOGGLE_POPUP ;
248
+ }
249
+
250
+ @ Override
251
+ public boolean doAccessibleAction (int i ) {
252
+ AccessibleAction aa = MyAccessibleJTextArea .super .getAccessibleAction ();
253
+ if ((aa != null ) && (i >= 0 ) && (i < aa .getAccessibleActionCount ())) {
254
+ return aa .doAccessibleAction (i );
255
+ }
256
+ JPopupMenu popup = createPopup ();
257
+ popup .show (MyTextArea .this , 0 , 0 );
258
+ return true ;
259
+ }
260
+ };
261
+ }
262
+ }
263
+ }
264
+
265
+ private static JPopupMenu createPopup () {
266
+ JPopupMenu popup = new JPopupMenu ("MENU" );
267
+ popup .add ("One" );
268
+ popup .add ("Two" );
269
+ popup .add ("Three" );
270
+ return popup ;
271
+ }
183
272
}
0 commit comments