Skip to content

Commit ca49685

Browse files
author
Satyen Subramaniam
committed
8354418: Open source Swing tests Batch 4
Backport-of: dda4b5a4ade2e5d7225117e58fce4038bb0e0f1b
1 parent d1aa40f commit ca49685

File tree

3 files changed

+291
-0
lines changed

3 files changed

+291
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
* @requires (os.family == "windows")
28+
* @summary Tests that Windows Look & Feel's MenuItem Accelerator Delimiter is
29+
* shown properly
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual WindowsLAFMenuAcceleratorDelimiter
33+
*/
34+
35+
import java.awt.BorderLayout;
36+
import java.awt.event.ActionEvent;
37+
import java.awt.event.KeyEvent;
38+
import javax.swing.JFrame;
39+
import javax.swing.JMenu;
40+
import javax.swing.JMenuBar;
41+
import javax.swing.JMenuItem;
42+
import javax.swing.JPanel;
43+
import javax.swing.KeyStroke;
44+
import javax.swing.UIManager;
45+
46+
public class WindowsLAFMenuAcceleratorDelimiter {
47+
public static void main(String[] args) throws Exception {
48+
try {
49+
UIManager.setLookAndFeel(
50+
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
51+
} catch (Exception e) {
52+
throw new RuntimeException("The Windows LAF failed to instantiate");
53+
}
54+
55+
String INSTRUCTIONS = """
56+
The visual design specification for the Windows LAF asks for
57+
a "+" to delimit the other two entities in a menuitem's
58+
accelerator.
59+
60+
As a point of reference, the visual design specifications for the
61+
L&Fs are as follows: JLF/Metal = "-", Mac = "-", Motif = "+",
62+
Windows = "+".
63+
64+
Click on "Menu" of "WindowsLAFMenuAcceleratorDelimiter" window,
65+
make sure it shows MenuItem with label "Hi There! Ctrl+H".
66+
67+
If it shows same label test passed otherwise failed.
68+
""";
69+
PassFailJFrame.builder()
70+
.instructions(INSTRUCTIONS)
71+
.columns(50)
72+
.testUI(WindowsLAFMenuAcceleratorDelimiter::initialize)
73+
.build()
74+
.awaitAndCheck();
75+
}
76+
77+
private static JFrame initialize() {
78+
JFrame fr = new JFrame("WindowsLAFMenuAcceleratorDelimiter");
79+
JPanel menuPanel = new JPanel();
80+
JMenuBar menuBar = new JMenuBar();
81+
menuBar.setOpaque(true);
82+
JMenu exampleMenu = new JMenu("Menu");
83+
JMenuItem hiMenuItem = new JMenuItem("Hi There!");
84+
hiMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,
85+
ActionEvent.CTRL_MASK));
86+
exampleMenu.add(hiMenuItem);
87+
menuBar.add(exampleMenu);
88+
menuPanel.add(menuBar);
89+
90+
fr.setLayout(new BorderLayout());
91+
fr.add(menuPanel, BorderLayout.CENTER);
92+
fr.setSize(250, 100);
93+
return fr;
94+
}
95+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2000, 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 4227768
27+
* @requires (os.family == "windows")
28+
* @summary Tests Z-ordering of Windows Look-and-Feel JInternalFrames
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug4227768
32+
*/
33+
34+
import java.awt.Dimension;
35+
import java.awt.Toolkit;
36+
import java.beans.PropertyVetoException;
37+
import javax.swing.JDesktopPane;
38+
import javax.swing.JFrame;
39+
import javax.swing.JInternalFrame;
40+
import javax.swing.UIManager;
41+
42+
public class bug4227768 {
43+
private static JDesktopPane desktop ;
44+
private static JFrame frame;
45+
private static int openFrameCount = 0;
46+
private static final int xOffset = 30;
47+
private static final int yOffset = 30;
48+
49+
public static void main(String[] args) throws Exception {
50+
try {
51+
UIManager.setLookAndFeel
52+
("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
53+
} catch (Exception e) {
54+
throw new RuntimeException("Failed to set Windows LAF");
55+
}
56+
57+
String INSTRUCTIONS = """
58+
Close the internal frame titled "Document #4". The internal frame
59+
titled "Document #3" should get active. Now close the internal
60+
frame titled "Document #2". The internal frame titled "Document #3"
61+
should remain active. If something is not like this, then test
62+
failed. Otherwise test succeeded.
63+
""";
64+
PassFailJFrame.builder()
65+
.instructions(INSTRUCTIONS)
66+
.columns(50)
67+
.testUI(bug4227768::initialize)
68+
.build()
69+
.awaitAndCheck();
70+
}
71+
72+
private static JFrame initialize() {
73+
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
74+
frame = new JFrame("bug4227768");
75+
frame.setSize(screenSize.width / 3, screenSize.height / 3);
76+
frame.add(desktop = new JDesktopPane());
77+
createFrame();
78+
createFrame();
79+
createFrame();
80+
createFrame();
81+
desktop.putClientProperty("JDesktopPane.dragMode", "outline");
82+
return frame;
83+
}
84+
85+
protected static void createFrame() {
86+
JInternalFrame internalFrame = new JInternalFrame
87+
("Document #" + (++openFrameCount), true, true, true, true);
88+
internalFrame.setSize(frame.getWidth() / 2, frame.getHeight() / 2);
89+
internalFrame.setLocation(xOffset * openFrameCount,
90+
yOffset * openFrameCount);
91+
desktop.add(internalFrame);
92+
internalFrame.setVisible(true);
93+
try {
94+
internalFrame.setSelected(true);
95+
} catch (PropertyVetoException e) {
96+
throw new RuntimeException(e);
97+
}
98+
}
99+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2000, 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 4305725
27+
* @requires (os.family == "windows")
28+
* @summary Tests if in Win LAF the JOptionPane.showInternalMessageDialog() is
29+
* not maximized to match background maximized internal frame.
30+
* @library /java/awt/regtesthelpers
31+
* @build PassFailJFrame
32+
* @run main/manual bug4305725
33+
*/
34+
35+
import java.awt.Dimension;
36+
import java.awt.Toolkit;
37+
import java.awt.event.ActionEvent;
38+
import java.awt.event.ActionListener;
39+
import javax.swing.JDesktopPane;
40+
import javax.swing.JFrame;
41+
import javax.swing.JInternalFrame;
42+
import javax.swing.JLayeredPane;
43+
import javax.swing.JMenu;
44+
import javax.swing.JMenuBar;
45+
import javax.swing.JMenuItem;
46+
import javax.swing.JOptionPane;
47+
import javax.swing.UIManager;
48+
49+
public class bug4305725 implements ActionListener {
50+
private static JDesktopPane desktop ;
51+
52+
public static void main(String[] args) throws Exception {
53+
try {
54+
UIManager.setLookAndFeel
55+
("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
56+
} catch (Exception e) {
57+
throw new RuntimeException("Failed to set Windows LAF");
58+
}
59+
60+
String INSTRUCTIONS = """
61+
Maximize the internal frame, then call Exit from File menu.
62+
You will see a message box. If message box is also the size of
63+
internal frame, then test failed. If it is of usual size,
64+
then test is passed.
65+
""";
66+
PassFailJFrame.builder()
67+
.instructions(INSTRUCTIONS)
68+
.columns(50)
69+
.testUI(bug4305725::initialize)
70+
.build()
71+
.awaitAndCheck();
72+
}
73+
74+
private static JFrame initialize() {
75+
JFrame frame = new JFrame("bug4305725");
76+
frame.add(desktop = new JDesktopPane());
77+
JMenuBar mb = new JMenuBar() ;
78+
JMenu menu = new JMenu("File");
79+
mb.add(menu) ;
80+
JMenuItem menuItem = menu.add(new JMenuItem("Exit"));
81+
menuItem.addActionListener(new bug4305725()) ;
82+
frame.setJMenuBar(mb) ;
83+
Dimension sDim = Toolkit.getDefaultToolkit().getScreenSize();
84+
frame.setSize(sDim.width / 2, sDim.height / 2) ;
85+
JInternalFrame internalFrame = new JInternalFrame
86+
("Internal", true, true, true, true);
87+
internalFrame.setSize(frame.getWidth(), frame.getHeight() / 2);
88+
internalFrame.setVisible(true);
89+
desktop.add(internalFrame, JLayeredPane.FRAME_CONTENT_LAYER);
90+
return frame;
91+
}
92+
93+
@Override
94+
public void actionPerformed(ActionEvent aEvent) {
95+
JOptionPane.showInternalMessageDialog(desktop, "Exiting test app");
96+
}
97+
}

0 commit comments

Comments
 (0)