1 /* 2 * Copyright (c) 2009, 2013, 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 6505027 27 * @summary Tests focus problem inside internal frame 28 * @author Sergey Malenkov 29 * @library .. 30 */ 31 32 import java.awt.AWTException; 33 import java.awt.BorderLayout; 34 import java.awt.Component; 35 import java.awt.Container; 36 import java.awt.KeyboardFocusManager; 37 import java.awt.Point; 38 import java.awt.Robot; 39 import java.awt.event.InputEvent; 40 import javax.swing.DefaultCellEditor; 41 import javax.swing.JComboBox; 42 import javax.swing.JDesktopPane; 43 import javax.swing.JFrame; 44 import javax.swing.JInternalFrame; 45 import javax.swing.JScrollPane; 46 import javax.swing.JTable; 47 import javax.swing.JTextField; 48 import javax.swing.SwingUtilities; 49 import javax.swing.table.DefaultTableModel; 50 import javax.swing.table.TableColumn; 51 52 public class Test6505027 { 53 54 private static final boolean INTERNAL = true; 55 private static final boolean TERMINATE = true; 56 57 private static final int WIDTH = 450; 58 private static final int HEIGHT = 200; 59 private static final int OFFSET = 10; 60 61 private static final String[] COLUMNS = { "Size", "Shape" }; // NON-NLS: column names 62 private static final String[] ITEMS = { "a", "b", "c", "d" }; // NON-NLS: combobox content 63 private static final String KEY = "terminateEditOnFocusLost"; // NON-NLS: property name 64 65 public static void main(String[] args) throws Throwable { 66 SwingTest.start(Test6505027.class); 67 } 68 69 private final JTable table = new JTable(new DefaultTableModel(COLUMNS, 2)); 70 71 public Test6505027(JFrame main) { 72 Container container = main; 73 if (INTERNAL) { 74 JInternalFrame frame = new JInternalFrame(); 75 frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT); 76 frame.setVisible(true); 77 78 JDesktopPane desktop = new JDesktopPane(); 79 desktop.add(frame, new Integer(1)); 80 81 container.add(desktop); 82 container = frame; 83 } 84 if (TERMINATE) { 85 this.table.putClientProperty(KEY, Boolean.TRUE); 86 } 87 TableColumn column = this.table.getColumn(COLUMNS[1]); 88 column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS))); 89 90 container.add(BorderLayout.NORTH, new JTextField()); 91 container.add(BorderLayout.CENTER, new JScrollPane(this.table)); 92 } 93 94 public void press() throws AWTException { 95 Point point = this.table.getCellRect(1, 1, false).getLocation(); 96 SwingUtilities.convertPointToScreen(point, this.table); 97 98 Robot robot = new Robot(); 99 robot.setAutoDelay(50); 100 robot.mouseMove(point.x + 1, point.y + 1); 101 robot.mousePress(InputEvent.BUTTON1_MASK); 102 robot.mouseRelease(InputEvent.BUTTON1_MASK); 103 } 104 105 public static void validate() { 106 Component component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 107 if (!component.getClass().equals(JComboBox.class)) { 108 throw new Error("unexpected focus owner: " + component); 109 } 110 } 111 }