Java Code Examples for javax.swing.event.TreeModelEvent#getChildIndices()
The following examples show how to use
javax.swing.event.TreeModelEvent#getChildIndices() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixedHeightLayoutCache.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * <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(); } } }
Example 2
Source File: FixedHeightLayoutCache.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * <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(); } } } }
Example 3
Source File: FixedHeightLayoutCache.java From Java8CN with Apache License 2.0 | 5 votes |
/** * <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(); } } } }
Example 4
Source File: SubTreeModel.java From pdfxtk with Apache License 2.0 | 5 votes |
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); }
Example 5
Source File: FixedHeightLayoutCache.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * <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(); } } }
Example 6
Source File: EventBroadcaster.java From netbeans with Apache License 2.0 | 5 votes |
/** 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; }
Example 7
Source File: FixedHeightLayoutCache.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * <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(); } } }
Example 8
Source File: FixedHeightLayoutCache.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * <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(); } } }
Example 9
Source File: VariableHeightLayoutCache.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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(); } } }
Example 10
Source File: VariableHeightLayoutCache.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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()); } } } }
Example 11
Source File: VariableHeightLayoutCache.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * 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()); } } } }
Example 12
Source File: VariableHeightLayoutCache.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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()); } } } }
Example 13
Source File: VariableHeightLayoutCache.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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(); } } }
Example 14
Source File: ProgramTreeModelListener.java From ghidra with Apache License 2.0 | 4 votes |
/** * 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); }
Example 15
Source File: VariableHeightLayoutCache.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * 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(); } } }
Example 16
Source File: VariableHeightLayoutCache.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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(); } } }
Example 17
Source File: VariableHeightLayoutCache.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * 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()); } } } }
Example 18
Source File: VariableHeightLayoutCache.java From Java8CN with Apache License 2.0 | 4 votes |
/** * 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(); } } }
Example 19
Source File: VariableHeightLayoutCache.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * 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()); } } } }
Example 20
Source File: VariableHeightLayoutCache.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * 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()); } } } }