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