author | dbuck |
Tue, 18 Aug 2015 04:29:28 -0700 | |
changeset 32417 | 6859107fc6c3 |
parent 31448 | 1066345d2a8a |
permissions | -rw-r--r-- |
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
1 |
/* |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
24163
diff
changeset
|
2 |
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. |
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
4 |
* |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
8 |
* |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
14 |
* |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
18 |
* |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
21 |
* questions. |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
22 |
*/ |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
23 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
24 |
import sun.swing.SwingUtilities2; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
25 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
26 |
import java.awt.Color; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
27 |
import java.awt.Graphics2D; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
28 |
import java.awt.Rectangle; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
29 |
import java.awt.image.BufferedImage; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
30 |
import java.io.File; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
31 |
import java.io.IOException; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
32 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
33 |
import javax.imageio.ImageIO; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
34 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
35 |
/** |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
36 |
* @test |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
37 |
* @bug 8032219 |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
38 |
* @author Sergey Bylokhov |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
24163
diff
changeset
|
39 |
* @modules java.desktop/sun.swing |
24163
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
40 |
*/ |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
41 |
public final class DrawRect { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
42 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
43 |
private static final int size = 50; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
44 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
45 |
private static final Rectangle[] rects = { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
46 |
new Rectangle(0, 0, 1, 1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
47 |
new Rectangle(0, 0, 1, 2), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
48 |
new Rectangle(0, 0, 2, 1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
49 |
new Rectangle(10, 10, 10, 10), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
50 |
new Rectangle(10, 10, -1, -1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
51 |
new Rectangle(-1, -1, 10, 10), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
52 |
new Rectangle(-1, -1, -10, -10), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
53 |
new Rectangle(0, 0, size, size), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
54 |
}; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
55 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
56 |
private static final Rectangle[] vlines = {new Rectangle(0, 0, 0, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
57 |
new Rectangle(0, 0, 0, 1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
58 |
new Rectangle(0, 0, 0, -1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
59 |
new Rectangle(1, 1, 0, 1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
60 |
new Rectangle(1, 1, 0, -1), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
61 |
new Rectangle(15, 15, 0, 10), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
62 |
new Rectangle(15, 15, 0, -10), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
63 |
}; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
64 |
private static final Rectangle[] hlines = {new Rectangle(0, 0, 0, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
65 |
new Rectangle(0, 0, 1, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
66 |
new Rectangle(0, 0, -1, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
67 |
new Rectangle(1, 1, 1, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
68 |
new Rectangle(1, 1, -1, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
69 |
new Rectangle(15, 15, 10, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
70 |
new Rectangle(15, 15, -10, 0), |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
71 |
}; |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
72 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
73 |
public static void main(final String[] args) throws IOException { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
74 |
BufferedImage gold = new BufferedImage(size, size, |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
75 |
BufferedImage.TYPE_INT_ARGB); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
76 |
Graphics2D g = gold.createGraphics(); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
77 |
BufferedImage bi = new BufferedImage(size, size, |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
78 |
BufferedImage.TYPE_INT_ARGB); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
79 |
Graphics2D g2d = bi.createGraphics(); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
80 |
g2d.setColor(new Color(0, 250, 0, 100)); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
81 |
g2d.setBackground(Color.BLACK); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
82 |
g.setColor(new Color(0, 250, 0, 100)); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
83 |
g.setBackground(Color.BLACK); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
84 |
// Rectangle |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
85 |
for (final Rectangle r : rects) { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
86 |
g.clearRect(0, 0, size, size); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
87 |
g2d.clearRect(0, 0, size, size); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
88 |
g.drawRect(r.x, r.y, r.width, r.height); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
89 |
SwingUtilities2.drawRect(g2d, r.x, r.y, r.width, r.height); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
90 |
test(gold, bi); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
91 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
92 |
// Vertical Line |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
93 |
for (final Rectangle l : vlines) { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
94 |
g.clearRect(0, 0, size, size); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
95 |
g2d.clearRect(0, 0, size, size); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
96 |
g.drawLine(l.x, l.y, l.x + l.width, l.y + l.height); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
97 |
SwingUtilities2.drawVLine(g2d, l.x, l.y, l.y + l.height); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
98 |
test(gold, bi); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
99 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
100 |
// Horizontal Line |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
101 |
for (final Rectangle l : hlines) { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
102 |
g.clearRect(0, 0, size, size); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
103 |
g2d.clearRect(0, 0, size, size); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
104 |
g.drawLine(l.x, l.y, l.x + l.width, l.y + l.height); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
105 |
SwingUtilities2.drawHLine(g2d, l.x, l.x+l.width, l.y); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
106 |
test(gold, bi); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
107 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
108 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
109 |
g.dispose(); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
110 |
g2d.dispose(); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
111 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
112 |
|
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
113 |
private static void test(final BufferedImage gold, final BufferedImage bi) |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
114 |
throws IOException { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
115 |
for (int x = 0; x < size; x++) { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
116 |
for (int y = 0; y < size; y++) { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
117 |
if (gold.getRGB(x, y) != bi.getRGB(x, y)) { |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
118 |
ImageIO.write(gold, "png", new File("gold.png")); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
119 |
ImageIO.write(bi, "png", new File("image.png")); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
120 |
throw new RuntimeException("wrong color"); |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
121 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
122 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
123 |
} |
d56df89854c4
8032219: [macosx] Scrollbars looks bad under retina in Motif and Metal L&F
serb
parents:
diff
changeset
|
124 |
} |
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
24163
diff
changeset
|
125 |
} |