author | serb |
Mon, 04 Dec 2017 16:14:29 -0800 | |
changeset 48271 | 95f173494fe9 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
15325 | 1 |
/* |
48271
95f173494fe9
8189656: The Windows L&F should be moved out from the shared folder
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
15325 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
40128
e635645d2a8a
8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents:
31448
diff
changeset
|
26 |
* @key headful |
15325 | 27 |
* @bug 8004298 |
48271
95f173494fe9
8189656: The Windows L&F should be moved out from the shared folder
serb
parents:
47216
diff
changeset
|
28 |
* @requires (os.family == "windows") |
15325 | 29 |
* @summary NPE in WindowsTreeUI.ensureRowsAreVisible |
30 |
* @author Alexander Scherbatiy |
|
31 |
* @library ../../regtesthelpers |
|
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
28071
diff
changeset
|
32 |
* @modules java.desktop/com.sun.java.swing.plaf.windows |
15325 | 33 |
* @build Util |
34 |
* @run main bug8004298 |
|
35 |
*/ |
|
36 |
||
37 |
import java.awt.*; |
|
38 |
import java.awt.event.InputEvent; |
|
39 |
import javax.swing.*; |
|
40 |
import javax.swing.tree.*; |
|
41 |
import java.util.concurrent.Callable; |
|
42 |
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel; |
|
43 |
import com.sun.java.swing.plaf.windows.WindowsTreeUI; |
|
44 |
||
45 |
public class bug8004298 { |
|
46 |
||
47 |
private static JTree tree; |
|
48 |
||
49 |
public static void main(String[] args) throws Exception { |
|
50 |
Robot robot = new Robot(); |
|
51 |
robot.setAutoDelay(50); |
|
16467
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
52 |
try { |
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
53 |
UIManager.setLookAndFeel(new WindowsLookAndFeel()); |
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
54 |
} catch (javax.swing.UnsupportedLookAndFeelException ulafe) { |
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
55 |
System.out.println(ulafe.getMessage()); |
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
56 |
System.out.println("The test is considered PASSED"); |
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
57 |
return; |
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
58 |
} |
15325 | 59 |
SwingUtilities.invokeAndWait(new Runnable() { |
60 |
||
61 |
@Override |
|
62 |
public void run() { |
|
63 |
createAndShowGUI(); |
|
64 |
} |
|
65 |
}); |
|
66 |
||
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
16467
diff
changeset
|
67 |
robot.waitForIdle(); |
15325 | 68 |
|
69 |
Point point = Util.invokeOnEDT(new Callable<Point>() { |
|
70 |
||
71 |
@Override |
|
72 |
public Point call() throws Exception { |
|
73 |
Rectangle rect = tree.getRowBounds(2); |
|
74 |
Point p = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2); |
|
75 |
SwingUtilities.convertPointToScreen(p, tree); |
|
76 |
return p; |
|
77 |
} |
|
78 |
}); |
|
79 |
||
80 |
robot.mouseMove(point.x, point.y); |
|
81 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
|
82 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
|
83 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
|
84 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
|
28071
3acb75b8df45
8063107: Change open swing regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents:
16467
diff
changeset
|
85 |
robot.waitForIdle(); |
15325 | 86 |
|
87 |
} |
|
88 |
||
89 |
private static void createAndShowGUI() { |
|
90 |
JFrame frame = new JFrame(); |
|
91 |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
92 |
||
93 |
DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); |
|
94 |
root.add(new DefaultMutableTreeNode("colors")); |
|
95 |
DefaultMutableTreeNode sports = new DefaultMutableTreeNode("sports"); |
|
96 |
sports.add(new DefaultMutableTreeNode("basketball")); |
|
97 |
sports.add(new DefaultMutableTreeNode("football")); |
|
98 |
root.add(sports); |
|
99 |
||
100 |
tree = new JTree(root); |
|
101 |
tree.setUI(new NullReturningTreeUI()); |
|
102 |
||
103 |
frame.getContentPane().add(tree); |
|
104 |
frame.pack(); |
|
105 |
frame.setVisible(true); |
|
106 |
||
107 |
} |
|
108 |
||
109 |
private static final class NullReturningTreeUI extends WindowsTreeUI { |
|
110 |
||
111 |
@Override |
|
112 |
public Rectangle getPathBounds(JTree tree, TreePath path) { |
|
113 |
// the method can return null and callers have to be ready for |
|
114 |
// that. Simulate the case by returning null for unknown reason. |
|
115 |
if (path != null && path.toString().contains("football")) { |
|
116 |
return null; |
|
117 |
} |
|
118 |
||
119 |
return super.getPathBounds(tree, path); |
|
120 |
} |
|
121 |
} |
|
16467
b73cb5dbcd22
8009881: TEST_BUG: javax/swing/JTree/8004298/bug8004298.java should be modified
kshefov
parents:
15325
diff
changeset
|
122 |
} |