Skip to content

Commit 0775bf2

Browse files
author
Abhishek Kumar
committedSep 15, 2023
8316106: Open source few swing JInternalFrame and JMenuBar tests
Reviewed-by: kizune, tr
1 parent 4a63eb0 commit 0775bf2

File tree

5 files changed

+457
-0
lines changed

5 files changed

+457
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 4268949
27+
* @summary Tests if JInternalFrame can do setBackground()
28+
* @run main bug4268949
29+
*/
30+
31+
import java.awt.Color;
32+
import javax.swing.JInternalFrame;
33+
import javax.swing.SwingUtilities;
34+
35+
public class bug4268949 {
36+
37+
static Color c1;
38+
static Color c2;
39+
static Color c3;
40+
41+
public static void main(String[] argv) throws Exception {
42+
SwingUtilities.invokeAndWait(() -> {
43+
JInternalFrame if1, if2, if3;
44+
if1 = new JInternalFrame("Frame 1");
45+
if2 = new JInternalFrame("Frame 2");
46+
if3 = new JInternalFrame("Frame 3");
47+
if1.setBounds(20, 20, 95, 95);
48+
if2.setBounds(120, 20, 95, 95);
49+
if3.setBounds(220, 20, 95, 95);
50+
if1.setBackground(Color.red);
51+
if2.setBackground(Color.blue);
52+
if3.setBackground(Color.green);
53+
c1 = if1.getContentPane().getBackground();
54+
c2 = if2.getContentPane().getBackground();
55+
c3 = if3.getContentPane().getBackground();
56+
});
57+
if (!(c1.equals(Color.red)) || !(c2.equals(Color.blue))
58+
|| !(c3.equals(Color.green))) {
59+
throw new RuntimeException("Test failed: JInternalFrame " +
60+
"cannot do setBackground()");
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright (c) 2000, 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 4309079
27+
* @summary Tests that when a JInternalFrame is activated,
28+
focused JTextField shows cursor.
29+
* @key headful
30+
* @run main bug4309079
31+
*/
32+
33+
import java.awt.FlowLayout;
34+
import java.awt.Point;
35+
import java.awt.Robot;
36+
import java.awt.event.InputEvent;
37+
import java.awt.event.FocusEvent;
38+
import java.awt.event.FocusListener;
39+
import javax.swing.JFrame;
40+
import javax.swing.JDesktopPane;
41+
import javax.swing.JInternalFrame;
42+
import javax.swing.JTextField;
43+
import javax.swing.SwingUtilities;
44+
45+
public class bug4309079 {
46+
47+
private static JFrame f;
48+
private static JTextField tf;
49+
private static JDesktopPane desktop;
50+
private static JInternalFrame f1;
51+
private static JInternalFrame f2;
52+
private static volatile boolean passed = true;
53+
private static volatile Point p;
54+
55+
public static void main(String[] args) throws Exception {
56+
try {
57+
Robot robot = new Robot();
58+
robot.setAutoDelay(100);
59+
SwingUtilities.invokeAndWait(() -> {
60+
f = new JFrame();
61+
f.setSize(500, 300);
62+
tf = new JTextField(10);
63+
tf.addFocusListener(new FocusListener() {
64+
public void focusGained(FocusEvent e) {
65+
passed = tf.getCaret().isVisible();
66+
}
67+
public void focusLost(FocusEvent e) {
68+
}
69+
});
70+
tf.requestFocus();
71+
f1 = AddFrame(new JTextField(10));
72+
f2 = AddFrame(tf);
73+
f.getContentPane().add(desktop);
74+
f.setVisible(true);
75+
});
76+
robot.waitForIdle();
77+
robot.delay(500);
78+
79+
SwingUtilities.invokeAndWait(() -> {
80+
f1.toFront();
81+
f2.toFront();
82+
p = tf.getLocationOnScreen();
83+
});
84+
robot.mouseMove(p.x, p.y);
85+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK );
86+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK );
87+
88+
if (!passed) {
89+
throw new RuntimeException("Test failed.");
90+
}
91+
} finally {
92+
SwingUtilities.invokeAndWait(() -> {
93+
if (f != null) {
94+
f.dispose();
95+
}
96+
});
97+
}
98+
}
99+
100+
private static JInternalFrame AddFrame(JTextField tf) {
101+
JInternalFrame frame = new JInternalFrame();
102+
desktop = new JDesktopPane();
103+
desktop.add(frame);
104+
frame.getContentPane().setLayout(new FlowLayout());
105+
frame.getContentPane().add(tf);
106+
frame.setSize(300, 200);
107+
frame.setVisible(true);
108+
return frame;
109+
}
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
* Copyright (c) 2002, 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 4732229
27+
* @summary Ctrl+Space, bringing up System menu on a JIF errors using Win LAF
28+
* @key headful
29+
* @run main bug4732229
30+
*/
31+
32+
import javax.swing.JFrame;
33+
import javax.swing.JDesktopPane;
34+
import javax.swing.JInternalFrame;
35+
import javax.swing.JTextArea;
36+
import javax.swing.SwingUtilities;
37+
import javax.swing.UIManager;
38+
import java.awt.Robot;
39+
import java.awt.event.FocusAdapter;
40+
import java.awt.event.FocusEvent;
41+
import java.awt.event.KeyEvent;
42+
43+
public class bug4732229 {
44+
45+
JFrame frame;
46+
JDesktopPane desktop;
47+
JInternalFrame jif;
48+
JTextArea ta;
49+
Robot robot;
50+
volatile boolean keyTyped = false;
51+
52+
public static void main(String[] args) throws Exception {
53+
bug4732229 b = new bug4732229();
54+
b.init();
55+
}
56+
57+
public void init() throws Exception {
58+
robot = new Robot();
59+
robot.setAutoDelay(100);
60+
try {
61+
SwingUtilities.invokeAndWait(() -> {
62+
frame = new JFrame("bug4732229");
63+
desktop = new JDesktopPane();
64+
frame.getContentPane().add(desktop);
65+
66+
ta = new JTextArea();
67+
ta.addFocusListener(new FocusAdapter() {
68+
public void focusGained(FocusEvent e) {
69+
synchronized (bug4732229.this) {
70+
keyTyped = true;
71+
bug4732229.this.notifyAll();
72+
}
73+
}
74+
});
75+
frame.setSize(200, 200);
76+
frame.setLocationRelativeTo(null);
77+
frame.setVisible(true);
78+
jif = new JInternalFrame("Internal Frame", true, false, true,
79+
true);
80+
jif.setBounds(10, 10, 100, 100);
81+
jif.getContentPane().add(ta);
82+
jif.setVisible(true);
83+
desktop.add(jif);
84+
try {
85+
jif.setSelected(true);
86+
} catch (Exception e) {
87+
throw new RuntimeException(e);
88+
}
89+
90+
});
91+
synchronized (this) {
92+
while (!keyTyped) {
93+
bug4732229.this.wait();
94+
}
95+
}
96+
robot.waitForIdle();
97+
robot.delay(200);
98+
robot.keyPress(KeyEvent.VK_CONTROL);
99+
robot.keyPress(KeyEvent.VK_SPACE);
100+
robot.keyRelease(KeyEvent.VK_SPACE);
101+
robot.keyRelease(KeyEvent.VK_CONTROL);
102+
robot.waitForIdle();
103+
robot.delay(200);
104+
SwingUtilities.invokeAndWait(() -> {
105+
try {
106+
jif.setSelected(false);
107+
} catch (Exception e) {
108+
throw new RuntimeException(e);
109+
}
110+
jif.setVisible(false);
111+
desktop.remove(jif);
112+
try {
113+
UIManager.setLookAndFeel(
114+
UIManager.getSystemLookAndFeelClassName());
115+
} catch (Exception e) {
116+
throw new RuntimeException(e);
117+
}
118+
desktop.updateUI();
119+
120+
jif = new JInternalFrame("Internal Frame", true, false, true,
121+
true);
122+
jif.setBounds(10, 10, 100, 100);
123+
jif.getContentPane().add(ta);
124+
jif.setVisible(true);
125+
desktop.add(jif);
126+
try {
127+
jif.setSelected(true);
128+
} catch (Exception e) {
129+
throw new RuntimeException(e);
130+
}
131+
});
132+
synchronized (this) {
133+
while (!keyTyped) {
134+
bug4732229.this.wait();
135+
}
136+
}
137+
robot.keyPress(KeyEvent.VK_CONTROL);
138+
robot.keyPress(KeyEvent.VK_SPACE);
139+
robot.keyRelease(KeyEvent.VK_SPACE);
140+
robot.keyRelease(KeyEvent.VK_CONTROL);
141+
robot.waitForIdle();
142+
robot.delay(200);
143+
} finally {
144+
SwingUtilities.invokeAndWait(() -> {
145+
if (frame != null) {
146+
frame.dispose();
147+
}
148+
});
149+
}
150+
}
151+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 5009724
27+
* @requires (os.family == "linux")
28+
* @summary JInternalFrame not serializable in GTK L&F
29+
* @key headful
30+
* @run main bug5009724
31+
*/
32+
33+
import java.awt.event.ActionEvent;
34+
import java.io.ByteArrayOutputStream;
35+
import java.io.IOException;
36+
import java.io.ObjectOutputStream;
37+
import java.io.Serializable;
38+
import javax.swing.AbstractAction;
39+
import javax.swing.JInternalFrame;
40+
import javax.swing.SwingUtilities;
41+
import javax.swing.UIManager;
42+
43+
public class bug5009724 {
44+
45+
public static void main(String []args) throws Exception {
46+
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
47+
SwingUtilities.invokeAndWait(() -> {
48+
JInternalFrame frame = new JInternalFrame();
49+
ObjectOutputStream out = null;
50+
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
51+
try {
52+
out = new ObjectOutputStream(byteStream);
53+
} catch (IOException e) {
54+
55+
}
56+
if (out != null) {
57+
System.out.println("Testing...");
58+
try {
59+
out.writeObject(frame);
60+
} catch (Exception e) {
61+
System.out.println(e);
62+
throw new RuntimeException("Serialization exception. Test failed.");
63+
}
64+
}
65+
});
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 4191374
27+
* @summary Verify if JMenuBar.getSubElements returns an array
28+
with null values
29+
* @run main bug4191374
30+
*/
31+
32+
import javax.swing.Box;
33+
import javax.swing.JMenu;
34+
import javax.swing.JMenuBar;
35+
import javax.swing.MenuElement;
36+
import javax.swing.SwingUtilities;
37+
38+
public class bug4191374 {
39+
static JMenuBar mb;
40+
static volatile boolean pass = true;
41+
42+
public static void main(String[] args) throws Exception {
43+
SwingUtilities.invokeAndWait(() -> {
44+
mb = new JMenuBar();
45+
newMenu(mb);
46+
newMenu(mb);
47+
mb.add(Box.createGlue());
48+
mb.add(new JMenu("Help"));
49+
MenuElement[] me = mb.getSubElements();
50+
for (int i = 0; i < me.length; i++) {
51+
if (me[i] == null)
52+
pass = false;
53+
}
54+
});
55+
if (!pass) {
56+
throw new RuntimeException("Bug 4191374 FAILED");
57+
}
58+
}
59+
60+
public static void newMenu(JMenuBar mb) {
61+
JMenu m = (JMenu) mb.add(new JMenu("File"));
62+
m.add("Menu item");
63+
m.add("Menu item");
64+
m.add("Menu item");
65+
}
66+
}

0 commit comments

Comments
 (0)
Please sign in to comment.