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

📄 automatedtreenode.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                int anIndex = parent.getIndex(this);
                if (anIndex != -1) {
                    int[] cIndexs = new int[1];
                    cIndexs[0] = anIndex;
                    //parent.nodesChanged(cIndexs);
                    Object[] cChildren = new Object[1];
                    cChildren[0] = this;
                    fireTreeNodesChanged(parent.getPath(), cIndexs, cChildren);
                }
            } else if (this == getRoot()) {
                fireTreeNodesChanged(getPath(), null, null);
            }
        }
    }

    /**
     * This method invoked after you've inserted some AutomatedTreeNodes into
     * node. childIndices should be the index of the new elements and must be
     * sorted in ascending order.
     */
    protected void nodesWereInserted(int[] childIndices) {
        if (listenerList != null && childIndices != null
                && childIndices.length > 0) {
            int cCount = childIndices.length;
            Object[] newChildren = new Object[cCount];
            for (int counter = 0; counter < cCount; counter++)
                newChildren[counter] = getChildAt(childIndices[counter]);
            fireTreeNodesInserted(childIndices, newChildren);
        }
    }

    /**
     * This method invoked after you've removed some AutomatedTreeNodes 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.
     */
    protected void nodesWereRemoved(int[] childIndices, Object[] removedChildren) {
        if (childIndices != null) {
            fireTreeNodesRemoved(childIndices, removedChildren);
        }
    }

    /**
     * Invoke this method if you've totally changed the children of node and its
     * childrens children... This will post a treeStructureChanged event.
     */
    protected void nodeStructureChanged() {
        fireTreeStructureChanged(null, null);
    }

    /**
     * Adds a listener for the TreeModelEvent posted after the node changes.
     * 
     * @see #removeTreeModelListener
     * @param l
     *            the listener to add
     */
    public void addTreeModelListener(TreeModelListener l) {
        listenerList.add(TreeModelListener.class, l);
    }

    /**
     * Removes a listener previously added with <B>addTreeModelListener() </B>.
     * 
     * @see #addTreeModelListener
     * @param l
     *            the listener to remove
     */
    public void removeTreeModelListener(TreeModelListener l) {
        listenerList.remove(TreeModelListener.class, l);
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesChanged() method.
     * 
     * @param childIndices
     *            the indices of the changed elements
     * @param children
     *            the changed elements
     * @see EventListenerList
     */
    protected void fireTreeNodesChanged(int[] childIndices, Object[] children) {
        fireTreeNodesChanged(getPath(), childIndices, children);
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesChanged() method.
     * 
     * @param path
     *            the path to the root node
     * @param childIndices
     *            the indices of the changed elements
     * @param children
     *            the changed elements
     * @see EventListenerList
     */
    protected void fireTreeNodesChanged(Object[] path, int[] childIndices,
            Object[] children) {
        fireTreeNodesChanged(this, path, childIndices, children);
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesChanged() 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
     * @see EventListenerList
     */
    protected void fireTreeNodesChanged(Object source, Object[] path,
            int[] childIndices, Object[] children) {
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        TreeModelEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == TreeModelListener.class) {
                // Lazily create the event:
                if (e == null)
                    e = new TreeModelEvent(source, path, childIndices, children);
                ((TreeModelListener) listeners[i + 1]).treeNodesChanged(e);
            }
        }
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesInserted() method.
     * 
     * @param childIndices
     *            the indices of the changed elements
     * @param children
     *            the changed elements
     * @see EventListenerList
     */
    protected void fireTreeNodesInserted(int[] childIndices, Object[] children) {
        fireTreeNodesInserted(this, getPath(), childIndices, children);
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesInserted() 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
     * @see EventListenerList
     */
    protected void fireTreeNodesInserted(Object source, Object[] path,
            int[] childIndices, Object[] children) {
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        TreeModelEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == TreeModelListener.class) {
                // Lazily create the event:
                if (e == null)
                    e = new TreeModelEvent(source, path, childIndices, children);
                ((TreeModelListener) listeners[i + 1]).treeNodesInserted(e);
            }
        }
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesRemoved() method.
     * 
     * @param childIndices
     *            the indices of the changed elements
     * @param children
     *            the changed elements
     * @see EventListenerList
     */
    protected void fireTreeNodesRemoved(int[] childIndices, Object[] children) {
        fireTreeNodesRemoved(this, getPath(), childIndices, children);
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeNodesRemoved() 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
     * @see EventListenerList
     */
    protected void fireTreeNodesRemoved(Object source, Object[] path,
            int[] childIndices, Object[] children) {
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        TreeModelEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == TreeModelListener.class) {
                // Lazily create the event:
                if (e == null)
                    e = new TreeModelEvent(source, path, childIndices, children);
                ((TreeModelListener) listeners[i + 1]).treeNodesRemoved(e);
            }
        }
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeStructureChanged() method.
     * 
     * @param childIndices
     *            the indices of the changed elements
     * @param children
     *            the changed elements
     * @see EventListenerList
     */
    protected void fireTreeStructureChanged(int[] childIndices,
            Object[] children) {
        fireTreeStructureChanged(this, getPath(), childIndices, children);
    }

    /**
     * Notifies all listeners that have registered interest for notification on
     * this event type by firing a treeStructureChanged() 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
     * @see EventListenerList
     */
    protected void fireTreeStructureChanged(Object source, Object[] path,
            int[] childIndices, Object[] children) {
        // Guaranteed to return a non-null array
        Object[] listeners = listenerList.getListenerList();
        TreeModelEvent e = null;
        // Process the listeners last to first, notifying
        // those that are interested in this event
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
            if (listeners[i] == TreeModelListener.class) {
                // Lazily create the event:
                if (e == null)
                    e = new TreeModelEvent(source, path, childIndices, children);
                ((TreeModelListener) listeners[i + 1]).treeStructureChanged(e);
            }
        }
    }
}

⌨️ 快捷键说明

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