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 |
|
* listeners that the model has changed. |
244 |
* |
* |
245 |
* @param value0 TODO |
* @param node - TODO |
246 |
*/ |
*/ |
247 |
public void reload(TreeNode value0) |
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 |
|
* value the model should post a treeNodesChanged event. |
256 |
* |
* |
257 |
* @param value0 TODO |
* @param path - path to the node that the user has altered |
258 |
* @param value1 TODO |
* @param newValue - the new value from the TreeCellEditor |
259 |
*/ |
*/ |
260 |
public void valueForPathChanged(TreePath value0, Object value1) |
public void valueForPathChanged(TreePath path, Object newValue) |
261 |
{ |
{ |
262 |
// TODO |
if (!path.equals(newValue)) |
263 |
|
{ |
264 |
|
TreeModelEvent event = new TreeModelEvent(this, path); |
265 |
|
TreeModelListener[] listeners = getTreeModelListeners(); |
266 |
|
|
267 |
|
for (int i = listeners.length - 1; i >= 0; --i) |
268 |
|
listeners[i].treeNodesChanged(event); |
269 |
|
} |
270 |
} |
} |
271 |
|
|
272 |
/** |
/** |
273 |
* insertNodeInto |
* Invoked this to insert newChild at location index in parents children. |
274 |
|
* This will then message nodesWereInserted to create the appropriate event. |
275 |
|
* This is the preferred way to add children as it will create the |
276 |
|
* appropriate event. |
277 |
* |
* |
278 |
* @param value0 TODO |
* @param newChild is the node to add to the parent's children |
279 |
* @param value1 TODO |
* @param parent is the parent of the newChild |
280 |
* @param value2 TODO |
* @param index is the index of the newChild |
281 |
*/ |
*/ |
282 |
public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1, |
public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, |
283 |
int value2) |
int index) |
284 |
{ |
{ |
285 |
// TODO |
parent.insert(newChild, index); |
286 |
|
int[] childIndices = new int[1]; |
287 |
|
childIndices[0] = index; |
288 |
|
nodesWereInserted(parent, childIndices); |
289 |
} |
} |
290 |
|
|
291 |
/** |
/** |
292 |
* removeNodeFromParent |
* Message this to remove node from its parent. This will message |
293 |
|
* nodesWereRemoved to create the appropriate event. This is the preferred |
294 |
|
* way to remove a node as it handles the event creation for you. |
295 |
* |
* |
296 |
* @param value0 TODO |
* @param node to be removed |
297 |
*/ |
*/ |
298 |
public void removeNodeFromParent(MutableTreeNode value0) |
public void removeNodeFromParent(MutableTreeNode node) |
299 |
{ |
{ |
300 |
// TODO |
TreeNode parent = node.getParent(); |
301 |
|
Object[] children = new Object[1]; |
302 |
|
children[0] = node; |
303 |
|
int[] childIndices = new int[1]; |
304 |
|
childIndices[0] = getIndexOfChild(parent, node); |
305 |
|
node.removeFromParent(); |
306 |
|
nodesWereRemoved(parent, childIndices, children); |
307 |
} |
} |
308 |
|
|
309 |
/** |
/** |
310 |
* nodeChanged |
* Invoke this method after you've changed how node is to be represented |
311 |
|
* in the tree. |
312 |
* |
* |
313 |
* @param value0 TODO |
* @param node that was changed |
314 |
*/ |
*/ |
315 |
public void nodeChanged(TreeNode value0) |
public void nodeChanged(TreeNode node) |
316 |
{ |
{ |
317 |
// TODO |
TreeNode parent = node.getParent(); |
318 |
|
int[] childIndices = new int[1]; |
319 |
|
childIndices[0] = getIndexOfChild(parent, node); |
320 |
|
Object[] children = new Object[1]; |
321 |
|
children[0] = node; |
322 |
|
fireTreeNodesChanged(this, getPathToRoot(parent), childIndices, children); |
323 |
} |
} |
324 |
|
|
325 |
/** |
/** |
326 |
* nodesWereInserted |
* Invoke this method after you've inserted some TreeNodes |
327 |
|
* into node. childIndices should be the index of the new elements and must |
328 |
|
* be sorted in ascending order. |
329 |
* |
* |
330 |
* @param value0 TODO |
* @param parent that had a child added to |
331 |
* @param value1 TODO |
* @param childIndices of the children added |
332 |
*/ |
*/ |
333 |
public void nodesWereInserted(TreeNode value0, int[] value1) |
public void nodesWereInserted(TreeNode parent, int[] childIndices) |
334 |
{ |
{ |
335 |
// TODO |
Object[] children = new Object[childIndices.length]; |
336 |
|
for (int i = 0; i < children.length; i++) |
337 |
|
children[i] = getChild(parent, childIndices[i]); |
338 |
|
fireTreeNodesInserted(this, getPathToRoot(parent), childIndices, children); |
339 |
} |
} |
340 |
|
|
341 |
/** |
/** |
342 |
* nodesWereRemoved |
* Invoke this method after you've removed some TreeNodes from node. |
343 |
|
* childIndices should be the index of the removed elements and |
344 |
|
* must be sorted in ascending order. And removedChildren should be the |
345 |
|
* array of the children objects that were removed. |
346 |
* |
* |
347 |
* @param value0 TODO |
* @param parent that had a child added to |
348 |
* @param value1 TODO |
* @param childIndices of the children added |
349 |
* @param value2 TODO |
* @param removeChildren are all the children removed from parent. |
350 |
*/ |
*/ |
351 |
public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2) |
public void nodesWereRemoved(TreeNode parent, int[] childIndices, |
352 |
|
Object[] removedChildren) |
353 |
{ |
{ |
354 |
// TODO |
fireTreeNodesRemoved(this, getPathToRoot(parent), childIndices, |
355 |
|
removedChildren); |
356 |
} |
} |
357 |
|
|
358 |
/** |
/** |
359 |
* nodesChanged |
* Invoke this method after you've changed how the children identified by |
360 |
|
* childIndices are to be represented in the tree. |
361 |
* |
* |
362 |
* @param value0 TODO |
* @param node that is the parent of the children that changed in a tree. |
363 |
* @param value1 TODO |
* @param childIndices are the child nodes that changed. |
364 |
*/ |
*/ |
365 |
public void nodesChanged(TreeNode value0, int[] value1) |
public void nodesChanged(TreeNode node, int[] childIndices) |
366 |
{ |
{ |
367 |
// TODO |
Object[] children = new Object[childIndices.length]; |
368 |
|
for (int i = 0; i < children.length; i++) |
369 |
|
children[i] = getChild(node, childIndices[i]); |
370 |
|
fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children); |
371 |
} |
} |
372 |
|
|
373 |
/** |
/** |
374 |
* nodeStructureChanged |
* Invoke this method if you've totally changed the children of node and |
375 |
|
* its childrens children. This will post a treeStructureChanged event. |
376 |
* |
* |
377 |
* @param value0 TODO |
* @param node that had its children and grandchildren changed. |
378 |
*/ |
*/ |
379 |
public void nodeStructureChanged(TreeNode value0) |
public void nodeStructureChanged(TreeNode node) |
380 |
{ |
{ |
381 |
// TODO |
// TODO |
382 |
} |
} |
383 |
|
|
384 |
/** |
/** |
385 |
* getPathToRoot |
* Builds the parents of node up to and including the root node, where |
386 |
|
* the original node is the last element in the returned array. The |
387 |
|
* length of the returned array gives the node's depth in the tree. |
388 |
* |
* |
389 |
* @param value0 TODO |
* @param node - the TreeNode to get the path for |
390 |
* @return TreeNode[] |
* @return TreeNode[] - the path from node to the root |
391 |
*/ |
*/ |
392 |
public TreeNode[] getPathToRoot(TreeNode value0) |
public TreeNode[] getPathToRoot(TreeNode node) |
393 |
{ |
{ |
394 |
return null; // TODO |
return getPathToRoot(node, 0); |
395 |
} |
} |
396 |
|
|
397 |
/** |
/** |
398 |
* getPathToRoot |
* Builds the parents of node up to and including the root node, where |
399 |
|
* the original node is the last element in the returned array. The |
400 |
|
* length of the returned array gives the node's depth in the tree. |
401 |
* |
* |
402 |
* @param value0 TODO |
* @param node - the TreeNode to get the path for |
403 |
* @param value1 TODO |
* @param depth - an int giving the number of steps already taken |
404 |
* @return TreeNode[] |
* towards the root (on recursive calls), used to size the returned array |
405 |
|
* @return an array of TreeNodes giving the path from the root to the |
406 |
|
* specified node |
407 |
*/ |
*/ |
408 |
protected TreeNode[] getPathToRoot(TreeNode value0, int value1) |
protected TreeNode[] getPathToRoot(TreeNode node, int depth) |
409 |
{ |
{ |
410 |
return null; // TODO |
if (node == null) |
411 |
|
{ |
412 |
|
if (depth == 0) |
413 |
|
return null; |
414 |
|
|
415 |
|
return new TreeNode[depth]; |
416 |
|
} |
417 |
|
|
418 |
|
TreeNode[] path = getPathToRoot(node.getParent(), depth + 1); |
419 |
|
path[path.length - depth - 1] = node; |
420 |
|
return path; |
421 |
} |
} |
422 |
|
|
423 |
/** |
/** |
454 |
} |
} |
455 |
|
|
456 |
/** |
/** |
457 |
* fireTreeNodesChanged |
* Notifies all listeners that have registered interest for notification |
458 |
|
* on this event type. The event instance is lazily created using the parameters |
459 |
|
* passed into the fire method. |
460 |
* |
* |
461 |
* @param source the node being changed |
* @param source the node being changed |
462 |
* @param path the path to the root node |
* @param path the path to the root node |