⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaulttreemodel.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        fireTreeNodesChanged(this, parentPath, ci, c);      }    }  /**   * 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 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 newChild, MutableTreeNode parent,                             int index)  {    newChild.setParent(parent);    parent.insert(newChild, index);    int[] childIndices = new int[1];    childIndices[0] = index;    nodesWereInserted(parent, childIndices);  }  /**   * 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 node to be removed   */  public void removeNodeFromParent(MutableTreeNode node)  {    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);  }  /**   * Invoke this method after you've changed how node is to be represented   * in the tree.   *    * @param node that was changed   */  public void nodeChanged(TreeNode node)  {    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(node), childIndices, children);  }  /**   * 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 parent that had a child added to   * @param childIndices of the children added   */  public void nodesWereInserted(TreeNode parent, int[] childIndices)  {    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);  }  /**   * 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 parent that had a child added to   * @param childIndices of the children added   * @param removedChildren are all the children removed from parent.   */  public void nodesWereRemoved(TreeNode parent, int[] childIndices,                                Object[] removedChildren)  {    fireTreeNodesRemoved(this, getPathToRoot(parent), childIndices,                          removedChildren);  }  /**   * Invoke this method after you've changed how the children identified by    * childIndices are to be represented in the tree.   *    * @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 node, int[] childIndices)  {    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);  }  /**   * Invoke this method if you've totally changed the children of node and    * its childrens children. This will post a treeStructureChanged event.   *    * @param node that had its children and grandchildren changed.   */  public void nodeStructureChanged(TreeNode node)  {    // TODO  }  /**   * 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 node - the TreeNode to get the path for   * @return TreeNode[] - the path from node to the root   */  public TreeNode[] getPathToRoot(TreeNode node)  {    return getPathToRoot(node, 0);  }  /**   * 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 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 node, int depth)  {    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;  }  /**   * Registers a listere to the model.   *    * @param listener the listener to add   */  public void addTreeModelListener(TreeModelListener listener)  {    listenerList.add(TreeModelListener.class, listener);  }  /**   * Removes a listener from the model.   *    * @param listener the listener to remove   */  public void removeTreeModelListener(TreeModelListener listener)  {    listenerList.remove(TreeModelListener.class, listener);  }  /**   * Returns all registered <code>TreeModelListener</code> listeners.   *    * @return an array of listeners.   *    * @since 1.4   */  public TreeModelListener[] getTreeModelListeners()  {    return (TreeModelListener[]) listenerList        .getListeners(TreeModelListener.class);  }  /**   * 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   * @param childIndices the indices of the changed elements   * @param children the changed elements   */  protected void fireTreeNodesChanged(Object source, Object[] path,      int[] childIndices, Object[] children)  {    TreeModelEvent event = new TreeModelEvent(source, path, childIndices,        children);    TreeModelListener[] listeners = getTreeModelListeners();    for (int i = listeners.length - 1; i >= 0; --i)      listeners[i].treeNodesChanged(event);  }  /**   * fireTreeNodesInserted   *    * @param source the node where new nodes got inserted   * @param path the path to the root node   * @param childIndices the indices of the new elements   * @param children the new elements   */  protected void fireTreeNodesInserted(Object source, Object[] path,      int[] childIndices, Object[] children)  {    TreeModelEvent event = new TreeModelEvent(source, path, childIndices,        children);    TreeModelListener[] listeners = getTreeModelListeners();    for (int i = listeners.length - 1; i >= 0; --i)      listeners[i].treeNodesInserted(event);  }  /**   * fireTreeNodesRemoved   *    * @param source the node where nodes got removed-   * @param path the path to the root node   * @param childIndices the indices of the removed elements   * @param children the removed elements   */  protected void fireTreeNodesRemoved(Object source, Object[] path,      int[] childIndices, Object[] children)  {    TreeModelEvent event = new TreeModelEvent(source, path, childIndices,        children);    TreeModelListener[] listeners = getTreeModelListeners();    for (int i = listeners.length - 1; i >= 0; --i)      listeners[i].treeNodesRemoved(event);  }  /**   * fireTreeStructureChanged   *    * @param source the node where the model has changed   * @param path the path to the root node   * @param childIndices the indices of the affected elements   * @param children the affected elements   */  protected void fireTreeStructureChanged(Object source, Object[] path,      int[] childIndices, Object[] children)  {    TreeModelEvent event = new TreeModelEvent(source, path, childIndices,        children);    TreeModelListener[] listeners = getTreeModelListeners();    for (int i = listeners.length - 1; i >= 0; --i)      listeners[i].treeStructureChanged(event);  }  /**   * Returns the registered listeners of a given type.   *   * @param listenerType the listener type to return   *   * @return an array of listeners   *   * @since 1.3   */  public EventListener[] getListeners(Class listenerType)  {    return listenerList.getListeners(listenerType);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -