|
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 java.util.logging.Level; |
|
38 import java.util.logging.Logger; |
|
39 import javax.swing.JFrame; |
|
40 import javax.swing.SwingUtilities; |
|
41 |
|
42 public class TestMultiScreenGConfigNotify { |
|
43 |
|
44 static JFrame f; |
|
45 static String propName[]; |
|
46 static int propCount = 0; |
|
47 static boolean result = false; |
|
48 public static void main(String[] args) throws Exception { |
|
49 |
|
50 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
51 GraphicsDevice[] gds = ge.getScreenDevices(); |
|
52 if (gds.length < 2) { |
|
53 return; |
|
54 } |
|
55 GraphicsConfiguration gc = gds[0].getDefaultConfiguration(); |
|
56 GraphicsConfiguration gc2 = gds[1].getDefaultConfiguration(); |
|
57 propName = new String[10]; |
|
58 SwingUtilities.invokeAndWait(() -> { |
|
59 f = new JFrame(); |
|
60 f.setSize(300, 300); |
|
61 f.setBounds(gc.getBounds().x, gc.getBounds().y, f.getWidth(), f.getHeight()); |
|
62 f.setVisible(true); |
|
63 |
|
64 f.addPropertyChangeListener((PropertyChangeEvent evt) -> { |
|
65 String name = evt.getPropertyName(); |
|
66 System.out.println("propertyChange " + name); |
|
67 propName[propCount] = name; |
|
68 propCount++; |
|
69 }); |
|
70 try { |
|
71 Thread.sleep(2000); |
|
72 } catch (InterruptedException ex) { |
|
73 } |
|
74 f.setBounds(gc2.getBounds().x, gc2.getBounds().y, |
|
75 f.getWidth(), f.getHeight()); |
|
76 }); |
|
77 |
|
78 Thread.sleep(1000); |
|
79 for(int i = 0; i < propCount; i++) { |
|
80 if (propName[i].equals("graphicsConfiguration")) { |
|
81 result = true; |
|
82 } |
|
83 } |
|
84 SwingUtilities.invokeAndWait(() -> f.dispose()); |
|
85 if(!result) { |
|
86 throw new RuntimeException("graphicsConfiguration notification not sent"); |
|
87 } |
|
88 } |
|
89 } |