Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTable/LostTextTest.java
41152 views
1
/*
2
* Copyright (c) 2016, 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
* @bug 8159068
26
* @summary Verifies if Jtable rendering is ok.
27
* @run main/manual LostTextTest
28
*/
29
import java.awt.BorderLayout;
30
import java.awt.Component;
31
import java.awt.FlowLayout;
32
import java.util.concurrent.CountDownLatch;
33
import java.util.concurrent.TimeUnit;
34
import javax.swing.JButton;
35
import javax.swing.JDialog;
36
import javax.swing.JFrame;
37
import javax.swing.JPanel;
38
import javax.swing.JTable;
39
import javax.swing.JTextArea;
40
import javax.swing.SwingUtilities;
41
import javax.swing.table.DefaultTableModel;
42
import javax.swing.table.TableModel;
43
44
public class LostTextTest {
45
46
static DefaultTableModel model;
47
48
public static void main(String[] args) throws Exception {
49
final CountDownLatch latch = new CountDownLatch(1);
50
51
LostText test = new LostText(latch);
52
Thread T1 = new Thread(test);
53
T1.start();
54
55
// wait for latch to complete
56
boolean ret = false;
57
try {
58
ret = latch.await(30, TimeUnit.SECONDS);
59
} catch (InterruptedException ie) {
60
throw ie;
61
}
62
if (!ret) {
63
test.dispose();
64
throw new RuntimeException(" User has not executed the test");
65
}
66
67
if (test.testResult == false) {
68
throw new RuntimeException("Some text were not rendered properly"
69
+ " during painting of Jtable rows ");
70
}
71
}
72
}
73
74
class LostText implements Runnable {
75
static JFrame f;
76
static JDialog dialog;
77
static DefaultTableModel model;
78
public boolean testResult = false;
79
private final CountDownLatch latch;
80
81
public LostText(CountDownLatch latch) throws Exception {
82
this.latch = latch;
83
}
84
85
@Override
86
public void run() {
87
try {
88
createUI();
89
lostTextTest();
90
} catch (Exception ex) {
91
if (f != null) {
92
f.dispose();
93
}
94
latch.countDown();
95
throw new RuntimeException("createUI Failed: " + ex.getMessage());
96
}
97
98
}
99
100
public void dispose() {
101
dialog.dispose();
102
f.dispose();
103
}
104
105
private static void lostTextTest() throws Exception {
106
SwingUtilities.invokeAndWait(new Runnable() {
107
@Override
108
public void run() {
109
f = new JFrame();
110
f.add(getComp());
111
f.setSize(300, 300);
112
f.setLocationRelativeTo(null);
113
f.setVisible(true);
114
}
115
116
private Component getComp() {
117
JTable jTable = new JTable(testSelectionWithFilterTable());
118
return jTable;
119
}
120
});
121
}
122
123
private static TableModel testSelectionWithFilterTable() {
124
model = new DefaultTableModel(0, 1);
125
int last = 10;
126
for (int i = 0; i <= last; i++) {
127
model.addRow(new Object[]{i});
128
}
129
return model;
130
}
131
132
private final void createUI() throws Exception {
133
SwingUtilities.invokeAndWait(new Runnable() {
134
@Override
135
public void run() {
136
137
String description
138
= " INSTRUCTIONS:\n"
139
+ " A JTable will be shown.\n"
140
+ " Try to select different rows via mouse or keyboard.\n "
141
+ " Please verify if text are painted properly.\n"
142
+ " If any moment any part of the rows will not be\n "
143
+ " painted properly and if some text are missing in JTable,\n "
144
+ " then press fail else press pass";
145
146
dialog = new JDialog();
147
dialog.setTitle("textselectionTest");
148
JTextArea textArea = new JTextArea(description);
149
textArea.setEditable(false);
150
final JButton passButton = new JButton("PASS");
151
passButton.addActionListener((e) -> {
152
testResult = true;
153
dispose();
154
latch.countDown();
155
});
156
final JButton failButton = new JButton("FAIL");
157
failButton.addActionListener((e) -> {
158
testResult = false;
159
dispose();
160
latch.countDown();
161
});
162
JPanel mainPanel = new JPanel(new BorderLayout());
163
mainPanel.add(textArea, BorderLayout.CENTER);
164
JPanel buttonPanel = new JPanel(new FlowLayout());
165
buttonPanel.add(passButton);
166
buttonPanel.add(failButton);
167
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
168
dialog.add(mainPanel);
169
dialog.pack();
170
dialog.setVisible(true);
171
}
172
});
173
}
174
}
175
176