本文整理汇总了Java中javax.swing.tree.TreeModel.getChildCount方法的典型用法代码示例。如果您正苦于以下问题:Java TreeModel.getChildCount方法的具体用法?Java TreeModel.getChildCount怎么用?Java TreeModel.getChildCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeModel
的用法示例。
在下文中一共展示了TreeModel.getChildCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: collapseChildren
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public void collapseChildren(int row) {
if (tree != null) try {
markExpansionTransaction();
TreePath tpath = tree.getPathForRow(row);
if (tpath == null || tree.isCollapsed(tpath)) return;
TreeModel tmodel = tree.getModel();
Object selected = tpath.getLastPathComponent();
int nchildren = tmodel.getChildCount(selected);
for (int i = 0; i < nchildren; i++)
tree.collapsePath(tpath.pathByAddingChild(tmodel.getChild(selected, i)));
} finally {
clearExpansionTransaction();
}
}
示例2: expandPlainPath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public void expandPlainPath(int row, int maxChildren) {
if (tree != null) try {
markExpansionTransaction();
TreePath tpath = tree.getPathForRow(row);
if (tpath == null) return;
TreeModel tmodel = tree.getModel();
int childCount = tmodel.getChildCount(tpath.getLastPathComponent());
while (childCount > 0 && childCount <= maxChildren) {
tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));
childCount = tmodel.getChildCount(tpath.getLastPathComponent());
}
tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
try { tree.expandPath(tpath); selectPath(tpath, true); }
finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }
} finally {
clearExpansionTransaction();
}
}
示例3: expandFirstPath
import javax.swing.tree.TreeModel; //导入方法依赖的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();
}
}
示例4: browseTree
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private void browseTree(Object root, TreeModel model, String string) {
Object node = Visualizer.findNode(root);
if (node instanceof Node) {
Node n = (Node) node;
System.out.println(n.getDisplayName());
}
System.out.println(string + node.getClass().getName());
int childCount = model.getChildCount(root);
for (int i = 0; i < childCount; i++) {
browseTree(model.getChild(root, i), model, string + " ");
}
}
示例5: autoExpand
import javax.swing.tree.TreeModel; //导入方法依赖的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);
}
示例6: hasOnlyLeafs
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public static boolean hasOnlyLeafs(JTree tree, Object node) {
TreeModel model = tree.getModel();
for (int i = 0; i < model.getChildCount(node); i++) {
if (!model.isLeaf(model.getChild(node, i))) {
return false;
}
}
return true;
}
示例7: closePaths
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public void closePaths(JTree tree, TreePath path) {
Object node = path.getLastPathComponent();
TreeModel model = tree.getModel();
if (model.isLeaf(node))
return;
int num = model.getChildCount(node);
for (int i = 0; i < num; i++)
closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
tree.collapsePath(path);
}
示例8: getSimilarPath
import javax.swing.tree.TreeModel; //导入方法依赖的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;
}
示例9: setCurrentSubcategory
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
void setCurrentSubcategory(String subpath) {
TreeModel mdl = errorTree.getModel();
for (int i = 0; i < mdl.getChildCount(mdl.getRoot()); i++) {
Object child = mdl.getChild(mdl.getRoot(), i);
Object data = ((DefaultMutableTreeNode) child).getUserObject();
if (data instanceof POMErrorFixBase) {
POMErrorFixBase rule = (POMErrorFixBase) data;
if (rule.getConfiguration().getId().equals(subpath)) {
errorTree.setSelectionRow(i);
break;
}
}
}
}
示例10: getChildren
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private ArrayList<String> getChildren(TreeModel tree, Object root, String spaces) {
int categoriesCount = tree.getChildCount(root);
ArrayList<String> returnList = new ArrayList<String>();
for (int i = 0; i <= categoriesCount - 1; i++) {
Object actualChild = tree.getChild(root, i);
returnList.add(spaces + actualChild.toString());
if (!tree.isLeaf(actualChild)) {
spaces = "+-" + spaces;
returnList.addAll(getChildren(tree, actualChild, spaces));
spaces = spaces.substring(2);
}
}
return returnList;
}
示例11: updateTree
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* Updates the tree based on the event type. This will invoke either
* updateTree with the root element, or handleChange.
*/
protected void updateTree(DocumentEvent event) {
updatingSelection = true;
try {
TreeModel model = getTreeModel();
Object root = model.getRoot();
for (int counter = model.getChildCount(root) - 1; counter >= 0;
counter--) {
updateTree(event, (Element) model.getChild(root, counter));
}
} finally {
updatingSelection = false;
}
}
示例12: getPath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private TreePath getPath(JTree tree, String path) {
String[] tokens = path.substring(1).split("(?<!\\\\)/");
TreeModel treeModel = tree.getModel();
if (treeModel == null) {
throw new RuntimeException("Could not find model for tree");
}
Object rootNode = treeModel.getRoot();
int start = tree.isRootVisible() ? 1 : 0;
TreePath treePath = new TreePath(rootNode);
StringBuilder searchedPath = new StringBuilder();
if (tree.isRootVisible()) {
String rootNodeText = unescapeSpecialCharacters(tokens[0]);
searchedPath.append("/" + rootNodeText);
assertTrue("JTree does not have a root node!", rootNode != null);
assertTrue("JTree root node does not match: Expected </" + getPathText(tree, treePath) + "> Actual: <"
+ searchedPath.toString() + ">", searchedPath.toString().equals("/" + getPathText(tree, treePath)));
}
for (int i = start; i < tokens.length; i++) {
String childText = unescapeSpecialCharacters(tokens[i]);
searchedPath.append("/" + childText);
boolean matched = false;
tree.expandPath(treePath);
for (int j = 0; j < treeModel.getChildCount(treePath.getLastPathComponent()); j++) {
Object child = treeModel.getChild(treePath.getLastPathComponent(), j);
TreePath childPath = treePath.pathByAddingChild(child);
if (childText.equals(getPathText(tree, childPath))) {
treePath = childPath;
matched = true;
break;
}
}
if (!matched) {
return null;
}
}
return treePath;
}
示例13: closePaths
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public static void closePaths(JTree tree, TreePath path) {
Object node = path.getLastPathComponent();
TreeModel model = tree.getModel();
if (model.isLeaf(node))
return;
int num = model.getChildCount(node);
for (int i = 0; i < num; i++)
closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
tree.collapsePath(path);
}
示例14: expandAll
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private void expandAll(JTree tree, TreePath path) {
tree.expandPath(path);
TreeModel model = tree.getModel();
Object lastComponent = path.getLastPathComponent();
for (int i = 0; i < model.getChildCount(lastComponent); i++) {
expandAll(tree,
path.pathByAddingChild(model.getChild(lastComponent, i)));
}
}
示例15: generatePath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private String generatePath(TreeModel model, Object currentNode, String path) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) currentNode;
if (checkIfRootNode(model, node)) {
path = "/";
}
StringBuilder pathBuilder = new StringBuilder(path + currentNode + System.getProperty("line.separator"));
for (int i = 0; i < model.getChildCount(currentNode); i++) {
pathBuilder.append(generatePath(model, model.getChild(currentNode, i), path + currentNode + "/"));
}
return pathBuilder.toString();
}