本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.getPath方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.getPath方法的具体用法?Java DefaultMutableTreeNode.getPath怎么用?Java DefaultMutableTreeNode.getPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultMutableTreeNode
的用法示例。
在下文中一共展示了DefaultMutableTreeNode.getPath方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPath
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private TreeNode[] getPath(Object node, String deap, String item, boolean debug) {
if (node instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) node;
if (debug) {
System.out.println(deap + dmtn.toString());
}
if (dmtn.toString().equals(item)) {
if (debug) {
System.out.println("EQUAL!!! <" + item + ">");
}
return dmtn.getPath();
}
TreeNode[] curPath;
for (int i = 0; i < dmtn.getChildCount(); i++) {
curPath = getPath(dmtn.getChildAt(i), deap + "__", item, debug);
if (curPath != null) {
return curPath;
}
}
}
return null;
}
示例2: addNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Recursively adds new nodes to the tree.
*/
protected void addNode(DefaultMutableTreeNode parent, Component component, Component selectedComponent) {
DefaultMutableTreeNode componentNode = new DefaultMutableTreeNode(new ComponentWrapper(component));
parent.add(componentNode);
if (component == selectedComponent) {
TreePath selectedPath = new TreePath(componentNode.getPath());
componentTree.setSelectionPath(selectedPath);
componentTree.scrollPathToVisible(selectedPath);
}
if (component instanceof Container) {
Container container = (Container) component;
Component[] childComponents = container.getComponents();
for (Component child : childComponents) {
addNode(componentNode, child, selectedComponent);
}
}
}
示例3: execute
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public void execute() {
TreeNode root = (TreeNode) this.tree.getModel().getRoot();
List<DefaultMutableTreeNode> collapsableNodes = new ArrayList<>();
for (int i = 0; i < root.getChildCount(); i++) {
TreeNode child = root.getChildAt(i);
if (isDirectoryNode(child)) {
for (int j = 0; j < child.getChildCount(); j++) {
collapsableNodes.add((DefaultMutableTreeNode) child.getChildAt(j));
}
} else {
collapsableNodes.add((DefaultMutableTreeNode) child);
}
}
for (DefaultMutableTreeNode node : collapsableNodes) {
TreePath path = new TreePath(node.getPath());
if (!this.tree.isCollapsed(path)) {
this.tree.collapsePath(path);
}
}
}
示例4: intervalAdded
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@Override
public void intervalAdded(ListDataEvent e) {
for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
Object obj = listModel.getElementAt(i);
if (obj instanceof ClassPathSupport.Item) {
DefaultMutableTreeNode node = toTreeNode(obj);
treeModel.insertNodeInto(node, (MutableTreeNode)treeModel.getRoot(), e.getIndex0());
TreePath path = new TreePath(node.getPath());
tree.setSelectionPath(path);
tree.makeVisible(path);
}
}
}
示例5: highlight
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
protected void highlight(Collection<DefaultMutableTreeNode> nodes) {
// Collapse everything and then show the paths to each node
for (int ctr = this.catalogTree.getRowCount(); ctr >= 0; ctr--) {
if (this.catalogTree.isExpanded(ctr)) {
this.catalogTree.collapseRow(ctr);
}
} // FOR
this.catalogTree.getSelectionModel().clearSelection();
for (DefaultMutableTreeNode node : nodes) {
TreePath path = new TreePath(node.getPath());
this.catalogTree.setSelectionPath(path);
this.catalogTree.expandPath(path);
} // FOR
}
示例6: select
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private void select(String id) {
DefaultMutableTreeNode node = nodeMap.get(id);
if (node == null) {
logger.warning("Unable to find node with id '" + id + "'.");
} else {
TreePath oldPath = tree.getSelectionPath();
if (oldPath != null && oldPath.getParentPath() != null) {
tree.collapsePath(oldPath.getParentPath());
}
TreePath newPath = new TreePath(node.getPath());
tree.scrollPathToVisible(newPath);
tree.expandPath(newPath);
showDetails((ColopediaTreeItem) node.getUserObject());
}
}
示例7: select
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private boolean select(DefaultMutableTreeNode parent, Predicate<IEntity> selectionPredicate) {
if (parent.getChildCount() == 0) {
return false;
}
Enumeration en = parent.depthFirstEnumeration();
while (en.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
IEntity ent = null;
if (node.getUserObject() instanceof IconTreeListItem) {
IconTreeListItem iconItem = (IconTreeListItem) node.getUserObject();
if (iconItem.getUserObject() instanceof IEntity) {
ent = (IEntity) iconItem.getUserObject();
}
} else if (node.getUserObject() instanceof IEntity) {
ent = (IEntity) node.getUserObject();
}
if (ent == null) {
continue;
}
if (selectionPredicate.test(ent)) {
final TreePath newSelection = new TreePath(node.getPath());
if (this.tree.getSelectionPath() != null && this.tree.getSelectionPath().equals(newSelection)) {
continue;
}
this.tree.setSelectionPath(newSelection);
TreePath path = this.tree.getSelectionPath();
if (path == null || !this.tree.isVisible()) {
return false;
}
Rectangle bounds = this.tree.getPathBounds(path);
if (bounds == null) {
return false;
}
// set the height to the visible height to force the node to top
bounds.height = this.tree.getVisibleRect().height;
this.tree.scrollRectToVisible(bounds);
return true;
}
}
return false;
}
示例8: createPath
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/** Callback factory method to create a {@link TreePath} object for a node. */
private TreePath createPath(DefaultMutableTreeNode node) {
return new TreePath(node.getPath());
}