0N/A/*
2603N/A * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
2603N/A * @bug 4631471 6972468
0N/A * @summary Tests DefaultTreeModel encoding
0N/A * @author Sergey Malenkov, Mark Davidson
0N/A */
0N/A
0N/Aimport javax.swing.JTree;
0N/Aimport javax.swing.tree.DefaultMutableTreeNode;
0N/Aimport javax.swing.tree.DefaultTreeModel;
0N/Aimport javax.swing.tree.TreeModel;
0N/Aimport javax.swing.tree.TreeNode;
0N/A
0N/Apublic abstract class Test4631471 extends AbstractTest {
0N/A public static void main(String[] args) throws Exception {
2603N/A main();
2603N/A System.setSecurityManager(new SecurityManager());
2603N/A main();
2603N/A }
2603N/A
2603N/A private static void main() throws Exception {
0N/A // the DefaultMutableTreeNode will archive correctly
0N/A new Test4631471() {
0N/A protected Object getObject() {
0N/A return getRoot();
0N/A }
0N/A }.test(false);
0N/A
0N/A // the DefaultTreeModel will also archive correctly
0N/A new Test4631471() {
0N/A protected Object getObject() {
0N/A return getModel();
0N/A }
0N/A }.test(false);
0N/A
0N/A // create a new model from the root node
0N/A // this simulates the the MetaData ctor:
0N/A // registerConstructor("javax.swing.tree.DefaultTreeModel", new String[]{"root"});
0N/A new Test4631471() {
0N/A protected Object getObject() {
0N/A return new DefaultTreeModel((TreeNode) getModel().getRoot());
0N/A }
0N/A }.test(false);
0N/A
0N/A // the JTree will archive correctly too
0N/A new Test4631471() {
0N/A protected Object getObject() {
0N/A return getTree();
0N/A }
0N/A }.test(false);
0N/A }
0N/A
0N/A protected final void validate(Object before, Object after) {
0N/A // do not any validation
0N/A }
0N/A
0N/A public static TreeNode getRoot() {
0N/A DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");
0N/A DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");
0N/A DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");
0N/A DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");
0N/A
0N/A first.add(new DefaultMutableTreeNode("1.1"));
0N/A first.add(new DefaultMutableTreeNode("1.2"));
0N/A first.add(new DefaultMutableTreeNode("1.3"));
0N/A
0N/A second.add(new DefaultMutableTreeNode("2.1"));
0N/A second.add(new DefaultMutableTreeNode("2.2"));
0N/A second.add(new DefaultMutableTreeNode("2.3"));
0N/A
0N/A third.add(new DefaultMutableTreeNode("3.1"));
0N/A third.add(new DefaultMutableTreeNode("3.2"));
0N/A third.add(new DefaultMutableTreeNode("3.3"));
0N/A
0N/A node.add(first);
0N/A node.add(second);
0N/A node.add(third);
0N/A
0N/A return node;
0N/A }
0N/A
0N/A public static JTree getTree() {
0N/A return new JTree(getRoot());
0N/A }
0N/A
0N/A public static TreeModel getModel() {
0N/A return getTree().getModel();
0N/A }
0N/A}