46 |
import java.io.Serializable; |
import java.io.Serializable; |
47 |
import java.util.ArrayList; |
import java.util.ArrayList; |
48 |
import java.util.Enumeration; |
import java.util.Enumeration; |
|
import java.util.Random; |
|
49 |
import java.util.Stack; |
import java.util.Stack; |
50 |
import java.util.Vector; |
import java.util.Vector; |
51 |
|
|
86 |
protected boolean allowsChildren; |
protected boolean allowsChildren; |
87 |
|
|
88 |
/** |
/** |
89 |
* Constructor DefaultMutableTreeNode |
* Creates a <code>DefaultMutableTreeNode</code> object. |
90 |
|
* This node allows to add child nodes. |
91 |
*/ |
*/ |
92 |
public DefaultMutableTreeNode() |
public DefaultMutableTreeNode() |
93 |
{ |
{ |
95 |
} |
} |
96 |
|
|
97 |
/** |
/** |
98 |
* Constructor DefaultMutableTreeNode |
* Creates a <code>DefaultMutableTreeNode</code> object with the given |
99 |
|
* user object attached to it. This node allows to add child nodes. |
100 |
* |
* |
101 |
* @param userObject TODO |
* @param userObject the user object |
102 |
*/ |
*/ |
103 |
public DefaultMutableTreeNode(Object userObject) |
public DefaultMutableTreeNode(Object userObject) |
104 |
{ |
{ |
106 |
} |
} |
107 |
|
|
108 |
/** |
/** |
109 |
* Constructor DefaultMutableTreeNode |
* Creates a <code>DefaultMutableTreeNode</code> object with the given |
110 |
|
* user object attached to it. |
111 |
* |
* |
112 |
* @param userObject TODO |
* @param userObject the user object |
113 |
* @param allowsChildren TODO |
* @param allowsChildren <code>true</code> if the code allows to add child |
114 |
|
* nodes, <code>false</code> otherwise |
115 |
*/ |
*/ |
116 |
public DefaultMutableTreeNode(Object userObject, boolean allowsChildren) |
public DefaultMutableTreeNode(Object userObject, boolean allowsChildren) |
117 |
{ |
{ |
139 |
} |
} |
140 |
|
|
141 |
/** |
/** |
142 |
* toString |
* Returns a string representation of this node |
143 |
* |
* |
144 |
* @return String |
* @return a human-readable String representing this node |
145 |
*/ |
*/ |
146 |
public String toString() |
public String toString() |
147 |
{ |
{ |
152 |
} |
} |
153 |
|
|
154 |
/** |
/** |
155 |
* add |
* Adds a new child node to this node. |
156 |
* |
* |
157 |
* @param child TODO |
* @param child the child node |
158 |
* |
* |
159 |
* @throws IllegalArgumentException if <code>child</code> is null |
* @throws IllegalArgumentException if <code>child</code> is null |
160 |
* @throws IllegalStateException if the node does not allow children |
* @throws IllegalStateException if the node does not allow children |
172 |
} |
} |
173 |
|
|
174 |
/** |
/** |
175 |
* getParent |
* Returns the parent node of this node. |
176 |
* |
* |
177 |
* @return TreeNode |
* @return the parent node |
178 |
*/ |
*/ |
179 |
public TreeNode getParent() |
public TreeNode getParent() |
180 |
{ |
{ |
182 |
} |
} |
183 |
|
|
184 |
/** |
/** |
185 |
* remove |
* Removes the child with the given index from this node |
186 |
* |
* |
187 |
* @param index TODO |
* @param index the index |
188 |
*/ |
*/ |
189 |
public void remove(int index) |
public void remove(int index) |
190 |
{ |
{ |
192 |
} |
} |
193 |
|
|
194 |
/** |
/** |
195 |
* remove |
* Removes the given child from this node. |
196 |
* |
* |
197 |
* @param node TODO |
* @param node the child node |
198 |
*/ |
*/ |
199 |
public void remove(MutableTreeNode node) |
public void remove(MutableTreeNode node) |
200 |
{ |
{ |
204 |
/** |
/** |
205 |
* writeObject |
* writeObject |
206 |
* |
* |
207 |
* @param stream TODO |
* @param stream the output stream |
208 |
* |
* |
209 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
210 |
*/ |
*/ |
217 |
/** |
/** |
218 |
* readObject |
* readObject |
219 |
* |
* |
220 |
* @param stream TODO |
* @param stream the input stream |
221 |
* |
* |
222 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
223 |
* @exception ClassNotFoundException TODO |
* @exception ClassNotFoundException TODO |
229 |
} |
} |
230 |
|
|
231 |
/** |
/** |
232 |
* insert |
* Inserts given child node at the given index. |
233 |
* |
* |
234 |
* @param node TODO |
* @param node the child node |
235 |
* @param value TODO |
* @param value the index. |
236 |
*/ |
*/ |
237 |
public void insert(MutableTreeNode node, int index) |
public void insert(MutableTreeNode node, int index) |
238 |
{ |
{ |
240 |
} |
} |
241 |
|
|
242 |
/** |
/** |
243 |
* getPath |
* Returns a path to this node from the root. |
244 |
* |
* |
245 |
* @return an array of tree nodes |
* @return an array of tree nodes |
246 |
*/ |
*/ |
250 |
} |
} |
251 |
|
|
252 |
/** |
/** |
253 |
* children |
* Returns an enumeration containing all children of this node. |
254 |
|
* <code>EMPTY_ENUMERATION</code> is returned if this node has no children. |
255 |
* |
* |
256 |
* @return an enumeration of tree nodes |
* @return an enumeration of tree nodes |
257 |
*/ |
*/ |
264 |
} |
} |
265 |
|
|
266 |
/** |
/** |
267 |
* setParent |
* Set the parent node for this node. |
268 |
* |
* |
269 |
* @param node TODO |
* @param node the parent node |
270 |
*/ |
*/ |
271 |
public void setParent(MutableTreeNode node) |
public void setParent(MutableTreeNode node) |
272 |
{ |
{ |
274 |
} |
} |
275 |
|
|
276 |
/** |
/** |
277 |
* getChildAt |
* Returns the child node at a given index. |
278 |
* |
* |
279 |
* @param index TODO |
* @param index the index |
280 |
* |
* |
281 |
* @return TreeNode |
* @return the child node |
282 |
*/ |
*/ |
283 |
public TreeNode getChildAt(int index) |
public TreeNode getChildAt(int index) |
284 |
{ |
{ |
286 |
} |
} |
287 |
|
|
288 |
/** |
/** |
289 |
* getChildCount |
* Returns the number of children of this node. |
290 |
* |
* |
291 |
* @return int |
* @return the number of children |
292 |
*/ |
*/ |
293 |
public int getChildCount() |
public int getChildCount() |
294 |
{ |
{ |
296 |
} |
} |
297 |
|
|
298 |
/** |
/** |
299 |
* getIndex |
* Returns the child index for a given node. |
300 |
* |
* |
301 |
* @param node TODO |
* @param node this node |
302 |
* |
* |
303 |
* @return int |
* @return the index |
304 |
*/ |
*/ |
305 |
public int getIndex(TreeNode node) |
public int getIndex(TreeNode node) |
306 |
{ |
{ |
328 |
} |
} |
329 |
|
|
330 |
/** |
/** |
331 |
* setUserObject |
* Sets the user object for this node |
332 |
* |
* |
333 |
* @param userObject TODO |
* @param userObject the user object |
334 |
*/ |
*/ |
335 |
public void setUserObject(Object userObject) |
public void setUserObject(Object userObject) |
336 |
{ |
{ |
338 |
} |
} |
339 |
|
|
340 |
/** |
/** |
341 |
* getUserObject |
* Returns the user object attached to this node. <code>null</code> is |
342 |
|
* returned when no user object is set. |
343 |
* |
* |
344 |
* @return Object |
* @return the user object |
345 |
*/ |
*/ |
346 |
public Object getUserObject() |
public Object getUserObject() |
347 |
{ |
{ |
349 |
} |
} |
350 |
|
|
351 |
/** |
/** |
352 |
* removeFromParent |
* Removes this node from its parent. |
353 |
*/ |
*/ |
354 |
public void removeFromParent() |
public void removeFromParent() |
355 |
{ |
{ |
356 |
|
// FIXME: IS this implementation really correct ? |
357 |
parent = null; |
parent = null; |
358 |
} |
} |
359 |
|
|
360 |
/** |
/** |
361 |
* removeAllChildren |
* Removes all child nodes from this node. |
362 |
*/ |
*/ |
363 |
public void removeAllChildren() |
public void removeAllChildren() |
364 |
{ |
{ |
547 |
} |
} |
548 |
|
|
549 |
TreeNode[] path = getPathToRoot(node.getParent(), depth + 1); |
TreeNode[] path = getPathToRoot(node.getParent(), depth + 1); |
550 |
path[depth] = node; |
path[path.length - depth - 1] = node; |
551 |
return path; |
return path; |
552 |
} |
} |
553 |
|
|
568 |
} |
} |
569 |
|
|
570 |
/** |
/** |
571 |
* getRoot |
* Returns the root node by iterating the parents of this node. |
572 |
* |
* |
573 |
* @return TreeNode |
* @return the root node |
574 |
*/ |
*/ |
575 |
public TreeNode getRoot() |
public TreeNode getRoot() |
576 |
{ |
{ |
587 |
} |
} |
588 |
|
|
589 |
/** |
/** |
590 |
* isRoot |
* Tells whether this node is the root node or not. |
591 |
* |
* |
592 |
* @return boolean |
* @return <code>true</code> if this is the root node, |
593 |
|
* <code>false</code>otherwise |
594 |
*/ |
*/ |
595 |
public boolean isRoot() |
public boolean isRoot() |
596 |
{ |
{ |
597 |
return (parent == null); |
return parent == null; |
598 |
} |
} |
599 |
|
|
600 |
/** |
/** |