Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JInternalFrame/8160248/JInternalFrameDraggingTest.java
41153 views
1
/*
2
* Copyright (c) 2016, 2018, 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.Point;
27
import java.awt.Rectangle;
28
import java.awt.Robot;
29
import java.awt.event.InputEvent;
30
import java.awt.image.BufferedImage;
31
import javax.swing.JDesktopPane;
32
import javax.swing.JFrame;
33
import javax.swing.JInternalFrame;
34
import javax.swing.SwingUtilities;
35
36
/**
37
* @test
38
* @key headful
39
* @bug 8160248 8160332 8186513
40
* @summary Dragged internal frame leaves artifacts for floating point ui scale
41
* @run main/othervm -Dsun.java2d.uiScale=1.2 JInternalFrameDraggingTest
42
* @run main/othervm -Dsun.java2d.uiScale=1.5 JInternalFrameDraggingTest
43
* @run main/othervm -Dsun.java2d.uiScale=1 JInternalFrameDraggingTest
44
* @run main/othervm -Dsun.java2d.uiScale=2.5 JInternalFrameDraggingTest
45
*/
46
47
public class JInternalFrameDraggingTest {
48
49
private static JFrame frame;
50
private static JDesktopPane desktopPane;
51
private static JInternalFrame internalFrame;
52
private static int FRAME_SIZE = 500;
53
private static Color BACKGROUND_COLOR = Color.ORANGE;
54
55
public static void main(String[] args) throws Exception {
56
try {
57
Robot robot = new Robot();
58
robot.setAutoDelay(20);
59
SwingUtilities.invokeAndWait(JInternalFrameDraggingTest::createAndShowGUI);
60
robot.waitForIdle();
61
62
final int translate = FRAME_SIZE / 4;
63
moveFrame(robot, translate, translate / 2, translate / 2);
64
robot.waitForIdle();
65
66
Point p = getDesktopPaneLocation();
67
int size = translate / 2;
68
Rectangle rect = new Rectangle(p.x, p.y, size, size);
69
BufferedImage img = robot.createScreenCapture(rect);
70
71
int testRGB = BACKGROUND_COLOR.getRGB();
72
for (int i = 1; i < size; i++) {
73
int rgbCW = img.getRGB(i, size / 2);
74
int rgbCH = img.getRGB(size / 2, i);
75
if (rgbCW != testRGB || rgbCH != testRGB) {
76
System.out.println("i " + i + " rgbCW " +
77
Integer.toHexString(rgbCW) +
78
" testRGB " + Integer.toHexString(testRGB) +
79
" rgbCH " + Integer.toHexString(rgbCH));
80
throw new RuntimeException("Background color is wrong!");
81
}
82
}
83
} finally {
84
if (frame != null) SwingUtilities.invokeAndWait(() -> frame.dispose());
85
}
86
}
87
88
private static void createAndShowGUI() {
89
90
frame = new JFrame();
91
frame.setUndecorated(true);
92
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
93
frame.setLayout(new BorderLayout());
94
95
desktopPane = new JDesktopPane();
96
desktopPane.setBackground(BACKGROUND_COLOR);
97
98
frame.add(desktopPane, BorderLayout.CENTER);
99
frame.setSize(FRAME_SIZE, FRAME_SIZE);
100
frame.setVisible(true);
101
102
internalFrame = new JInternalFrame("Test");
103
internalFrame.setSize(FRAME_SIZE / 2, FRAME_SIZE / 2);
104
desktopPane.add(internalFrame);
105
internalFrame.setVisible(true);
106
internalFrame.setResizable(true);
107
108
frame.setVisible(true);
109
}
110
111
private static void moveFrame(Robot robot, int w, int h, int N) throws Exception {
112
Point p = getInternalFrameLocation();
113
int xs = p.x + 100;
114
int ys = p.y + 15;
115
robot.mouseMove(xs, ys);
116
try {
117
robot.mousePress(InputEvent.BUTTON1_MASK);
118
119
int dx = w / N;
120
int dy = h / N;
121
122
int y = ys;
123
for (int x = xs; x < xs + w; x += dx, y += dy) {
124
robot.mouseMove(x, y);
125
}
126
} finally {
127
robot.mouseRelease(InputEvent.BUTTON1_MASK);
128
}
129
}
130
131
private static Point getInternalFrameLocation() throws Exception {
132
final Point[] points = new Point[1];
133
SwingUtilities.invokeAndWait(() -> {
134
points[0] = internalFrame.getLocationOnScreen();
135
});
136
return points[0];
137
}
138
139
private static Point getDesktopPaneLocation() throws Exception {
140
final Point[] points = new Point[1];
141
SwingUtilities.invokeAndWait(() -> {
142
points[0] = desktopPane.getLocationOnScreen();
143
});
144
return points[0];
145
}
146
}
147
148