KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dom4j > swing > LeafTreeNode


1 /*
2  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3  *
4  * This software is open source.
5  * See the bottom of this file for the licence.
6  */

7
8 package org.dom4j.swing;
9
10 import java.util.Enumeration JavaDoc;
11
12 import javax.swing.tree.TreeNode JavaDoc;
13
14 import org.dom4j.Node;
15
16 /**
17  * <p>
18  * <code>LeafTreeNode</code> implements the Swing TreeNode interface to bind a
19  * leaf XML nodes to a Swing TreeModel.
20  * </p>
21  *
22  * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan </a>
23  * @author Jakob Jenkov
24  * @version $Revision: 1.7 $
25  */

26 public class LeafTreeNode implements TreeNode JavaDoc {
27     protected static final Enumeration JavaDoc EMPTY_ENUMERATION = new Enumeration JavaDoc() {
28         public boolean hasMoreElements() {
29             return false;
30         }
31
32         public Object JavaDoc nextElement() {
33             return null;
34         }
35     };
36
37     /** The parent node of this TreeNode */
38     private TreeNode JavaDoc parent;
39
40     /** The dom4j Node which contains the */
41     protected Node JavaDoc xmlNode;
42
43     public LeafTreeNode() {
44     }
45
46     public LeafTreeNode(Node JavaDoc xmlNode) {
47         this.xmlNode = xmlNode;
48     }
49
50     public LeafTreeNode(TreeNode JavaDoc parent, Node JavaDoc xmlNode) {
51         this.parent = parent;
52         this.xmlNode = xmlNode;
53     }
54
55     // TreeNode methods
56
// -------------------------------------------------------------------------
57
public Enumeration JavaDoc children() {
58         return EMPTY_ENUMERATION;
59     }
60
61     public boolean getAllowsChildren() {
62         return false;
63     }
64
65     public TreeNode JavaDoc getChildAt(int childIndex) {
66         return null;
67     }
68
69     public int getChildCount() {
70         return 0;
71     }
72
73     public int getIndex(TreeNode JavaDoc node) {
74         return -1;
75     }
76
77     public TreeNode JavaDoc getParent() {
78         return parent;
79     }
80
81     public boolean isLeaf() {
82         return true;
83     }
84
85     public String JavaDoc toString() {
86         // should maybe do things differently based on content?
87
String JavaDoc text = xmlNode.getText();
88
89         return (text != null) ? text.trim() : "";
90     }
91
92     // Properties
93
// -------------------------------------------------------------------------
94

95     /**
96      * Sets the parent of this node but doesn't change the parents children
97      *
98      * @param parent
99      * DOCUMENT ME!
100      */

101     public void setParent(LeafTreeNode parent) {
102         this.parent = parent;
103     }
104
105     public Node JavaDoc getXmlNode() {
106         return xmlNode;
107     }
108 }
109
110 /*
111  * Redistribution and use of this software and associated documentation
112  * ("Software"), with or without modification, are permitted provided that the
113  * following conditions are met:
114  *
115  * 1. Redistributions of source code must retain copyright statements and
116  * notices. Redistributions must also contain a copy of this document.
117  *
118  * 2. Redistributions in binary form must reproduce the above copyright notice,
119  * this list of conditions and the following disclaimer in the documentation
120  * and/or other materials provided with the distribution.
121  *
122  * 3. The name "DOM4J" must not be used to endorse or promote products derived
123  * from this Software without prior written permission of MetaStuff, Ltd. For
124  * written permission, please contact dom4j-info@metastuff.com.
125  *
126  * 4. Products derived from this Software may not be called "DOM4J" nor may
127  * "DOM4J" appear in their names without prior written permission of MetaStuff,
128  * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
129  *
130  * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
131  *
132  * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
133  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
134  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
135  * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
136  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
137  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
138  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
139  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
140  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
141  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
142  * POSSIBILITY OF SUCH DAMAGE.
143  *
144  * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
145  */

146
Popular Tags