Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#breadthFirstEnumeration()
The following examples show how to use
javax.swing.tree.DefaultMutableTreeNode#breadthFirstEnumeration() .
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: AbstractFormattedDisk.java From DiskBrowser with GNU General Public License v3.0 | 6 votes |
protected DefaultMutableTreeNode findNode (DefaultMutableTreeNode node, String name) // ---------------------------------------------------------------------------------// { Enumeration<TreeNode> children = node.breadthFirstEnumeration (); if (children != null) { while (children.hasMoreElements ()) { DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) children.nextElement (); if (childNode.getUserObject ().toString ().indexOf (name) > 0) return childNode; } } return null; }
Example 2
Source File: FileSystemTab.java From DiskBrowser with GNU General Public License v3.0 | 6 votes |
public void replaceDisk (FormattedDisk disk) // ---------------------------------------------------------------------------------// { // first check currently selected disk FileNode fn = (FileNode) getSelectedObject (); if (fn != null && fn.replaceDisk (disk)) return; // find the old disk and replace it DefaultMutableTreeNode rootNode = getRootNode (); Enumeration<TreeNode> children = rootNode.breadthFirstEnumeration (); while (children.hasMoreElements ()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement (); fn = (FileNode) node.getUserObject (); if (fn.replaceDisk (disk)) break; } }
Example 3
Source File: TreeTestBase.java From jenetics with Apache License 2.0 | 6 votes |
@Test public void getPath() { final T tree = newTree(5, new Random(123)); final DefaultMutableTreeNode stree = newSwingTree(5, new Random(123)); final Iterator<T> treeIt = tree.breadthFirstIterator(); final Enumeration<?> streeIt = stree.breadthFirstEnumeration(); while (treeIt.hasNext()) { final T node = treeIt.next(); final DefaultMutableTreeNode snode = (DefaultMutableTreeNode)streeIt.nextElement(); Assert.assertEquals( node.pathElements().map(t -> t.value()), ISeq.of(snode.getUserObjectPath()) ); } }
Example 4
Source File: TreeTestBase.java From jenetics with Apache License 2.0 | 6 votes |
@Test(dataProvider = "nodeQueryMethods") public void nodeQueryMethod(final QueryMethod method) { final Iterator<T> tree = newTree(5, new Random(123)) .breadthFirstIterator(); final Enumeration<?> swing = newSwingTree(5, new Random(123)) .breadthFirstEnumeration(); while (tree.hasNext()) { final T node1 = tree.next(); final DefaultMutableTreeNode node2 = (DefaultMutableTreeNode)swing.nextElement(); final Iterator<T> tree1 = node1.breadthFirstIterator(); final Enumeration<?> swing1 = node2.breadthFirstEnumeration(); while (tree1.hasNext()) { final T node21 = tree1.next(); final DefaultMutableTreeNode node22 = (DefaultMutableTreeNode)swing1.nextElement(); assertEqualNodes( Try(() -> method._method1.apply(node1, node21)), Try(() -> method._method2.apply(node2, node22)) ); } } }
Example 5
Source File: LastNodeLowerHalfDrop.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void expandTree(JTree tree) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel() .getRoot(); Enumeration e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); if (node.isLeaf()) { continue; } int row = tree.getRowForPath(new TreePath(node.getPath())); tree.expandRow(row); } }
Example 6
Source File: TypesTreeModel.java From binnavi with Apache License 2.0 | 5 votes |
private List<DefaultMutableTreeNode> collectSubtreeNodes(final DefaultMutableTreeNode node) { final List<DefaultMutableTreeNode> nodes = new ArrayList<DefaultMutableTreeNode>(); for (final Enumeration<?> e = node.breadthFirstEnumeration(); e.hasMoreElements();) { nodes.add((DefaultMutableTreeNode) e.nextElement()); } return nodes; }
Example 7
Source File: TypesTreeModelTests.java From binnavi with Apache License 2.0 | 5 votes |
private static Multimap<Integer, DefaultMutableTreeNode> getNodesByLevel( final DefaultMutableTreeNode root) { final Multimap<Integer, DefaultMutableTreeNode> nodesByLevel = HashMultimap.create(); for (final Enumeration<?> e = root.breadthFirstEnumeration(); e.hasMoreElements();) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); nodesByLevel.put(node.getLevel(), node); } return nodesByLevel; }
Example 8
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
public static void collapseFirstHierarchy(JTree tree) { TreeModel model = tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); // // Java 9: // Collections.list(root.breadthFirstEnumeration()).stream() // .filter(DefaultMutableTreeNode.class::isInstance) // .map(DefaultMutableTreeNode.class::cast) // .takeWhile(node -> node.getLevel() <= 1) // .dropWhile(DefaultMutableTreeNode::isRoot) // .dropWhile(DefaultMutableTreeNode::isLeaf) // .map(DefaultMutableTreeNode::getPath) // .map(TreePath::new) // .forEach(tree::collapsePath); // Java 9: Enumeration<TreeNode> e = root.breadthFirstEnumeration(); Enumeration<?> e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); boolean isOverFirstLevel = node.getLevel() > 1; if (isOverFirstLevel) { // Collapse only nodes in the first hierarchy return; } else if (node.isLeaf() || node.isRoot()) { continue; } collapseNode(tree, node); } }
Example 9
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private void updateAllChildrenUserObject(DefaultMutableTreeNode root, boolean match) { Enumeration<?> breadth = root.breadthFirstEnumeration(); while (breadth.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) breadth.nextElement(); if (Objects.equals(root, node)) { continue; } FilterableNode uo = (FilterableNode) node.getUserObject(); uo.status = match; } }
Example 10
Source File: TreeTestBase.java From jenetics with Apache License 2.0 | 5 votes |
@Test public void breathFirstIterator() { final T tree = newTree(5, new Random(123)); final DefaultMutableTreeNode stree = newSwingTree(5, new Random(123)); final Iterator<T> treeIt = tree.breadthFirstIterator(); final Enumeration<?> streeIt = stree.breadthFirstEnumeration(); while (treeIt.hasNext()) { final T node = treeIt.next(); final DefaultMutableTreeNode snode = (DefaultMutableTreeNode)streeIt.nextElement(); Assert.assertEquals(node.value(), snode.getUserObject()); } }
Example 11
Source File: TreeUtils.java From MavenHelper with Apache License 2.0 | 5 votes |
public static void nodesChanged(DefaultTreeModel rightTreeModel) { DefaultMutableTreeNode root = (DefaultMutableTreeNode) rightTreeModel.getRoot(); Enumeration enumeration = root.breadthFirstEnumeration(); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) enumeration.nextElement(); rightTreeModel.nodeChanged(defaultMutableTreeNode); } }