1 /* 2 * Copyright (c) 2015, 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.Dialog; 24 import java.awt.Frame; 25 import java.awt.Graphics; 26 import java.awt.Graphics2D; 27 import java.awt.GraphicsConfiguration; 28 import java.awt.GraphicsDevice; 29 import java.awt.GraphicsEnvironment; 30 import java.awt.Panel; 31 import java.awt.geom.AffineTransform; 32 33 /* 34 * @test 35 * @bug 8069361 36 * @summary SunGraphics2D.getDefaultTransform() does not include scale factor 37 * @author Alexander Scherbatiy 38 * @run main ScaledTransform 39 */ 40 public class ScaledTransform { 41 42 private static volatile boolean passed = false; 43 44 public static void main(String[] args) { 45 GraphicsEnvironment ge = GraphicsEnvironment. 46 getLocalGraphicsEnvironment(); 47 48 if (ge.isHeadlessInstance()) { 49 return; 50 } 51 52 for (GraphicsDevice gd : ge.getScreenDevices()) { 53 for (GraphicsConfiguration gc : gd.getConfigurations()) { 54 testScaleFactor(gc); 55 } 56 } 57 } 58 59 private static void testScaleFactor(final GraphicsConfiguration gc) { 60 final Dialog dialog = new Dialog((Frame) null, "Test", true, gc); 61 62 try { 63 dialog.setSize(100, 100); 64 Panel panel = new Panel() { 65 66 @Override 67 public void paint(Graphics g) { 68 if (g instanceof Graphics2D) { 69 AffineTransform gcTx = gc.getDefaultTransform(); 70 AffineTransform gTx 71 = ((Graphics2D) g).getTransform(); 72 passed = gcTx.getScaleX() == gTx.getScaleX() 73 && gcTx.getScaleY() == gTx.getScaleY(); 74 } else { 75 passed = true; 76 } 77 dialog.setVisible(false); 78 } 79 }; 80 dialog.add(panel); 81 dialog.setVisible(true); 82 83 if (!passed) { 84 throw new RuntimeException("Transform is not scaled!"); 85 } 86 } finally { 87 dialog.dispose(); 88 } 89 } 90 }