Skip to content

Commit 24080c2

Browse files
author
Satyen Subramaniam
committed
8353000: Open source several swing tests batch2
Backport-of: 4e3f184
1 parent 1f54090 commit 24080c2

File tree

6 files changed

+484
-0
lines changed

6 files changed

+484
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (c) 1999, 2025, 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+
* @bug 4210461
27+
* @summary Confirm Metal Look & Feel's MenuItem Accelerator Delimiter
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual JavaLAFMenuAcceleratorDelimiter
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.event.ActionEvent;
35+
import java.awt.event.KeyEvent;
36+
37+
import javax.swing.JFrame;
38+
import javax.swing.JMenu;
39+
import javax.swing.JMenuBar;
40+
import javax.swing.JMenuItem;
41+
import javax.swing.JPanel;
42+
import javax.swing.KeyStroke;
43+
import javax.swing.UIManager;
44+
45+
public class JavaLAFMenuAcceleratorDelimiter {
46+
static final String INSTRUCTIONS = """
47+
A simple check. The visual design specification for JLF/Metal asks for
48+
a "-" to delimit the other two entities in a menu item's accelerator.
49+
The test passes if the delimiter for the accelerator is correct when
50+
opening the example menu. Otherwise, the test fails.
51+
""";
52+
53+
public static void main(String[] args) throws Exception {
54+
// Set Metal L&F
55+
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
56+
PassFailJFrame.builder()
57+
.title("JavaLAFMenuAcceleratorDelimiter Test Instructions")
58+
.instructions(INSTRUCTIONS)
59+
.columns(40)
60+
.testUI(JavaLAFMenuAcceleratorDelimiter::createUI)
61+
.build()
62+
.awaitAndCheck();
63+
}
64+
65+
static JFrame createUI() {
66+
JFrame frame = new JFrame("Metal L&F Accelerator Delimiter Test");
67+
JPanel menuPanel = new JPanel();
68+
JMenuBar menuBar = new JMenuBar();
69+
menuBar.setOpaque(true);
70+
JMenu exampleMenu = new JMenu("Example");
71+
JMenuItem hiMenuItem = new JMenuItem("Hi There!");
72+
hiMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,
73+
ActionEvent.CTRL_MASK));
74+
exampleMenu.add(hiMenuItem);
75+
menuBar.add(exampleMenu);
76+
menuPanel.add(menuBar);
77+
78+
frame.getContentPane().setLayout(new BorderLayout());
79+
frame.getContentPane().add(menuPanel, BorderLayout.CENTER);
80+
frame.setSize(250, 150);
81+
return frame;
82+
}
83+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 2004, 2025, 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+
* @bug 4952462
27+
* @summary Ocean: Tests that disabled selected JRadioButton dot is NOT
28+
* painted with the foreground color
29+
* @modules java.desktop/sun.awt
30+
* @library /test/lib
31+
* @key headful
32+
* @run main bug4952462
33+
*/
34+
35+
import java.awt.Color;
36+
import java.awt.FlowLayout;
37+
import java.awt.Point;
38+
import java.awt.Robot;
39+
40+
import javax.swing.JFrame;
41+
import javax.swing.JRadioButton;
42+
import javax.swing.SwingUtilities;
43+
import javax.swing.UIManager;
44+
import javax.swing.plaf.metal.MetalTheme;
45+
46+
import jtreg.SkippedException;
47+
import sun.awt.AppContext;
48+
49+
public class bug4952462 {
50+
private static JFrame frame;
51+
private static JRadioButton rb;
52+
53+
public static void main(String[] args) throws Exception {
54+
try {
55+
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
56+
57+
MetalTheme theme = (MetalTheme) AppContext.getAppContext().get("currentMetalTheme");
58+
if (theme == null || !"Ocean".equals(theme.getName())) {
59+
throw new SkippedException("Current theme is not Ocean. Test is " +
60+
"only for Metal's Ocean theme. Skipping test.");
61+
} else {
62+
Robot r = new Robot();
63+
SwingUtilities.invokeAndWait(() -> {
64+
frame = new JFrame("Metal JRadioButton Foreground Color Test");
65+
frame.getContentPane().setLayout(new FlowLayout());
66+
rb = new JRadioButton("RadioButton", true);
67+
rb.setEnabled(false);
68+
rb.setForeground(Color.RED);
69+
frame.getContentPane().add(rb);
70+
frame.setSize(250, 100);
71+
frame.setLocationRelativeTo(null);
72+
frame.setVisible(true);
73+
});
74+
75+
r.waitForIdle();
76+
r.delay(500);
77+
78+
SwingUtilities.invokeAndWait(() -> {
79+
Point p = rb.getLocationOnScreen();
80+
for (int i = 0; i < 50; i++) {
81+
Color c = r.getPixelColor(p.x + 10 + i, p.y + (rb.getHeight() / 2));
82+
System.out.println(c);
83+
if (c.getRed() > 200 && c.getBlue() < 200 && c.getGreen() < 200) {
84+
throw new RuntimeException("Test failed. Radiobutton is red " +
85+
"and not grey.");
86+
}
87+
}
88+
});
89+
}
90+
} finally {
91+
SwingUtilities.invokeAndWait(() -> {
92+
if (frame != null) {
93+
frame.dispose();
94+
}
95+
});
96+
}
97+
}
98+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2001, 2025, 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+
* @bug 4186347
27+
* @summary Tests changing Slider.horizontalThumbIcon UIResource
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual bug4186347
31+
*/
32+
33+
import javax.swing.Icon;
34+
import javax.swing.ImageIcon;
35+
import javax.swing.JFrame;
36+
import javax.swing.JSlider;
37+
import javax.swing.UIDefaults;
38+
import javax.swing.UIManager;
39+
import javax.swing.plaf.IconUIResource;
40+
41+
public class bug4186347 {
42+
static final String INSTRUCTIONS = """
43+
If the slider's thumb icon is painted correctly
44+
(that is centered vertically relative to slider
45+
channel) then test passed, otherwise it failed.
46+
""";
47+
48+
public static void main(String[] args) throws Exception {
49+
// Set Metal L&F
50+
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
51+
PassFailJFrame.builder()
52+
.title("bug4186347 Test Instructions")
53+
.instructions(INSTRUCTIONS)
54+
.columns(40)
55+
.testUI(bug4186347::createUI)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
static JFrame createUI() {
61+
JFrame frame = new JFrame("Metal JSlider Icon Test");
62+
String a = System.getProperty("test.src", ".")
63+
+ System.getProperty("file.separator")
64+
+ "duke.gif";
65+
Icon icon = new ImageIcon(a);
66+
IconUIResource iconResource = new IconUIResource(icon);
67+
UIDefaults defaults = UIManager.getDefaults();
68+
defaults.put("Slider.horizontalThumbIcon", iconResource);
69+
JSlider s = new JSlider();
70+
frame.getContentPane().add(s);
71+
frame.setSize(250, 150);
72+
return frame;
73+
}
74+
}
1.58 KB
Loading

0 commit comments

Comments
 (0)