Skip to content

Commit 6910365

Browse files
author
Andrew Lu
committedJun 11, 2024
8316104: Open source several Swing SplitPane and RadioButton related tests
Backport-of: f52e500f806085f9645cb7857cc7b4e648685351
1 parent 36384e8 commit 6910365

File tree

3 files changed

+332
-0
lines changed

3 files changed

+332
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 javax.swing.JFrame;
25+
import javax.swing.JRadioButton;
26+
import javax.swing.SwingUtilities;
27+
import javax.swing.plaf.ButtonUI;
28+
import javax.swing.plaf.metal.MetalRadioButtonUI;
29+
import java.awt.Dimension;
30+
import java.awt.Graphics;
31+
import java.awt.Rectangle;
32+
import java.awt.Robot;
33+
34+
/*
35+
* @test
36+
* @bug 4823809
37+
* @summary No Mnemonic or Focus Indicator when using HTML for a Component Text
38+
* @key headful
39+
* @run main bug4823809
40+
*/
41+
42+
public class bug4823809 {
43+
private static ButtonUI testUI;
44+
private static volatile boolean passed = false;
45+
private static JFrame frame;
46+
private static Robot robot;
47+
48+
public static void main(String[] args) throws Exception {
49+
try {
50+
robot = new Robot();
51+
SwingUtilities.invokeAndWait(() -> {
52+
frame = new JFrame("RadioButton Test");
53+
testUI = new TestRadioButtonUI();
54+
JRadioButton radio = new TestRadioButton("<html>This is a radiobutton test!</html>");
55+
56+
frame.getContentPane().add(radio);
57+
frame.pack();
58+
frame.setVisible(true);
59+
});
60+
robot.waitForIdle();
61+
robot.delay(1000);
62+
63+
if (!passed) {
64+
throw new Error("Focus isn't painted for JRadioButton with HTML text.");
65+
}
66+
System.out.println("Test Passed!");
67+
} finally {
68+
SwingUtilities.invokeAndWait(() -> {
69+
if (frame != null) {
70+
frame.dispose();
71+
}
72+
});
73+
}
74+
}
75+
76+
static class TestRadioButton extends JRadioButton {
77+
public TestRadioButton(String s) {
78+
super(s);
79+
}
80+
81+
public void setUI(ButtonUI ui) {
82+
super.setUI(testUI);
83+
}
84+
}
85+
86+
static class TestRadioButtonUI extends MetalRadioButtonUI {
87+
protected void paintFocus(Graphics g, Rectangle t, Dimension d) {
88+
super.paintFocus(g, t, d);
89+
passed = true;
90+
}
91+
}
92+
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 1999, 2023, 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 javax.swing.JSplitPane;
25+
import java.beans.PropertyChangeEvent;
26+
import java.beans.PropertyChangeListener;
27+
28+
/*
29+
* @test
30+
* @bug 4147653
31+
* @summary JSplitPane.DIVIDER_LOCATION_PROPERTY is a property,
32+
* you can use that to know when the position changes.
33+
* @run main bug4147653
34+
*/
35+
36+
public class bug4147653 {
37+
private static volatile boolean flag = false;
38+
39+
static class DevMoved implements PropertyChangeListener {
40+
public void propertyChange(PropertyChangeEvent evt) {
41+
flag = true;
42+
}
43+
}
44+
45+
public static void main(String[] args) throws Exception {
46+
JSplitPane sp = new JSplitPane();
47+
48+
DevMoved pl = new DevMoved();
49+
sp.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, pl);
50+
sp.setDividerLocation(sp.getDividerLocation() + 10);
51+
Thread.sleep(1000);
52+
53+
if (!flag) {
54+
throw new RuntimeException("Divider property was not changed...");
55+
}
56+
System.out.println("Test Passed!");
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* Copyright (c) 2003, 2023, 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 javax.swing.JButton;
25+
import javax.swing.JFrame;
26+
import javax.swing.JSplitPane;
27+
import javax.swing.SwingUtilities;
28+
import javax.swing.plaf.basic.BasicSplitPaneDivider;
29+
import javax.swing.plaf.basic.BasicSplitPaneUI;
30+
import java.awt.GridLayout;
31+
import java.awt.Point;
32+
import java.awt.Robot;
33+
import java.awt.event.InputEvent;
34+
35+
/*
36+
* @test
37+
* @bug 4870674
38+
* @summary JSplitPane's one-touch buttons should deal with resized split panes better
39+
* @key headful
40+
* @run main bug4870674
41+
*/
42+
43+
public class bug4870674 {
44+
private static JSplitPane jsp0, jsp1;
45+
private static JButton[] leftOneTouchButton = new JButton[2];
46+
private static JButton[] rightOneTouchButton = new JButton[2];
47+
private static JFrame frame;
48+
private static Robot robot;
49+
private static volatile boolean passed = true;
50+
private static volatile Point rightBtnPos0;
51+
private static volatile Point leftBtnPos0;
52+
private static volatile Point rightBtnPos1;
53+
private static volatile Point leftBtnPos1;
54+
55+
public static void main(String[] args) throws Exception {
56+
try {
57+
robot = new Robot();
58+
SwingUtilities.invokeAndWait(() -> {
59+
frame = new JFrame("Test");
60+
frame.getContentPane().setLayout(new GridLayout(2, 1));
61+
62+
jsp0 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
63+
new JButton("Left"),
64+
new JButton("Right"));
65+
frame.getContentPane().add(jsp0);
66+
67+
jsp0.setUI(new TestSplitPaneUI(0));
68+
jsp0.setOneTouchExpandable(true);
69+
70+
jsp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
71+
new JButton("Left"),
72+
new JButton("Right"));
73+
frame.getContentPane().add(jsp1);
74+
75+
jsp1.setUI(new TestSplitPaneUI(1));
76+
jsp1.setOneTouchExpandable(true);
77+
78+
frame.setSize(300, 100);
79+
frame.setVisible(true);
80+
});
81+
robot.waitForIdle();
82+
robot.delay(1000);
83+
SwingUtilities.invokeAndWait(() -> {
84+
rightBtnPos0 = rightOneTouchButton[0].getLocationOnScreen();
85+
rightBtnPos0.x += rightOneTouchButton[0].getWidth() / 2;
86+
rightBtnPos0.y += rightOneTouchButton[0].getHeight() / 2;
87+
88+
leftBtnPos1 = leftOneTouchButton[1].getLocationOnScreen();
89+
leftBtnPos1.x += leftOneTouchButton[0].getWidth() / 2;
90+
leftBtnPos1.y += leftOneTouchButton[0].getHeight() / 2;
91+
92+
leftBtnPos0 = leftOneTouchButton[0].getLocationOnScreen();
93+
leftBtnPos0.x += leftOneTouchButton[0].getWidth() / 2;
94+
leftBtnPos0.y += leftOneTouchButton[0].getHeight() / 2;
95+
96+
rightBtnPos1 = rightOneTouchButton[1].getLocationOnScreen();
97+
rightBtnPos1.x += rightOneTouchButton[0].getWidth() / 2;
98+
rightBtnPos1.y += rightOneTouchButton[0].getHeight() / 2;
99+
100+
jsp0.setDividerLocation(250);
101+
});
102+
robot.mouseMove(rightBtnPos0.x, rightBtnPos0.y);
103+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
104+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
105+
SwingUtilities.invokeAndWait(() -> {
106+
jsp1.setDividerLocation(250);
107+
});
108+
robot.waitForIdle();
109+
robot.delay(100);
110+
robot.mouseMove(leftBtnPos1.x, leftBtnPos1.y);
111+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
112+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
113+
SwingUtilities.invokeAndWait(() -> {
114+
frame.setSize(200, 100);
115+
});
116+
robot.waitForIdle();
117+
robot.delay(100);
118+
robot.mouseMove(leftBtnPos0.x, leftBtnPos0.y);
119+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
120+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
121+
robot.waitForIdle();
122+
robot.delay(100);
123+
robot.mouseMove(rightBtnPos1.x, rightBtnPos1.y);
124+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
125+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
126+
robot.waitForIdle();
127+
robot.delay(100);
128+
129+
SwingUtilities.invokeAndWait(() -> {
130+
if (jsp0.getDividerLocation() > jsp0.getMaximumDividerLocation() ||
131+
jsp1.getDividerLocation() > jsp1.getMaximumDividerLocation()) {
132+
passed = false;
133+
}
134+
});
135+
136+
if (!passed) {
137+
throw new RuntimeException("The divider location couldn't " +
138+
"be greater then its maximum location");
139+
}
140+
System.out.println("Test Passed!");
141+
} finally {
142+
SwingUtilities.invokeAndWait(() -> {
143+
if (frame != null) {
144+
frame.dispose();
145+
}
146+
});
147+
}
148+
}
149+
150+
static class TestSplitPaneUI extends BasicSplitPaneUI {
151+
int i;
152+
153+
public TestSplitPaneUI(int i) {
154+
super();
155+
this.i = i;
156+
}
157+
158+
public BasicSplitPaneDivider createDefaultDivider() {
159+
return new TestSplitPaneDivider(this, i);
160+
}
161+
}
162+
163+
static class TestSplitPaneDivider extends BasicSplitPaneDivider {
164+
int i = 0;
165+
166+
public TestSplitPaneDivider(BasicSplitPaneUI ui, int i) {
167+
super(ui);
168+
this.i = i;
169+
}
170+
171+
protected JButton createLeftOneTouchButton() {
172+
leftOneTouchButton[i] = super.createLeftOneTouchButton();
173+
return leftOneTouchButton[i];
174+
}
175+
176+
protected JButton createRightOneTouchButton() {
177+
rightOneTouchButton[i] = super.createRightOneTouchButton();
178+
return rightOneTouchButton[i];
179+
}
180+
}
181+
}

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jun 11, 2024

@openjdk-notifier[bot]
Please sign in to comment.