253 |
* Messaged when the user has altered the value for the item |
* Messaged when the user has altered the value for the item |
254 |
* identified by path to newValue. If newValue signifies a truly new |
* identified by path to newValue. If newValue signifies a truly new |
255 |
* value the model should post a treeNodesChanged event. |
* value the model should post a treeNodesChanged event. |
256 |
|
* This sets the user object of the TreeNode identified by |
257 |
|
* path and posts a node changed. If you use custom user objects |
258 |
|
* 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 |
* |
* |
261 |
* @param path - path to the node that the user has altered |
* @param path - path to the node that the user has altered |
262 |
* @param newValue - the new value from the TreeCellEditor |
* @param newValue - the new value from the TreeCellEditor |
263 |
*/ |
*/ |
264 |
public void valueForPathChanged(TreePath path, Object newValue) |
public void valueForPathChanged(TreePath path, Object newValue) |
265 |
{ |
{ |
266 |
if (!path.equals(newValue)) |
Object node = path.getLastPathComponent(); |
267 |
|
if (node instanceof MutableTreeNode) |
268 |
{ |
{ |
269 |
TreeModelEvent event = new TreeModelEvent(this, path); |
((MutableTreeNode) node).setUserObject(newValue); |
270 |
TreeModelListener[] listeners = getTreeModelListeners(); |
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 |
for (int i = listeners.length - 1; i >= 0; --i) |
fireTreeNodesChanged(this, parentPath, ci, c); |
|
listeners[i].treeNodesChanged(event); |
|
286 |
} |
} |
287 |
} |
} |
288 |
|
|
289 |
/** |
/** |
290 |
* Invoked this to insert newChild at location index in parents children. |
* Invoked this to insert newChild at location index in parents children. |
336 |
childIndices[0] = getIndexOfChild(parent, node); |
childIndices[0] = getIndexOfChild(parent, node); |
337 |
Object[] children = new Object[1]; |
Object[] children = new Object[1]; |
338 |
children[0] = node; |
children[0] = node; |
339 |
fireTreeNodesChanged(this, getPathToRoot(parent), childIndices, children); |
fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children); |
340 |
} |
} |
341 |
|
|
342 |
/** |
/** |
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) |