Skip to content

Commit c8a7fbf

Browse files
committed
8339982: Open source several AWT Mouse tests - Batch 2
Backport-of: b6a4047387dbe4e07df0032dfdd7ee5ad8f571a4
1 parent 854ca51 commit c8a7fbf

File tree

6 files changed

+606
-0
lines changed

6 files changed

+606
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ java/awt/SplashScreen/MultiResolutionSplash/unix/UnixMultiResolutionSplashTest.j
439439
java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java 7107528 linux-all,macosx-all
440440
java/awt/Mouse/MouseDragEvent/MouseDraggedTest.java 8080676 linux-all
441441
java/awt/Mouse/MouseModifiersUnitTest/MouseModifiersInKeyEvent.java 8157147 linux-all,windows-all,macosx-all
442+
java/awt/Mouse/MouseClickCount.java 8017182 macosx-all
442443
java/awt/Toolkit/ToolkitPropertyTest/ToolkitPropertyTest_Enable.java 6847163 linux-all
443444
java/awt/xembed/server/RunTestXEmbed.java 7034201 linux-all
444445
java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java 8164473 linux-all
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright (c) 2001, 2024, 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 java.awt.BorderLayout;
25+
import java.awt.Button;
26+
import java.awt.Color;
27+
import java.awt.Frame;
28+
import java.awt.GraphicsConfiguration;
29+
import java.awt.GraphicsDevice;
30+
import java.awt.GraphicsEnvironment;
31+
import java.awt.Label;
32+
import java.awt.Rectangle;
33+
import java.awt.event.WindowAdapter;
34+
import java.awt.event.WindowEvent;
35+
import java.util.List;
36+
37+
/*
38+
* @test
39+
* @bug 4473671
40+
* @summary Test to verify GraphicsEnvironment.getDefaultScreenDevice always
41+
* returning first screen
42+
* @requires (os.family == "windows")
43+
* @library /java/awt/regtesthelpers
44+
* @build PassFailJFrame
45+
* @run main/manual DefaultScreenDeviceTest
46+
*/
47+
48+
public class DefaultScreenDeviceTest {
49+
private static Frame testFrame;
50+
51+
public static void main(String[] args) throws Exception {
52+
GraphicsEnvironment ge = GraphicsEnvironment.
53+
getLocalGraphicsEnvironment();
54+
GraphicsDevice[] gds = ge.getScreenDevices();
55+
if (gds.length < 2) {
56+
System.out.println("Test requires at least 2 displays");
57+
return;
58+
}
59+
60+
String INSTRUCTIONS = """
61+
1. The test is for systems which allows primary display
62+
selection in multiscreen systems.
63+
Set the system primary screen to be the rightmost
64+
(i.e. the right screen in two screen configuration)
65+
This can be done by going to OS Display Settings
66+
selecting the screen and checking the 'Use this device
67+
as primary monitor' checkbox.
68+
2. When done, click on 'Frame on Primary Screen' button and
69+
see where the frame will pop up
70+
3. If Primary Frame pops up on the primary display,
71+
the test passed, otherwise it failed
72+
""";
73+
PassFailJFrame.builder()
74+
.title("Test Instructions")
75+
.instructions(INSTRUCTIONS)
76+
.rows((int) INSTRUCTIONS.lines().count() + 2)
77+
.columns(35)
78+
.testUI(initialize())
79+
.build()
80+
.awaitAndCheck();
81+
}
82+
83+
private static List<Frame> initialize() {
84+
Frame frame = new Frame("Default screen device test");
85+
GraphicsConfiguration gc =
86+
GraphicsEnvironment.getLocalGraphicsEnvironment().
87+
getDefaultScreenDevice().getDefaultConfiguration();
88+
89+
testFrame = new Frame("Primary screen frame", gc);
90+
frame.setLayout(new BorderLayout());
91+
frame.setSize(200, 200);
92+
93+
Button b = new Button("Frame on Primary Screen");
94+
b.addActionListener(e -> {
95+
if (testFrame != null) {
96+
testFrame.setVisible(false);
97+
testFrame.dispose();
98+
}
99+
100+
testFrame.addWindowListener(new WindowAdapter() {
101+
public void windowClosing(WindowEvent e1) {
102+
testFrame.setVisible(false);
103+
testFrame.dispose();
104+
}
105+
});
106+
testFrame.add(new Label("This frame should be on the primary screen"));
107+
testFrame.setBackground(Color.red);
108+
testFrame.pack();
109+
Rectangle rect = gc.getBounds();
110+
testFrame.setLocation(rect.x + 100, rect.y + 100);
111+
testFrame.setVisible(true);
112+
});
113+
frame.add(b);
114+
return List.of(testFrame, frame);
115+
}
116+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 1998, 2024, 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 java.awt.BorderLayout;
25+
import java.awt.Color;
26+
import java.awt.Dimension;
27+
import java.awt.Event;
28+
import java.awt.Frame;
29+
import java.awt.Panel;
30+
import java.awt.TextArea;
31+
32+
/*
33+
* @test
34+
* @bug 4092370
35+
* @summary Test to verify double click
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual DoubleClickTest
39+
*/
40+
41+
public class DoubleClickTest {
42+
static TextArea ta = new TextArea("", 10, 40);
43+
44+
public static void main(String[] args) throws Exception {
45+
String INSTRUCTIONS = """
46+
1. Double click on the red area.
47+
2. Verify that the event reports click_count > 1 on
48+
Double-Click. If click_count shows only 1 for every
49+
Double-Clicks then test FAILS, else test PASS.
50+
""";
51+
PassFailJFrame.builder()
52+
.title("Test Instructions")
53+
.instructions(INSTRUCTIONS)
54+
.rows((int) INSTRUCTIONS.lines().count() + 2)
55+
.columns(35)
56+
.testUI(initialize())
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
public static Frame initialize() {
62+
Frame frame = new Frame("Double-click Test");
63+
frame.setLayout(new BorderLayout());
64+
frame.add("East", new MyPanel(ta));
65+
frame.add("West", ta);
66+
frame.setSize(200, 200);
67+
return frame;
68+
}
69+
}
70+
71+
class MyPanel extends Panel {
72+
TextArea ta;
73+
74+
MyPanel(TextArea ta) {
75+
this.ta = ta;
76+
setBackground(Color.red);
77+
}
78+
79+
public Dimension getPreferredSize() {
80+
return new Dimension(50, 50);
81+
}
82+
83+
84+
public boolean mouseDown(Event event, int x, int y) {
85+
ta.append("event click count= " + event.clickCount + "\n");
86+
return false;
87+
}
88+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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 java.awt.Frame;
25+
import java.awt.TextArea;
26+
import java.awt.event.MouseAdapter;
27+
import java.awt.event.MouseEvent;
28+
29+
/*
30+
* @test
31+
* @bug 4199397
32+
* @summary Test to mouse click count
33+
* @library /java/awt/regtesthelpers
34+
* @build PassFailJFrame
35+
* @run main/manual MouseClickCount
36+
*/
37+
38+
public class MouseClickCount {
39+
public static void main(String[] args) throws Exception {
40+
String INSTRUCTIONS = """
41+
1. Clicking on Frame panel quickly will produce clickCount larger than 1
42+
in the TextArea the count is printed for each mouse click
43+
2. Verify that a left-button click followed by a right button click quickly
44+
will not generate 1, 2, i.e. it's not considered a double clicking.
45+
""";
46+
PassFailJFrame.builder()
47+
.title("Test Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.rows((int) INSTRUCTIONS.lines().count() + 2)
50+
.columns(35)
51+
.testUI(initialize())
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
private static Frame initialize() {
57+
Frame f = new Frame("Mouse Click Count Test");
58+
final TextArea ta = new TextArea();
59+
f.add("South", ta);
60+
f.addMouseListener(new MouseAdapter() {
61+
public void mousePressed(MouseEvent e) {
62+
if (e.getClickCount() == 1) ta.append("\n1");
63+
else ta.append(", " + e.getClickCount());
64+
}
65+
});
66+
f.setSize(300, 500);
67+
return f;
68+
}
69+
}

0 commit comments

Comments
 (0)