javax.swing.tree.TreeModel#isLeaf ( )源码实例Demo

下面列出了javax.swing.tree.TreeModel#isLeaf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: pentaho-reporting   文件: ReportDesignerFrame.java
private void insertReports( final TreeModel model,
                            final Object currentLevel,
                            final XulMenupopup popup ) throws XulException {
  final int childCount = model.getChildCount( currentLevel );
  for ( int i = 0; i < childCount; i += 1 ) {
    final ReportDesignerView frame = context.getView();

    final Object child = model.getChild( currentLevel, i );
    if ( model.isLeaf( child ) ) {
      final DefaultMutableTreeNode node = (DefaultMutableTreeNode) child;
      final File file = new File( String.valueOf( node.getUserObject() ) );
      final OpenSampleReportAction action = new OpenSampleReportAction( file, node.toString() );
      action.setReportDesignerContext( context );
      popup.addChild( frame.createMenuItem( action ) );
    } else {
      final XulMenupopup childPopup = frame.createPopupMenu( String.valueOf( child ), popup );
      insertReports( model, child, childPopup );
    }
  }
}
 
源代码2 项目: consulo   文件: TreeExpandCollapse.java
public int expand(JTree tree, TreePath path) {
  if (myLevelsLeft == 0) return myExpansionLimit;
  TreeModel model = tree.getModel();
  Object node = path.getLastPathComponent();
  int levelDecrement = 0;
  if (!tree.isExpanded(path) && !model.isLeaf(node)) {
    tree.expandPath(path);
    levelDecrement = 1;
    myExpansionLimit--;
  }
  for (int i = 0; i < model.getChildCount(node); i++) {
    Object child = model.getChild(node, i);
    if (model.isLeaf(child)) continue;
    ExpandContext childContext = new ExpandContext(myExpansionLimit, myLevelsLeft - levelDecrement);
    myExpansionLimit = childContext.expand(tree, path.pathByAddingChild(child));
    if (myExpansionLimit <= 0) return 0;
  }
  return myExpansionLimit;
}
 
源代码3 项目: netbeans   文件: UIUtils.java
/** 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);
}
 
源代码4 项目: netbeans   文件: UIUtils.java
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;
}
 
源代码5 项目: netbeans   文件: WebProjectValidation.java
private void dumpNode(TreeModel model, Object node, int offset) {
    for (int i = 0; i < offset; i++) {
        getRef().print("\t");
    }
    getRef().println(node.toString());
    if (model.isLeaf(node)) {
        return;
    }
    for (int i = 0; i < model.getChildCount(node); i++) {
        Object object = model.getChild(node, i);
        dumpNode(model, object, offset + 1);
    }
}
 
源代码6 项目: netbeans   文件: NewProjectTest.java
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;
}
 
源代码7 项目: visualvm   文件: UIUtils.java
/** 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);
}
 
源代码8 项目: visualvm   文件: UIUtils.java
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;
}
 
源代码9 项目: snap-desktop   文件: CatalogTree.java
private void getLeaves(Object node, TreeModel model, Set<OpendapLeaf> result) {
    for (int i = 0; i < model.getChildCount(node); i++) {
        if (model.isLeaf(model.getChild(node, i))) {
            final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) (model.getChild(node, i));
            if (CatalogTreeUtils.isDapNode(childNode) || CatalogTreeUtils.isFileNode(childNode)) {
                result.add((OpendapLeaf) childNode.getUserObject());
            }
        } else {
            getLeaves(model.getChild(node, i), model, result);
        }
    }
}
 
源代码10 项目: nextreports-designer   文件: TreeUtil.java
/**
 * Expand a tree node and all its child nodes recursively.
 *
 * @param tree The tree whose nodes to expand.
 * @param path Path to the node to start at.
 */
public static void expandAll(JTree tree, TreePath path) {
    Object node = path.getLastPathComponent();
    TreeModel model = tree.getModel();
    if (model.isLeaf(node)) {
        return;
    }
    tree.expandPath(path);
    int num = model.getChildCount(node);
    for (int i = 0; i < num; i++) {
        expandAll(tree, path.pathByAddingChild(model.getChild(node, i)));
    }
}
 
源代码11 项目: nextreports-designer   文件: TreeUtil.java
/**
 * Collapse a tree node and all its child nodes recursively.
 *
 * @param tree The tree whose nodes to collapse.
 * @param path Path to the node to start at.
 */
public static void collapseAll(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++) {
        collapseAll(tree, path.pathByAddingChild(model.getChild(node, i)));
    }
    tree.collapsePath(path);
}
 
源代码12 项目: nextreports-designer   文件: TreeUtil.java
/**
 * Search for a path in the specified tree model, whose nodes have
 * the same name (compared using <code>equals()</code>)
 * as the ones specified in the old path.
 *
 * @return a new path for the specified model, or null if no such path
 *         could be found.
 */
public static TreePath searchPath(TreeModel model, TreePath oldPath) {
    Object treenode = model.getRoot();
    Object[] oldPathNodes = oldPath.getPath();
    TreePath newPath = new TreePath(treenode);
    for (int i = 0; i < oldPathNodes.length; ++i) {
        Object oldPathNode = oldPathNodes[i];
        if (treenode.toString().equals(oldPathNode.toString())) {
            if (i == (oldPathNodes.length - 1)) {
                return newPath;
            } else {
                if (model.isLeaf(treenode)) {
                    return null; // not found
                } else {
                    int count = model.getChildCount(treenode);
                    boolean foundChild = false;
                    for (int j = 0; j < count; ++j) {
                        Object child = model.getChild(treenode, j);
                        if (child.toString().equals(oldPathNodes[i + 1].toString())) {
                            newPath = newPath.pathByAddingChild(child);
                            treenode = child;
                            foundChild = true;
                            break;
                        }
                    }
                    if (!foundChild) {
                        return null; // couldn't find child with same name
                    }
                }
            }
        }
    }
    return null;
}
 
源代码13 项目: TrakEM2   文件: DNDTree.java
static public void expandAllNodes(final JTree tree, final TreePath path) {
	final DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
	final TreeModel tree_model = tree.getModel();
	if (tree_model.isLeaf(node)) return;
	tree.expandPath(path);
	final int n_children = tree_model.getChildCount(node);
	for (int i=0; i<n_children; i++) {
		expandAllNodes(tree, path.pathByAddingChild(tree_model.getChild(node, i)));
	}
}
 
源代码14 项目: TrakEM2   文件: DNDTree.java
static public boolean expandNode(final DNDTree tree, final DefaultMutableTreeNode node) {
	final TreeModel tree_model = tree.getModel();
	if (tree_model.isLeaf(node)) return false;
	tree.expandPath(new TreePath(node.getPath()));
	tree.updateUILater();
	return true;
}