Java Code Examples for javax.swing.event.TreeModelEvent

The following examples show how to use javax.swing.event.TreeModelEvent. These examples are extracted from open source projects. 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 Project: spotbugs   Source File: BugTreeModel.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
public void sortBranch(TreePath pathToBranch) {
    BugSet bs = bugSet.query((BugAspects) pathToBranch.getLastPathComponent());
    bs.sortList();
    Debug.println("Data in sorted branch: " + pathToBranch.getLastPathComponent());
    for (BugLeafNode b : bs) {
        Debug.println(b);
    }

    Object[] children = new Object[getChildCount(pathToBranch.getLastPathComponent())];
    int[] childIndices = new int[children.length];
    for (int x = 0; x < children.length; x++) {
        children[x] = getChild(pathToBranch.getLastPathComponent(), x);
        childIndices[x] = x;
    }
    for (TreeModelListener l : listeners) {
        TreeModelEvent event = new TreeModelEvent(this, pathToBranch, childIndices, children);
        l.treeNodesChanged(event);
    }

}
 
Example 2
Source Project: netbeans-mmd-plugin   Source File: NodeProjectGroup.java    License: Apache License 2.0 6 votes vote down vote up
@Nonnull
public NodeProject addProjectFolder(@Nonnull final File folder) throws IOException {
  NodeProject newProject = findForFolder(folder);
  if (newProject == null) {
    newProject = new NodeProject(this, folder);

    final int index = this.children.size();
    this.children.add(newProject);

    final TreeModelEvent event = new TreeModelEvent(this, new Object[]{this}, new int[]{index}, new Object[]{newProject});
    for (final TreeModelListener l : this.listeners) {
      l.treeNodesInserted(event);
    }
  }
  return newProject;
}
 
Example 3
Source Project: pcgen   Source File: JTreeTable.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void treeNodesChanged(TreeModelEvent e)
{
	TreePath parentPath = e.getTreePath();
	int leadingRow = Integer.MAX_VALUE;
	int trailingRow = -1;
	if (e.getChildren() != null)
	{
		for (Object node : e.getChildren())
		{
			TreePath childPath = parentPath.pathByAddingChild(node);
			int row = tree.getRowForPath(childPath);
			leadingRow = Math.min(leadingRow, row);
			trailingRow = Math.max(trailingRow, row);
		}
	}
	fireTableRowsUpdated(leadingRow, trailingRow);
}
 
Example 4
Source Project: ghidra   Source File: GTreeModel.java    License: Apache License 2.0 6 votes vote down vote up
public void fireNodeAdded(final GTreeNode parentNode, final GTreeNode newNode) {
	if (!eventsEnabled) {
		return;
	}
	SystemUtilities.assertThisIsTheSwingThread(
		"GTreeModel.fireNodeAdded() must be " + "called from the AWT thread");

	GTreeNode parent = convertToViewNode(parentNode);
	if (parent == null) {  // it will be null if filtered out
		return;
	}

	int index = parent.getIndexOfChild(newNode);
	if (index < 0) {
		// the index will be -1 if filtered out
		return;
	}
	TreeModelEvent event = new TreeModelEvent(this, parent.getTreePath(), new int[] { index },
		new Object[] { newNode });
	for (TreeModelListener listener : listeners) {
		listener.treeNodesInserted(event);
	}
}
 
Example 5
Source Project: ghidra   Source File: GTreeModel.java    License: Apache License 2.0 6 votes vote down vote up
private TreeModelEvent getChangedNodeEvent(GTreeNode changedNode) {
	GTreeNode parentNode = changedNode.getParent();
	if (parentNode == null) { // tree requires different event form when it is the root that changes
		return new TreeModelEvent(this, root.getTreePath(), null, null);
	}

	GTreeNode node = convertToViewNode(changedNode);
	if (node == null) {
		return null;
	}

	int indexInParent = node.getIndexInParent();
	if (indexInParent < 0) {
		return null;
	}

	return new TreeModelEvent(this, node.getParent().getTreePath(), new int[] { indexInParent },
		new Object[] { changedNode });

}
 
Example 6
Source Project: ghidra   Source File: ProgramTreeModelListener.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Method called when nodes are being inserted into the tree; update the treePath and the 
 * group path fields in the ProgramNode object.
 */
@Override
public void treeNodesInserted(TreeModelEvent e) {

	Object[] path = e.getPath();
	Object[] me = e.getChildren();

	// build the tree path for the node being inserted
	Object[] childPath = new Object[path.length + 1];
	System.arraycopy(path, 0, childPath, 0, path.length);
	childPath[childPath.length - 1] = me[0];

	ProgramNode node = (ProgramNode) me[0];

	node.setTreePath(new TreePath(childPath));

	// set up GroupPath
	tree.setGroupPath(node);
}
 
Example 7
public void fireParameterRemoved( final ParameterDefinitionEntry parameter ) {
  final TreePath pathForNode = new TreePath( new Object[] { getRoot(), getReportParametersNode() } );
  final TreeModelListener[] treeModelListeners = getListeners();
  final int index = findParameterInCache( parameter );
  if ( index == -1 ) {
    return;
  }

  final TreeModelEvent treeEvent = new TreeModelEvent( this, pathForNode,
    new int[] { index }, new Object[] { parameter } );
  for ( int i = treeModelListeners.length - 1; i >= 0; i -= 1 ) {
    final TreeModelListener listener = treeModelListeners[ i ];
    listener.treeNodesRemoved( treeEvent );
  }

  refreshParameterCache();
}
 
Example 8
/**
 * <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 Project: snap-desktop   Source File: LayerTreeModel.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void fireTreeNodesRemoved(Layer parentLayer) {
    TreeModelEvent event = createTreeModelEvent(parentLayer);
    if (event == null) {
        return;
    }
    for (TreeModelListener treeModelListener : treeModelListeners.keySet()) {
        treeModelListener.treeNodesRemoved(event);
    }
}
 
Example 10
Source Project: netbeans   Source File: LanguagesNavigatorModel.java    License: Apache License 2.0 5 votes vote down vote up
private void fireRemove(ASTNavigatorNode node, int[] indices, ASTNavigatorNode[] children,
        LinkedList<ASTNavigatorNode> nodePath) {
    TreeModelListener[] listeners = listenerList.getListeners (TreeModelListener.class);
    if (listeners.length == 0) return;
    TreePath path = new TreePath(nodePath.toArray());
    TreeModelEvent e = new TreeModelEvent (this, path, indices, children);
    for (int i = 0; i < listeners.length; i++)
        listeners [i].treeNodesRemoved (e);
}
 
Example 11
/**
 * <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 12
Source Project: netbeans-mmd-plugin   Source File: NodeProjectGroup.java    License: Apache License 2.0 5 votes vote down vote up
public boolean deleteNode(@Nonnull final NodeFileOrFolder node, final boolean notifyListeners) {
  final NodeFileOrFolder parentNode = node.getNodeParent();
  if (parentNode != null) {
    final TreeModelEvent event = new TreeModelEvent(this, parentNode.makeTreePath(), new int[]{node.getIndexAtParent()}, new Object[]{node});
    if (parentNode.deleteChild(node)) {
      if (notifyListeners) {
        for (final TreeModelListener l : this.listeners) {
          l.treeNodesRemoved(event);
        }
      }
      return true;
    }
  }
  return false;
}
 
Example 13
Source Project: netbeans   Source File: LookTreeModel.java    License: Apache License 2.0 5 votes vote down vote up
void fireDisplayChange(LookTreeNode source) {
    if (listeners.isEmpty()) {
        return;
    }
    LookTreeNode parent = source.getParent();
    TreePath path = findPath(parent != null ? parent : source);
    int[] childIndices = parent != null ? new int[] {getIndexOfChild(parent, source)} : null;
    Object[] children = parent != null ? new Object[] {source} : null;
    TreeModelEvent ev = new TreeModelEvent(this, path, childIndices, children);
    for (TreeModelListener l : listeners) {
        l.treeNodesChanged(ev);
    }
}
 
Example 14
Source Project: DroidUIBuilder   Source File: WidgetTreeModel.java    License: Apache License 2.0 5 votes vote down vote up
public void removeWidget(Widget w)
{
	Layout parent = w.getParent();
	Object[] path = findPath(parent);
	int index = parent.getWidgets().indexOf(w);
	fireNodeRemovedEvent(new TreeModelEvent(this, path,
			new int[] { index }, new Object[] { w }));
}
 
Example 15
Source Project: snap-desktop   Source File: LayerTreeModel.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void fireTreeNodeChanged(Layer layer) {
    TreeModelEvent event = createTreeModelEvent(layer);
    if (event == null) {
        return;
    }
    for (TreeModelListener treeModelListener : treeModelListeners.keySet()) {
        treeModelListener.treeNodesChanged(event);
    }
}
 
Example 16
Source Project: netbeans   Source File: EventBroadcaster.java    License: Apache License 2.0 5 votes vote down vote up
/** 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 17
Source Project: Bytecoder   Source File: FixedHeightLayoutCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <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 18
/**
 * <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 19
/**
 * <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 20
/**
 * <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 21
/**
 * <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 22
Source Project: Java8CN   Source File: FixedHeightLayoutCache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <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 23
/**
 * Informs all listeners, that the tree's contents have changed.
 */
private void fireTreeModelChanged() {
  for ( int i = 0; i < listeners.size(); i++ ) {
    final TreeModelListener l = listeners.get( i );
    l.treeStructureChanged( new TreeModelEvent( this, new TreePath( root ) ) );
  }
}
 
Example 24
Source Project: libreveris   Source File: ScoreTree.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void refreshAll ()
{
    nodeMap.clear();

    TreeModelEvent modelEvent = new TreeModelEvent(
            this,
            new Object[]{score});

    for (TreeModelListener listener : listeners) {
        listener.treeStructureChanged(modelEvent);
    }
}
 
Example 25
/**
 * <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 26
Source Project: libreveris   Source File: ScoreTree.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
public void refreshPath (TreePath path)
{
    TreeModelEvent modelEvent = new TreeModelEvent(this, path);

    for (TreeModelListener listener : listeners) {
        listener.treeStructureChanged(modelEvent);
    }
}
 
Example 27
/**
 * 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 28
Source Project: openjdk-jdk8u   Source File: Test8015926.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void treeNodesRemoved(TreeModelEvent event) {
}
 
Example 29
Source Project: Bytecoder   Source File: VariableHeightLayoutCache.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Invoked after the tree has drastically changed structure from a
 * given node down.  If the path returned by <code>e.getPath</code>
 * is of length one and the first element does not identify the
 * current root node the first element should become the new root
 * of the tree.
 *
 * <p><code>e.path</code> holds the path to the node.
 * <p><code>e.childIndices</code> returns <code>null</code>.
 *
 * @param e the <code>TreeModelEvent</code> of interest
 */
public void treeStructureChanged(TreeModelEvent e) {
    if(e != null)
    {
        TreePath          changedPath = SwingUtilities2.getTreePath(e, getModel());
        TreeStateNode     changedNode;

        changedNode = getNodeForPath(changedPath, false, false);

        // Check if root has changed, either to a null root, or
        // to an entirely new root.
        if(changedNode == root ||
           (changedNode == null &&
            ((changedPath == null && treeModel != null &&
              treeModel.getRoot() == null) ||
             (changedPath != null && changedPath.getPathCount() == 1)))) {
            rebuild(true);
        }
        else if(changedNode != null) {
            int                              nodeIndex;
            TreeStateNode                    newNode, parent;
            boolean                          wasExpanded, wasVisible;
            int                              newIndex;

            wasExpanded = changedNode.isExpanded();
            wasVisible = (changedNode.getRow() != -1);
            /* Remove the current node and recreate a new one. */
            parent = (TreeStateNode)changedNode.getParent();
            nodeIndex = parent.getIndex(changedNode);
            if(wasVisible && wasExpanded) {
                changedNode.collapse(false);
            }
            if(wasVisible)
                visibleNodes.removeElement(changedNode);
            changedNode.removeFromParent();
            createNodeAt(parent, nodeIndex);
            newNode = (TreeStateNode)parent.getChildAt(nodeIndex);
            if(wasVisible && wasExpanded)
                newNode.expand(false);
            newIndex = newNode.getRow();
            if(!isFixedRowHeight() && wasVisible) {
                if(newIndex == 0)
                    updateYLocationsFrom(newIndex);
                else
                    updateYLocationsFrom(newIndex - 1);
                this.visibleNodesChanged();
            }
            else if(wasVisible)
                this.visibleNodesChanged();
        }
    }
}
 
Example 30
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 4 votes vote down vote up
@Override public void treeNodesRemoved(TreeModelEvent e) {
  /* not needed */
}