< prev index next >

test/java/awt/Robot/HiDPIScreenCapture/HiDPIRobotScreenCaptureTest.java

Print this page


   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.BorderLayout;
  25 import java.awt.Canvas;
  26 import java.awt.Color;
  27 import java.awt.Frame;
  28 import java.awt.Graphics;
  29 import java.awt.Panel;
  30 import java.awt.Rectangle;
  31 import java.awt.Robot;
  32 import java.awt.image.BufferedImage;
  33 import javax.swing.UIManager;

  34 
  35 /* @test
  36  * @bug 8073320
  37  * @summary  Windows HiDPI support
  38  * @author Alexander Scherbatiy
  39  * @requires (os.family == "windows")



  40  * @run main/othervm -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2
  41  *                    HiDPIRobotScreenCaptureTest


  42  */
  43 public class HiDPIRobotScreenCaptureTest {
  44 
  45     private static final Color[] COLORS = {
  46         Color.GREEN, Color.BLUE, Color.ORANGE, Color.RED};
  47 
  48     public static void main(String[] args) throws Exception {
  49 
  50         try {
  51             UIManager.setLookAndFeel(
  52                     "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
  53         } catch (Exception e) {
  54             return;
  55         }
  56 
  57         Frame frame = new Frame();
  58         frame.setBounds(40, 30, 400, 300);
  59         frame.setUndecorated(true);
  60 
  61         Panel panel = new Panel(new BorderLayout());
  62         Canvas canvas = new Canvas() {
  63             @Override
  64             public void paint(Graphics g) {
  65                 super.paint(g);
  66                 int w = getWidth();
  67                 int h = getHeight();
  68                 g.setColor(COLORS[0]);
  69                 g.fillRect(0, 0, w / 2, h / 2);
  70                 g.setColor(COLORS[1]);
  71                 g.fillRect(w / 2, 0, w / 2, h / 2);
  72                 g.setColor(COLORS[2]);
  73                 g.fillRect(0, h / 2, w / 2, h / 2);
  74                 g.setColor(COLORS[3]);
  75                 g.fillRect(w / 2, h / 2, w / 2, h / 2);
  76             }
  77         };
  78 


   1 /*
   2  * Copyright (c) 2015, 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.BorderLayout;
  25 import java.awt.Canvas;
  26 import java.awt.Color;
  27 import java.awt.Frame;
  28 import java.awt.Graphics;
  29 import java.awt.Panel;
  30 import java.awt.Rectangle;
  31 import java.awt.Robot;
  32 import java.awt.image.BufferedImage;
  33 
  34 import jdk.testlibrary.OSInfo;
  35 
  36 /* @test
  37  * @bug 8073320
  38  * @summary  Windows HiDPI support
  39  * @library ../../../../lib/testlibrary
  40  * @build jdk.testlibrary.OSInfo
  41  * @run main/othervm HiDPIRobotScreenCaptureTest
  42  * @run main/othervm -Dsun.java2d.uiScale=1 HiDPIRobotScreenCaptureTest
  43  * @run main/othervm -Dsun.java2d.uiScale=2 HiDPIRobotScreenCaptureTest
  44  * @run main/othervm -Dsun.java2d.win.uiScaleX=3 -Dsun.java2d.win.uiScaleY=2
  45  *                    HiDPIRobotScreenCaptureTest
  46  * @run main/othervm -Dsun.java2d.win.uiScaleX=2 -Dsun.java2d.win.uiScaleY=3
  47  *                    HiDPIRobotScreenCaptureTest
  48  */
  49 public class HiDPIRobotScreenCaptureTest {
  50 
  51     private static final Color[] COLORS = {
  52         Color.GREEN, Color.BLUE, Color.ORANGE, Color.RED};
  53 
  54     public static void main(String[] args) throws Exception {
  55         if (!OSInfo.getOSType().equals(OSInfo.OSType.WINDOWS)
  56                 && System.getProperty("sun.java2d.win.uiScaleX") != null) {



  57             return;
  58         }
  59 
  60         Frame frame = new Frame();
  61         frame.setBounds(97, 87, 101, 123);
  62         frame.setUndecorated(true);
  63 
  64         Panel panel = new Panel(new BorderLayout());
  65         Canvas canvas = new Canvas() {
  66             @Override
  67             public void paint(Graphics g) {
  68                 super.paint(g);
  69                 int w = getWidth();
  70                 int h = getHeight();
  71                 g.setColor(COLORS[0]);
  72                 g.fillRect(0, 0, w / 2, h / 2);
  73                 g.setColor(COLORS[1]);
  74                 g.fillRect(w / 2, 0, w / 2, h / 2);
  75                 g.setColor(COLORS[2]);
  76                 g.fillRect(0, h / 2, w / 2, h / 2);
  77                 g.setColor(COLORS[3]);
  78                 g.fillRect(w / 2, h / 2, w / 2, h / 2);
  79             }
  80         };
  81 


< prev index next >