Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/accessibility/JTable/JTableCellEditor.java
41152 views
1
/*
2
* Copyright (c) 2019, 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.awt.EventQueue;
25
import java.lang.reflect.InvocationTargetException;
26
import java.util.Locale;
27
28
import javax.accessibility.AccessibleRole;
29
import javax.accessibility.AccessibleTable;
30
import javax.swing.JFrame;
31
import javax.swing.JTable;
32
import javax.swing.table.DefaultTableModel;
33
import javax.swing.table.TableModel;
34
35
/**
36
* @test
37
* @bug 8226653
38
* @key headful
39
* @summary The active cell editor should be reported as a child of the table.
40
* Note that the accessibility API ignores the real children of the
41
* table, but reports the "virtual" child per cell in the grid.
42
*/
43
public final class JTableCellEditor {
44
45
private static final int COUNT = 3;
46
private static JTable table;
47
private static JFrame frame;
48
49
public static void main(final String[] args)
50
throws InvocationTargetException, InterruptedException {
51
EventQueue.invokeAndWait(() -> {
52
frame = new JFrame();
53
table = new JTable(testSelectionWithFilterTable());
54
frame.add(table);
55
frame.pack();
56
});
57
EventQueue.invokeAndWait(() -> table.editCellAt(1, 1));
58
EventQueue.invokeAndWait(() -> {
59
AccessibleTable aTable = table.getAccessibleContext()
60
.getAccessibleTable();
61
int aColumns = aTable.getAccessibleColumnCount();
62
int aRows = aTable.getAccessibleRowCount();
63
// We cannot assume which component will be used as an editor of the
64
// table cell, but we can expect it will have the "text" role.
65
AccessibleRole role = aTable.getAccessibleAt(1, 1)
66
.getAccessibleContext()
67
.getAccessibleRole();
68
frame.dispose();
69
if (!role.toDisplayString(Locale.ENGLISH).equals("text")) {
70
throw new RuntimeException("Unexpected role: " + role);
71
}
72
if (aColumns != COUNT) {
73
throw new RuntimeException("Wrong columns: " + aColumns);
74
}
75
if (aRows != COUNT) {
76
throw new RuntimeException("Wrong rows: " + aRows);
77
}
78
});
79
}
80
81
/**
82
* Creates a dummy table model.
83
*/
84
private static TableModel testSelectionWithFilterTable() {
85
DefaultTableModel model = new DefaultTableModel(0, 3);
86
for (int i = 0; i < COUNT; i++) {
87
model.addRow(new Object[]{i + "x0", i + "x1", i + "x2"});
88
}
89
return model;
90
}
91
}
92
93