bug4220171.java revision 4901
0N/A/*
5270N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/A
0N/A/*
0N/A * @test
0N/A * @bug 4220171
0N/A * @author Konstantin Eremin
0N/A * @summary Tests
0N/A * @library ../../regtesthelpers
0N/A * @build Util
0N/A * @run main bug4220171
0N/A */
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Robot;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.event.InputEvent;
0N/Aimport java.awt.event.KeyEvent;
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.border.LineBorder;
0N/Aimport sun.awt.SunToolkit;
0N/A
0N/Apublic class bug4220171 {
0N/A
0N/A private static JTable table;
0N/A
0N/A public static void main(String args[]) throws Exception {
0N/A
0N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
0N/A Robot robot = new Robot();
0N/A robot.setAutoDelay(50);
0N/A
0N/A javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
0N/A
0N/A public void run() {
0N/A createAndShowGUI();
0N/A }
0N/A });
0N/A
0N/A toolkit.realSync();
0N/A
0N/A clickMouse(robot, 0, 0);
0N/A Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER);
0N/A toolkit.realSync();
0N/A checkCell(0, 0);
0N/A
0N/A clickMouse(robot, 0, 1);
0N/A Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER);
0N/A toolkit.realSync();
0N/A checkCell(0, 1);
0N/A
0N/A clickMouse(robot, 1, 0);
0N/A Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER);
0N/A toolkit.realSync();
0N/A checkCell(1, 0);
0N/A
0N/A clickMouse(robot, 1, 1);
0N/A Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER);
0N/A toolkit.realSync();
0N/A checkCell(1, 1);
0N/A }
0N/A
0N/A static void checkCell(final int row, final int column) throws Exception {
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A
0N/A public void run() {
0N/A if (table.getValueAt(row, column) != null) {
0N/A throw new RuntimeException(
0N/A String.format("Cell (%d, %d) is editable", row, column));
0N/A }
0N/A }
0N/A });
0N/A }
0N/A
0N/A static void clickMouse(Robot robot, int row, int column) throws Exception {
0N/A Point point = getCellClickPoint(row, column);
0N/A robot.mouseMove(point.x, point.y);
0N/A robot.mousePress(InputEvent.BUTTON1_MASK);
0N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
0N/A }
0N/A
0N/A private static Point getCellClickPoint(final int row, final int column) throws Exception {
0N/A final Point[] result = new Point[1];
5270N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A
5270N/A @Override
0N/A public void run() {
0N/A Rectangle rect = table.getCellRect(row, column, false);
0N/A Point point = new Point(rect.x + rect.width / 2,
0N/A rect.y + rect.height / 2);
0N/A SwingUtilities.convertPointToScreen(point, table);
0N/A result[0] = point;
0N/A }
0N/A });
0N/A
0N/A return result[0];
0N/A }
0N/A
0N/A private static void createAndShowGUI() {
0N/A JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
table = new JTable(2, 2);
table.setEnabled(false);
frame.getContentPane().add(table);
frame.setVisible(true);
}
}