1 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 26 public class LeafTreeNode implements TreeNode { 27 protected static final Enumeration EMPTY_ENUMERATION = new Enumeration () { 28 public boolean hasMoreElements() { 29 return false; 30 } 31 32 public Object nextElement() { 33 return null; 34 } 35 }; 36 37 38 private TreeNode parent; 39 40 41 protected Node xmlNode; 42 43 public LeafTreeNode() { 44 } 45 46 public LeafTreeNode(Node xmlNode) { 47 this.xmlNode = xmlNode; 48 } 49 50 public LeafTreeNode(TreeNode parent, Node xmlNode) { 51 this.parent = parent; 52 this.xmlNode = xmlNode; 53 } 54 55 public Enumeration children() { 58 return EMPTY_ENUMERATION; 59 } 60 61 public boolean getAllowsChildren() { 62 return false; 63 } 64 65 public TreeNode getChildAt(int childIndex) { 66 return null; 67 } 68 69 public int getChildCount() { 70 return 0; 71 } 72 73 public int getIndex(TreeNode node) { 74 return -1; 75 } 76 77 public TreeNode getParent() { 78 return parent; 79 } 80 81 public boolean isLeaf() { 82 return true; 83 } 84 85 public String toString() { 86 String text = xmlNode.getText(); 88 89 return (text != null) ? text.trim() : ""; 90 } 91 92 95 101 public void setParent(LeafTreeNode parent) { 102 this.parent = parent; 103 } 104 105 public Node getXmlNode() { 106 return xmlNode; 107 } 108 } 109 110 146 | Popular Tags |