Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTable/TestClearSel.java
41149 views
1
/*
2
* Copyright (c) 2018, 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
* @test
25
* @key headful
26
* @bug 8202702
27
* @summary Verifies if Jtable clear selction causes disappearance of a row.
28
* @run main/manual TestClearSel
29
*/
30
import java.awt.BorderLayout;
31
import java.awt.Component;
32
import java.awt.FlowLayout;
33
import java.awt.event.MouseAdapter;
34
import java.awt.event.MouseEvent;
35
import java.util.concurrent.CountDownLatch;
36
import java.util.concurrent.TimeUnit;
37
import javax.swing.JButton;
38
import javax.swing.JDialog;
39
import javax.swing.JFrame;
40
import javax.swing.JPanel;
41
import javax.swing.JTable;
42
import javax.swing.JTextArea;
43
import javax.swing.SwingUtilities;
44
import javax.swing.table.DefaultTableModel;
45
import javax.swing.table.TableModel;
46
47
public class TestClearSel {
48
49
static DefaultTableModel model;
50
51
public static void main(String[] args) throws Exception {
52
final CountDownLatch latch = new CountDownLatch(1);
53
54
ClearSelTest test = new ClearSelTest(latch);
55
Thread T1 = new Thread(test);
56
T1.start();
57
58
// wait for latch to complete
59
boolean ret = false;
60
try {
61
ret = latch.await(60, TimeUnit.SECONDS);
62
} catch (InterruptedException ie) {
63
throw ie;
64
}
65
if (!ret) {
66
test.dispose();
67
throw new RuntimeException(" User has not executed the test");
68
}
69
70
if (test.testResult == false) {
71
throw new RuntimeException("Some text were not rendered properly"
72
+ " during painting of Jtable rows ");
73
}
74
}
75
}
76
77
class ClearSelTest implements Runnable {
78
static JFrame f;
79
static JDialog dialog;
80
static DefaultTableModel model;
81
public boolean testResult = false;
82
private final CountDownLatch latch;
83
private static String[] rows = new String[]{
84
"Row1", "Row2", "Row3", "Row4", "Row5",
85
"Row6", "Row7", "Row8", "Row9", "Row10"};
86
87
public ClearSelTest(CountDownLatch latch) throws Exception {
88
this.latch = latch;
89
}
90
91
@Override
92
public void run() {
93
try {
94
SwingUtilities.invokeAndWait(() -> {
95
createUI();
96
clearSelTest();
97
});
98
} catch (Exception ex) {
99
if (f != null) {
100
f.dispose();
101
}
102
latch.countDown();
103
throw new RuntimeException("createUI Failed: " + ex.getMessage());
104
}
105
106
}
107
108
public void dispose() {
109
dialog.dispose();
110
f.dispose();
111
}
112
113
private static void clearSelTest() {
114
final DefaultTableModel model = new DefaultTableModel();
115
model.addColumn("Test", rows);
116
final JTable table = new JTable(model);
117
table.setRowHeight(25);
118
119
final MouseAdapter adapt = new MouseAdapter() {
120
121
@Override
122
public void mouseMoved(final MouseEvent pE) {
123
final int row = table.rowAtPoint(pE.getPoint());
124
if (row > -1) {
125
table.setRowSelectionInterval(row, row);
126
} else {
127
table.clearSelection();
128
}
129
}
130
131
@Override
132
public void mouseEntered(final MouseEvent pE) {
133
final int row = table.rowAtPoint(pE.getPoint());
134
if (row > -1) {
135
table.setRowSelectionInterval(row, row);
136
} else {
137
table.clearSelection();
138
}
139
}
140
141
@Override
142
public void mouseExited(final MouseEvent pE) {
143
table.clearSelection();
144
}
145
};
146
table.addMouseListener(adapt);
147
table.addMouseMotionListener(adapt);
148
149
f = new JFrame();
150
f.setSize(300, 300);
151
f.setLocationRelativeTo(null);
152
f.add(table);
153
f.setVisible(true);
154
}
155
156
157
private final void createUI() {
158
String description
159
= " INSTRUCTIONS:\n"
160
+ " A JTable will be shown.\n"
161
+ " Move mouse over different row to select the row.\n "
162
+ " Please verify if row text disappear "
163
+ " if mouse is moved out of table.\n"
164
+ " If any moment any part of the rows will not be\n "
165
+ " painted properly and if some text are missing in JTable,\n "
166
+ " then press fail else press pass";
167
168
dialog = new JDialog();
169
dialog.setTitle("textselectionTest");
170
JTextArea textArea = new JTextArea(description);
171
textArea.setEditable(false);
172
final JButton passButton = new JButton("PASS");
173
passButton.addActionListener((e) -> {
174
testResult = true;
175
dispose();
176
latch.countDown();
177
});
178
final JButton failButton = new JButton("FAIL");
179
failButton.addActionListener((e) -> {
180
testResult = false;
181
dispose();
182
latch.countDown();
183
});
184
JPanel mainPanel = new JPanel(new BorderLayout());
185
mainPanel.add(textArea, BorderLayout.CENTER);
186
JPanel buttonPanel = new JPanel(new FlowLayout());
187
buttonPanel.add(passButton);
188
buttonPanel.add(failButton);
189
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
190
dialog.add(mainPanel);
191
dialog.pack();
192
dialog.setVisible(true);
193
}
194
}
195
196