/Users/lyon/j4p/src/j3d/viewer/SceneTreeModel.java

1    package j3d.viewer; 
2     
3    /* 
4     * 
5     * (c) September 1998 by Mauro Marinilli 
6     * 
7     */ 
8     
9    import javax.media.j3d.Group; 
10   import javax.media.j3d.VirtualUniverse; 
11   import javax.swing.tree.TreePath; 
12   import java.io.Serializable; 
13   import java.util.Enumeration; 
14    
15   public class SceneTreeModel extends AbstractTreeModel implements Serializable { 
16    
17       VirtualUniverse root; 
18    
19       public SceneTreeModel(VirtualUniverse vu) { 
20           root = vu; 
21       } 
22    
23       public Object getRoot() { 
24           return root; 
25       } 
26    
27       public Object getChild(Object parent, int index) { 
28    
29           int count = 0; 
30           if (parent instanceof VirtualUniverse) { 
31               Enumeration e = ((VirtualUniverse) parent).getAllLocales(); 
32               Object current = new Object(); 
33               for (; e.hasMoreElements();) { 
34                   current = e.nextElement(); 
35    
36                   if (count++ == index) { 
37                       break; 
38                   } 
39               }//-for 
40               return current; 
41           } 
42    
43           if (parent instanceof javax.media.j3d.Locale) { 
44               Enumeration e = ((javax.media.j3d.Locale) parent).getAllBranchGraphs(); 
45               Object current = new Object(); 
46               for (; e.hasMoreElements();) { 
47                   current = e.nextElement(); 
48    
49                   if (count++ == index) { 
50                       break; 
51                   } 
52               }//-for 
53               return current; 
54           } 
55    
56    
57           Enumeration e = ((Group) parent).getAllChildren(); 
58           Object current = new Object(); 
59           for (; e.hasMoreElements();) { 
60               current = e.nextElement(); 
61    
62               if (count++ == index) { 
63                   break; 
64               } 
65           }//-for 
66           return current; 
67       } 
68    
69       public int getChildCount(Object parent) { 
70    
71           if (parent instanceof VirtualUniverse) { 
72               return ((VirtualUniverse) parent).numLocales(); 
73           } 
74    
75           if (parent instanceof javax.media.j3d.Locale) { 
76               return ((javax.media.j3d.Locale) parent).numBranchGraphs(); 
77           } 
78    
79           return ((Group) parent).numChildren(); 
80       } 
81    
82       public boolean isLeaf(Object node) { 
83    
84           if (node instanceof VirtualUniverse) { 
85               return (((VirtualUniverse) node).numLocales() == 0); 
86           } 
87    
88           if (node instanceof javax.media.j3d.Locale) { 
89               return (((javax.media.j3d.Locale) node).numBranchGraphs() == 0); 
90           } 
91    
92           return (!(node instanceof Group)); 
93       } 
94    
95       public void valueForPathChanged(TreePath path, Object newValue) { 
96       } 
97    
98       public int getIndexOfChild(Object parent, Object child) { 
99    
100          int count = -1; 
101          if (parent instanceof VirtualUniverse) { 
102   
103              Enumeration e = ((VirtualUniverse) parent).getAllLocales(); 
104              Object current = new Object(); 
105              for (; e.hasMoreElements();) { 
106                  current = e.nextElement(); 
107                  count++; 
108   
109                  if (current.equals(child)) { 
110                      break; 
111                  } 
112              }//-for 
113              return count; 
114          } 
115   
116          if (parent instanceof javax.media.j3d.Locale) { 
117              Enumeration e = ((javax.media.j3d.Locale) parent).getAllBranchGraphs(); 
118              Object current = new Object(); 
119              for (; e.hasMoreElements();) { 
120                  current = e.nextElement(); 
121                  count++; 
122   
123                  if (current.equals(child)) { 
124                      break; 
125                  } 
126              }//-for 
127              return count; 
128          } 
129   
130          Enumeration e = ((Group) parent).getAllChildren(); 
131          Object current = new Object(); 
132          for (; e.hasMoreElements();) { 
133              current = e.nextElement(); 
134              count++; 
135   
136              if (current.equals(child)) { 
137                  break; 
138              } 
139          }//-for 
140          return count; 
141   
142      } 
143  } 
144   
145   
146