1 /*
   2  * Copyright (c) 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    @bug      8166897
  27    @summary  Some font overlap in the Optionpane dialog.
  28    @run      main ChangeWindowResizabiltyTest
  29 */
  30 
  31 import java.awt.*;
  32 
  33 public class ChangeWindowResizabiltyTest {
  34     public static void main(String[] args) throws Exception {
  35         Robot robot = new Robot();
  36         for(int i = 0; i < 10; i++) {
  37             Dialog dialog = new Dialog((Frame) null);
  38             dialog.setLocation(100, 100);
  39             Component panel = new Panel();
  40             panel.setPreferredSize(new Dimension(200, 100));
  41             dialog.add(panel);
  42             dialog.pack();
  43             dialog.setVisible(true);
  44             robot.waitForIdle();
  45             robot.delay(200);
  46 
  47             Point frameLoc = dialog.getLocationOnScreen();
  48             Point contentLoc = panel.getLocationOnScreen();
  49 
  50             System.out.println("Decor location " + frameLoc);
  51             System.out.println("Content location " + contentLoc);
  52 
  53             dialog.setResizable(false);
  54             robot.waitForIdle();
  55             robot.delay(200);
  56 
  57             Point l = dialog.getLocationOnScreen();
  58             if (!l.equals(frameLoc)) {
  59                 dialog.dispose();
  60                 throw new RuntimeException("Decorated frame location moved " +
  61                         "after setResizable(false)" + l);
  62             }
  63 
  64             l = panel.getLocationOnScreen();
  65             if (!l.equals(contentLoc)) {
  66                 dialog.dispose();
  67                 throw new RuntimeException("Content location moved after " +
  68                         "setResizable(false)" + l);
  69             }
  70 
  71             if (panel.getLocationOnScreen().y <
  72                       dialog.getLocationOnScreen().y + dialog.getInsets().top) {
  73                 dialog.dispose();
  74                 throw new RuntimeException(
  75                             "Wrong content position after setResizable(false)");
  76             }
  77 
  78             dialog.setResizable(true);
  79             robot.waitForIdle();
  80             robot.delay(200);
  81 
  82             l = dialog.getLocationOnScreen();
  83             if (!l.equals(frameLoc)) {
  84                 dialog.dispose();
  85                 throw new RuntimeException("Decorated frame location moved " +
  86                         "after setResizable(true)" + l);
  87             }
  88 
  89             l = panel.getLocationOnScreen();
  90             if (!l.equals(contentLoc)) {
  91                 dialog.dispose();
  92                 throw new RuntimeException("Content location moved after " +
  93                         "setResizable(true)" + l);
  94             }
  95             if (panel.getLocationOnScreen().y <
  96                       dialog.getLocationOnScreen().y + dialog.getInsets().top) {
  97                 dialog.dispose();
  98                 throw new RuntimeException(
  99                              "Wrong content position after setResizable(true)");
 100             }
 101 
 102             dialog.dispose();
 103         }
 104     }
 105 }
--- EOF ---