bug8004298.java revision 5655
0N/A/*
3261N/A * Copyright (c) 2013, 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 8004298
0N/A * @summary NPE in WindowsTreeUI.ensureRowsAreVisible
0N/A * @author Alexander Scherbatiy
0N/A * @library ../../regtesthelpers
0N/A * @build Util
0N/A * @run main bug8004298
0N/A */
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.InputEvent;
0N/Aimport javax.swing.*;
0N/Aimport javax.swing.tree.*;
914N/Aimport java.util.concurrent.Callable;
0N/Aimport sun.awt.SunToolkit;
0N/Aimport com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
0N/Aimport com.sun.java.swing.plaf.windows.WindowsTreeUI;
0N/A
0N/Apublic class bug8004298 {
0N/A
0N/A private static JTree tree;
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A Robot robot = new Robot();
0N/A robot.setAutoDelay(50);
0N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
0N/A UIManager.setLookAndFeel(new WindowsLookAndFeel());
0N/A
0N/A SwingUtilities.invokeAndWait(new Runnable() {
0N/A
0N/A @Override
0N/A public void run() {
0N/A createAndShowGUI();
0N/A }
0N/A });
0N/A
0N/A toolkit.realSync();
0N/A
0N/A Point point = Util.invokeOnEDT(new Callable<Point>() {
3170N/A
2684N/A @Override
942N/A public Point call() throws Exception {
942N/A Rectangle rect = tree.getRowBounds(2);
942N/A Point p = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
942N/A SwingUtilities.convertPointToScreen(p, tree);
942N/A return p;
942N/A }
942N/A });
942N/A
2684N/A robot.mouseMove(point.x, point.y);
2684N/A robot.mousePress(InputEvent.BUTTON1_MASK);
2684N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
2684N/A robot.mousePress(InputEvent.BUTTON1_MASK);
942N/A robot.mouseRelease(InputEvent.BUTTON1_MASK);
942N/A toolkit.realSync();
942N/A
334N/A }
334N/A
334N/A private static void createAndShowGUI() {
334N/A JFrame frame = new JFrame();
334N/A frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
334N/A
334N/A DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
334N/A root.add(new DefaultMutableTreeNode("colors"));
334N/A DefaultMutableTreeNode sports = new DefaultMutableTreeNode("sports");
334N/A sports.add(new DefaultMutableTreeNode("basketball"));
334N/A sports.add(new DefaultMutableTreeNode("football"));
334N/A root.add(sports);
334N/A
334N/A tree = new JTree(root);
334N/A tree.setUI(new NullReturningTreeUI());
334N/A
334N/A frame.getContentPane().add(tree);
334N/A frame.pack();
334N/A frame.setVisible(true);
334N/A
334N/A }
334N/A
334N/A private static final class NullReturningTreeUI extends WindowsTreeUI {
334N/A
334N/A @Override
334N/A public Rectangle getPathBounds(JTree tree, TreePath path) {
334N/A // the method can return null and callers have to be ready for
334N/A // that. Simulate the case by returning null for unknown reason.
334N/A if (path != null && path.toString().contains("football")) {
334N/A return null;
334N/A }
334N/A
334N/A return super.getPathBounds(tree, path);
334N/A }
334N/A }
334N/A}