1 /*
2  * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
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
26  * @bug 6657026
27  * @summary Tests shared BasicSplitPaneUI in different application contexts
28  * @author Sergey Malenkov
29  */
30 
31 import sun.awt.SunToolkit;
32 
33 import java.awt.event.ActionEvent;
34 import java.util.Set;
35 import javax.swing.JSplitPane;
36 import javax.swing.plaf.basic.BasicSplitPaneUI;
37 
38 public class Test6657026 extends BasicSplitPaneUI implements Runnable {
39 
main(String[] args)40     public static void main(String[] args) throws InterruptedException {
41         if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()){
42             throw new Error("unexpected traversal keys");
43         }
44         new JSplitPane() {
45             public void setFocusTraversalKeys(int id, Set keystrokes) {
46                 keystrokes.clear();
47                 super.setFocusTraversalKeys(id, keystrokes);
48             }
49         };
50         if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
51             throw new Error("shared traversal keys");
52         }
53         KEYBOARD_DIVIDER_MOVE_OFFSET = -KEYBOARD_DIVIDER_MOVE_OFFSET;
54 
55         ThreadGroup group = new ThreadGroup("$$$");
56         Thread thread = new Thread(group, new Test6657026());
57         thread.start();
58         thread.join();
59     }
60 
run()61     public void run() {
62         SunToolkit.createNewAppContext();
63         if (new JSplitPane().getFocusTraversalKeys(0).isEmpty()) {
64             throw new Error("shared traversal keys");
65         }
66         JSplitPane pane = new JSplitPane();
67         pane.setUI(this);
68 
69         createFocusListener().focusGained(null); // allows actions
70         test(pane, "positiveIncrement", 3);
71         test(pane, "negativeIncrement", 0);
72     }
73 
test(JSplitPane pane, String action, int expected)74     private static void test(JSplitPane pane, String action, int expected) {
75         ActionEvent event = new ActionEvent(pane, expected, action);
76         pane.getActionMap().get(action).actionPerformed(event);
77         int actual = pane.getDividerLocation();
78         if (actual != expected) {
79             throw new Error(actual + ", but expected " + expected);
80         }
81     }
82 }
83