本文整理匯總了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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
}
示例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});
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}
}
示例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());
}
}
示例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);
}
}