author | serb |
Fri, 16 Feb 2018 12:24:38 -0800 | |
changeset 49090 | 82c1fe23c469 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
37701
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
1 |
/* |
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. |
37701
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
4 |
* |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
8 |
* |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
13 |
* accompanied this code). |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
14 |
* |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
18 |
* |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
21 |
* questions. |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
22 |
*/ |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
23 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
24 |
import java.awt.EventQueue; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
25 |
import java.io.ByteArrayInputStream; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
26 |
import java.io.ByteArrayOutputStream; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
27 |
import java.io.ObjectInputStream; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
28 |
import java.io.ObjectOutputStream; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
29 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
30 |
import javax.swing.JButton; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
31 |
import javax.swing.JComponent; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
32 |
import javax.swing.SwingUtilities; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
33 |
import javax.swing.UIClientPropertyKey; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
34 |
import javax.swing.UIManager; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
35 |
import javax.swing.UnsupportedLookAndFeelException; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
36 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
37 |
import static javax.swing.UIManager.getInstalledLookAndFeels; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
38 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
39 |
/** |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
40 |
* @test |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
41 |
* @bug 8141544 |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
42 |
*/ |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
43 |
public final class UIClientPropertyKeyTest { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
44 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
45 |
private static Object key = new UIClientPropertyKey() { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
46 |
}; |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
47 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
48 |
public static void main(final String[] args) throws Exception { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
49 |
EventQueue.invokeAndWait(UIClientPropertyKeyTest::testSetUI); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
50 |
EventQueue.invokeAndWait(UIClientPropertyKeyTest::testSerialization); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
51 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
52 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
53 |
/** |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
54 |
* UIClientPropertyKey should be removed after deserialization. |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
55 |
*/ |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
56 |
private static void testSerialization() { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
57 |
JComponent comp = new JButton(); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
58 |
comp.putClientProperty("key1", "value1"); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
59 |
comp.putClientProperty(key, "value2"); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
60 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
61 |
comp = serializeDeserialize(comp); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
62 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
63 |
validate(comp); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
64 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
65 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
66 |
/** |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
67 |
* UIClientPropertyKey should be removed on updateUI(). |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
68 |
*/ |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
69 |
private static void testSetUI() { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
70 |
JComponent comp = new JButton(); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
71 |
comp.putClientProperty("key1", "value1"); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
72 |
for (final UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
73 |
comp.putClientProperty(key, "value2"); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
74 |
setLookAndFeel(laf); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
75 |
SwingUtilities.updateComponentTreeUI(comp); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
76 |
validate(comp); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
77 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
78 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
79 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
80 |
private static void validate(JComponent comp) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
81 |
Object value = comp.getClientProperty("key1"); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
82 |
if (!value.equals("value1")) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
83 |
throw new RuntimeException("Incorrect value: " + value); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
84 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
85 |
value = comp.getClientProperty(key); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
86 |
if (value != null) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
87 |
throw new RuntimeException("Incorrect value: " + value); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
88 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
89 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
90 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
91 |
private static void setLookAndFeel(final UIManager.LookAndFeelInfo laf) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
92 |
try { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
93 |
UIManager.setLookAndFeel(laf.getClassName()); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
94 |
System.out.println("LookAndFeel: " + laf.getClassName()); |
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
95 |
} catch (final UnsupportedLookAndFeelException ignored){ |
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
96 |
System.out.println("Unsupported LookAndFeel: " + laf.getClassName()); |
37701
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
97 |
} catch (ClassNotFoundException | InstantiationException | |
49090
82c1fe23c469
8196196: Headful tests should not be run in headless mode
serb
parents:
47216
diff
changeset
|
98 |
IllegalAccessException e) { |
37701
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
99 |
throw new RuntimeException(e); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
100 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
101 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
102 |
|
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
103 |
private static JComponent serializeDeserialize(JComponent comp) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
104 |
try { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
105 |
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
106 |
ObjectOutputStream out = new ObjectOutputStream(byteOut); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
107 |
out.writeObject(comp); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
108 |
out.close(); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
109 |
return (JComponent) new ObjectInputStream(new ByteArrayInputStream( |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
110 |
byteOut.toByteArray())).readObject(); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
111 |
} catch (Exception e) { |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
112 |
throw new RuntimeException(e); |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
113 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
114 |
} |
ab17d4b56946
8141544: The interface sun.swing.UIClientPropertyKey can be made public
serb
parents:
diff
changeset
|
115 |
} |