author | serb |
Fri, 16 Feb 2018 12:24:38 -0800 | |
changeset 49090 | 82c1fe23c469 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
4225 | 1 |
/* |
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2009, 2018, Oracle and/or its affiliates. All rights reserved. |
4225 | 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 |
* |
|
5506 | 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. |
|
4225 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6657138 |
|
27 |
* @summary Verifies that buttons and labels don't share their ui's across appContexts |
|
28 |
* @author Alexander Potochkin |
|
31448
1066345d2a8a
8076468: Add @modules to tests in jdk_desktop test group
yan
parents:
5506
diff
changeset
|
29 |
* @modules java.desktop/sun.awt |
4225 | 30 |
*/ |
31 |
||
32 |
import sun.awt.SunToolkit; |
|
33 |
||
34 |
import javax.swing.*; |
|
35 |
import javax.swing.plaf.ButtonUI; |
|
36 |
import javax.swing.plaf.ComponentUI; |
|
37 |
import java.util.Collections; |
|
38 |
import java.util.HashMap; |
|
39 |
import java.util.Map; |
|
40 |
import java.util.Set; |
|
41 |
||
42 |
public class bug6657138 implements Runnable { |
|
43 |
||
44 |
private static Map<JComponent, Map<String, ComponentUI>> componentMap = |
|
45 |
Collections.synchronizedMap( |
|
46 |
new HashMap<JComponent, Map<String, ComponentUI>>()); |
|
47 |
||
48 |
public void run() { |
|
49 |
SunToolkit.createNewAppContext(); |
|
50 |
try { |
|
51 |
testUIMap(); |
|
52 |
} catch (Exception e) { |
|
53 |
throw new RuntimeException(e); |
|
54 |
} |
|
55 |
} |
|
56 |
||
57 |
private static void testUIMap() throws Exception { |
|
58 |
UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels(); |
|
59 |
Set<JComponent> components = componentMap.keySet(); |
|
60 |
for (JComponent c : components) { |
|
61 |
Map<String, ComponentUI> uiMap = componentMap.get(c); |
|
62 |
||
63 |
for (UIManager.LookAndFeelInfo laf : lafs) { |
|
64 |
if ("Nimbus".equals(laf.getName())) { |
|
65 |
// for some unclear reasons |
|
66 |
// Nimbus ui delegate for a button is null |
|
67 |
// when this method is called from the new AppContext |
|
68 |
continue; |
|
69 |
} |
|
70 |
String className = laf.getClassName(); |
|
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
71 |
try { |
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
72 |
UIManager.setLookAndFeel(className); |
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
73 |
} catch (final UnsupportedLookAndFeelException ignored) { |
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
74 |
continue; |
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
75 |
} |
4225 | 76 |
ComponentUI ui = UIManager.getUI(c); |
77 |
if (ui == null) { |
|
78 |
throw new RuntimeException("UI is null for " + c); |
|
79 |
} |
|
80 |
if (ui == uiMap.get(laf.getName())) { |
|
81 |
throw new RuntimeException( |
|
82 |
"Two AppContexts share the same UI delegate! \n" + |
|
83 |
c + "\n" + ui); |
|
84 |
} |
|
85 |
uiMap.put(laf.getName(), ui); |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
89 |
||
90 |
public static void main(String[] args) throws Exception { |
|
91 |
componentMap.put(new JButton("JButton"), |
|
92 |
new HashMap<String, ComponentUI>()); |
|
93 |
componentMap.put(new JToggleButton("JToggleButton"), |
|
94 |
new HashMap<String, ComponentUI>()); |
|
95 |
componentMap.put(new JRadioButton("JRadioButton"), |
|
96 |
new HashMap<String, ComponentUI>()); |
|
97 |
componentMap.put(new JCheckBox("JCheckBox"), |
|
98 |
new HashMap<String, ComponentUI>()); |
|
99 |
componentMap.put(new JCheckBox("JLabel"), |
|
100 |
new HashMap<String, ComponentUI>()); |
|
101 |
testUIMap(); |
|
102 |
ThreadGroup group = new ThreadGroup("6657138"); |
|
103 |
Thread thread = new Thread(group, new bug6657138()); |
|
104 |
thread.start(); |
|
105 |
thread.join(); |
|
106 |
} |
|
107 |
} |
|
108 |