Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JSplitPane/4816114/bug4816114.java
41153 views
1
/*
2
* Copyright (c) 2013, 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 4816114 8203904
28
* @summary REGRESSION: Regression in divider location behavior when JSplitPane is resized
29
* @author Andrey Pikalev
30
* @run main bug4816114
31
*/
32
33
import java.awt.Robot;
34
import java.awt.Dimension;
35
import java.awt.AWTException;
36
import java.awt.BorderLayout;
37
import javax.swing.JFrame;
38
import javax.swing.JButton;
39
import javax.swing.SwingUtilities;
40
import javax.swing.JSplitPane;
41
import javax.swing.BorderFactory;
42
import java.lang.reflect.InvocationTargetException;
43
44
public class bug4816114 {
45
46
static JFrame fr;
47
JSplitPane splitPane;
48
49
boolean[] resized = new boolean[] { false, false, false,
50
false, false, false };
51
static int step = 0;
52
boolean h_passed = false;
53
boolean v_passed = false;
54
55
static bug4816114 test = new bug4816114();
56
57
public static void main(String[] args) throws InterruptedException, InvocationTargetException, AWTException {
58
try {
59
SwingUtilities.invokeAndWait(new Runnable() {
60
public void run() {
61
test.createAndShowGUI();
62
}
63
});
64
Robot robot = new Robot();
65
robot.waitForIdle();
66
Thread.sleep(1000);
67
Thread.sleep(2000);
68
69
step++;
70
test.doTest(150, 300);
71
72
step++;
73
test.doTest(650, 300);
74
75
SwingUtilities.invokeAndWait(new Runnable() {
76
public void run() {
77
test.splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
78
}
79
});
80
81
step++;
82
test.doTest(300, 650);
83
84
step++;
85
test.doTest(300, 150);
86
87
step++;
88
test.doTest(300, 650);
89
90
if ( !test.isPassed() ) {
91
throw new Error("The divider location is wrong.");
92
}
93
} finally {
94
SwingUtilities.invokeAndWait(() -> fr.dispose());
95
}
96
}
97
98
public void createAndShowGUI() {
99
fr = new JFrame("Test");
100
fr.setUndecorated(true);
101
102
splitPane = new TestSplitPane();
103
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
104
splitPane.setResizeWeight(0);
105
splitPane.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
106
107
JButton leftButton = new JButton("LEFT");
108
leftButton.setPreferredSize(new Dimension(300, 300));
109
leftButton.setMinimumSize(new Dimension(150, 150));
110
splitPane.setLeftComponent(leftButton);
111
112
JButton rightButton = new JButton("RIGHT");
113
rightButton.setPreferredSize(new Dimension(300, 300));
114
rightButton.setMinimumSize(new Dimension(150, 150));
115
splitPane.setRightComponent(rightButton);
116
117
fr.getContentPane().add(splitPane, BorderLayout.CENTER);
118
119
fr.pack();
120
fr.setVisible(true);
121
}
122
123
void doTest(final int width, final int height) throws InterruptedException, InvocationTargetException {
124
SwingUtilities.invokeAndWait(new Runnable() {
125
public void run() {
126
splitPane.setPreferredSize(new Dimension(width, height));
127
fr.pack();
128
}
129
});
130
131
synchronized (bug4816114.this) {
132
while (!resized[step]) {
133
bug4816114.this.wait();
134
}
135
}
136
}
137
138
synchronized void setPassed(int orientation, boolean passed) {
139
if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
140
this.h_passed = passed;
141
}
142
else {
143
this.v_passed = passed;
144
}
145
}
146
147
synchronized boolean isPassed() {
148
return h_passed && v_passed;
149
}
150
151
152
class TestSplitPane extends JSplitPane {
153
public void setDividerLocation(int location) {
154
super.setDividerLocation(location);
155
156
if ( splitPane.getDividerLocation() == 151 ) {
157
setPassed(getOrientation(), true);
158
}
159
160
synchronized (bug4816114.this) {
161
resized[step] = true;
162
bug4816114.this.notifyAll();
163
}
164
}
165
}
166
}
167
168