5475N/A/*
5475N/A * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
5475N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5475N/A *
5475N/A * This code is free software; you can redistribute it and/or modify it
5475N/A * under the terms of the GNU General Public License version 2 only, as
5475N/A * published by the Free Software Foundation.
5475N/A *
5475N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5475N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5475N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5475N/A * version 2 for more details (a copy is included in the LICENSE file that
5475N/A * accompanied this code).
5475N/A *
5475N/A * You should have received a copy of the GNU General Public License version
5475N/A * 2 along with this work; if not, write to the Free Software Foundation,
5475N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5475N/A *
5475N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5475N/A * or visit www.oracle.com if you need additional information or have any
5475N/A * questions.
5475N/A */
5475N/A
5475N/A/*
5475N/A * Portions Copyright (c) 2012 IBM Corporation
5475N/A */
5475N/A
5475N/A/* @test
5475N/A * @bug 7188612
5475N/A * @summary AccessibleTableHeader and AccessibleJTableCell should stick to
5475N/A * AccessibleComponent.getLocationOnScreen api.
5475N/A * @author Frank Ding
5475N/A */
5475N/A
5475N/Aimport javax.accessibility.AccessibleComponent;
5475N/Aimport javax.accessibility.AccessibleTable;
5475N/Aimport javax.swing.JComponent;
5475N/Aimport javax.swing.JFrame;
5475N/Aimport javax.swing.JTable;
5475N/Aimport javax.swing.SwingUtilities;
5475N/A
5475N/Apublic class JTableAccessibleGetLocationOnScreen {
5475N/A private static JFrame frame;
5475N/A private static JTable table;
5475N/A
5475N/A public static void main(String[] args) throws Exception {
5475N/A
5475N/A SwingUtilities.invokeAndWait(new Runnable() {
5475N/A
5475N/A @Override
5475N/A public void run() {
5475N/A constructInEDT();
5475N/A try {
5475N/A assertGetLocation();
5475N/A } finally {
5475N/A frame.dispose();
5475N/A }
5475N/A }
5475N/A });
5475N/A
5475N/A }
5475N/A
5475N/A private static void constructInEDT() {
5475N/A String[] columnNames = { "col1", "col2", };
5475N/A Object[][] data = { { "row1, col1", "row1, col2" },
5475N/A { "row2, col1", "row2, col2" }, };
5475N/A
5475N/A frame = new JFrame(
5475N/A "JTable AccessibleTableHeader and AccessibleJTableCell test");
5475N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5475N/A table = new JTable(data, columnNames);
5475N/A frame.add(table);
5475N/A frame.pack();
5475N/A }
5475N/A
5475N/A private static void assertGetLocation() {
5475N/A // the frame is now invisible
5475N/A // test getLocationOnScreen() of
5475N/A // JTable$AccessibleJTable$AccessibleJTableHeaderCell
5475N/A // and JTable$AccessibleJTable$AccessibleJTableCell
5475N/A AccessibleTable accessibleTable = (AccessibleTable) table
5475N/A .getAccessibleContext();
5475N/A AccessibleTable header = accessibleTable.getAccessibleColumnHeader();
5475N/A AccessibleComponent accessibleComp1 = (AccessibleComponent) header
5475N/A .getAccessibleAt(0, 0);
5475N/A // getLocation() must be null according to its javadoc and no exception
5475N/A // is thrown
5475N/A if (null != accessibleComp1.getLocationOnScreen()) {
5475N/A throw new RuntimeException(
5475N/A "JTable$AccessibleJTable$AccessibleJTableHeaderCell."
5475N/A + "getLocation() must be null");
5475N/A }
5475N/A
5475N/A JComponent.AccessibleJComponent accessibleJComponent =
5475N/A (JComponent.AccessibleJComponent) table.getAccessibleContext();
5475N/A AccessibleComponent accessibleComp2 = (AccessibleComponent)
5475N/A accessibleJComponent.getAccessibleChild(3);
5475N/A // getLocation() must be null according to its javadoc and no exception
5475N/A // is thrown
5475N/A if (null != accessibleComp2.getLocationOnScreen()) {
5475N/A throw new RuntimeException("JTable$AccessibleJTable$"
5475N/A + "AccessibleJTableCell.getLocation() must be null");
5475N/A }
5475N/A
5475N/A }
5475N/A}