Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JTabbedPane/7024235/Test7024235.java
41153 views
1
/*
2
* Copyright (c) 2013, 2020, 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.BorderLayout;
25
import java.awt.Container;
26
import java.awt.Rectangle;
27
import java.awt.Robot;
28
29
import javax.swing.JButton;
30
import javax.swing.JCheckBox;
31
import javax.swing.JFrame;
32
import javax.swing.JTabbedPane;
33
import javax.swing.SwingUtilities;
34
import javax.swing.UIManager;
35
import javax.swing.UIManager.LookAndFeelInfo;
36
37
/*
38
* @test
39
* @key headful
40
* @bug 7024235
41
* @summary Tests JFrame.pack() with the JTabbedPane
42
* @run main Test7024235
43
*/
44
45
public class Test7024235 implements Runnable {
46
47
private static final boolean AUTO = null != System.getProperty("test.src", null);
48
49
public static void main(String[] args) throws Exception {
50
Test7024235 test = new Test7024235();
51
for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
52
String className = info.getClassName();
53
System.out.println("className = " + className);
54
UIManager.setLookAndFeel(className);
55
56
test.test();
57
try {
58
Robot robot = new Robot();
59
robot.waitForIdle();
60
robot.delay(1000);
61
}catch(Exception ex) {
62
ex.printStackTrace();
63
throw new Error("Unexpected Failure");
64
}
65
test.test();
66
}
67
}
68
69
private volatile JTabbedPane pane;
70
private volatile boolean passed;
71
72
public void run() {
73
if (this.pane == null) {
74
this.pane = new JTabbedPane();
75
this.pane.addTab("1", new Container());
76
this.pane.addTab("2", new JButton());
77
this.pane.addTab("3", new JCheckBox());
78
79
JFrame frame = new JFrame();
80
frame.add(BorderLayout.WEST, this.pane);
81
frame.pack();
82
frame.setLocationRelativeTo(null);
83
frame.setVisible(true);
84
85
test("first");
86
}
87
else {
88
test("second");
89
if (this.passed || AUTO) { // do not close a frame for manual review
90
SwingUtilities.getWindowAncestor(this.pane).dispose();
91
}
92
this.pane = null;
93
}
94
}
95
96
private void test() throws Exception {
97
SwingUtilities.invokeAndWait(this);
98
if (!this.passed && AUTO) { // error reporting only for automatic testing
99
throw new Error("TEST FAILED");
100
}
101
}
102
103
private void test(String step) {
104
this.passed = true;
105
for (int index = 0; index < this.pane.getTabCount(); index++) {
106
Rectangle bounds = this.pane.getBoundsAt(index);
107
if (bounds == null) {
108
continue;
109
}
110
int centerX = bounds.x + bounds.width / 2;
111
int centerY = bounds.y + bounds.height / 2;
112
int actual = this.pane.indexAtLocation(centerX, centerY);
113
if (index != actual) {
114
System.out.println("name = " + UIManager.getLookAndFeel().getName());
115
System.out.println("step = " + step);
116
System.out.println("index = " + index);
117
System.out.println("bounds = " + bounds);
118
System.out.println("indexAtLocation(" + centerX + "," + centerX + ") returns " + actual);
119
this.passed = false;
120
}
121
}
122
}
123
}
124
125