Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/java2d/marlin/StrokeShapeTest.java
41149 views
1
/*
2
* Copyright (c) 2009, 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
import java.awt.*;
24
import java.awt.geom.Ellipse2D;
25
import java.awt.geom.GeneralPath;
26
import java.awt.image.BufferedImage;
27
import java.io.File;
28
29
import javax.imageio.ImageIO;
30
31
/**
32
* @author [email protected] (Chris Nokleberg)
33
* @author [email protected] (Hiroshi Yamauchi)
34
*/
35
public class StrokeShapeTest {
36
public static void main(String[] args) throws Exception {
37
BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB);
38
Graphics2D g = image.createGraphics();
39
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
40
g.setPaint(Color.WHITE);
41
g.fill(new Rectangle(image.getWidth(), image.getHeight()));
42
g.translate(25, 100);
43
44
Stroke stroke = new BasicStroke(200, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
45
Shape shape = new Polygon(new int[] {0, 1500, 0}, new int[] {750, 0, -750}, 3);
46
47
g.scale(.1, .1);
48
g.setPaint(Color.BLACK);
49
g.setStroke(stroke);
50
g.draw(shape);
51
g.setPaint(Color.RED);
52
g.fill(stroke.createStrokedShape(shape));
53
54
// To visually check it
55
//ImageIO.write(image, "PNG", new File(args[0]));
56
57
boolean blackPixelFound = false;
58
outer:
59
for (int x = 0; x < 200; ++x) {
60
for (int y = 0; y < 200; ++y) {
61
if (image.getRGB(x, y) == Color.BLACK.getRGB()) {
62
blackPixelFound = true;
63
break outer;
64
}
65
}
66
}
67
if (blackPixelFound) {
68
throw new RuntimeException("The shape hasn't been filled in red.");
69
}
70
}
71
}
72
73