rev 17435 : 8183286: Some java/awt and javax/swing tests miss headful jtreg keyword
1 /*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.lang.reflect.InvocationTargetException;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.List;
28
29 import javax.accessibility.Accessible;
30 import javax.accessibility.AccessibleContext;
31 import javax.swing.AbstractListModel;
32 import javax.swing.JFrame;
33 import javax.swing.JList;
34 import javax.swing.SwingUtilities;
35 import javax.swing.WindowConstants;
36
37 /* @test
38 @key headful
39 @bug 8076249
40 @summary NPE in AccessBridge while editing JList model
41 @author Mikhail Cherkasov
42 @run main AccessibleJListChildNPETest
43 */
44 public class AccessibleJListChildNPETest {
45
46 private static String[] model = { "1", "2", "3", "4", "5", "6" };
47 private static JList<String> list;
48
49 public static void main(String[] args) throws InvocationTargetException, InterruptedException {
50 SwingUtilities.invokeAndWait(new Runnable() {
51 @Override
52 public void run() {
53 JFrame frame = new JFrame();
54 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
55 final MyModel dataModel = new MyModel(Arrays.asList(model));
56 list = new JList<>(dataModel);
57 frame.getContentPane().add(list);
58 frame.pack();
59 frame.setVisible(true);
60
61 }
62 });
63
64 SwingUtilities.invokeAndWait(new Runnable() {
65 @Override
66 public void run() {
67 AccessibleContext ac = list.getAccessibleContext();
68 MyModel model = (MyModel)list.getModel();
69 Accessible accessibleChild = ac.getAccessibleChild(model.getSize()-1);
70 model.removeFirst();
71 accessibleChild.getAccessibleContext().getAccessibleSelection();
72 accessibleChild.getAccessibleContext().getAccessibleText();
73 accessibleChild.getAccessibleContext().getAccessibleValue();
74 }
75 });
76 }
77
78 protected static class MyModel extends AbstractListModel<String> {
79 private List<String> items = new ArrayList<>();
80
81 MyModel(final List<String> newItems) {
82 super();
83 items.addAll(newItems);
84 fireIntervalAdded(this, 0, getSize() - 1);
85 }
86
87 void removeFirst() {
88 if(getSize() > 0) {
89 items.remove(0);
90 fireIntervalRemoved(this, 0, 0);
91 }
92 }
93
94 @Override
95 public int getSize() {
96 return items.size();
97 }
98
99 @Override
100 public String getElementAt(int index) {
101 return items.get(index);
102 }
103 }
104 }
--- EOF ---