1 /* 2 * Copyright (c) 2011, 2013, 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 * @summary Test the positioning of complex strokes. 27 * @summary <rdar://problem/4732981> [JavaJDK15] 1.5 [clone for Leopard]- SAP: drawing problem using BasicStroke 28 * @summary com.apple.junit.java.graphics.primitives 29 * @run junit DrawRectWithComplexStroke 30 */ 31 32 import junit.framework.*; 33 import java.awt.*; 34 import java.awt.geom.Rectangle2D; 35 import java.awt.image.BufferedImage; 36 37 public class DrawRectWithComplexStroke extends TestCase { 38 public void testCopyArea() throws Exception { 39 GraphicsEnvironment environment = 40 GraphicsEnvironment.getLocalGraphicsEnvironment(); 41 42 GraphicsDevice device = 43 environment.getDefaultScreenDevice(); 44 45 GraphicsConfiguration config = device.getDefaultConfiguration(); 46 47 // Create an image that does not support transparency (Opaque) 48 BufferedImage bi = config.createCompatibleImage(500, 500, Transparency.OPAQUE); 49 50 Graphics2D big = bi.createGraphics(); 51 52 big.setColor(Color.white); 53 big.fillRect(0, 0, 1000, 1000); 54 55 big.setColor(Color.red); 56 57 Rectangle2D r = new Rectangle2D.Double(10, 10, 20, 20); 58 Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND); 59 60 big.setStroke(stroke); 61 big.draw(r); 62 63 int testPixel = bi.getRGB(15, 10); 64 int redPixel = Color.red.getRGB(); 65 assertEquals("The line of the rectangle should be red", testPixel, redPixel); 66 67 } 68 69 public static Test suite() { 70 return new TestSuite(DrawRectWithComplexStroke.class); 71 } 72 73 public static void main (String[] args) throws RuntimeException { 74 TestResult tr = junit.textui.TestRunner.run(suite()); 75 if ((tr.errorCount() != 0) || (tr.failureCount() != 0)) { 76 throw new RuntimeException("### FAILED: unexpected JUnit errors or failures."); 77 } 78 } 79 }