jdk/test/javax/swing/JInternalFrame/Test6505027.java
author malenkov
Thu, 16 Jul 2009 20:12:14 +0400
changeset 3341 9d092207230a
child 3502 821e773cae60
permissions -rw-r--r--
6505027: terminateEditOnFocusLost making problems for table in JDesktopPane Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3341
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     1
/*
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     2
 * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     4
 *
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     8
 *
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    13
 * accompanied this code).
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    14
 *
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    18
 *
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    21
 * have any questions.
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    22
 */
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    23
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    24
/*
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    25
 * @test
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    26
 * @bug 6505027
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    27
 * @summary Tests focus problem inside internal frame
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    28
 * @author Sergey Malenkov
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    29
 */
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    30
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    31
import java.awt.AWTException;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    32
import java.awt.BorderLayout;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    33
import java.awt.Component;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    34
import java.awt.Container;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    35
import java.awt.KeyboardFocusManager;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    36
import java.awt.Point;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    37
import java.awt.Robot;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    38
import java.awt.event.InputEvent;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    39
import javax.swing.DefaultCellEditor;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    40
import javax.swing.JComboBox;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    41
import javax.swing.JDesktopPane;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    42
import javax.swing.JFrame;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    43
import javax.swing.JInternalFrame;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    44
import javax.swing.JScrollPane;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    45
import javax.swing.JTable;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    46
import javax.swing.JTextField;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    47
import javax.swing.SwingUtilities;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    48
import javax.swing.WindowConstants;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    49
import javax.swing.table.DefaultTableModel;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    50
import javax.swing.table.TableColumn;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    51
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    52
public class Test6505027 implements Runnable {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    53
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    54
    private static final boolean INTERNAL = true;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    55
    private static final boolean TERMINATE = true;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    56
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    57
    private static final int WIDTH = 450;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    58
    private static final int HEIGHT = 200;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    59
    private static final int OFFSET = 10;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    60
    private static final long PAUSE = 2048L;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    61
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    62
    private static final String[] COLUMNS = { "Size", "Shape" }; // NON-NLS
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    63
    private static final String[] ITEMS = { "a", "b", "c", "d" }; // NON-NLS
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    64
    private static final String KEY = "terminateEditOnFocusLost"; // NON-NLS
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    65
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    66
    public static void main(String[] args) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    67
        SwingUtilities.invokeLater(new Test6505027());
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    68
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    69
        Component component = null;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    70
        while (component == null) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    71
            try {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    72
                Thread.sleep(PAUSE);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    73
            }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    74
            catch (InterruptedException exception) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    75
                // ignore interrupted exception
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    76
            }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    77
            component = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    78
        }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    79
        if (!component.getClass().equals(JComboBox.class)) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    80
            throw new Error("unexpected focus owner: " + component);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    81
        }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    82
        SwingUtilities.getWindowAncestor(component).dispose();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    83
    }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    84
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    85
    private JTable table;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    86
    private Point point;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    87
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    88
    public void run() {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    89
        if (this.table == null) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    90
            JFrame main = new JFrame();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    91
            main.setSize(WIDTH + OFFSET * 3, HEIGHT + OFFSET * 5);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    92
            main.setLocationRelativeTo(null);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    93
            main.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    94
            main.setVisible(true);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    95
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    96
            Container container = main;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    97
            if (INTERNAL) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    98
                JInternalFrame frame = new JInternalFrame();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
    99
                frame.setBounds(OFFSET, OFFSET, WIDTH, HEIGHT);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   100
                frame.setVisible(true);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   101
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   102
                JDesktopPane desktop = new JDesktopPane();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   103
                desktop.add(frame, new Integer(1));
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   104
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   105
                container.add(desktop);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   106
                container = frame;
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   107
            }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   108
            this.table = new JTable(new DefaultTableModel(COLUMNS, 2));
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   109
            if (TERMINATE) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   110
                this.table.putClientProperty(KEY, Boolean.TRUE);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   111
            }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   112
            TableColumn column = this.table.getColumn(COLUMNS[1]);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   113
            column.setCellEditor(new DefaultCellEditor(new JComboBox(ITEMS)));
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   114
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   115
            container.add(BorderLayout.NORTH, new JTextField());
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   116
            container.add(BorderLayout.CENTER, new JScrollPane(this.table));
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   117
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   118
            SwingUtilities.invokeLater(this);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   119
        }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   120
        else if (this.point == null) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   121
            this.point = this.table.getCellRect(1, 1, false).getLocation();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   122
            SwingUtilities.convertPointToScreen(this.point, this.table);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   123
            SwingUtilities.invokeLater(this);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   124
        }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   125
        else {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   126
            try {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   127
                Robot robot = new Robot();
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   128
                robot.mouseMove(this.point.x + 1, this.point.y + 1);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   129
                robot.mousePress(InputEvent.BUTTON1_MASK);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   130
            }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   131
            catch (AWTException exception) {
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   132
                throw new Error("unexpected exception", exception);
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   133
            }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   134
        }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   135
    }
9d092207230a 6505027: terminateEditOnFocusLost making problems for table in JDesktopPane
malenkov
parents:
diff changeset
   136
}