rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX

   1 /*
   2  * Copyright (c) 2020, 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.Frame;
  25 import java.awt.GraphicsDevice;
  26 import java.awt.GraphicsEnvironment;
  27 import java.awt.Rectangle;
  28 import java.awt.Robot;
  29 import java.awt.Toolkit;
  30 
  31 /**
  32  * @test
  33  * @bug 8176359 8231564
  34  * @key headful
  35  * @requires (os.family == "windows" | os.family == "mac")
  36  * @summary setMaximizedBounds() should work if set to the screen other than
  37  *          current screen of the Frame, the size of the frame is intentionally
  38  *          small
  39  */
  40 public final class MaximizedToOppositeScreenSmall {
  41 
  42     public static void main(String[] args) throws Exception {
  43         //Supported platforms are Windows and OS X.
  44         String os = System.getProperty("os.name").toLowerCase();
  45         if (!os.contains("windows") && !os.contains("os x")) {
  46             return;
  47         }
  48 
  49         if (!Toolkit.getDefaultToolkit().
  50                 isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
  51             return;
  52         }
  53 
  54         var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  55         GraphicsDevice[] gds = ge.getScreenDevices();
  56         Robot robot = new Robot();
  57         for (GraphicsDevice gd1 : gds) {
  58             Rectangle framAt = gd1.getDefaultConfiguration().getBounds();
  59             framAt.grow(-framAt.width / 2 + 100, -framAt.height / 2 + 100);
  60             for (GraphicsDevice gd2 : gds) {
  61                 Rectangle maxTo = gd2.getDefaultConfiguration().getBounds();
  62                 maxTo.grow(-maxTo.width / 2 + 120, -maxTo.height / 2 + 120);
  63                 Frame frame = new Frame(gd1.getDefaultConfiguration());
  64                 try {


  65                     frame.setBounds(framAt);

  66                     frame.setVisible(true);
  67                     robot.waitForIdle();
  68                     robot.delay(1000);







  69 
  70                     frame.setMaximizedBounds(maxTo);
  71                     frame.setExtendedState(Frame.MAXIMIZED_BOTH);
  72                     robot.waitForIdle();
  73                     robot.delay(1000);
  74 
  75                     Rectangle actual = frame.getBounds();
  76                     if (!actual.equals(maxTo)) {
  77                         System.err.println("Actual: " + actual);
  78                         System.err.println("Expected: " + maxTo);
  79                         throw new RuntimeException("Wrong bounds");
  80                     }
  81                 } finally {
  82                     frame.dispose();
  83                 }
  84             }
  85         }
  86     }
  87 }
  88 
--- EOF ---