Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTable/4220171/bug4220171.java
41153 views
1
/*
2
* Copyright (c) 2012, 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
/*
25
* @test
26
* @key headful
27
* @bug 4220171
28
* @author Konstantin Eremin
29
* @summary Tests
30
* @library ../../regtesthelpers
31
* @build Util
32
* @run main bug4220171
33
*/
34
import java.awt.Color;
35
import java.awt.Point;
36
import java.awt.Rectangle;
37
import java.awt.Robot;
38
import java.awt.event.InputEvent;
39
import java.awt.event.KeyEvent;
40
import javax.swing.*;
41
import javax.swing.border.LineBorder;
42
43
public class bug4220171 {
44
45
private static JTable table;
46
private static JFrame frame;
47
48
public static void main(String args[]) throws Exception {
49
try {
50
51
Robot robot = new Robot();
52
robot.setAutoDelay(50);
53
54
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
55
56
public void run() {
57
createAndShowGUI();
58
}
59
});
60
61
robot.waitForIdle();
62
63
clickMouse(robot, 0, 0);
64
Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER);
65
robot.waitForIdle();
66
checkCell(0, 0);
67
68
clickMouse(robot, 0, 1);
69
Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER);
70
robot.waitForIdle();
71
checkCell(0, 1);
72
73
clickMouse(robot, 1, 0);
74
Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER);
75
robot.waitForIdle();
76
checkCell(1, 0);
77
78
clickMouse(robot, 1, 1);
79
Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER);
80
robot.waitForIdle();
81
checkCell(1, 1);
82
} finally {
83
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
84
}
85
}
86
87
static void checkCell(final int row, final int column) throws Exception {
88
SwingUtilities.invokeAndWait(new Runnable() {
89
90
public void run() {
91
if (table.getValueAt(row, column) != null) {
92
throw new RuntimeException(
93
String.format("Cell (%d, %d) is editable", row, column));
94
}
95
}
96
});
97
}
98
99
static void clickMouse(Robot robot, int row, int column) throws Exception {
100
Point point = getCellClickPoint(row, column);
101
robot.mouseMove(point.x, point.y);
102
robot.mousePress(InputEvent.BUTTON1_MASK);
103
robot.mouseRelease(InputEvent.BUTTON1_MASK);
104
}
105
106
private static Point getCellClickPoint(final int row, final int column) throws Exception {
107
final Point[] result = new Point[1];
108
SwingUtilities.invokeAndWait(new Runnable() {
109
110
@Override
111
public void run() {
112
Rectangle rect = table.getCellRect(row, column, false);
113
Point point = new Point(rect.x + rect.width / 2,
114
rect.y + rect.height / 2);
115
SwingUtilities.convertPointToScreen(point, table);
116
result[0] = point;
117
}
118
});
119
120
return result[0];
121
}
122
123
private static void createAndShowGUI() {
124
frame = new JFrame("Test");
125
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
126
frame.setSize(200, 200);
127
128
table = new JTable(2, 2);
129
table.setEnabled(false);
130
131
frame.getContentPane().add(table);
132
frame.setVisible(true);
133
}
134
}
135
136