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