📄 devstree.java
字号:
/*
* ====================================================================
* The Vovida Software License, Version 1.0
*
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
* and "Vovida Open Communication Application Library (VOCAL)" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact vocal@vovida.org.
*
* 4. Products derived from this software may not be called "VOCAL", nor
* may "VOCAL" appear in their name, without prior written
* permission of Vovida Networks, Inc.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* ====================================================================
*
* This software consists of voluntary contributions made by Vovida
* Networks, Inc. and many individuals on behalf of Vovida Networks,
* Inc. For more information on Vovida Networks, Inc., please see
* <http://www.vovida.org/>.
*
*/
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Based on DOMTree by Andy Clark, IBM
* Note that the Apache license applies to the original
* software and the Vovida license applies to changes
* to that software.
*/
package vocal.data;
import java.util.Vector;
import java.io.Serializable;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreeSelectionModel;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.w3c.dom.Attr;
import org.w3c.dom.traversal.NodeFilter;
import java.util.Hashtable;
import java.util.Enumeration;
/**
* This class manages the JTree that is the basis of
* navigation through server-side provisioning.
* This class has an outer and inner component. The outer
* component provides an API for the GUI classes in the ui package.
* Each type of screen (ie Marshal, Feature, Group, etc)
* has its own pair of methods to call, either to populate
* its textfields with data from an existing server or to set
* it up for creating a new server.
* <p>
* The inner class component contains a Document Object Model
* that holds all server data in a tree and the classes for
* converting the nodes of this DOM to be rendered as JTree
* nodes.
*
* @author Barbara Samson, Vovida Networks
*/
public class DevsTree extends JTree implements TreeNodeTypes
{
private JTree tree;
private JTree tmp_tree;
private DefaultTreeModel treeModel;
public DevsTree()
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("EMS Server");
DefaultMutableTreeNode subroot = new DefaultMutableTreeNode("视频机");
DefaultMutableTreeNode subroot1 = new DefaultMutableTreeNode("环境机");
DefaultMutableTreeNode dvrleaf1 = new DefaultMutableTreeNode("DVR1");
DefaultMutableTreeNode dvrleaf2 = new DefaultMutableTreeNode("DVR2");
DefaultMutableTreeNode dvrleaf3 = new DefaultMutableTreeNode("DVR3");
DefaultMutableTreeNode dvrleaf4 = new DefaultMutableTreeNode("DVR4");
DefaultMutableTreeNode dvrleaf5 = new DefaultMutableTreeNode("DVR4");
DefaultMutableTreeNode envleaf1 = new DefaultMutableTreeNode("ENV1");
DefaultMutableTreeNode envleaf2 = new DefaultMutableTreeNode("ENV2");
DefaultMutableTreeNode envleaf3 = new DefaultMutableTreeNode("ENV3");
DefaultMutableTreeNode envleaf4 = new DefaultMutableTreeNode("ENV4");
treeModel = new DefaultTreeModel(root);
tree = new JTree(treeModel);
tree.setShowsRootHandles(true);
treeModel.insertNodeInto(subroot,root,0);
treeModel.insertNodeInto(subroot1,root,1);
subroot.add(dvrleaf1);
subroot.add(dvrleaf2);
subroot.add(dvrleaf3);
subroot.add(dvrleaf4);
subroot.add(dvrleaf5);
subroot1.add(envleaf1);
subroot1.add(envleaf2);
subroot1.add(envleaf3);
subroot1.add(envleaf4);
//getContentPane().add(tree,BorderLayout.CENTER);
//tree.setExpandsSelectedPaths(false);
tree.setVisible(true);
tree.expandRow(2);
//return tree;
}
public int getSelectedNodeType()
{
DefaultMutableTreeNode currentNode =
(DefaultMutableTreeNode) getLastSelectedPathComponent();
if (currentNode == null)
{
System.out.println("selected node is null");
return UNKNOWN;
}
DevsUserObject theObject = (DevsUserObject) (currentNode.getUserObject());
return theObject.getNodeType();
}
}
/**
* There is one UserObject per DefaultMutableTreeNode.
*/
class DevsUserObject implements TreeNodeTypes
{
private int nodeType = UNKNOWN;
private String displayString = "";
/**
*
*/
public String toString()
{
return displayString;
}
/**
*
* @param string
*/
public void setDisplayString(String string)
{
displayString = string;
}
/**
*
*/
public int getNodeType()
{
return nodeType;
}
/**
*
* @param type
* @param string
*/
DevsUserObject(int type, String string)
{
nodeType = type;
setDisplayString(string);
}
} // class UserObject
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -