5655N/A/*
5655N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5655N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5655N/A *
5655N/A * This code is free software; you can redistribute it and/or modify it
5655N/A * under the terms of the GNU General Public License version 2 only, as
5655N/A * published by the Free Software Foundation.
5655N/A *
5655N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5655N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5655N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5655N/A * version 2 for more details (a copy is included in the LICENSE file that
5655N/A * accompanied this code).
5655N/A *
5655N/A * You should have received a copy of the GNU General Public License version
5655N/A * 2 along with this work; if not, write to the Free Software Foundation,
5655N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5655N/A *
5655N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5655N/A * or visit www.oracle.com if you need additional information or have any
5655N/A * questions.
5655N/A */
5655N/A
5655N/A/*
5655N/A * @test
5655N/A * @bug 8004298
5655N/A * @summary NPE in WindowsTreeUI.ensureRowsAreVisible
5655N/A * @author Alexander Scherbatiy
5655N/A * @library ../../regtesthelpers
5655N/A * @build Util
5655N/A * @run main bug8004298
5655N/A */
5655N/A
5655N/Aimport java.awt.*;
5655N/Aimport java.awt.event.InputEvent;
5655N/Aimport javax.swing.*;
5655N/Aimport javax.swing.tree.*;
5655N/Aimport java.util.concurrent.Callable;
5655N/Aimport sun.awt.SunToolkit;
5655N/Aimport com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
5655N/Aimport com.sun.java.swing.plaf.windows.WindowsTreeUI;
5655N/A
5655N/Apublic class bug8004298 {
5655N/A
5655N/A private static JTree tree;
5655N/A
5655N/A public static void main(String[] args) throws Exception {
5655N/A Robot robot = new Robot();
5655N/A robot.setAutoDelay(50);
5655N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
5868N/A try {
5868N/A UIManager.setLookAndFeel(new WindowsLookAndFeel());
5868N/A } catch (javax.swing.UnsupportedLookAndFeelException ulafe) {
5868N/A System.out.println(ulafe.getMessage());
5868N/A System.out.println("The test is considered PASSED");
5868N/A return;
5868N/A }
5655N/A SwingUtilities.invokeAndWait(new Runnable() {
5655N/A
5655N/A @Override
5655N/A public void run() {
5655N/A createAndShowGUI();
5655N/A }
5655N/A });
5655N/A
5655N/A toolkit.realSync();
5655N/A
5655N/A Point point = Util.invokeOnEDT(new Callable<Point>() {
5655N/A
5655N/A @Override
5655N/A public Point call() throws Exception {
5655N/A Rectangle rect = tree.getRowBounds(2);
5655N/A Point p = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
5655N/A SwingUtilities.convertPointToScreen(p, tree);
5655N/A return p;
5655N/A }
5655N/A });
5655N/A
5655N/A robot.mouseMove(point.x, point.y);
5655N/A robot.mousePress(InputEvent.BUTTON1_MASK);
5655N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
5655N/A robot.mousePress(InputEvent.BUTTON1_MASK);
5655N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
5655N/A toolkit.realSync();
5655N/A
5655N/A }
5655N/A
5655N/A private static void createAndShowGUI() {
5655N/A JFrame frame = new JFrame();
5655N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
5655N/A
5655N/A DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
5655N/A root.add(new DefaultMutableTreeNode("colors"));
5655N/A DefaultMutableTreeNode sports = new DefaultMutableTreeNode("sports");
5655N/A sports.add(new DefaultMutableTreeNode("basketball"));
5655N/A sports.add(new DefaultMutableTreeNode("football"));
5655N/A root.add(sports);
5655N/A
5655N/A tree = new JTree(root);
5655N/A tree.setUI(new NullReturningTreeUI());
5655N/A
5655N/A frame.getContentPane().add(tree);
5655N/A frame.pack();
5655N/A frame.setVisible(true);
5655N/A
5655N/A }
5655N/A
5655N/A private static final class NullReturningTreeUI extends WindowsTreeUI {
5655N/A
5655N/A @Override
5655N/A public Rectangle getPathBounds(JTree tree, TreePath path) {
5655N/A // the method can return null and callers have to be ready for
5655N/A // that. Simulate the case by returning null for unknown reason.
5655N/A if (path != null && path.toString().contains("football")) {
5655N/A return null;
5655N/A }
5655N/A
5655N/A return super.getPathBounds(tree, path);
5655N/A }
5655N/A }
5868N/A}