|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| LeafTreeNode.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 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; | |
| 11 | ||
| 12 | import javax.swing.tree.TreeNode; | |
| 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 { | |
| 27 | protected static final Enumeration EMPTY_ENUMERATION = new Enumeration() { | |
| 28 | 0 | public boolean hasMoreElements() { |
| 29 | 0 | return false; |
| 30 | } | |
| 31 | ||
| 32 | 0 | public Object nextElement() { |
| 33 | 0 | return null; |
| 34 | } | |
| 35 | }; | |
| 36 | ||
| 37 | /** The parent node of this TreeNode */ | |
| 38 | private TreeNode parent; | |
| 39 | ||
| 40 | /** The dom4j Node which contains the */ | |
| 41 | protected Node xmlNode; | |
| 42 | ||
| 43 | 0 | public LeafTreeNode() { |
| 44 | } | |
| 45 | ||
| 46 | 0 | public LeafTreeNode(Node xmlNode) { |
| 47 | 0 | this.xmlNode = xmlNode; |
| 48 | } | |
| 49 | ||
| 50 | 0 | public LeafTreeNode(TreeNode parent, Node xmlNode) { |
| 51 | 0 | this.parent = parent; |
| 52 | 0 | this.xmlNode = xmlNode; |
| 53 | } | |
| 54 | ||
| 55 | // TreeNode methods | |
| 56 | // ------------------------------------------------------------------------- | |
| 57 | 0 | public Enumeration children() { |
| 58 | 0 | return EMPTY_ENUMERATION; |
| 59 | } | |
| 60 | ||
| 61 | 0 | public boolean getAllowsChildren() { |
| 62 | 0 | return false; |
| 63 | } | |
| 64 | ||
| 65 | 0 | public TreeNode getChildAt(int childIndex) { |
| 66 | 0 | return null; |
| 67 | } | |
| 68 | ||
| 69 | 0 | public int getChildCount() { |
| 70 | 0 | return 0; |
| 71 | } | |
| 72 | ||
| 73 | 0 | public int getIndex(TreeNode node) { |
| 74 | 0 | return -1; |
| 75 | } | |
| 76 | ||
| 77 | 0 | public TreeNode getParent() { |
| 78 | 0 | return parent; |
| 79 | } | |
| 80 | ||
| 81 | 0 | public boolean isLeaf() { |
| 82 | 0 | return true; |
| 83 | } | |
| 84 | ||
| 85 | 0 | public String toString() { |
| 86 | // should maybe do things differently based on content? | |
| 87 | 0 | String text = xmlNode.getText(); |
| 88 | ||
| 89 | 0 | 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 | 0 | public void setParent(LeafTreeNode parent) { |
| 102 | 0 | this.parent = parent; |
| 103 | } | |
| 104 | ||
| 105 | 0 | public Node getXmlNode() { |
| 106 | 0 | 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 | */ |
|
||||||||||