Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JScrollBar/4708809/bug4708809.java
41153 views
1
/*
2
* Copyright (c) 2011, 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
* @key headful
27
* @bug 4708809
28
* @summary JScrollBar functionality slightly different from native scrollbar
29
* @author Andrey Pikalev
30
* @run main bug4708809
31
*/
32
import javax.swing.*;
33
import java.awt.*;
34
import java.awt.Point;
35
import java.awt.event.*;
36
37
public class bug4708809 {
38
39
private static volatile boolean do_test = false;
40
private static volatile boolean passed = true;
41
private static JScrollPane spane;
42
private static JScrollBar sbar;
43
private static JFrame fr;
44
45
public static void main(String[] args) throws Exception {
46
try {
47
Robot robot = new Robot();
48
robot.setAutoDelay(350);
49
50
SwingUtilities.invokeAndWait(new Runnable() {
51
52
public void run() {
53
createAndShowGUI();
54
}
55
});
56
57
robot.waitForIdle();
58
59
SwingUtilities.invokeAndWait(new Runnable() {
60
61
public void run() {
62
spane.requestFocus();
63
sbar.setValue(sbar.getMaximum());
64
}
65
});
66
67
robot.waitForIdle();
68
69
Point point = getClickPoint(0.5, 0.5);
70
robot.mouseMove(point.x, point.y);
71
robot.mousePress(InputEvent.BUTTON1_MASK);
72
73
robot.waitForIdle();
74
75
SwingUtilities.invokeAndWait(new Runnable() {
76
77
public void run() {
78
final int oldValue = sbar.getValue();
79
sbar.addAdjustmentListener(new AdjustmentListener() {
80
81
public void adjustmentValueChanged(AdjustmentEvent e) {
82
if (e.getValue() >= oldValue) {
83
passed = false;
84
}
85
do_test = true;
86
}
87
});
88
89
}
90
});
91
92
robot.waitForIdle();
93
94
point = getClickPoint(0.5, 0.2);
95
robot.mouseMove(point.x, point.y);
96
robot.mouseRelease(InputEvent.BUTTON1_MASK);
97
robot.waitForIdle();
98
99
if (!do_test || !passed) {
100
throw new Exception("The scrollbar moved with incorrect direction");
101
}
102
} finally {
103
if (fr != null) SwingUtilities.invokeAndWait(() -> fr.dispose());
104
}
105
106
}
107
108
private static Point getClickPoint(final double scaleX, final double scaleY) throws Exception {
109
final Point[] result = new Point[1];
110
111
SwingUtilities.invokeAndWait(new Runnable() {
112
113
@Override
114
public void run() {
115
Point p = sbar.getLocationOnScreen();
116
Rectangle rect = sbar.getBounds();
117
result[0] = new Point((int) (p.x + scaleX * rect.width),
118
(int) (p.y + scaleY * rect.height));
119
}
120
});
121
122
return result[0];
123
124
}
125
126
private static void createAndShowGUI() {
127
fr = new JFrame("Test");
128
129
JLabel label = new JLabel("picture");
130
label.setPreferredSize(new Dimension(500, 500));
131
spane = new JScrollPane(label);
132
fr.getContentPane().add(spane);
133
sbar = spane.getVerticalScrollBar();
134
135
fr.setSize(200, 200);
136
fr.setVisible(true);
137
}
138
}
139
140