Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java
41155 views
1
/*
2
* Copyright (c) 2013, 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.Rectangle;
25
import java.awt.Toolkit;
26
import java.awt.Color;
27
import java.awt.image.BufferedImage;
28
29
import javax.swing.JFrame;
30
import javax.swing.SwingUtilities;
31
32
import jdk.test.lib.Platform;
33
34
/**
35
* @test
36
* @key headful
37
* @bug 7124513
38
* @requires (os.family == "mac")
39
* @summary We should support NSTexturedBackgroundWindowMask style on OSX.
40
* @library /test/lib
41
* /lib/client
42
* @build ExtendedRobot jdk.test.lib.Platform
43
* @run main NSTexturedJFrame
44
*/
45
46
public final class NSTexturedJFrame {
47
48
private static final String BRUSH = "apple.awt.brushMetalLook";
49
private static final String STYLE = "Window.style";
50
private static final BufferedImage[] images = new BufferedImage[3];
51
private static Rectangle bounds;
52
private static volatile int step;
53
private static JFrame frame;
54
private static ExtendedRobot robot;
55
56
public static void main(final String[] args) throws Exception {
57
if (!Platform.isOSX()) {
58
System.out.println("This test is for OSX, considered passed.");
59
return;
60
}
61
robot = new ExtendedRobot();
62
robot.setAutoDelay(50);
63
// Default window appearance
64
showFrame();
65
step++;
66
// apple.awt.brushMetalLook appearance
67
showFrame();
68
step++;
69
// Window.style appearance
70
showFrame();
71
72
// images on step 1 and 2 should be same
73
testImages(images[1], images[2], false);
74
// images on step 1 and 2 should be different from default
75
testImages(images[0], images[1], true);
76
testImages(images[0], images[2], true);
77
}
78
79
private static void testImages(BufferedImage img1, BufferedImage img2,
80
boolean shouldbeDifferent) {
81
boolean different = false;
82
int tol = 5;
83
for (int x = 0; x < img1.getWidth(); ++x) {
84
for (int y = 0; y < img1.getHeight(); ++y) {
85
Color c1 = new Color(img1.getRGB(x, y));
86
Color c2 = new Color(img2.getRGB(x, y));
87
88
if ((Math.abs(c1.getRed() - c2.getRed()) > tol) &&
89
(Math.abs(c1.getBlue() - c2.getBlue()) > tol) &&
90
(Math.abs(c1.getGreen() - c2.getGreen()) > tol )) {
91
92
different = true;
93
}
94
}
95
}
96
if (different != shouldbeDifferent) {
97
throw new RuntimeException("Textured property does not work");
98
}
99
}
100
101
private static void showFrame() throws Exception {
102
createUI();
103
images[step] = robot.createScreenCapture(bounds);
104
SwingUtilities.invokeAndWait(frame::dispose);
105
robot.waitForIdle(1000);
106
}
107
108
private static void createUI() throws Exception {
109
SwingUtilities.invokeAndWait(() -> {
110
frame = new JFrame();
111
frame.setUndecorated(true);
112
frame.setSize(400, 400);
113
frame.setLocationRelativeTo(null);
114
switch (step) {
115
case 1:
116
frame.getRootPane().putClientProperty(BRUSH, true);
117
break;
118
case 2:
119
frame.getRootPane().putClientProperty(STYLE, "textured");
120
}
121
frame.setVisible(true);
122
});
123
robot.waitForIdle(1000);
124
SwingUtilities.invokeAndWait(() -> {
125
bounds = frame.getBounds();
126
});
127
robot.waitForIdle(1000);
128
}
129
130
}
131
132