Skip to content

Commit 1452e0e

Browse files
committed
8328190: Convert AWTPanelSmoothWheel.html applet test to main
Backport-of: c7bbf849290b39b8e89290234d70d8333df24710
1 parent 7d1f639 commit 1452e0e

File tree

3 files changed

+131
-294
lines changed

3 files changed

+131
-294
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* Copyright (c) 2009, 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.Frame;
27+
import java.awt.Panel;
28+
import java.awt.event.MouseWheelEvent;
29+
import javax.swing.JOptionPane;
30+
31+
/*
32+
* @test
33+
* @bug 6730447
34+
* @summary To verify the support for high resolution mouse wheel.
35+
* AWT panel needs to support high-res mouse wheel rotation.
36+
* @library /java/awt/regtesthelpers
37+
* @build PassFailJFrame
38+
* @run main/manual AWTPanelSmoothWheel
39+
*/
40+
41+
public class AWTPanelSmoothWheel {
42+
private static int wheelEventCount = 0;
43+
private static int hiResWheelCount = 0;
44+
private static final String WARNING_MSG = "WARNING !!!"
45+
+ " You might NOT be using a hi-res mouse.";
46+
private static final String INSTRUCTIONS = """
47+
<html>
48+
<body>
49+
This test is relevant on platforms with high-resolution mouse wheel
50+
or a trackpad can be used too.
51+
Please press PASS if this is not the case.<br> <br>
52+
53+
Place the mouse cursor above the green panel and rotate the mouse wheel,
54+
the test will print mouse wheel event messages in the format
55+
<b> [Event#, WheelRotation, PreciseWheelRotation]</b> into the logging
56+
panel below the instruction window.<br> <br>
57+
58+
A hi-res mouse/trackpad is one which produces MouseWheelEvents having:
59+
<pre><b> Math.abs(preciseWheelRotation) &lt; 1. </b></pre><br>
60+
61+
Check if the test works OK when the mouse-wheel/trackpad is scrolled
62+
very slowly.<br> <br>
63+
This is a semi-automated test, if you are using a hi-res mouse/trackpad
64+
and it satisfies the hi-res MouseWheelEvents as described below,
65+
the test should automatically pass.<br> <br>
66+
67+
When preciseWheelRotation adds up, wheelRotation becomes non-zero
68+
(can be negative when mouse wheel is scrolled down). <br>
69+
You should see many events where the absolute value of
70+
preciseWheelRotation &lt; 1 &amp; wheelRotation = 0 followed by
71+
an event where wheelRotation != 0 in the logs.<br> <br>
72+
73+
<hr>
74+
<b> NOTE: </b>
75+
<ul>
76+
<li> If you don't see events with preciseWheelRotation &lt; 1,
77+
then the mouse doesn't support high-resolution scrolling. </li>
78+
<li> A warning is shown if you are not using a hi-res mouse. </li>
79+
<li> MouseWheelEvent logs are displayed in the log area
80+
for user reference. </li>
81+
<li> When mouse is scrolled up, preciseWheelRotation & wheelRotation
82+
are positive and they are negative when scrolled down. </li>
83+
</ul>
84+
</body>
85+
</html>
86+
""";
87+
88+
public static void main(String[] args) throws Exception {
89+
PassFailJFrame.builder()
90+
.title("Test Instructions")
91+
.instructions(INSTRUCTIONS)
92+
.rows(30)
93+
.columns(54)
94+
.testTimeOut(10)
95+
.logArea(10)
96+
.testUI(AWTPanelSmoothWheel::createUI)
97+
.build()
98+
.awaitAndCheck();
99+
}
100+
101+
private static Frame createUI() {
102+
Frame frame = new Frame("Test Wheel Rotation");
103+
Panel panel = new Panel();
104+
panel.setBackground(Color.GREEN);
105+
panel.addMouseWheelListener(e -> {
106+
if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
107+
PassFailJFrame.log("WheelEvent#" + (++wheelEventCount)
108+
+ " --- Wheel Rotation: " + e.getWheelRotation()
109+
+ " --- Precise Wheel Rotation: "
110+
+ String.format("%.2f", e.getPreciseWheelRotation()));
111+
if (Math.abs(e.getPreciseWheelRotation()) < 1) {
112+
hiResWheelCount++;
113+
}
114+
if (wheelEventCount >= 5 && hiResWheelCount == 0) {
115+
PassFailJFrame.log(WARNING_MSG);
116+
JOptionPane.showMessageDialog(frame, WARNING_MSG,
117+
"Warning", JOptionPane.WARNING_MESSAGE);
118+
}
119+
if (e.getWheelRotation() != 0 && hiResWheelCount > 0) {
120+
PassFailJFrame.log("The test passes: hiResWheelCount = "
121+
+ hiResWheelCount);
122+
PassFailJFrame.forcePass();
123+
}
124+
}
125+
});
126+
frame.setSize(400, 200);
127+
frame.setLayout(new BorderLayout());
128+
frame.add(panel, BorderLayout.CENTER);
129+
return frame;
130+
}
131+
}

test/jdk/java/awt/event/MouseEvent/AWTPanelSmoothWheel/AWTPanelSmoothWheel.html

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)