1 /*
   2  * Copyright (c) 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  * @test
  25  * @bug 8178025
  26  * @summary  Verifies if graphicsConfiguration property notification is sent
  27  *           when frame is moved from one screen to another in multiscreen
  28  *           environment.
  29  * @run main TestMultiScreenGConfigNotify
  30  */
  31 
  32 import java.awt.GraphicsConfiguration;
  33 import java.awt.GraphicsDevice;
  34 import java.awt.GraphicsEnvironment;
  35 import java.beans.PropertyChangeEvent;
  36 import java.beans.PropertyChangeListener;
  37 import javax.swing.JFrame;
  38 import javax.swing.SwingUtilities;
  39 
  40 public class TestMultiScreenGConfigNotify {
  41     
  42     static JFrame f;
  43     static String propName[];
  44     static int propCount = 0;
  45     static boolean result = false;
  46 
  47     public static void main(String[] args) throws Exception {
  48         
  49         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
  50         GraphicsDevice[] gds = ge.getScreenDevices();        
  51         if (gds.length < 2) {
  52             return;
  53         } 
  54         GraphicsConfiguration gc = gds[0].getDefaultConfiguration();        
  55         propName = new String[10];
  56         SwingUtilities.invokeAndWait(() -> {
  57             f = new JFrame();
  58             f.setSize(300, 300);
  59             f.setVisible(true);                        
  60             f.addPropertyChangeListener((PropertyChangeEvent evt) -> {
  61                 String name = evt.getPropertyName();
  62                 System.out.println("propertyChange " + name);
  63                 propName[propCount] = name;
  64                 propCount++;
  65             });            
  66             f.setBounds(gc.getBounds().width, gc.getBounds().height/2, 
  67                         f.getWidth(), f.getHeight());
  68         });
  69            
  70         Thread.sleep(1000);
  71         for(int i = 0; i < propCount; i++) {            
  72             if (propName[i].equals("graphicsConfiguration")) {
  73                 result = true;                
  74             }
  75                 
  76         }
  77         f.dispose();
  78         if(!result) {
  79             throw new RuntimeException("graphicsConfiguration notification not sent");
  80         }
  81     }
  82 }