1 21 24 package org.lobobrowser.html.test; 25 26 import javax.swing.event.TreeModelListener ; 27 import javax.swing.tree.*; 28 29 import org.w3c.dom.*; 30 31 class NodeTreeModel implements TreeModel { 32 private final Node rootNode; 33 34 37 public NodeTreeModel(Node node) { 38 super(); 39 rootNode = node; 40 } 41 42 public Object getRoot() { 43 return this.rootNode; 44 } 45 46 public Object getChild(Object parent, int index) { 47 Node parentNode = (Node) parent; 48 return parentNode == null ? null : parentNode.getChildNodes().item(index); 49 } 50 51 public int getChildCount(Object parent) { 52 Node parentNode = (Node) parent; 53 return parentNode == null ? 0 : parentNode.getChildNodes().getLength(); 54 } 55 56 public boolean isLeaf(Object node) { 57 if(node == this.rootNode) { 58 return false; 59 } 60 Node domNode = (Node) node; 61 return domNode == null ? true : domNode.getChildNodes().getLength() == 0; 62 } 63 64 public void valueForPathChanged(TreePath path, Object newValue) { 65 } 66 67 public int getIndexOfChild(Object parent, Object child) { 68 Node parentNode = (Node) parent; 69 NodeList nodeList = parentNode == null ? null : parentNode.getChildNodes(); 70 if(nodeList == null) { 71 return -1; 72 } 73 int length = nodeList.getLength(); 74 for(int i = 0; i < length; i++) { 75 if(nodeList.item(i) == child) { 76 return i; 77 } 78 } 79 return -1; 80 } 81 82 public void addTreeModelListener(TreeModelListener l) { 83 } 85 86 public void removeTreeModelListener(TreeModelListener l) { 87 } 89 } 90 | Popular Tags |