jgodinez | d6fc981 | 2009-01-28 09:38:55 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2009 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any questions. |
| 22 | */ |
| 23 | |
| 24 | /* @test |
| 25 | * @summary verify that first element is a dash |
| 26 | * @bug 6793344 |
| 27 | */ |
| 28 | |
| 29 | import java.awt.*; |
| 30 | import java.awt.image.*; |
| 31 | |
| 32 | import javax.swing.JButton; |
| 33 | import javax.swing.JFrame; |
| 34 | import javax.swing.SwingUtilities; |
| 35 | import javax.swing.WindowConstants; |
| 36 | |
| 37 | public class DashStrokeTest extends Component { |
| 38 | |
| 39 | static BufferedImage bi; |
| 40 | static boolean printed = false; |
| 41 | |
| 42 | public Dimension getPreferredSize() { |
| 43 | return new Dimension(200,200); |
| 44 | } |
| 45 | |
| 46 | public static void drawGui() { |
| 47 | bi = new BufferedImage(200, 20, BufferedImage.TYPE_INT_RGB); |
| 48 | Graphics2D g2d = bi.createGraphics(); |
| 49 | BasicStroke dashStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, |
| 50 | BasicStroke.JOIN_ROUND, 1.0f, new float[] { 0.0f, 200 }, |
| 51 | 1.0f); |
| 52 | |
| 53 | g2d.setStroke(dashStroke); |
| 54 | g2d.setColor(Color.RED); |
| 55 | g2d.drawLine(5,10, 100,10); |
| 56 | printed =true; |
| 57 | } |
| 58 | |
| 59 | public static void main(String[] args) { |
| 60 | try { |
| 61 | SwingUtilities.invokeAndWait(new Runnable() { |
| 62 | |
| 63 | @Override |
| 64 | public void run() { |
| 65 | drawGui(); |
| 66 | } |
| 67 | |
| 68 | }); |
| 69 | } catch (Exception e) { |
| 70 | } |
| 71 | |
| 72 | if (printed) { |
| 73 | checkBI(bi, Color.RED); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | static void checkBI(BufferedImage bi, Color badColor) { |
| 78 | int badrgb = badColor.getRGB(); |
| 79 | |
| 80 | int col = bi.getRGB(6, 9); |
| 81 | if (col == badrgb) { |
| 82 | throw new RuntimeException("A pixel was turned on. "); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |