1 /* 2 * Copyright (c) 2013, 2015, 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 6345002 27 @summary grab problems with EmbeddedFrame 28 @requires (os.family == "windows") 29 @modules java.desktop/java.awt.peer 30 @modules java.desktop/sun.awt 31 @modules java.desktop/sun.awt.windows 32 @author Oleg.Semenov@sun.com area=EmbeddedFrame 33 @run main EmbeddedFrameGrabTest 34 */ 35 36 /** 37 * EmbeddedFrameGrabTest.java 38 * 39 * summary: grab problems with EmbeddedFrame 40 */ 41 42 import java.awt.Frame; 43 import java.awt.peer.FramePeer; 44 import javax.swing.JComboBox; 45 import java.awt.Panel; 46 import java.awt.BorderLayout; 47 import java.awt.Robot; 48 import java.awt.event.InputEvent; 49 import java.awt.Rectangle; 50 import java.awt.TextArea; 51 import java.awt.Dialog; 52 53 import java.lang.reflect.Constructor; 54 import java.lang.reflect.Field; 55 56 import sun.awt.AWTAccessor; 57 58 public class EmbeddedFrameGrabTest { 59 60 /** 61 * Test fails if it throws any exception. 62 * @throws Exception 63 */ 64 private void init() throws Exception { 65 66 if (!System.getProperty("os.name").startsWith("Windows")) { 67 System.out.println("This is Windows only test."); 68 return; 69 } 70 71 final Frame frame = new Frame("AWT Frame"); 72 frame.pack(); 73 frame.setSize(200,200); 74 FramePeer frame_peer = AWTAccessor.getComponentAccessor().getPeer(frame); 75 Class comp_peer_class = 76 Class.forName("sun.awt.windows.WComponentPeer"); 77 Field hwnd_field = comp_peer_class.getDeclaredField("hwnd"); 78 hwnd_field.setAccessible(true); 79 long hwnd = hwnd_field.getLong(frame_peer); 80 81 Class clazz = Class.forName("sun.awt.windows.WEmbeddedFrame"); 82 Constructor constructor = 83 clazz.getConstructor (new Class [] {long.class}); 84 final Frame embedded_frame = 85 (Frame) constructor.newInstance (new Object[] { 86 new Long(hwnd)});; 87 final JComboBox<String> combo = new JComboBox<>(new String[] { 88 "Item 1", "Item 2" 89 } ); 90 combo.setSelectedIndex(1); 91 final Panel p = new Panel(); 92 p.setLayout(new BorderLayout()); 93 embedded_frame.add(p,BorderLayout.CENTER); 94 embedded_frame.validate(); 95 p.add(combo); 96 p.validate(); 97 frame.setVisible(true); 98 Robot robot = new Robot(); 99 robot.delay(2000); 100 Rectangle clos = new Rectangle( 101 combo.getLocationOnScreen(),combo.getSize()); 102 robot.mouseMove(clos.x+clos.width/2,clos.y+clos.height/2); 103 robot.mousePress(InputEvent.BUTTON1_MASK); 104 robot.mouseRelease(InputEvent.BUTTON1_MASK); 105 robot.delay(1000); 106 if (!combo.isPopupVisible()) { 107 throw new RuntimeException("Combobox popup is not visible!"); 108 } 109 robot.mouseMove(clos.x+clos.width/2,clos.y+clos.height+3); 110 robot.mousePress(InputEvent.BUTTON1_MASK); 111 robot.mouseRelease(InputEvent.BUTTON1_MASK); 112 robot.delay(1000); 113 if (combo.getSelectedIndex() != 0) { 114 throw new RuntimeException("Combobox selection has not changed!"); 115 } 116 embedded_frame.remove(p); 117 embedded_frame.dispose(); 118 frame.dispose(); 119 120 } 121 122 123 124 public static void main( String args[] ) throws Exception { 125 new EmbeddedFrameGrabTest().init(); 126 } 127 128 }