javax.swing.event.TreeModelEvent#getChildIndices()源码实例Demo

下面列出了javax.swing.event.TreeModelEvent#getChildIndices() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * <p>Invoked after nodes have been inserted into the tree.</p>
 *
 * <p>e.path() returns the parent of the new nodes
 * <p>e.childIndices() returns the indices of the new nodes in
 * ascending order.
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParent != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            boolean          isVisible =
                (changedParent.isVisible() &&
                 changedParent.isExpanded());

            for(int counter = 0; counter < maxCounter; counter++) {
                changedParent.childInsertedAtModelIndex
                    (changedIndexs[counter], isVisible);
            }
            if(isVisible && treeSelectionModel != null)
                treeSelectionModel.resetRowSelection();
            if(changedParent.isVisible())
                this.visibleNodesChanged();
        }
    }
}
 
源代码2 项目: Java8CN   文件: FixedHeightLayoutCache.java
/**
 * <p>Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.</p>
 *
 * <p>e.path() returns the path the parent of the changed node(s).</p>
 *
 * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if (changedParent != null) {
            if (changedIndexs != null &&
                (maxCounter = changedIndexs.length) > 0) {
                Object       parentValue = changedParent.getUserObject();

                for(int counter = 0; counter < maxCounter; counter++) {
                    FHTreeStateNode    child = changedParent.
                             getChildAtModelIndex(changedIndexs[counter]);

                    if(child != null) {
                        child.setUserObject(treeModel.getChild(parentValue,
                                                 changedIndexs[counter]));
                    }
                }
                if(changedParent.isVisible() && changedParent.isExpanded())
                    visibleNodesChanged();
            }
            // Null for root indicates it changed.
            else if (changedParent == root && changedParent.isVisible() &&
                     changedParent.isExpanded()) {
                visibleNodesChanged();
            }
        }
    }
}
 
源代码3 项目: JDKSourceCode1.8   文件: FixedHeightLayoutCache.java
/**
 * <p>Invoked after nodes have been inserted into the tree.</p>
 *
 * <p>e.path() returns the parent of the new nodes
 * <p>e.childIndices() returns the indices of the new nodes in
 * ascending order.
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParent != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            boolean          isVisible =
                (changedParent.isVisible() &&
                 changedParent.isExpanded());

            for(int counter = 0; counter < maxCounter; counter++) {
                changedParent.childInsertedAtModelIndex
                    (changedIndexs[counter], isVisible);
            }
            if(isVisible && treeSelectionModel != null)
                treeSelectionModel.resetRowSelection();
            if(changedParent.isVisible())
                this.visibleNodesChanged();
        }
    }
}
 
源代码4 项目: netbeans   文件: EventBroadcaster.java
/** Creates an identical TreeModelEvent with the model we are proxying
 * as the event source */
private TreeModelEvent translateEvent (TreeModelEvent e) {
    //Create a new TreeModelEvent with us as the source
    TreeModelEvent nue = new TreeModelEvent (getModel(), e.getPath(), 
        e.getChildIndices(), e.getChildren());
    return nue;
}
 
源代码5 项目: openjdk-jdk9   文件: FixedHeightLayoutCache.java
/**
 * <p>Invoked after nodes have been inserted into the tree.</p>
 *
 * <p>e.path() returns the parent of the new nodes
 * <p>e.childIndices() returns the indices of the new nodes in
 * ascending order.
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParent != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            boolean          isVisible =
                (changedParent.isVisible() &&
                 changedParent.isExpanded());

            for(int counter = 0; counter < maxCounter; counter++) {
                changedParent.childInsertedAtModelIndex
                    (changedIndexs[counter], isVisible);
            }
            if(isVisible && treeSelectionModel != null)
                treeSelectionModel.resetRowSelection();
            if(changedParent.isVisible())
                this.visibleNodesChanged();
        }
    }
}
 
源代码6 项目: openjdk-8-source   文件: FixedHeightLayoutCache.java
/**
 * <p>Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.</p>
 *
 * <p>e.path() returns the former parent of the deleted nodes.</p>
 *
 * <p>e.childIndices() returns the indices the nodes had before they were deleted in ascending order.</p>
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int                  changedIndexs[];
        int                  maxCounter;
        TreePath             parentPath = SwingUtilities2.getTreePath(e, getModel());
        FHTreeStateNode      changedParentNode = getNodeForPath
                                   (parentPath, false, false);

        changedIndexs = e.getChildIndices();
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           (maxCounter = changedIndexs.length) > 0) {
            Object[]           children = e.getChildren();
            boolean            isVisible =
                (changedParentNode.isVisible() &&
                 changedParentNode.isExpanded());

            for(int counter = maxCounter - 1; counter >= 0; counter--) {
                changedParentNode.removeChildAtModelIndex
                                 (changedIndexs[counter], isVisible);
            }
            if(isVisible) {
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                if (treeModel.getChildCount(changedParentNode.
                                            getUserObject()) == 0 &&
                              changedParentNode.isLeaf()) {
                    // Node has become a leaf, collapse it.
                    changedParentNode.collapse(false);
                }
                visibleNodesChanged();
            }
            else if(changedParentNode.isVisible())
                visibleNodesChanged();
        }
    }
}
 
源代码7 项目: pdfxtk   文件: SubTreeModel.java
public void treeNodesChanged(TreeModelEvent e) {
  if(!Util.contains(e.getTreePath().getPath(), root)) return;
  TreeModelListener[] listeners = (TreeModelListener[])listenerList.getListeners(TreeModelListener.class);
  TreeModelEvent ev = listeners.length == 0 ? 
    null : 
    new TreeModelEvent(this, relative(e.getTreePath()), e.getChildIndices(), e.getChildren());
  for(int i = 0; i < listeners.length; i++)
    listeners[i].treeNodesChanged(ev);
}
 
源代码8 项目: jdk8u_jdk   文件: FixedHeightLayoutCache.java
/**
 * <p>Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.</p>
 *
 * <p>e.path() returns the path the parent of the changed node(s).</p>
 *
 * <p>e.childIndices() returns the index(es) of the changed node(s).</p>
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int                 changedIndexs[];
        FHTreeStateNode     changedParent = getNodeForPath
                              (SwingUtilities2.getTreePath(e, getModel()), false, false);
        int                 maxCounter;

        changedIndexs = e.getChildIndices();
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if (changedParent != null) {
            if (changedIndexs != null &&
                (maxCounter = changedIndexs.length) > 0) {
                Object       parentValue = changedParent.getUserObject();

                for(int counter = 0; counter < maxCounter; counter++) {
                    FHTreeStateNode    child = changedParent.
                             getChildAtModelIndex(changedIndexs[counter]);

                    if(child != null) {
                        child.setUserObject(treeModel.getChild(parentValue,
                                                 changedIndexs[counter]));
                    }
                }
                if(changedParent.isVisible() && changedParent.isExpanded())
                    visibleNodesChanged();
            }
            // Null for root indicates it changed.
            else if (changedParent == root && changedParent.isVisible() &&
                     changedParent.isExpanded()) {
                visibleNodesChanged();
            }
        }
    }
}
 
/**
 * Invoked after nodes have been inserted into the tree.
 *
 * <p><code>e.path</code> returns the parent of the new nodes.
 * <p><code>e.childIndices</code> returns the indices of the new nodes in
 * ascending order.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedParentNode;

        changedIndexs = e.getChildIndices();
        changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParentNode != null && changedIndexs != null &&
           changedIndexs.length > 0) {
            if(changedParentNode.hasBeenExpanded()) {
                boolean            makeVisible;
                int                counter;
                Object             changedParent;
                TreeStateNode      newNode;
                int                oldChildCount = changedParentNode.
                                      getChildCount();

                changedParent = changedParentNode.getValue();
                makeVisible = ((changedParentNode == root &&
                                !rootVisible) ||
                               (changedParentNode.getRow() != -1 &&
                                changedParentNode.isExpanded()));
                for(counter = 0;counter < changedIndexs.length;counter++)
                {
                    newNode = this.createNodeAt(changedParentNode,
                                                changedIndexs[counter]);
                }
                if(oldChildCount == 0) {
                    // Update the size of the parent.
                    changedParentNode.updatePreferredSize();
                }
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                /* Update the y origins from the index of the parent
                   to the end of the visible rows. */
                if(!isFixedRowHeight() && (makeVisible ||
                                           (oldChildCount == 0 &&
                                    changedParentNode.isVisible()))) {
                    if(changedParentNode == root)
                        this.updateYLocationsFrom(0);
                    else
                        this.updateYLocationsFrom(changedParentNode.
                                                  getRow());
                    this.visibleNodesChanged();
                }
                else if(makeVisible)
                    this.visibleNodesChanged();
            }
            else if(treeModel.getChildCount(changedParentNode.getValue())
                    - changedIndexs.length == 0) {
                changedParentNode.updatePreferredSize();
                if(!isFixedRowHeight() && changedParentNode.isVisible())
                    updateYLocationsFrom(changedParentNode.getRow());
            }
        }
    }
}
 
源代码10 项目: openjdk-8   文件: VariableHeightLayoutCache.java
/**
 * Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.
 *
 * <p><code>e.path</code> returns the former parent of the deleted nodes.
 *
 * <p><code>e.childIndices</code> returns the indices the nodes had
 * before they were deleted in ascending order.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedParentNode;

        changedIndexs = e.getChildIndices();
        changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           changedIndexs.length > 0) {
            if(changedParentNode.hasBeenExpanded()) {
                boolean            makeInvisible;
                int                counter;
                int                removedRow;
                TreeStateNode      removedNode;

                makeInvisible = ((changedParentNode == root &&
                                  !rootVisible) ||
                                 (changedParentNode.getRow() != -1 &&
                                  changedParentNode.isExpanded()));
                for(counter = changedIndexs.length - 1;counter >= 0;
                    counter--) {
                    removedNode = (TreeStateNode)changedParentNode.
                            getChildAt(changedIndexs[counter]);
                    if(removedNode.isExpanded()) {
                        removedNode.collapse(false);
                    }

                    /* Let the selection model now. */
                    if(makeInvisible) {
                        removedRow = removedNode.getRow();
                        if(removedRow != -1) {
                            visibleNodes.removeElementAt(removedRow);
                        }
                    }
                    changedParentNode.remove(changedIndexs[counter]);
                }
                if(changedParentNode.getChildCount() == 0) {
                    // Update the size of the parent.
                    changedParentNode.updatePreferredSize();
                    if (changedParentNode.isExpanded() &&
                               changedParentNode.isLeaf()) {
                        // Node has become a leaf, collapse it.
                        changedParentNode.collapse(false);
                    }
                }
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                /* Update the y origins from the index of the parent
                   to the end of the visible rows. */
                if(!isFixedRowHeight() && (makeInvisible ||
                           (changedParentNode.getChildCount() == 0 &&
                            changedParentNode.isVisible()))) {
                    if(changedParentNode == root) {
                        /* It is possible for first row to have been
                           removed if the root isn't visible, in which
                           case ylocations will be off! */
                        if(getRowCount() > 0)
                            getNode(0).setYOrigin(0);
                        updateYLocationsFrom(0);
                    }
                    else
                        updateYLocationsFrom(changedParentNode.getRow());
                    this.visibleNodesChanged();
                }
                else if(makeInvisible)
                    this.visibleNodesChanged();
            }
            else if(treeModel.getChildCount(changedParentNode.getValue())
                    == 0) {
                changedParentNode.updatePreferredSize();
                if(!isFixedRowHeight() && changedParentNode.isVisible())
                    this.updateYLocationsFrom(changedParentNode.getRow());
            }
        }
    }
}
 
源代码11 项目: Java8CN   文件: VariableHeightLayoutCache.java
/**
 * Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.
 *
 * <p><code>e.path</code> returns the path the parent of the
 * changed node(s).
 *
 * <p><code>e.childIndices</code> returns the index(es) of the
 * changed node(s).
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedNode;

        changedIndexs = e.getChildIndices();
        changedNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        if(changedNode != null) {
            Object            changedValue = changedNode.getValue();

            /* Update the size of the changed node, as well as all the
               child indexs that are passed in. */
            changedNode.updatePreferredSize();
            if(changedNode.hasBeenExpanded() && changedIndexs != null) {
                int                counter;
                TreeStateNode      changedChildNode;

                for(counter = 0; counter < changedIndexs.length;
                    counter++) {
                    changedChildNode = (TreeStateNode)changedNode
                                .getChildAt(changedIndexs[counter]);
                    /* Reset the user object. */
                    changedChildNode.setUserObject
                                (treeModel.getChild(changedValue,
                                                 changedIndexs[counter]));
                    changedChildNode.updatePreferredSize();
                }
            }
            else if (changedNode == root) {
                // Null indicies for root indicates it changed.
                changedNode.updatePreferredSize();
            }
            if(!isFixedRowHeight()) {
                int          aRow = changedNode.getRow();

                if(aRow != -1)
                    this.updateYLocationsFrom(aRow);
            }
            this.visibleNodesChanged();
        }
    }
}
 
源代码12 项目: hottub   文件: VariableHeightLayoutCache.java
/**
 * Invoked after nodes have been inserted into the tree.
 *
 * <p><code>e.path</code> returns the parent of the new nodes.
 * <p><code>e.childIndices</code> returns the indices of the new nodes in
 * ascending order.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedParentNode;

        changedIndexs = e.getChildIndices();
        changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParentNode != null && changedIndexs != null &&
           changedIndexs.length > 0) {
            if(changedParentNode.hasBeenExpanded()) {
                boolean            makeVisible;
                int                counter;
                Object             changedParent;
                TreeStateNode      newNode;
                int                oldChildCount = changedParentNode.
                                      getChildCount();

                changedParent = changedParentNode.getValue();
                makeVisible = ((changedParentNode == root &&
                                !rootVisible) ||
                               (changedParentNode.getRow() != -1 &&
                                changedParentNode.isExpanded()));
                for(counter = 0;counter < changedIndexs.length;counter++)
                {
                    newNode = this.createNodeAt(changedParentNode,
                                                changedIndexs[counter]);
                }
                if(oldChildCount == 0) {
                    // Update the size of the parent.
                    changedParentNode.updatePreferredSize();
                }
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                /* Update the y origins from the index of the parent
                   to the end of the visible rows. */
                if(!isFixedRowHeight() && (makeVisible ||
                                           (oldChildCount == 0 &&
                                    changedParentNode.isVisible()))) {
                    if(changedParentNode == root)
                        this.updateYLocationsFrom(0);
                    else
                        this.updateYLocationsFrom(changedParentNode.
                                                  getRow());
                    this.visibleNodesChanged();
                }
                else if(makeVisible)
                    this.visibleNodesChanged();
            }
            else if(treeModel.getChildCount(changedParentNode.getValue())
                    - changedIndexs.length == 0) {
                changedParentNode.updatePreferredSize();
                if(!isFixedRowHeight() && changedParentNode.isVisible())
                    updateYLocationsFrom(changedParentNode.getRow());
            }
        }
    }
}
 
/**
 * Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.
 *
 * <p><code>e.path</code> returns the path the parent of the
 * changed node(s).
 *
 * <p><code>e.childIndices</code> returns the index(es) of the
 * changed node(s).
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedNode;

        changedIndexs = e.getChildIndices();
        changedNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        if(changedNode != null) {
            Object            changedValue = changedNode.getValue();

            /* Update the size of the changed node, as well as all the
               child indexs that are passed in. */
            changedNode.updatePreferredSize();
            if(changedNode.hasBeenExpanded() && changedIndexs != null) {
                int                counter;
                TreeStateNode      changedChildNode;

                for(counter = 0; counter < changedIndexs.length;
                    counter++) {
                    changedChildNode = (TreeStateNode)changedNode
                                .getChildAt(changedIndexs[counter]);
                    /* Reset the user object. */
                    changedChildNode.setUserObject
                                (treeModel.getChild(changedValue,
                                                 changedIndexs[counter]));
                    changedChildNode.updatePreferredSize();
                }
            }
            else if (changedNode == root) {
                // Null indicies for root indicates it changed.
                changedNode.updatePreferredSize();
            }
            if(!isFixedRowHeight()) {
                int          aRow = changedNode.getRow();

                if(aRow != -1)
                    this.updateYLocationsFrom(aRow);
            }
            this.visibleNodesChanged();
        }
    }
}
 
/**
 * Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.
 *
 * <p><code>e.path</code> returns the path the parent of the
 * changed node(s).
 *
 * <p><code>e.childIndices</code> returns the index(es) of the
 * changed node(s).
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedNode;

        changedIndexs = e.getChildIndices();
        changedNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        if(changedNode != null) {
            Object            changedValue = changedNode.getValue();

            /* Update the size of the changed node, as well as all the
               child indexs that are passed in. */
            changedNode.updatePreferredSize();
            if(changedNode.hasBeenExpanded() && changedIndexs != null) {
                int                counter;
                TreeStateNode      changedChildNode;

                for(counter = 0; counter < changedIndexs.length;
                    counter++) {
                    changedChildNode = (TreeStateNode)changedNode
                                .getChildAt(changedIndexs[counter]);
                    /* Reset the user object. */
                    changedChildNode.setUserObject
                                (treeModel.getChild(changedValue,
                                                 changedIndexs[counter]));
                    changedChildNode.updatePreferredSize();
                }
            }
            else if (changedNode == root) {
                // Null indicies for root indicates it changed.
                changedNode.updatePreferredSize();
            }
            if(!isFixedRowHeight()) {
                int          aRow = changedNode.getRow();

                if(aRow != -1)
                    this.updateYLocationsFrom(aRow);
            }
            this.visibleNodesChanged();
        }
    }
}
 
源代码15 项目: ghidra   文件: ProgramTreeModelListener.java
/**
 * Called when a node changes; update the Group name for the node being changed.
 */
@Override
public void treeNodesChanged(TreeModelEvent e) {
	ProgramNode node = (ProgramNode) e.getTreePath().getLastPathComponent();

	int[] indices = e.getChildIndices();
	if (indices != null) {
		node = (ProgramNode) node.getChildAt(indices[0]);
	}

	String newName = node.getUserObject().toString().trim();
	if (newName.isEmpty()) {

		node.setUserObject(node.getName());
		Msg.showError(this, null, "Rename Failed", "Please enter a name.");

		// maintain the editing state
		SystemUtilities.runSwingLater(() -> tree.rename());
		return;
	}

	Group group = node.getGroup();
	String oldName = group.getName();
	if (newName.equals(oldName)) {
		return;    // name hasn't changed
	}

	RenameCmd cmd =
		new RenameCmd(tree.getTreeName(), (group instanceof ProgramModule), oldName, newName);
	if (tree.getTool().execute(cmd, tree.getProgram())) {

		StringKeyIndexer nameIndexer = tree.getNameIndexer();
		nameIndexer.remove(oldName);
		nameIndexer.put(newName);
	}
	else {
		node.setUserObject(node.getName());
		Msg.showError(this, tree, "Rename Failed", cmd.getStatusMsg());

		// maintain the editing state
		SystemUtilities.runSwingLater(() -> tree.rename());
	}
	tree.setEditable(false);
}
 
源代码16 项目: TencentKona-8   文件: VariableHeightLayoutCache.java
/**
 * Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.
 *
 * <p><code>e.path</code> returns the path the parent of the
 * changed node(s).
 *
 * <p><code>e.childIndices</code> returns the index(es) of the
 * changed node(s).
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedNode;

        changedIndexs = e.getChildIndices();
        changedNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        if(changedNode != null) {
            Object            changedValue = changedNode.getValue();

            /* Update the size of the changed node, as well as all the
               child indexs that are passed in. */
            changedNode.updatePreferredSize();
            if(changedNode.hasBeenExpanded() && changedIndexs != null) {
                int                counter;
                TreeStateNode      changedChildNode;

                for(counter = 0; counter < changedIndexs.length;
                    counter++) {
                    changedChildNode = (TreeStateNode)changedNode
                                .getChildAt(changedIndexs[counter]);
                    /* Reset the user object. */
                    changedChildNode.setUserObject
                                (treeModel.getChild(changedValue,
                                                 changedIndexs[counter]));
                    changedChildNode.updatePreferredSize();
                }
            }
            else if (changedNode == root) {
                // Null indicies for root indicates it changed.
                changedNode.updatePreferredSize();
            }
            if(!isFixedRowHeight()) {
                int          aRow = changedNode.getRow();

                if(aRow != -1)
                    this.updateYLocationsFrom(aRow);
            }
            this.visibleNodesChanged();
        }
    }
}
 
源代码17 项目: TencentKona-8   文件: VariableHeightLayoutCache.java
/**
 * Invoked after nodes have been inserted into the tree.
 *
 * <p><code>e.path</code> returns the parent of the new nodes.
 * <p><code>e.childIndices</code> returns the indices of the new nodes in
 * ascending order.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedParentNode;

        changedIndexs = e.getChildIndices();
        changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParentNode != null && changedIndexs != null &&
           changedIndexs.length > 0) {
            if(changedParentNode.hasBeenExpanded()) {
                boolean            makeVisible;
                int                counter;
                Object             changedParent;
                TreeStateNode      newNode;
                int                oldChildCount = changedParentNode.
                                      getChildCount();

                changedParent = changedParentNode.getValue();
                makeVisible = ((changedParentNode == root &&
                                !rootVisible) ||
                               (changedParentNode.getRow() != -1 &&
                                changedParentNode.isExpanded()));
                for(counter = 0;counter < changedIndexs.length;counter++)
                {
                    newNode = this.createNodeAt(changedParentNode,
                                                changedIndexs[counter]);
                }
                if(oldChildCount == 0) {
                    // Update the size of the parent.
                    changedParentNode.updatePreferredSize();
                }
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                /* Update the y origins from the index of the parent
                   to the end of the visible rows. */
                if(!isFixedRowHeight() && (makeVisible ||
                                           (oldChildCount == 0 &&
                                    changedParentNode.isVisible()))) {
                    if(changedParentNode == root)
                        this.updateYLocationsFrom(0);
                    else
                        this.updateYLocationsFrom(changedParentNode.
                                                  getRow());
                    this.visibleNodesChanged();
                }
                else if(makeVisible)
                    this.visibleNodesChanged();
            }
            else if(treeModel.getChildCount(changedParentNode.getValue())
                    - changedIndexs.length == 0) {
                changedParentNode.updatePreferredSize();
                if(!isFixedRowHeight() && changedParentNode.isVisible())
                    updateYLocationsFrom(changedParentNode.getRow());
            }
        }
    }
}
 
/**
 * Invoked after nodes have been removed from the tree.  Note that
 * if a subtree is removed from the tree, this method may only be
 * invoked once for the root of the removed subtree, not once for
 * each individual set of siblings removed.
 *
 * <p><code>e.path</code> returns the former parent of the deleted nodes.
 *
 * <p><code>e.childIndices</code> returns the indices the nodes had
 * before they were deleted in ascending order.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesRemoved(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedParentNode;

        changedIndexs = e.getChildIndices();
        changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        // PENDING(scott): make sure that changedIndexs are sorted in
        // ascending order.
        if(changedParentNode != null && changedIndexs != null &&
           changedIndexs.length > 0) {
            if(changedParentNode.hasBeenExpanded()) {
                boolean            makeInvisible;
                int                counter;
                int                removedRow;
                TreeStateNode      removedNode;

                makeInvisible = ((changedParentNode == root &&
                                  !rootVisible) ||
                                 (changedParentNode.getRow() != -1 &&
                                  changedParentNode.isExpanded()));
                for(counter = changedIndexs.length - 1;counter >= 0;
                    counter--) {
                    removedNode = (TreeStateNode)changedParentNode.
                            getChildAt(changedIndexs[counter]);
                    if(removedNode.isExpanded()) {
                        removedNode.collapse(false);
                    }

                    /* Let the selection model now. */
                    if(makeInvisible) {
                        removedRow = removedNode.getRow();
                        if(removedRow != -1) {
                            visibleNodes.removeElementAt(removedRow);
                        }
                    }
                    changedParentNode.remove(changedIndexs[counter]);
                }
                if(changedParentNode.getChildCount() == 0) {
                    // Update the size of the parent.
                    changedParentNode.updatePreferredSize();
                    if (changedParentNode.isExpanded() &&
                               changedParentNode.isLeaf()) {
                        // Node has become a leaf, collapse it.
                        changedParentNode.collapse(false);
                    }
                }
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                /* Update the y origins from the index of the parent
                   to the end of the visible rows. */
                if(!isFixedRowHeight() && (makeInvisible ||
                           (changedParentNode.getChildCount() == 0 &&
                            changedParentNode.isVisible()))) {
                    if(changedParentNode == root) {
                        /* It is possible for first row to have been
                           removed if the root isn't visible, in which
                           case ylocations will be off! */
                        if(getRowCount() > 0)
                            getNode(0).setYOrigin(0);
                        updateYLocationsFrom(0);
                    }
                    else
                        updateYLocationsFrom(changedParentNode.getRow());
                    this.visibleNodesChanged();
                }
                else if(makeInvisible)
                    this.visibleNodesChanged();
            }
            else if(treeModel.getChildCount(changedParentNode.getValue())
                    == 0) {
                changedParentNode.updatePreferredSize();
                if(!isFixedRowHeight() && changedParentNode.isVisible())
                    this.updateYLocationsFrom(changedParentNode.getRow());
            }
        }
    }
}
 
源代码19 项目: jdk8u-jdk   文件: VariableHeightLayoutCache.java
/**
 * Invoked after nodes have been inserted into the tree.
 *
 * <p><code>e.path</code> returns the parent of the new nodes.
 * <p><code>e.childIndices</code> returns the indices of the new nodes in
 * ascending order.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesInserted(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedParentNode;

        changedIndexs = e.getChildIndices();
        changedParentNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        /* Only need to update the children if the node has been
           expanded once. */
        // PENDING(scott): make sure childIndexs is sorted!
        if(changedParentNode != null && changedIndexs != null &&
           changedIndexs.length > 0) {
            if(changedParentNode.hasBeenExpanded()) {
                boolean            makeVisible;
                int                counter;
                Object             changedParent;
                TreeStateNode      newNode;
                int                oldChildCount = changedParentNode.
                                      getChildCount();

                changedParent = changedParentNode.getValue();
                makeVisible = ((changedParentNode == root &&
                                !rootVisible) ||
                               (changedParentNode.getRow() != -1 &&
                                changedParentNode.isExpanded()));
                for(counter = 0;counter < changedIndexs.length;counter++)
                {
                    newNode = this.createNodeAt(changedParentNode,
                                                changedIndexs[counter]);
                }
                if(oldChildCount == 0) {
                    // Update the size of the parent.
                    changedParentNode.updatePreferredSize();
                }
                if(treeSelectionModel != null)
                    treeSelectionModel.resetRowSelection();
                /* Update the y origins from the index of the parent
                   to the end of the visible rows. */
                if(!isFixedRowHeight() && (makeVisible ||
                                           (oldChildCount == 0 &&
                                    changedParentNode.isVisible()))) {
                    if(changedParentNode == root)
                        this.updateYLocationsFrom(0);
                    else
                        this.updateYLocationsFrom(changedParentNode.
                                                  getRow());
                    this.visibleNodesChanged();
                }
                else if(makeVisible)
                    this.visibleNodesChanged();
            }
            else if(treeModel.getChildCount(changedParentNode.getValue())
                    - changedIndexs.length == 0) {
                changedParentNode.updatePreferredSize();
                if(!isFixedRowHeight() && changedParentNode.isVisible())
                    updateYLocationsFrom(changedParentNode.getRow());
            }
        }
    }
}
 
源代码20 项目: jdk8u-jdk   文件: VariableHeightLayoutCache.java
/**
 * Invoked after a node (or a set of siblings) has changed in some
 * way. The node(s) have not changed locations in the tree or
 * altered their children arrays, but other attributes have
 * changed and may affect presentation. Example: the name of a
 * file has changed, but it is in the same location in the file
 * system.
 *
 * <p><code>e.path</code> returns the path the parent of the
 * changed node(s).
 *
 * <p><code>e.childIndices</code> returns the index(es) of the
 * changed node(s).
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeNodesChanged(TreeModelEvent e) {
    if(e != null) {
        int               changedIndexs[];
        TreeStateNode     changedNode;

        changedIndexs = e.getChildIndices();
        changedNode = getNodeForPath(SwingUtilities2.getTreePath(e, getModel()), false, false);
        if(changedNode != null) {
            Object            changedValue = changedNode.getValue();

            /* Update the size of the changed node, as well as all the
               child indexs that are passed in. */
            changedNode.updatePreferredSize();
            if(changedNode.hasBeenExpanded() && changedIndexs != null) {
                int                counter;
                TreeStateNode      changedChildNode;

                for(counter = 0; counter < changedIndexs.length;
                    counter++) {
                    changedChildNode = (TreeStateNode)changedNode
                                .getChildAt(changedIndexs[counter]);
                    /* Reset the user object. */
                    changedChildNode.setUserObject
                                (treeModel.getChild(changedValue,
                                                 changedIndexs[counter]));
                    changedChildNode.updatePreferredSize();
                }
            }
            else if (changedNode == root) {
                // Null indicies for root indicates it changed.
                changedNode.updatePreferredSize();
            }
            if(!isFixedRowHeight()) {
                int          aRow = changedNode.getRow();

                if(aRow != -1)
                    this.updateYLocationsFrom(aRow);
            }
            this.visibleNodesChanged();
        }
    }
}