Java Code Examples for javax.swing.tree.TreeNode#children()

The following examples show how to use javax.swing.tree.TreeNode#children() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DProperties.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
private void expandTwoLevels(TreePath treePath) {
	if (treePath.getPathCount() > 2) {
		return;
	}

	TreeNode node = (TreeNode) treePath.getLastPathComponent();

	if (node.getChildCount() >= 0) {
		for (Enumeration<?> enumChildren = node.children(); enumChildren.hasMoreElements();) {
			TreeNode subNode = (TreeNode) enumChildren.nextElement();
			TreePath path = treePath.pathByAddingChild(subNode);
			expandTwoLevels(path);
		}
	}

	jtrProperties.expandPath(treePath);
}
 
Example 2
Source File: DecorationTrees.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void expandAll(JTree tree, TreePath parent, boolean expand) {
    // Traverse children
    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);
        }
    }

    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}
 
Example 3
Source File: BeansTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static TreePath getTreePath(JTreeOperator treeOperator, String targetNode, NodeConverter converter) {
    Stack<TreeNode> lifo = new Stack<TreeNode>();        
    lifo.push((TreeNode) treeOperator.getRoot());
    while(!lifo.isEmpty()) {
        TreeNode actNode = lifo.pop();
        if(targetNode.equals(converter.getDisplayName(actNode))) {
            List<TreeNode> path = new LinkedList<TreeNode>();
            path.add(actNode);
            actNode = actNode.getParent();
            while(actNode!=null) {
                path.add(0,actNode);
                actNode = actNode.getParent();
            }
            TreeNode[] res = path.toArray(new TreeNode[path.size()]);                
            return new TreePath(res);
        }
        final Enumeration children = actNode.children();            
        while(children.hasMoreElements()) {
            lifo.add((TreeNode)children.nextElement());
        }            
    }
    return null;
}
 
Example 4
Source File: BaseExecuteBeforeRunDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void expacndChecked(Tree tree) {
  TreeNode root = (TreeNode)tree.getModel().getRoot();
  Enumeration factories = root.children();
  ArrayList<TreeNode[]> toExpand = new ArrayList<TreeNode[]>();
  while (factories.hasMoreElements()) {
    DefaultMutableTreeNode factoryNode = (DefaultMutableTreeNode)factories.nextElement();
    Enumeration configurations = factoryNode.children();
    while (configurations.hasMoreElements()) {
      DefaultMutableTreeNode node = (DefaultMutableTreeNode)configurations.nextElement();
      ConfigurationDescriptor config = (ConfigurationDescriptor)node.getUserObject();
      if (config.isChecked()) {
        toExpand.add(factoryNode.getPath());
        break;
      }
    }
  }
  for (TreeNode[] treeNodes : toExpand) {
    tree.expandPath(new TreePath(treeNodes));
  }
}
 
Example 5
Source File: PopupMenuTreeTools.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void expandOrCollapseFromNode(TreePath parent, boolean expand) {
    TreeNode tn = (TreeNode) parent.getLastPathComponent();

    if (tn.getChildCount() > 0) {
        for (Enumeration<? extends TreeNode> e = tn.children(); e.hasMoreElements(); ) {
            TreePath path = parent.pathByAddingChild(e.nextElement());
            expandOrCollapseFromNode(path, expand);
        }
    }

    if (expand) {
        sitesTree.expandPath(parent);
    } else {
        sitesTree.collapsePath(parent);
    }
}
 
Example 6
Source File: TreeList.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a <code>JList</code> with an empty model.
 */
public TreeList(TreeModel treeModel) {
  super.setModel(myListModel);
  myTreeModel = treeModel;
  myTreeModel.addTreeModelListener(this);
  Object root = myTreeModel.getRoot();
  if (root instanceof TreeNode) {
    TreeNode node = (TreeNode) root;
    myListModel.addElement(node);
    if (myTreeModel instanceof DefaultTreeModel && ((DefaultTreeModel)myTreeModel).asksAllowsChildren() && node.getAllowsChildren()) {
      Enumeration enumeration = node.children();
      while (enumeration.hasMoreElements()) {
        Object object = enumeration.nextElement();
        myListModel.addElement(object);
      }
    }
  }
}
 
Example 7
Source File: GuiUtils.java    From nosql4idea with Apache License 2.0 5 votes vote down vote up
public static void expand(@NotNull JTree tree, @NotNull TreePath path, int levels) {
    if (levels == 0) return;
    tree.expandPath(path);
    TreeNode node = (TreeNode) path.getLastPathComponent();
    Enumeration children = node.children();
    while (children.hasMoreElements()) {
        expand(tree, path.pathByAddingChild(children.nextElement()), levels - 1);
    }
}
 
Example 8
Source File: OperationsTree.java    From cstc with GNU General Public License v3.0 5 votes vote down vote up
private void expandAll(TreePath path) {
	TreeNode node = (TreeNode) path.getLastPathComponent();
	
	if (node.getChildCount() >= 0) {
		Enumeration enumeration = node.children();
		while (enumeration.hasMoreElements()) {
			TreeNode n = (TreeNode) enumeration.nextElement();
			TreePath p = path.pathByAddingChild(n);

			expandAll(p);
		}
	}
	this.expandPath(path);
}
 
Example 9
Source File: DViewCertificate.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void expandTree(JTree tree, TreePath parent) {
	TreeNode node = (TreeNode) parent.getLastPathComponent();
	if (node.getChildCount() >= 0) {
		for (Enumeration<?> enumNodes = node.children(); enumNodes.hasMoreElements();) {
			TreeNode subNode = (TreeNode) enumNodes.nextElement();
			TreePath path = parent.pathByAddingChild(subNode);
			expandTree(tree, path);
		}
	}

	tree.expandPath(parent);
}
 
Example 10
Source File: DualView.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void collapsePath(JTree tree, TreePath path) {

    final TreeNode node = ((TreeNode)path.getLastPathComponent());
    final Enumeration children = node.children();
    while (children.hasMoreElements()) {
      TreeNode child = (TreeNode)children.nextElement();
      collapsePath(tree, path.pathByAddingChild(child));
    }

    if (!((path.getLastPathComponent() == tree.getModel().getRoot()) && !myRootVisible)) {
      tree.collapsePath(path);
    }
  }
 
Example 11
Source File: ClassBrowser.java    From beanshell with Apache License 2.0 5 votes vote down vote up
/**
    Map out the location of the nodes by package name.
    Seems like we should be able to do this while we build above...
    I'm tired... just going to do this.
*/
void mapNodes( TreeNode node ) {
    addNodeMap( node );

    Enumeration e = node.children();
    while(e.hasMoreElements()) {
        TreeNode tn = (TreeNode)e.nextElement();
        mapNodes( tn );
    }
}
 
Example 12
Source File: RandomArmyDialog.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
private TreePath findNextNode(TreePath parent, String[] nodes, int depth) {
    TreeNode node = (TreeNode)parent.getLastPathComponent();
    String currNode = node.toString();

    // If equal, go down the branch
    if (currNode.equals(nodes[depth].trim())) {
        // If at end, return match
        if (depth == nodes.length-1) {
            return parent;
        }

        // Traverse children
        if (node.getChildCount() >= 0) {
            for (Enumeration<?> e = node.children(); e.hasMoreElements(); ) {
                TreeNode n = (TreeNode)e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                TreePath result = findNextNode(path, nodes, depth + 1);
                // Found a match
                if (result != null) {
                    return result;
                }
            }
        }
    }
    // No match at this branch
    return null;
}
 
Example 13
Source File: SettingsDialog.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
private void expandAll(final TreePath parent, final 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(path, expand);
		}
	}
	if (expand) {
		jTree.expandPath(parent);
	} else {
		jTree.collapsePath(parent);
	}
}
 
Example 14
Source File: TreeUtil.java    From Zettelkasten with GNU General Public License v3.0 5 votes vote down vote up
private static void expandAllTrees(TreePath parent, boolean expand, JTree tree) {
    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);
            expandAllTrees(path, expand, tree);
        }
    }
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}
 
Example 15
Source File: DualView.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void expandPath(JTree tree, TreePath path) {
  tree.expandPath(path);

  final TreeNode node = ((TreeNode)path.getLastPathComponent());
  final Enumeration children = node.children();
  while (children.hasMoreElements()) {
    TreeNode child = (TreeNode)children.nextElement();
    expandPath(tree, path.pathByAddingChild(child));
  }
}
 
Example 16
Source File: JDeckChooserDialog.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
private void expandAll(TreePath parent) {
	TreeNode node = (TreeNode) parent.getLastPathComponent();
	if (node.getChildCount() >= 0) {
		for (Enumeration<? extends TreeNode>e = node.children(); e.hasMoreElements();) {
			TreeNode n =  e.nextElement();
			TreePath path = parent.pathByAddingChild(n);
			expandAll(path);
		}
	}
	tree.expandPath(parent);
}
 
Example 17
Source File: JFrameRTStats.java    From mts with GNU General Public License v3.0 5 votes vote down vote up
public static void expandAll(JTree tree, TreePath 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);
            expandAll(tree, path);
        }
    }
    tree.expandPath(parent);
}
 
Example 18
Source File: TreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void expandOrCollapseAll(TreePath parent, boolean expand) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    if (node.getChildCount() > 0) {
        for (Enumeration<? extends TreeNode> e = node.children(); e.hasMoreElements();) {
            TreeNode n = e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandOrCollapseAll(path, expand);
        }
    }
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}
 
Example 19
Source File: AutoExpandingJTree.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
private void expand(TreePath path) {
   if(!(path.getLastPathComponent() instanceof TreeNode)) {
     if(isVisible(path)) return;
     makeVisible(path);
     return;
   }
   TreeNode node = (TreeNode)path.getLastPathComponent();
   if(node.getChildCount() == 0) {
     if(isVisible(path)) return;
     makeVisible(path);
   } else {
     for(Enumeration e = node.children(); e.hasMoreElements();)
expand(path.pathByAddingChild(e.nextElement()));
   } 
 }
 
Example 20
Source File: TreeUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @param tree com.sun.java.swing.JTree
 * @param start com.sun.java.swing.tree.DefaultMutableTreeNode
 */
public static void expandTree(JTree tree, TreeNode start, int level) {
    for (Enumeration children = start.children(); children.hasMoreElements();) {
        DefaultMutableTreeNode dtm = (DefaultMutableTreeNode) children.nextElement();
        //System.out.println(dtm.getUserObject()+" "+dtm.getDepth());
        if (!dtm.isLeaf() && dtm.getLevel() <= level) {
            //
            TreePath tp = new TreePath(dtm.getPath());
            tree.expandPath(tp);
            //
            expandTree(tree, dtm, level);
        }
    }
    return;
}