test/jdk/java/awt/hidpi/properties/HiDPIPropertiesWindowsTest.java
author prr
Mon, 14 May 2018 08:58:32 -0700
changeset 50146 0bb0e464ee76
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198991: Move Java2D demo to the open repository Reviewed-by: serb, jeff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     1
/*
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 34394
diff changeset
     2
 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     4
 *
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     7
 * published by the Free Software Foundation.
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     8
 *
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    13
 * accompanied this code).
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    14
 *
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    18
 *
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    21
 * questions.
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    22
 */
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    23
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    24
import java.awt.Dialog;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    25
import java.awt.Frame;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    26
import java.awt.Graphics;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    27
import java.awt.Graphics2D;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    28
import java.awt.geom.AffineTransform;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    29
import javax.swing.UIManager;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    30
46151
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 34394
diff changeset
    31
/**
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 34394
diff changeset
    32
 * @test
5fa789776f7d 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
goetz
parents: 34394
diff changeset
    33
 * @key headful
34394
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    34
 * @bug 8073320
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    35
 * @summary  Windows HiDPI support
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    36
 * @author Alexander Scherbatiy
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    37
 * @requires (os.family == "windows")
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    38
 * @run main/othervm -Dsun.java2d.uiScale.enabled=false
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    39
 *                   -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    40
 *                    HiDPIPropertiesWindowsTest UISCALE_DISABLED
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    41
 * @run main/othervm -Dsun.java2d.uiScale.enabled=false
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    42
 *                   -Dsun.java2d.uiScale=3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    43
 *                    HiDPIPropertiesWindowsTest UISCALE_DISABLED
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    44
 * @run main/othervm -Dsun.java2d.uiScale.enabled=false
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    45
 *                   -Dsun.java2d.uiScale=3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    46
 *                   -Dsun.java2d.win.uiScaleX=5 -Dsun.java2d.win.uiScaleY=6
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    47
 *                    HiDPIPropertiesWindowsTest UISCALE_DISABLED
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    48
 * @run main/othervm -Dsun.java2d.uiScale.enabled=true
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    49
 *                   -Dsun.java2d.uiScale=3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    50
 *                    HiDPIPropertiesWindowsTest UISCALE_3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    51
 * @run main/othervm -Dsun.java2d.uiScale.enabled=true
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    52
 *                   -Dsun.java2d.uiScale=4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    53
 *                   -Dsun.java2d.win.uiScaleX=2 -Dsun.java2d.win.uiScaleY=3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    54
 *                    HiDPIPropertiesWindowsTest UISCALE_2X3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    55
 * @run main/othervm -Dsun.java2d.uiScale.enabled=true
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    56
 *                   -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    57
 *                    HiDPIPropertiesWindowsTest UISCALE_3X2
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    58
 * @run main/othervm -Dsun.java2d.uiScale=4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    59
 *                    HiDPIPropertiesWindowsTest UISCALE_4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    60
 * @run main/othervm -Dsun.java2d.uiScale=4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    61
 *                   -Dsun.java2d.win.uiScaleX=2 -Dsun.java2d.win.uiScaleY=3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    62
 *                    HiDPIPropertiesWindowsTest UISCALE_2X3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    63
 * @run main/othervm -Dsun.java2d.win.uiScaleX=4 -Dsun.java2d.win.uiScaleY=5
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    64
 *                    HiDPIPropertiesWindowsTest UISCALE_4X5
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    65
 * @run main/othervm -Dsun.java2d.uiScale=3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    66
 *                   -Dsun.java2d.win.uiScaleX=0 -Dsun.java2d.win.uiScaleY=0
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    67
 *                    HiDPIPropertiesWindowsTest UISCALE_3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    68
 * @run main/othervm -Dsun.java2d.uiScale=4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    69
 *                   -Dsun.java2d.win.uiScaleX=-7 -Dsun.java2d.win.uiScaleY=-8
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    70
 *                    HiDPIPropertiesWindowsTest UISCALE_4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    71
 * @run main/othervm -Dsun.java2d.uiScale=4x
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    72
 *                    HiDPIPropertiesWindowsTest UISCALE_4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    73
 * @run main/othervm -Dsun.java2d.win.uiScaleX=4x -Dsun.java2d.win.uiScaleY=5x
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    74
 *                    HiDPIPropertiesWindowsTest UISCALE_4X5
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    75
 * @run main/othervm -Dsun.java2d.uiScale=384dpi
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    76
 *                    HiDPIPropertiesWindowsTest UISCALE_4
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    77
 * @run main/othervm -Dsun.java2d.uiScale=300%
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    78
 *                    HiDPIPropertiesWindowsTest UISCALE_3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    79
 * @run main/othervm -Dsun.java2d.win.uiScaleX=400% -Dsun.java2d.win.uiScaleY=500%
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    80
 *                    HiDPIPropertiesWindowsTest UISCALE_4X5
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    81
 * @run main/othervm -Dsun.java2d.win.uiScaleX=288dpi -Dsun.java2d.win.uiScaleY=192dpi
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    82
 *                    HiDPIPropertiesWindowsTest UISCALE_3X2
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    83
 * @run main/othervm -Dsun.java2d.win.uiScaleX=200% -Dsun.java2d.win.uiScaleY=288dpi
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    84
 *                    HiDPIPropertiesWindowsTest UISCALE_2X3
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    85
 */
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    86
public class HiDPIPropertiesWindowsTest {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    87
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    88
    public static void main(String[] args) throws Exception {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    89
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    90
        try {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    91
            UIManager.setLookAndFeel(
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    92
                    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    93
        } catch (Exception e) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    94
            return;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    95
        }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    96
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    97
        String testCase = args[0];
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    98
        switch (testCase) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
    99
            case "UISCALE_DISABLED":
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   100
                testScale(1.0, 1.0);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   101
                break;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   102
            case "UISCALE_3":
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   103
                testScale(3.0, 3.0);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   104
                break;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   105
            case "UISCALE_4":
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   106
                testScale(4.0, 4.0);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   107
                break;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   108
            case "UISCALE_2X3":
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   109
                testScale(2.0, 3.0);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   110
                break;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   111
            case "UISCALE_3X2":
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   112
                testScale(3.0, 2.0);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   113
                break;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   114
            case "UISCALE_4X5":
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   115
                testScale(4.0, 5.0);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   116
                break;
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   117
            default:
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   118
                throw new RuntimeException("Unknown test case: " + testCase);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   119
        }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   120
    }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   121
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   122
    private static void testScale(double scaleX, double scaleY) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   123
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   124
        Dialog dialog = new Dialog((Frame) null, true) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   125
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   126
            @Override
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   127
            public void paint(Graphics g) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   128
                super.paint(g);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   129
                AffineTransform tx = ((Graphics2D) g).getTransform();
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   130
                dispose();
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   131
                if (scaleX != tx.getScaleX() || scaleY != tx.getScaleY()) {
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   132
                    throw new RuntimeException(String.format("Wrong scale:"
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   133
                            + "[%f, %f] instead of [%f, %f].",
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   134
                            tx.getScaleX(), tx.getScaleY(), scaleX, scaleY));
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   135
                }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   136
            }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   137
        };
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   138
        dialog.setSize(200, 300);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   139
        dialog.setVisible(true);
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   140
    }
259d6e4e0978 8073320: Windows HiDPI Graphics support
alexsch
parents:
diff changeset
   141
}