当前位置: 首页>>代码示例>>Java>>正文


Java TreePath.pathByAddingChild方法代码示例

本文整理汇总了Java中javax.swing.tree.TreePath.pathByAddingChild方法的典型用法代码示例。如果您正苦于以下问题:Java TreePath.pathByAddingChild方法的具体用法?Java TreePath.pathByAddingChild怎么用?Java TreePath.pathByAddingChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.tree.TreePath的用法示例。


在下文中一共展示了TreePath.pathByAddingChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRowSpanOfLastElement

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
 * Gets the total rowspan of the last element of irTreePath.
 *
 * @param irTreePath
 * @return
 */
protected int getRowSpanOfLastElement(TreePath irTreePath) {
    OutlineModel lrModel = getOutline().getOutlineModel();

    if (!isExpanded(irTreePath)) {
        return 1;
    }

    Object lrLast = irTreePath.getLastPathComponent();
    int lnRowspan = 1; //1 for the current node
    int lnChildCount = lrModel.getChildCount(lrLast);

    for (int i = 0; i < lnChildCount; i++) {
        Object lnChild = lrModel.getChild(lrLast, i);

        TreePath lrTempPath = irTreePath.pathByAddingChild(lnChild);
        lnRowspan += getRowSpanOfLastElement(lrTempPath);
    }

    return lnRowspan;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:OutlineOperator.java

示例2: getNextPath

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
TreePath getNextPath(TreePath path, boolean down) {
    TreeModel _model = model.treeModel;
    TreeNode node = (TreeNode)path.getLastPathComponent();
    if (down && _model.getChildCount(node) > 0)
        return path.pathByAddingChild(_model.getChild(node, 0));

    TreePath parentPath = path.getParentPath();
    if (!down && parentPath == null)
        return path.pathByAddingChild(_model.getChild(node, 0));
    
    TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
    int idx = _model.getIndexOfChild(parent, node) + 1;

    if (_model.getChildCount(parent) > idx)
        return parentPath.pathByAddingChild(_model.getChild(parent, idx));

    if (!down && parentPath.getParentPath() == null) {
        return parentPath.pathByAddingChild(_model.getChild(parent, 0));
    } else {
        return getNextPath(parentPath, false);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ProfilerTreeTable.java

示例3: expandAll

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
 * iterate through every child and do the action
 *
 * @param parent
 * @param expand
 */
private void expandAll(TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (getChildCount(node) >= 0) {
        for (int i = 0; i < getChildCount(node); i++) {
            TreePath path = parent.pathByAddingChild(getChildAt(node, i));
            expandAll(path, expand);
        }
    }
    if (expand) {
        expandPath(parent);
    } else {
        collapsePath(parent);
    }

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:22,代码来源:JCheckBoxTree.java

示例4: expandFirstPath

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public void expandFirstPath(int row) {
    if (tree != null) try {
        markExpansionTransaction();

        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null) return;

        TreeModel tmodel = tree.getModel();    

        while (tmodel.getChildCount(tpath.getLastPathComponent()) > 0)
            tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));

        tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
        try { selectPath(tpath, true); }
        finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }

    } finally {
        clearExpansionTransaction();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:ProfilerTreeTable.java

示例5: optionTreeExpand

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
 * Option tree expand.
 *
 * @param parent the parent
 * @param expand the expand
 * @param currNodeLevel the curr node level
 * @param up2TreeLevel the up2 tree level
 */
private void optionTreeExpand(TreePath parent, boolean expand, Integer currNodeLevel, Integer up2TreeLevel) {
   
       TreeNode node = (TreeNode)parent.getLastPathComponent();
       if (currNodeLevel >= up2TreeLevel) {
       	return;
       }
       if (node.getChildCount() >= 0) {
           for ( @SuppressWarnings("rawtypes") Enumeration e=node.children(); e.hasMoreElements(); ) {
               TreeNode n = (TreeNode) e.nextElement();
               TreePath path = parent.pathByAddingChild(n);
               optionTreeExpand(path, expand, currNodeLevel+1, up2TreeLevel);
           }
       }    
       // Expansion or collapse must be done bottom-up
       if (expand) {
       	jTreeOptions.expandPath(parent);
       } else {
       	jTreeOptions.collapsePath(parent);
       }
   }
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:29,代码来源:OptionDialog.java

示例6: toggleRemoveSelection

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private void toggleRemoveSelection(TreePath path) {
    Stack stack = new Stack();
    TreePath parent = path.getParentPath();
    while (parent != null && !isPathSelected(parent)) {
        stack.push(parent);
        parent = parent.getParentPath();
    }
    if (parent != null) {
        stack.push(parent);
    } else {
        super.removeSelectionPaths(new TreePath[]{path});
        return;
    }

    while (!stack.isEmpty()) {
        TreePath temp = (TreePath) stack.pop();
        TreePath peekPath = stack.isEmpty() ? path : (TreePath) stack.peek();
        Object node = temp.getLastPathComponent();
        Object peekNode = peekPath.getLastPathComponent();
        int childCount = model.getChildCount(node);
        for (int i = 0; i < childCount; i++) {
            Object childNode = model.getChild(node, i);
            if (childNode != peekNode) {
                super.addSelectionPaths(new TreePath[]{temp.pathByAddingChild(childNode)});
            }
        }
    }
    super.removeSelectionPaths(new TreePath[]{parent});
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:CheckTreeSelectionModel.java

示例7: getPathForIndex

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
 * Returns a TreePath to the element at <code>position</code>.
 */
protected TreePath getPathForIndex(int position, Object root,
        Element rootElement) {
    TreePath path = new TreePath(root);
    Element child = rootElement.getElement(rootElement.getElementIndex(
            position));

    path = path.pathByAddingChild(rootElement);
    path = path.pathByAddingChild(child);
    while (!child.isLeaf()) {
        child = child.getElement(child.getElementIndex(position));
        path = path.pathByAddingChild(child);
    }
    return path;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:ElementTreePanel.java

示例8: autoExpand

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/** Checks give TreePath for the last node, and if it ends with a node with just one child,
 * it keeps expanding further.
 * Current implementation expands through the first child that is not leaf. To more correctly
 * fulfil expected semantics in case maxChildToExpand is > 1, it should expand all paths through
 * all children.
 *
 * @param tree
 * @param path
 * @param maxChildToExpand
 */
public static void autoExpand(JTree tree, TreePath path, int maxLines, int maxChildToExpand, boolean dontExpandToLeafs) {
    TreeModel model = tree.getModel();
    Object node = path.getLastPathComponent();
    TreePath newPath = path;

    int currentLines = 0;

    while (currentLines++ < maxLines &&
            !model.isLeaf(node) &&
            (model.getChildCount(node) > 0) &&
            (model.getChildCount(node) <= maxChildToExpand)) {
        for (int i = 0; i < model.getChildCount(node); i++) {
            node = tree.getModel().getChild(node, i);

            if (!model.isLeaf(node)) {
                if (dontExpandToLeafs && hasOnlyLeafs(tree, node)) {
                    break;
                }

                newPath = newPath.pathByAddingChild(node); // if the leaf is added the path will not expand

                break; // from for
            }
        }
    }

    tree.expandPath(newPath);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:UIUtils.java

示例9: getSimilarPath

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private TreePath getSimilarPath(TreePath oldPath) {
    if (oldPath == null || oldPath.getPathCount() < 1) return null;

    TreeModel currentModel = getModel();
    Object currentRoot = currentModel.getRoot();
    if (!currentRoot.equals(oldPath.getPathComponent(0))) return null;

    TreePath p = new TreePath(currentRoot);
    Object[] op = oldPath.getPath();
    Object n = currentRoot;

    for (int i = 1; i < op.length; i++) {
        Object nn = null;

        for (int ii = 0; ii < currentModel.getChildCount(n); ii++) {
            Object c = currentModel.getChild(n, ii);
            if (c.equals(op[i])) {
                nn = c;
                break;
            }
        }

        if (nn == null) return null;

        n = nn;
        p = p.pathByAddingChild(n);
    }

    return p;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:ProfilerTreeTable.java

示例10: expandAll

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private void expandAll(final JTree tree, final TreePath parent) {
  final TreeNode node = (TreeNode) parent.getLastPathComponent();
  if (node.getChildCount() >= 0) {
    for (@SuppressWarnings("rawtypes")
    final Enumeration e = node.children(); e.hasMoreElements();) {
      final TreeNode n = (TreeNode) e.nextElement();
      final TreePath path = parent.pathByAddingChild(n);
      this.expandAll(tree, path);
    }
  }
  tree.expandPath(parent);
  // tree.collapsePath(parent);
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:14,代码来源:CreateAtom.java

示例11: selectTreeNode

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public void selectTreeNode(int offset) {
    TreeNodeAdapter root = (TreeNodeAdapter)tree.getModel().getRoot();
    
    int from = root.getStart();
    int to = root.getEnd();
    // sanity check:
    if (offset < from || offset >= to) {
        // retain the selection path as it is
        return;
    }
    TreePath p = new TreePath(root);
    boolean cont = true;
    OUT: while (cont) {
        cont = false;
        Enumeration chE = root.children();
        while (chE.hasMoreElements()) {
            TreeNodeAdapter ch = (TreeNodeAdapter)chE.nextElement();
            if (offset < ch.getStart()) {
                break OUT;
            }
            if (offset < ch.getEnd()) {
                root = ch;
                p = p.pathByAddingChild(ch);
                cont = true;
                break;
            }
        }
    };
    tree.scrollPathToVisible(p);
    tree.setSelectionPath(p);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:NavigatorContent.java

示例12: expandAll

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
public static void expandAll(Tree tree, TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children() ; e.hasMoreElements() ; ) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }
    }
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}
 
开发者ID:semihunaldi,项目名称:IdeaCurrency,代码行数:16,代码来源:Util.java

示例13: expandTreeRecursively

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
private static void expandTreeRecursively(JTree tree, TreePath parent) {
    tree.expandPath(parent);
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements(); ) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandTreeRecursively(tree, path);
        }
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:12,代码来源:SwingUtils.java

示例14: getChildPath

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/**
 * Constructs new path from a path and index's subnode of it last node.
 *
 * @param path a path indicating a node to get a child of.
 * @param index a child node index.
 * @return a number of children.
 */
public TreePath getChildPath(TreePath path, int index) {
    if (path != null) {
        return (path.
                pathByAddingChild(getChild(path.
                        getLastPathComponent(), index)));
    } else {
        throw (new NoSuchPathException());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:JTreeOperator.java

示例15: getPathTo

import javax.swing.tree.TreePath; //导入方法依赖的package包/类
/** Creates TreePath leading to the specified operator. */
public TreePath getPathTo(Operator operator) {
	if (operator.getParent() == null) {
		return new TreePath(operator);
	} else {
		TreePath pathToParent;
		if (operator.getParent().getNumberOfSubprocesses() == 1) {
			pathToParent = getPathTo(operator.getParent());
		} else {
			pathToParent = getPathTo(operator.getExecutionUnit());
		}
		return pathToParent.pathByAddingChild(operator);
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:15,代码来源:ProcessTreeModel.java


注:本文中的javax.swing.tree.TreePath.pathByAddingChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。