< prev index next >

test/jdk/java/awt/Toolkit/ScreenInsetsTest/ScreenInsetsTest.java

Print this page


   1 /*
   2  * Copyright (c) 2006, 2016, 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 /*
  25   @test
  26   @key headful
  27   @bug 4737732
  28   @summary Tests that Toolkit.getScreenInsets() returns correct insets
  29   @author artem.ananiev: area=awt.toplevel
  30   @library ../../regtesthelpers
  31   @build Util
  32   @run main ScreenInsetsTest
  33 */
  34 
  35 import java.awt.*;
  36 import java.awt.event.*;





  37 
  38 import test.java.awt.regtesthelpers.Util;
  39 
  40 public class ScreenInsetsTest
  41 {
  42     public static void main(String[] args)
  43     {
  44         if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
  45         {
  46             // this state is used in the test - sorry
  47             return;
  48         }
  49 
  50         boolean passed = true;
  51 
  52         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  53         GraphicsDevice[] gds = ge.getScreenDevices();
  54         for (GraphicsDevice gd : gds)
  55         {
  56             GraphicsConfiguration gc = gd.getDefaultConfiguration();
  57             Rectangle gcBounds = gc.getBounds();
  58             Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);


















  59 
  60             Frame f = new Frame("Test", gc);
  61             f.setUndecorated(true);
  62             f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
  63             f.setVisible(true);
  64             Util.waitForIdle(null);
  65 
  66             f.setExtendedState(Frame.MAXIMIZED_BOTH);
  67             Util.waitForIdle(null);
  68 
  69             Rectangle fBounds = f.getBounds();
  70             // workaround: on Windows maximized windows have negative coordinates
  71             if (fBounds.x < gcBounds.x)
  72             {
  73                 fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
  74                 fBounds.x = gcBounds.x;
  75             }
  76             if (fBounds.y < gcBounds.y)
  77             {
  78                 fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased


   1 /*
   2  * Copyright (c) 2006, 2018, 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 /*
  25   @test
  26   @key headful
  27   @bug 4737732
  28   @summary Tests that Toolkit.getScreenInsets() returns correct insets
  29   @author artem.ananiev: area=awt.toplevel
  30   @library ../../regtesthelpers
  31   @build Util
  32   @run main ScreenInsetsTest
  33 */
  34 
  35 import java.awt.Frame;
  36 import java.awt.GraphicsConfiguration;
  37 import java.awt.GraphicsDevice;
  38 import java.awt.GraphicsEnvironment;
  39 import java.awt.Insets;
  40 import java.awt.Rectangle;
  41 import java.awt.Toolkit;
  42 
  43 import test.java.awt.regtesthelpers.Util;
  44 
  45 public class ScreenInsetsTest
  46 {
  47     public static void main(String[] args)
  48     {






  49         boolean passed = true;
  50 
  51         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  52         GraphicsDevice[] gds = ge.getScreenDevices();
  53         for (GraphicsDevice gd : gds) {
  54 
  55             GraphicsConfiguration gc = gd.getDefaultConfiguration();
  56             Rectangle gcBounds = gc.getBounds();
  57             Insets gcInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
  58             int left = gcInsets.left;
  59             int right = gcInsets.right;
  60             int bottom = gcInsets.bottom;
  61             int top = gcInsets.top;
  62             if (left < 0 || right < 0 || bottom < 0 || top < 0) {
  63                 throw new RuntimeException("Negative value: " + gcInsets);
  64             }
  65             int maxW = gcBounds.width / 3;
  66             int maxH = gcBounds.height / 3;
  67             if (left > maxW || right > maxW || bottom > maxH || top > maxH) {
  68                 throw new RuntimeException("Big value: " + gcInsets);
  69             }
  70 
  71             if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH))
  72             {
  73                 // this state is used in the test - sorry
  74                 continue;
  75             }
  76 
  77             Frame f = new Frame("Test", gc);
  78             f.setUndecorated(true);
  79             f.setBounds(gcBounds.x + 100, gcBounds.y + 100, 320, 240);
  80             f.setVisible(true);
  81             Util.waitForIdle(null);
  82 
  83             f.setExtendedState(Frame.MAXIMIZED_BOTH);
  84             Util.waitForIdle(null);
  85 
  86             Rectangle fBounds = f.getBounds();
  87             // workaround: on Windows maximized windows have negative coordinates
  88             if (fBounds.x < gcBounds.x)
  89             {
  90                 fBounds.width -= (gcBounds.x - fBounds.x) * 2; // width is decreased
  91                 fBounds.x = gcBounds.x;
  92             }
  93             if (fBounds.y < gcBounds.y)
  94             {
  95                 fBounds.height -= (gcBounds.y - fBounds.y) * 2; // height is decreased


< prev index next >