Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/XMLEncoder/Test4631471.java
41152 views
1
/*
2
* Copyright (c) 2003, 2013, 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 4631471 6972468
27
* @summary Tests DefaultTreeModel encoding
28
* @run main/othervm -Djava.security.manager=allow Test4631471
29
* @author Sergey Malenkov, Mark Davidson
30
*/
31
32
import javax.swing.JTree;
33
import javax.swing.tree.DefaultMutableTreeNode;
34
import javax.swing.tree.DefaultTreeModel;
35
import javax.swing.tree.TreeModel;
36
import javax.swing.tree.TreeNode;
37
38
public abstract class Test4631471 extends AbstractTest {
39
public static void main(String[] args) throws Exception {
40
main();
41
System.setSecurityManager(new SecurityManager());
42
main();
43
}
44
45
private static void main() throws Exception {
46
// the DefaultMutableTreeNode will archive correctly
47
new Test4631471() {
48
protected Object getObject() {
49
return getRoot();
50
}
51
}.test(false);
52
53
// the DefaultTreeModel will also archive correctly
54
new Test4631471() {
55
protected Object getObject() {
56
return getModel();
57
}
58
}.test(false);
59
60
// create a new model from the root node
61
// this simulates the the MetaData ctor:
62
// registerConstructor("javax.swing.tree.DefaultTreeModel", new String[]{"root"});
63
new Test4631471() {
64
protected Object getObject() {
65
return new DefaultTreeModel((TreeNode) getModel().getRoot());
66
}
67
}.test(false);
68
69
// the JTree will archive correctly too
70
new Test4631471() {
71
protected Object getObject() {
72
return getTree();
73
}
74
}.test(false);
75
}
76
77
protected final void validate(Object before, Object after) {
78
// do not any validation
79
}
80
81
public static TreeNode getRoot() {
82
DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");
83
DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");
84
DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");
85
DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");
86
87
first.add(new DefaultMutableTreeNode("1.1"));
88
first.add(new DefaultMutableTreeNode("1.2"));
89
first.add(new DefaultMutableTreeNode("1.3"));
90
91
second.add(new DefaultMutableTreeNode("2.1"));
92
second.add(new DefaultMutableTreeNode("2.2"));
93
second.add(new DefaultMutableTreeNode("2.3"));
94
95
third.add(new DefaultMutableTreeNode("3.1"));
96
third.add(new DefaultMutableTreeNode("3.2"));
97
third.add(new DefaultMutableTreeNode("3.3"));
98
99
node.add(first);
100
node.add(second);
101
node.add(third);
102
103
return node;
104
}
105
106
public static JTree getTree() {
107
return new JTree(getRoot());
108
}
109
110
public static TreeModel getModel() {
111
return getTree().getModel();
112
}
113
}
114
115