< prev index next >

test/jdk/java/awt/BasicStroke/DashScaleMinWidth.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2017, 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.BasicStroke;
  25 import java.awt.Color;
  26 import java.awt.Graphics2D;
  27 import java.awt.GraphicsConfiguration;
  28 import java.awt.GraphicsEnvironment;
  29 import java.awt.Image;
  30 import java.awt.geom.Line2D;
  31 import java.awt.image.BufferedImage;

  32 import java.awt.image.VolatileImage;
  33 
  34 import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
  35 
  36 /**
  37  * @test
  38  * @bug 4917097 8019816

  39  * @summary 1.4.1 REGRESSION: BasicStroke Dashes don't show when scale * line width = 1.0
  40  * @run main/othervm -Dsun.java2d.uiScale=1 DashScaleMinWidth
  41  */
  42 public final class DashScaleMinWidth  {
  43 
  44     public static void main(final String[] args) {
  45         BufferedImage img = new BufferedImage(200, 40, TYPE_INT_ARGB);
  46         draw(img);
  47         validate(img);
  48 
  49         if (GraphicsEnvironment.isHeadless()) {
  50             return;
  51         }
  52 
  53         GraphicsConfiguration gc =
  54                 GraphicsEnvironment.getLocalGraphicsEnvironment()
  55                         .getDefaultScreenDevice().getDefaultConfiguration();




  56 
  57         VolatileImage vi = gc.createCompatibleVolatileImage(200, 40);
  58         BufferedImage snapshot;
  59         int attempt = 0;
  60         while (true) {
  61             if (++attempt > 10) {
  62                 throw new RuntimeException("Too many attempts: " + attempt);
  63             }
  64             vi.validate(gc);
  65             draw(vi);
  66             snapshot = vi.getSnapshot();
  67             if (!vi.contentsLost()) {
  68                 break;
  69             }
  70         }
  71         validate(snapshot);
  72     }
  73 
  74     private static void draw(final Image img) {
  75         float[] dashes = {200.0f, 200.0f};


   1 /*
   2  * Copyright (c) 2003, 2019, 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.BasicStroke;
  25 import java.awt.Color;
  26 import java.awt.Graphics2D;
  27 import java.awt.GraphicsConfiguration;
  28 import java.awt.GraphicsEnvironment;
  29 import java.awt.Image;
  30 import java.awt.geom.Line2D;
  31 import java.awt.image.BufferedImage;
  32 import java.awt.image.IndexColorModel;
  33 import java.awt.image.VolatileImage;
  34 
  35 import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
  36 
  37 /**
  38  * @test
  39  * @bug 4917097 8019816 8198411
  40  * @key headful
  41  * @summary 1.4.1 REGRESSION: BasicStroke Dashes don't show when scale * line width = 1.0
  42  * @run main/othervm -Dsun.java2d.uiScale=1 DashScaleMinWidth
  43  */
  44 public final class DashScaleMinWidth  {
  45 
  46     public static void main(final String[] args) {
  47         BufferedImage img = new BufferedImage(200, 40, TYPE_INT_ARGB);
  48         draw(img);
  49         validate(img);
  50 




  51         GraphicsConfiguration gc =
  52                 GraphicsEnvironment.getLocalGraphicsEnvironment()
  53                         .getDefaultScreenDevice().getDefaultConfiguration();
  54         if (gc.getColorModel() instanceof IndexColorModel) {
  55             System.err.println("Skipping VolatileImage because of IndexColorModel");
  56             return;
  57         }
  58 
  59         VolatileImage vi = gc.createCompatibleVolatileImage(200, 40);
  60         BufferedImage snapshot;
  61         int attempt = 0;
  62         while (true) {
  63             if (++attempt > 10) {
  64                 throw new RuntimeException("Too many attempts: " + attempt);
  65             }
  66             vi.validate(gc);
  67             draw(vi);
  68             snapshot = vi.getSnapshot();
  69             if (!vi.contentsLost()) {
  70                 break;
  71             }
  72         }
  73         validate(snapshot);
  74     }
  75 
  76     private static void draw(final Image img) {
  77         float[] dashes = {200.0f, 200.0f};


< prev index next >