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 8073320 33 * @summary Windows HiDPI support 34 * @author Alexander Scherbatiy 35 * @requires (os.family == "windows") 36 * @run main/othervm -Dsun.java2d.uiScale.enabled=false 37 * -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2 38 * HiDPIPropertiesWindowsTest UISCALE_DISABLED 39 * @run main/othervm -Dsun.java2d.uiScale.enabled=false 40 * -Dsun.java2d.uiScale=3 41 * HiDPIPropertiesWindowsTest UISCALE_DISABLED 42 * @run main/othervm -Dsun.java2d.uiScale.enabled=false 43 * -Dsun.java2d.uiScale=3 44 * -Dsun.java2d.win.uiScaleX=5 -Dsun.java2d.win.uiScaleY=6 45 * HiDPIPropertiesWindowsTest UISCALE_DISABLED 46 * @run main/othervm -Dsun.java2d.uiScale.enabled=true 47 * -Dsun.java2d.uiScale=3 48 * HiDPIPropertiesWindowsTest UISCALE_3 49 * @run main/othervm -Dsun.java2d.uiScale.enabled=true 50 * -Dsun.java2d.uiScale=4 51 * -Dsun.java2d.win.uiScaleX=2 -Dsun.java2d.win.uiScaleY=3 52 * HiDPIPropertiesWindowsTest UISCALE_2X3 53 * @run main/othervm -Dsun.java2d.uiScale.enabled=true 54 * -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2 55 * HiDPIPropertiesWindowsTest UISCALE_3X2 56 * @run main/othervm -Dsun.java2d.uiScale=4 57 * HiDPIPropertiesWindowsTest UISCALE_4 58 * @run main/othervm -Dsun.java2d.uiScale=4 59 * -Dsun.java2d.win.uiScaleX=2 -Dsun.java2d.win.uiScaleY=3 60 * HiDPIPropertiesWindowsTest UISCALE_2X3 61 * @run main/othervm -Dsun.java2d.win.uiScaleX=4 -Dsun.java2d.win.uiScaleY=5 62 * HiDPIPropertiesWindowsTest UISCALE_4X5 63 * @run main/othervm -Dsun.java2d.uiScale=3 64 * -Dsun.java2d.win.uiScaleX=0 -Dsun.java2d.win.uiScaleY=0 65 * HiDPIPropertiesWindowsTest UISCALE_3 66 * @run main/othervm -Dsun.java2d.uiScale=4 67 * -Dsun.java2d.win.uiScaleX=-7 -Dsun.java2d.win.uiScaleY=-8 68 * HiDPIPropertiesWindowsTest UISCALE_4 69 * @run main/othervm -Dsun.java2d.uiScale=4x 70 * HiDPIPropertiesWindowsTest UISCALE_4 71 * @run main/othervm -Dsun.java2d.win.uiScaleX=4x -Dsun.java2d.win.uiScaleY=5x 72 * HiDPIPropertiesWindowsTest UISCALE_4X5 73 * @run main/othervm -Dsun.java2d.uiScale=384dpi 74 * HiDPIPropertiesWindowsTest UISCALE_4 75 * @run main/othervm -Dsun.java2d.uiScale=300% 76 * HiDPIPropertiesWindowsTest UISCALE_3 77 * @run main/othervm -Dsun.java2d.win.uiScaleX=400% -Dsun.java2d.win.uiScaleY=500% 78 * HiDPIPropertiesWindowsTest UISCALE_4X5 79 * @run main/othervm -Dsun.java2d.win.uiScaleX=288dpi -Dsun.java2d.win.uiScaleY=192dpi 80 * HiDPIPropertiesWindowsTest UISCALE_3X2 81 * @run main/othervm -Dsun.java2d.win.uiScaleX=200% -Dsun.java2d.win.uiScaleY=288dpi 82 * HiDPIPropertiesWindowsTest UISCALE_2X3 83 */ 84 public class HiDPIPropertiesWindowsTest { 85 86 public static void main(String[] args) throws Exception { 87 88 try { 89 UIManager.setLookAndFeel( 90 "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 91 } catch (Exception e) { 92 return; 93 } 94 95 String testCase = args[0]; 96 switch (testCase) { 97 case "UISCALE_DISABLED": 98 testScale(1.0, 1.0); 99 break; 100 case "UISCALE_3": 101 testScale(3.0, 3.0); 102 break; 103 case "UISCALE_4": 104 testScale(4.0, 4.0); 105 break; 106 case "UISCALE_2X3": 107 testScale(2.0, 3.0); 108 break; 109 case "UISCALE_3X2": 110 testScale(3.0, 2.0); 111 break; 112 case "UISCALE_4X5": 113 testScale(4.0, 5.0); 114 break; 115 default: 116 throw new RuntimeException("Unknown test case: " + testCase); 117 } 118 } 119 120 private static void testScale(double scaleX, double scaleY) { 121 122 Dialog dialog = new Dialog((Frame) null, true) { 123 124 @Override 125 public void paint(Graphics g) { 126 super.paint(g); 127 AffineTransform tx = ((Graphics2D) g).getTransform(); 128 dispose(); 129 if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) { 130 throw new RuntimeException(String.format("Wrong scale:" 131 + "[%f, %f] instead of [%f, %f].", 132 tx.getScaleX(), tx.getScaleY(), scaleX, scaleY)); 133 } 134 } 135 }; 136 dialog.setSize(200, 300); 137 dialog.setVisible(true); 138 } 139 }