2005-08-19  Lillian Angel  <[EMAIL PROTECTED]>

        * javax/swing/tree/DefaultTreeModel.java
        (setAsksAllowsChildren): Removed comment, unneeded.
        (setRoot): Formatting.
        (getIndexOfChild): Formatting.
        (reload): Added API documentation.
        (reload): Likewise.
        (valueForPathChanged): Implemented.
        (insertNodeInto): Implemented.
        (removeNodeFromParent): Implemented.
        (nodeChanged): Implemented.
        (nodesWereInserted): Implemented.
        (nodesWereRemoved): Implemented.
        (nodesChanged): Implemented.
        (nodeStructureChanged): Added API documentation.
        (getPathToRoot): Implemented.
        (getPathToRoot): Implemented.
        (fireTreeNodesChanged): Added API documentation.

Index: javax/swing/tree/DefaultTreeModel.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/tree/DefaultTreeModel.java,v
retrieving revision 1.13
diff -u -r1.13 DefaultTreeModel.java
--- javax/swing/tree/DefaultTreeModel.java	9 Aug 2005 14:57:14 -0000	1.13
+++ javax/swing/tree/DefaultTreeModel.java	19 Aug 2005 14:25:05 -0000
@@ -138,7 +138,7 @@
    */
   public void setAsksAllowsChildren(boolean value)
   {
-    asksAllowsChildren = value; // TODO
+    asksAllowsChildren = value;
   }
 
   /**
@@ -150,13 +150,11 @@
   {
     // Sanity Check
     if (root == null)
-    {
-      throw new IllegalArgumentException("null root");
-    }
+      {
+        throw new IllegalArgumentException("null root");
+      }
     // Set new root
     this.root = root;
-
-    // TODO
   }
 
   /**
@@ -179,10 +177,10 @@
   public int getIndexOfChild(Object parent, Object child)
   {
     for (int i = 0; i < getChildCount(parent); i++)
-    {
-      if (getChild(parent, i).equals(child))
-	return i;
-    }
+      {
+        if (getChild(parent, i).equals(child))
+          return i;
+      }
     return -1;
   }
 
@@ -230,7 +228,9 @@
   }
 
   /**
-   * reload
+   * Invoke this method if you've modified the TreeNodes upon 
+   * which this model depends. The model will notify all of its 
+   * listeners that the model has changed.
    */
   public void reload()
   {
@@ -238,124 +238,186 @@
   }
 
   /**
-   * reload
+   * Invoke this method if you've modified the TreeNodes upon 
+   * which this model depends. The model will notify all of its 
+   * listeners that the model has changed.
    * 
-   * @param value0 TODO
+   * @param node - TODO
    */
-  public void reload(TreeNode value0)
+  public void reload(TreeNode node)
   {
     // TODO
   }
 
   /**
-   * valueForPathChanged
+   * Messaged when the user has altered the value for the item 
+   * identified by path to newValue. If newValue signifies a truly new 
+   * value the model should post a treeNodesChanged event.
    * 
-   * @param value0 TODO
-   * @param value1 TODO
+   * @param path - path to the node that the user has altered
+   * @param newValue - the new value from the TreeCellEditor
    */
-  public void valueForPathChanged(TreePath value0, Object value1)
+  public void valueForPathChanged(TreePath path, Object newValue)
   {
-    // TODO
+    if (!path.equals(newValue))
+      {
+        TreeModelEvent event = new TreeModelEvent(this, path);
+        TreeModelListener[] listeners = getTreeModelListeners();
+        
+        for (int i = listeners.length - 1; i >= 0; --i)
+          listeners[i].treeNodesChanged(event);
+      }
   }
 
   /**
-   * insertNodeInto
+   * Invoked this to insert newChild at location index in parents children.
+   * This will then message nodesWereInserted to create the appropriate event. 
+   * This is the preferred way to add children as it will create the 
+   * appropriate event.
    * 
-   * @param value0 TODO
-   * @param value1 TODO
-   * @param value2 TODO
+   * @param newChild is the node to add to the parent's children
+   * @param parent is the parent of the newChild
+   * @param index is the index of the newChild
    */
-  public void insertNodeInto(MutableTreeNode value0, MutableTreeNode value1,
-      int value2)
+  public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent,
+                             int index)
   {
-    // TODO
+    parent.insert(newChild, index);
+    int[] childIndices = new int[1];
+    childIndices[0] = index;
+    nodesWereInserted(parent, childIndices);
   }
 
   /**
-   * removeNodeFromParent
+   * Message this to remove node from its parent. This will message 
+   * nodesWereRemoved to create the appropriate event. This is the preferred 
+   * way to remove a node as it handles the event creation for you.
    * 
-   * @param value0 TODO
+   * @param node to be removed
    */
-  public void removeNodeFromParent(MutableTreeNode value0)
+  public void removeNodeFromParent(MutableTreeNode node)
   {
-    // TODO
+    TreeNode parent = node.getParent();
+    Object[] children = new Object[1];
+    children[0] = node;
+    int[] childIndices = new int[1];
+    childIndices[0] = getIndexOfChild(parent, node);
+    node.removeFromParent();
+    nodesWereRemoved(parent, childIndices, children);
   }
 
   /**
-   * nodeChanged
+   * Invoke this method after you've changed how node is to be represented
+   * in the tree.
    * 
-   * @param value0 TODO
+   * @param node that was changed
    */
-  public void nodeChanged(TreeNode value0)
+  public void nodeChanged(TreeNode node)
   {
-    // TODO
+    TreeNode parent = node.getParent();
+    int[] childIndices = new int[1];
+    childIndices[0] = getIndexOfChild(parent, node);
+    Object[] children = new Object[1];
+    children[0] = node;
+    fireTreeNodesChanged(this, getPathToRoot(parent), childIndices, children);
   }
 
   /**
-   * nodesWereInserted
+   * Invoke this method after you've inserted some TreeNodes 
+   * into node. childIndices should be the index of the new elements and must 
+   * be sorted in ascending order.
    * 
-   * @param value0 TODO
-   * @param value1 TODO
+   * @param parent that had a child added to
+   * @param childIndices of the children added
    */
-  public void nodesWereInserted(TreeNode value0, int[] value1)
+  public void nodesWereInserted(TreeNode parent, int[] childIndices)
   {
-    // TODO
+    Object[] children = new Object[childIndices.length];
+    for (int i = 0; i < children.length; i++)
+      children[i] = getChild(parent, childIndices[i]);
+    fireTreeNodesInserted(this, getPathToRoot(parent), childIndices, children);
   }
 
   /**
-   * nodesWereRemoved
+   * Invoke this method after you've removed some TreeNodes from node. 
+   * childIndices should be the index of the removed elements and 
+   * must be sorted in ascending order. And removedChildren should be the 
+   * array of the children objects that were removed.
    * 
-   * @param value0 TODO
-   * @param value1 TODO
-   * @param value2 TODO
+   * @param parent that had a child added to
+   * @param childIndices of the children added
+   * @param removeChildren are all the children removed from parent.
    */
-  public void nodesWereRemoved(TreeNode value0, int[] value1, Object[] value2)
+  public void nodesWereRemoved(TreeNode parent, int[] childIndices, 
+                               Object[] removedChildren)
   {
-    // TODO
+    fireTreeNodesRemoved(this, getPathToRoot(parent), childIndices, 
+                         removedChildren);
   }
 
   /**
-   * nodesChanged
+   * Invoke this method after you've changed how the children identified by 
+   * childIndices are to be represented in the tree.
    * 
-   * @param value0 TODO
-   * @param value1 TODO
+   * @param node that is the parent of the children that changed in a tree.
+   * @param childIndices are the child nodes that changed.
    */
-  public void nodesChanged(TreeNode value0, int[] value1)
+  public void nodesChanged(TreeNode node, int[] childIndices)
   {
-    // TODO
+    Object[] children = new Object[childIndices.length];
+    for (int i = 0; i < children.length; i++)
+      children[i] = getChild(node, childIndices[i]);
+    fireTreeNodesChanged(this, getPathToRoot(node), childIndices, children);
   }
 
   /**
-   * nodeStructureChanged
+   * Invoke this method if you've totally changed the children of node and 
+   * its childrens children. This will post a treeStructureChanged event.
    * 
-   * @param value0 TODO
+   * @param node that had its children and grandchildren changed.
    */
-  public void nodeStructureChanged(TreeNode value0)
+  public void nodeStructureChanged(TreeNode node)
   {
     // TODO
   }
 
   /**
-   * getPathToRoot
+   * Builds the parents of node up to and including the root node, where 
+   * the original node is the last element in the returned array. The 
+   * length of the returned array gives the node's depth in the tree.
    * 
-   * @param value0 TODO
-   * @return TreeNode[]
+   * @param node - the TreeNode to get the path for
+   * @return TreeNode[] - the path from node to the root
    */
-  public TreeNode[] getPathToRoot(TreeNode value0)
+  public TreeNode[] getPathToRoot(TreeNode node)
   {
-    return null; // TODO
+    return getPathToRoot(node, 0);
   }
 
   /**
-   * getPathToRoot
+   * Builds the parents of node up to and including the root node, where 
+   * the original node is the last element in the returned array. The 
+   * length of the returned array gives the node's depth in the tree.
    * 
-   * @param value0 TODO
-   * @param value1 TODO
-   * @return TreeNode[]
+   * @param node - the TreeNode to get the path for
+   * @param depth - an int giving the number of steps already taken 
+   * towards the root (on recursive calls), used to size the returned array
+   * @return an array of TreeNodes giving the path from the root to the 
+   * specified node
    */
-  protected TreeNode[] getPathToRoot(TreeNode value0, int value1)
+  protected TreeNode[] getPathToRoot(TreeNode node, int depth)
   {
-    return null; // TODO
+    if (node == null)
+      {
+        if (depth == 0)
+          return null;
+        
+        return new TreeNode[depth];
+      }
+
+    TreeNode[] path = getPathToRoot(node.getParent(), depth + 1);
+    path[path.length - depth - 1] = node;
+    return path;
   }
 
   /**
@@ -392,7 +454,9 @@
   }
 
   /**
-   * fireTreeNodesChanged
+   * Notifies all listeners that have registered interest for notification 
+   * on this event type. The event instance is lazily created using the parameters 
+   * passed into the fire method.
    * 
    * @param source the node being changed
    * @param path the path to the root node
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to