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 24 import java.awt.Dialog; 25 import java.awt.Frame; 26 import java.awt.Graphics; 27 import java.awt.Graphics2D; 28 import java.awt.geom.AffineTransform; 29 import javax.swing.UIManager; 30 31 /* @test 32 * @bug 8137571 33 * @summary Linux HiDPI Graphics support 34 * @author Alexander Scherbatiy 35 * @requires (os.family == "linux" | os.family == "mac") 36 * @run main/othervm -Dsun.java2d.uiScale.enabled=false 37 * -Dsun.java2d.uiScale=2 38 * HiDPIPropertiesUnixTest UISCALE_DISABLED 39 * @run main/othervm -Dsun.java2d.uiScale.enabled=true 40 * -Dsun.java2d.uiScale=3 41 * HiDPIPropertiesUnixTest UISCALE_3 42 * @run main/othervm -Dsun.java2d.uiScale=4 43 * HiDPIPropertiesUnixTest UISCALE_4 44 */ 45 public class HiDPIPropertiesUnixTest { 46 47 public static void main(String[] args) throws Exception { 48 49 try { 50 UIManager.setLookAndFeel( 51 "com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); 52 } catch (Exception e) { 53 return; 54 } 55 56 String testCase = args[0]; 57 switch (testCase) { 58 case "UISCALE_DISABLED": 59 testScale(1.0, 1.0); 60 break; 61 case "UISCALE_3": 62 testScale(3.0, 3.0); 63 break; 64 case "UISCALE_4": 65 testScale(4.0, 4.0); 66 break; 67 default: 68 throw new RuntimeException("Unknown test case: " + testCase); 69 } 70 } 71 72 private static void testScale(double scaleX, double scaleY) { 73 74 Dialog dialog = new Dialog((Frame) null, true) { 75 76 @Override 77 public void paint(Graphics g) { 78 super.paint(g); 79 AffineTransform tx = ((Graphics2D) g).getTransform(); 80 dispose(); 81 if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) { 82 throw new RuntimeException(String.format("Wrong scale:" 83 + "[%f, %f] instead of [%f, %f].", 84 tx.getScaleX(), tx.getScaleY(), scaleX, scaleY)); 85 } 86 } 87 }; 88 dialog.setSize(200, 300); 89 dialog.setVisible(true); 90 } 91 }