Skip to content

Commit 3105538

Browse files
author
Alisen Chung
committedOct 4, 2023
8316146: Open some swing tests 4
Reviewed-by: honkar, aivanov, prr
1 parent 36314a9 commit 3105538

File tree

4 files changed

+311
-0
lines changed

4 files changed

+311
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
/*
25+
* @test
26+
* @bug 4239714
27+
* @summary Tests that BasicMenuItemUI.installComponent() is protected
28+
*/
29+
30+
import javax.swing.JMenuItem;
31+
import javax.swing.plaf.basic.BasicMenuItemUI;
32+
33+
public class bug4239714 {
34+
public static void main(String[] argv) throws Exception {
35+
Tester tester = new Tester();
36+
tester.test();
37+
}
38+
39+
static class Tester extends BasicMenuItemUI {
40+
public void test() {
41+
JMenuItem mi = new JMenuItem("bug4239714");
42+
installComponents(mi);
43+
}
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
/*
25+
* @test
26+
* @bug 4244616
27+
* @summary Tests that debug output in BasicMenuUI private inner classes
28+
* is commented out
29+
*/
30+
31+
import java.awt.event.ActionEvent;
32+
import java.io.ByteArrayOutputStream;
33+
import java.io.PrintStream;
34+
import javax.swing.Action;
35+
import javax.swing.ActionMap;
36+
import javax.swing.JMenu;
37+
import javax.swing.plaf.basic.BasicMenuUI;
38+
39+
public class bug4244616 {
40+
public static void main(String[] argv) throws Exception {
41+
JMenu menu = new JMenu();
42+
BasicMenuUI ui = new BasicMenuUI();
43+
ui.installUI(menu);
44+
ActionMap amap = menu.getActionMap();
45+
46+
String[] names = {"selectMenu", "cancel",
47+
"selectNext", "selectPrevious"};
48+
ActionEvent ev = new ActionEvent(menu,
49+
ActionEvent.ACTION_PERFORMED, "test event");
50+
51+
// Stream redirection
52+
final PrintStream oldOut = System.out;
53+
final PrintStream oldErr = System.err;
54+
try (ByteArrayOutputStream bout = new ByteArrayOutputStream();
55+
ByteArrayOutputStream berr = new ByteArrayOutputStream();
56+
PrintStream out = new PrintStream(bout);
57+
PrintStream err = new PrintStream(berr)) {
58+
for (int i = 0; i < names.length; i++) {
59+
Action action = amap.get(names[i]);
60+
try {
61+
action.actionPerformed(ev);
62+
} catch (Exception ignored) {
63+
}
64+
}
65+
66+
if (bout.size() != 0 || berr.size() != 0) {
67+
System.out.println("bout: " + bout);
68+
System.out.println("berr: " + berr);
69+
throw new RuntimeException("Failed: some debug output occurred");
70+
}
71+
} finally {
72+
// Restore streams
73+
System.setOut(oldOut);
74+
System.setErr(oldErr);
75+
}
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2001, 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+
/*
25+
* @test
26+
* @bug 4306431
27+
* @summary Tests that Metal themes allow font definition for JList
28+
*/
29+
30+
import java.awt.Font;
31+
import javax.swing.LookAndFeel;
32+
import javax.swing.plaf.FontUIResource;
33+
import javax.swing.plaf.metal.DefaultMetalTheme;
34+
import javax.swing.plaf.metal.MetalLookAndFeel;
35+
36+
public class bug4306431 {
37+
static final Font FONT = new Font(Font.MONOSPACED, Font.ITALIC, 24);
38+
39+
public static void main(String[] argv) throws Exception {
40+
MetalLookAndFeel.setCurrentTheme(new TestMetalTheme());
41+
LookAndFeel laf = new MetalLookAndFeel();
42+
Font font = laf.getDefaults().getFont("List.font");
43+
if (!font.equals(FONT)) {
44+
throw new RuntimeException("Failed: font wasn't customized");
45+
}
46+
}
47+
48+
static class TestMetalTheme extends DefaultMetalTheme {
49+
public FontUIResource getControlTextFont() {
50+
return new FontUIResource(FONT);
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright (c) 2004, 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+
/*
25+
* @test
26+
* @bug 5078214
27+
* @key headful
28+
* @summary ToolTip is shown partially when the application is near the bottom of screen.
29+
* @library /test/lib
30+
* @build jtreg.SkippedException
31+
* @run main bug5078214
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.GraphicsConfiguration;
36+
import java.awt.GraphicsDevice;
37+
import java.awt.GraphicsEnvironment;
38+
import java.awt.Insets;
39+
import java.awt.Point;
40+
import java.awt.Rectangle;
41+
import java.awt.Robot;
42+
import java.awt.Toolkit;
43+
import java.awt.Window;
44+
import java.awt.event.MouseEvent;
45+
import javax.swing.JButton;
46+
import javax.swing.JFrame;
47+
import javax.swing.SwingUtilities;
48+
import javax.swing.ToolTipManager;
49+
50+
import jtreg.SkippedException;
51+
52+
public class bug5078214 {
53+
static volatile boolean passed = false;
54+
55+
static volatile JFrame mainFrame;
56+
static volatile Rectangle bounds;
57+
static volatile Insets insets;
58+
static Robot robot;
59+
60+
public static void main(String[] args) throws Exception {
61+
try {
62+
if (getGraphicsConfig() == null) {
63+
throw new SkippedException("We need at least one screen " +
64+
"with the taskbar at the bottom position.");
65+
}
66+
bounds = getGraphicsConfig().getBounds();
67+
68+
SwingUtilities.invokeAndWait(() -> {
69+
mainFrame = new JFrame("bug5078214");
70+
mainFrame.setLayout(new BorderLayout());
71+
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
72+
JButton button = new JButton("Button with tooltip") {
73+
public Point getToolTipLocation(MouseEvent ev) {
74+
return new Point(100, 100);
75+
}
76+
};
77+
mainFrame.add(button, BorderLayout.CENTER);
78+
button.setToolTipText("ToolTip for this button");
79+
80+
// Position frame
81+
mainFrame.setSize(200, 200);
82+
int x = bounds.x + 200;
83+
int y = bounds.y + bounds.height - insets.bottom - 100;
84+
mainFrame.setLocation(x, y);
85+
mainFrame.setVisible(true);
86+
});
87+
88+
robot = new Robot();
89+
robot.waitForIdle();
90+
robot.delay(1000);
91+
92+
test(bounds, insets);
93+
94+
if (!passed) {
95+
throw new RuntimeException("ToolTip shown outside of the visible area. Test failed.");
96+
}
97+
} finally {
98+
SwingUtilities.invokeAndWait(() -> {
99+
if (mainFrame != null) {
100+
mainFrame.dispose();
101+
}
102+
});
103+
}
104+
}
105+
106+
public static void test(Rectangle b, Insets i) throws Exception {
107+
SwingUtilities.invokeAndWait(() -> {
108+
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
109+
ToolTipManager.sharedInstance().setInitialDelay(100);
110+
});
111+
112+
robot.mouseMove(b.x + 300, b.y + b.height - i.bottom - 10);
113+
robot.delay(500);
114+
Window[] ow = mainFrame.getOwnedWindows();
115+
if (ow == null || ow.length < 1) {
116+
throw new RuntimeException("No owned windows for JFrame - no tooltip shown?");
117+
}
118+
119+
Window ttwnd = ow[0];
120+
int wy = ttwnd.getBounds().y + ttwnd.getBounds().height - 1;
121+
passed = wy < (b.y + b.height - i.bottom);
122+
}
123+
124+
public static GraphicsConfiguration getGraphicsConfig() {
125+
GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment()
126+
.getScreenDevices();
127+
for (GraphicsDevice device : devices) {
128+
GraphicsConfiguration config = device.getDefaultConfiguration();
129+
insets = Toolkit.getDefaultToolkit().getScreenInsets(config);
130+
if (insets.bottom != 0) {
131+
return config;
132+
}
133+
}
134+
return null;
135+
}
136+
}

0 commit comments

Comments
 (0)
Please sign in to comment.