KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > TextTreeModel


1 package org.enhydra.jawe;
2
3 import javax.swing.tree.*;
4 import javax.swing.event.*;
5 import java.util.List JavaDoc;
6
7 import org.enhydra.jawe.xml.*;
8
9 public class TextTreeModel extends DefaultTreeModel {
10
11 // XMLElement root;
12

13    public TextTreeModel (XMLElement root) {
14       super( root.getNode() );
15 // this.root=root;
16
}
17
18 /*
19    public Object getChild(Object parent, int index) {
20       if( parent instanceof XMLCollection ) {
21          return ((XMLCollection)parent).get(index);
22       }
23       else if ( parent instanceof XMLComplexElement ) {
24          return ((XMLComplexElement)parent).get(index);
25       }
26       return null;
27    }
28
29    public int getChildCount(Object parent) {
30       if( parent instanceof XMLCollection ) {
31          return ((XMLCollection)parent).size();
32       }
33       else if ( parent instanceof XMLComplexElement ) {
34          return ((XMLComplexElement)parent).getElementsCount();
35       }
36       return 0;
37    }
38
39    public int getIndexOfChild(Object parent, Object child) {
40       if( parent instanceof XMLCollection ) {
41          List col = (List)((XMLCollection)parent).toCollection();
42          for( int i = 0; i < col.size(); i++ ) {
43             if( col.get(i).equals( child ))
44                return i;
45          }
46       }
47       else if ( parent instanceof XMLComplexElement ) {
48          List col = (List)((XMLComplexElement)parent).getChildElements();
49          for( int i = 0; i < col.size(); i++ ) {
50             if( col.get(i).equals( child ))
51                return i;
52          }
53       }
54       return -1; //child not found
55    }
56
57    public Object getRoot() {
58       return this.root;
59    }
60
61    public boolean isLeaf(Object node) {
62       if( node instanceof XMLCollection ) {
63          return ( ((XMLCollection)node).size() == 0 );
64       }
65       else if ( node instanceof XMLComplexElement ) {
66          return ( ((XMLComplexElement)node).getElementsCount() == 0 );
67       }
68       return true;
69
70    }
71 */

72
73 }
74
Popular Tags