138 |
*/ |
*/ |
139 |
public void setAsksAllowsChildren(boolean value) |
public void setAsksAllowsChildren(boolean value) |
140 |
{ |
{ |
141 |
asksAllowsChildren = value; // TODO |
asksAllowsChildren = value; |
142 |
} |
} |
143 |
|
|
144 |
/** |
/** |
150 |
{ |
{ |
151 |
// Sanity Check |
// Sanity Check |
152 |
if (root == null) |
if (root == null) |
153 |
{ |
{ |
154 |
throw new IllegalArgumentException("null root"); |
throw new IllegalArgumentException("null root"); |
155 |
} |
} |
156 |
// Set new root |
// Set new root |
157 |
this.root = root; |
this.root = root; |
|
|
|
|
// TODO |
|
158 |
} |
} |
159 |
|
|
160 |
/** |
/** |
177 |
public int getIndexOfChild(Object parent, Object child) |
public int getIndexOfChild(Object parent, Object child) |
178 |
{ |
{ |
179 |
for (int i = 0; i < getChildCount(parent); i++) |
for (int i = 0; i < getChildCount(parent); i++) |
180 |
{ |
{ |
181 |
if (getChild(parent, i).equals(child)) |
if (getChild(parent, i).equals(child)) |
182 |
return i; |
return i; |
183 |
} |
} |
184 |
return -1; |
return -1; |
185 |
} |
} |
186 |
|
|
228 |
} |
} |
229 |
|
|
230 |
/** |
/** |
231 |
* reload |
* Invoke this method if you've modified the TreeNodes upon |
232 |
|
* which this model depends. The model will notify all of its |
233 |
|
* listeners that the model has changed. |
234 |
*/ |
*/ |
235 |
public void reload() |
public void reload() |
236 |
{ |
{ |
238 |
} |
} |
239 |
|
|
240 |
/** |
/** |
241 |
* reload |
* Invoke this method if you've modified the TreeNodes upon |
242 |
* |
* which this model depends. The model will notify all of its |
243 |
* @param value0 TODO |
* listeners that the model has changed. |
244 |
*/ |
* |
245 |
public void reload(TreeNode value0) |
* @param node - TODO |
246 |
|
*/ |
247 |
|
public void reload(TreeNode node) |
248 |
{ |
{ |
249 |
// TODO |
// TODO |
250 |
} |
} |
251 |
|
|
252 |
/** |
/** |
253 |
* valueForPathChanged |
* Messaged when the user has altered the value for the item |
254 |
* |
* identified by path to newValue. If newValue signifies a truly new |
255 |
* @param value0 TODO |
* value the model should post a treeNodesChanged event. |
256 |
* @param value1 TODO |
* This sets the user object of the TreeNode identified by |
257 |
*/ |
* path and posts a node changed. If you use custom user objects |
258 |
public void valueForPathChanged(TreePath value0, Object value1) |
* in the TreeModel you're going to need to subclass this and set |
259 |
{ |
* the user object of the changed node to something meaningful. |
260 |
// TODO |
* |
261 |
} |
* @param path - path to the node that the user has altered |
262 |
|
* @param newValue - the new value from the TreeCellEditor |
263 |
|
*/ |
264 |
|
public void valueForPathChanged(TreePath path, Object newValue) |
265 |
|
{ |
266 |
|
Object node = path.getLastPathComponent(); |
267 |
|
if (node instanceof MutableTreeNode) |
268 |
|
{ |
269 |
|
((MutableTreeNode) node).setUserObject(newValue); |
270 |
|
int[] ci = null; |
271 |
|
Object[] c = null; |
272 |
|
Object[] parentPath = path.getPath(); |
273 |
|
if (path.getPathCount() > 1) |
274 |
|
{ |
275 |
|
Object parent = ((TreeNode) node).getParent(); |
276 |
|
ci = new int[1]; |
277 |
|
ci[0] = getIndexOfChild(parent, node); |
278 |
|
node = newValue; |
279 |
|
path = path.getParentPath().pathByAddingChild(node); |
280 |
|
c = new Object[1]; |
281 |
|
c[0] = node; |
282 |
|
parentPath = path.getParentPath().getPath(); |
283 |
|
} |
284 |
|
|
285 |
|
fireTreeNodesChanged(this, parentPath, ci, c); |
286 |
|
} |
287 |
|
} |
288 |
|
|
289 |
/** |
/** |
290 |
* insertNodeInto |
* Invoked this to insert newChild at location index in parents children. |
291 |
|
* This will then message nodesWereInserted to create the appropriate event. |
292 |
|
* This is the preferred way to add children as it will create the |
293 |
|
* appropriate event. |
294 |
* |
* |
295 |
* @param value0 TODO |
* @param newChild is the node to add to the parent's children |
296 |
* @param value1 TODO |
* @param parent is the parent of the newChild |
297 |
* @param value2 TODO |
* @param index is the index of the newChild |
298 |
*/ |
*/ |
299 |
public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1, |
public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, |
300 |
int value2) |
int index) |
301 |
{ |
{ |
302 |
// TODO |
parent.insert(newChild, index); |
303 |
|
int[] childIndices = new int[1]; |
304 |
|
childIndices[0] = index; |
305 |
|
nodesWereInserted(parent, childIndices); |
306 |
} |
} |
307 |
|
|
308 |
/** |
/** |
309 |
* removeNodeFromParent |
* Message this to remove node from its parent. This will message |
310 |
|
* nodesWereRemoved to create the appropriate event. This is the preferred |
311 |
|
* way to remove a node as it handles the event creation for you. |
312 |
* |
* |
313 |
* @param value0 TODO |
* @param node to be removed |
314 |
*/ |
*/ |
315 |
public void removeNodeFromParent(MutableTreeNode value0) |
public void removeNodeFromParent(MutableTreeNode node) |
316 |
{ |
{ |
317 |
// TODO |
TreeNode parent = node.getParent(); |
318 |
|
Object[] children = new Object[1]; |
319 |
|
children[0] = node; |
320 |
|
int[] childIndices = new int[1]; |
321 |
|
childIndices[0] = getIndexOfChild(parent, node); |
322 |
|
node.removeFromParent(); |
323 |
|
nodesWereRemoved(parent, childIndices, children); |
324 |
} |
} |
325 |
|
|
326 |
/** |
/** |
327 |
* nodeChanged |
* Invoke this method after you've changed how node is to be represented |
328 |
|
* in the tree. |
329 |
* |
* |
330 |
* @param value0 TODO |
* @param node that was changed |
331 |
*/ |
*/ |
332 |
public void nodeChanged(TreeNode value0) |
public void nodeChanged(TreeNode node) |
333 |
{ |
{ |
334 |
// TODO |
TreeNode parent = node.getParent(); |
335 |
|
int[] childIndices = new int[1]; |
336 |
|
childIndices[0] = getIndexOfChild(parent, node); |
337 |
|
Object[] children = new Object[1]; |
338 |
|
children[0] = node; |
339 |
|
fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children); |
340 |
} |
} |
341 |
|
|
342 |
/** |
/** |
343 |
* nodesWereInserted |
* Invoke this method after you've inserted some TreeNodes |
344 |
|
* into node. childIndices should be the index of the new elements and must |
345 |
|
* be sorted in ascending order. |
346 |
* |
* |
347 |
* @param value0 TODO |
* @param parent that had a child added to |
348 |
* @param value1 TODO |
* @param childIndices of the children added |
349 |
*/ |
*/ |
350 |
public void nodesWereInserted(TreeNode value0, int[] value1) |
public void nodesWereInserted(TreeNode parent, int[] childIndices) |
351 |
{ |
{ |
352 |
// TODO |
Object[] children = new Object[childIndices.length]; |
353 |
|
for (int i = 0; i < children.length; i++) |
354 |
|
children[i] = getChild(parent, childIndices[i]); |
355 |
|
fireTreeNodesInserted(this, getPathToRoot(parent), childIndices, children); |
356 |
} |
} |
357 |
|
|
358 |
/** |
/** |
359 |
* nodesWereRemoved |
* Invoke this method after you've removed some TreeNodes from node. |
360 |
|
* childIndices should be the index of the removed elements and |
361 |
|
* must be sorted in ascending order. And removedChildren should be the |
362 |
|
* array of the children objects that were removed. |
363 |
* |
* |
364 |
* @param value0 TODO |
* @param parent that had a child added to |
365 |
* @param value1 TODO |
* @param childIndices of the children added |
366 |
* @param value2 TODO |
* @param removedChildren are all the children removed from parent. |
367 |
*/ |
*/ |
368 |
public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2) |
public void nodesWereRemoved(TreeNode parent, int[] childIndices, |
369 |
|
Object[] removedChildren) |
370 |
{ |
{ |
371 |
// TODO |
fireTreeNodesRemoved(this, getPathToRoot(parent), childIndices, |
372 |
|
removedChildren); |
373 |
} |
} |
374 |
|
|
375 |
/** |
/** |
376 |
* nodesChanged |
* Invoke this method after you've changed how the children identified by |
377 |
|
* childIndices are to be represented in the tree. |
378 |
* |
* |
379 |
* @param value0 TODO |
* @param node that is the parent of the children that changed in a tree. |
380 |
* @param value1 TODO |
* @param childIndices are the child nodes that changed. |
381 |
*/ |
*/ |
382 |
public void nodesChanged(TreeNode value0, int[] value1) |
public void nodesChanged(TreeNode node, int[] childIndices) |
383 |
{ |
{ |
384 |
// TODO |
Object[] children = new Object[childIndices.length]; |
385 |
|
for (int i = 0; i < children.length; i++) |
386 |
|
children[i] = getChild(node, childIndices[i]); |
387 |
|
fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children); |
388 |
} |
} |
389 |
|
|
390 |
/** |
/** |
391 |
* nodeStructureChanged |
* Invoke this method if you've totally changed the children of node and |
392 |
|
* its childrens children. This will post a treeStructureChanged event. |
393 |
* |
* |
394 |
* @param value0 TODO |
* @param node that had its children and grandchildren changed. |
395 |
*/ |
*/ |
396 |
public void nodeStructureChanged(TreeNode value0) |
public void nodeStructureChanged(TreeNode node) |
397 |
{ |
{ |
398 |
// TODO |
// TODO |
399 |
} |
} |
400 |
|
|
401 |
/** |
/** |
402 |
* getPathToRoot |
* Builds the parents of node up to and including the root node, where |
403 |
|
* the original node is the last element in the returned array. The |
404 |
|
* length of the returned array gives the node's depth in the tree. |
405 |
* |
* |
406 |
* @param value0 TODO |
* @param node - the TreeNode to get the path for |
407 |
* @return TreeNode[] |
* @return TreeNode[] - the path from node to the root |
408 |
*/ |
*/ |
409 |
public TreeNode[] getPathToRoot(TreeNode value0) |
public TreeNode[] getPathToRoot(TreeNode node) |
410 |
{ |
{ |
411 |
return null; // TODO |
return getPathToRoot(node, 0); |
412 |
} |
} |
413 |
|
|
414 |
/** |
/** |
415 |
* getPathToRoot |
* Builds the parents of node up to and including the root node, where |
416 |
|
* the original node is the last element in the returned array. The |
417 |
|
* length of the returned array gives the node's depth in the tree. |
418 |
* |
* |
419 |
* @param value0 TODO |
* @param node - the TreeNode to get the path for |
420 |
* @param value1 TODO |
* @param depth - an int giving the number of steps already taken |
421 |
* @return TreeNode[] |
* towards the root (on recursive calls), used to size the returned array |
422 |
|
* @return an array of TreeNodes giving the path from the root to the |
423 |
|
* specified node |
424 |
*/ |
*/ |
425 |
protected TreeNode[] getPathToRoot(TreeNode value0, int value1) |
protected TreeNode[] getPathToRoot(TreeNode node, int depth) |
426 |
{ |
{ |
427 |
return null; // TODO |
if (node == null) |
428 |
|
{ |
429 |
|
if (depth == 0) |
430 |
|
return null; |
431 |
|
|
432 |
|
return new TreeNode[depth]; |
433 |
|
} |
434 |
|
|
435 |
|
TreeNode[] path = getPathToRoot(node.getParent(), depth + 1); |
436 |
|
path[path.length - depth - 1] = node; |
437 |
|
return path; |
438 |
} |
} |
439 |
|
|
440 |
/** |
/** |
471 |
} |
} |
472 |
|
|
473 |
/** |
/** |
474 |
* fireTreeNodesChanged |
* Notifies all listeners that have registered interest for notification |
475 |
|
* on this event type. The event instance is lazily created using the parameters |
476 |
|
* passed into the fire method. |
477 |
* |
* |
478 |
* @param source the node being changed |
* @param source the node being changed |
479 |
* @param path the path to the root node |
* @param path the path to the root node |
485 |
{ |
{ |
486 |
TreeModelEvent event = new TreeModelEvent(source, path, childIndices, |
TreeModelEvent event = new TreeModelEvent(source, path, childIndices, |
487 |
children); |
children); |
488 |
|
|
489 |
TreeModelListener[] listeners = getTreeModelListeners(); |
TreeModelListener[] listeners = getTreeModelListeners(); |
490 |
|
|
491 |
for (int i = listeners.length - 1; i >= 0; --i) |
for (int i = listeners.length - 1; i >= 0; --i) |