Refine search
private void expandAll(TreePath parent, boolean expand) { // Traverse children 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, expand); } } if (expand) { expandPath(parent); } else { collapsePath(parent); } } }
@Override public void treeExpanded(final TreeExpansionEvent event) { final TreePath treePath = event.getPath(); final Object expandedTreePathObject = treePath.getLastPathComponent(); if (!(expandedTreePathObject instanceof TreeNode)) { return; } final TreeNode expandedTreeNode = (TreeNode) expandedTreePathObject; if (expandedTreeNode.getChildCount() == 1) { final TreeNode descendantTreeNode = expandedTreeNode.getChildAt(0); if (descendantTreeNode.isLeaf()) { return; } final TreePath nextTreePath = treePath.pathByAddingChild(descendantTreeNode); tree.expandPath(nextTreePath); } }
private Object[] makeTreePathArray(FileTreeNode node) { List<TreeNode> path = new ArrayList<>(); path.add(node); TreeNode child = node; while(child != this.getRoot()) { child = child.getParent(); path.add(0, child); } return path.toArray(); }
private int countLoops() { DefaultMutableTreeNode treeNode = stack.getLastLeaf(); int counter = 0; if (treeNode.getParent() != null) { // for some unknown reasons the parent of treeNode might be null, // see bug 1597987 // see https://sourceforge.net/p/pmd/bugs/606/ int childCount = treeNode.getParent().getChildCount(); for (int i = 0; i < childCount; i++) { DefaultMutableTreeNode tNode = (DefaultMutableTreeNode) treeNode.getParent().getChildAt(i); PathElement e = (PathElement) tNode.getUserObject(); if (e != null && !e.isPseudoPathElement()) { counter++; } } } return counter; }
/** * Remove all the nodes from the Tree */ public void reset() { Enumeration<TreeNode> children = root.children(); while (children.hasMoreElements()) { removeNodeFromParent((MutableTreeNode) children.nextElement()); children = root.children(); } }
@Override public void actionPerformed(ActionEvent e) { TreeNode root = (TreeNode) configTree[num].getModel().getRoot(); TreePath parent = new TreePath(root); for (Enumeration cat = root.children(); cat.hasMoreElements();) { TreeNode n = (TreeNode) cat.nextElement(); TreePath child = parent.pathByAddingChild(n); configTree[num].expandPath(child); } } });
@Override public void actionPerformed(ActionEvent e) { TreeNode root = (TreeNode) configTree[num].getModel().getRoot(); TreePath parent = new TreePath(root); for (Enumeration categ = root.children(); categ.hasMoreElements();) { TreeNode n = (TreeNode) categ.nextElement(); TreePath child = parent.pathByAddingChild(n); configTree[num].collapsePath(child); } } });
private static void expandAll(JTree tree, TreePath parent) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.isLeaf() && tree.isVisible(parent) == false) { tree.makeVisible(parent); } else { for (Enumeration en = node.children(); en.hasMoreElements();) { TreeNode child = (TreeNode) en.nextElement(); expandAll(tree, parent.pathByAddingChild(child)); } } }
/** * Returns a copy of the tree starting at the given node. * * @param tree The tree to copy (may be {@code null}). * @return A mutable copy of the given tree, or {@code null} if the tree was null. * @todo Use {@code getUserObject} when we can. * @since 2.5 */ public static MutableTreeNode copy(final TreeNode node) { if (node == null) { return null; } final DefaultMutableTreeNode target = new DefaultMutableTreeNode(node.toString(), node.getAllowsChildren()); final Enumeration children = node.children(); if (children != null) { while (children.hasMoreElements()) { final TreeNode child = (TreeNode) children.nextElement(); target.add(copy(child)); } } return target; }
TreeNode root = (TreeNode)tree.getModel().getRoot(); Enumeration childrenEnum = root.children(); while (childrenEnum.hasMoreElements()) { TreeNode childNode = (TreeNode)childrenEnum.nextElement(); String childString = childNode.toString(); // .... }
@Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { TreePath path = directoryChooser.getPathForLocation(e.getX(), e.getY()); if (path != null && path.equals(directoryChooser.getSelectionPath()) && directoryChooser.getSelectedFiles().length > 0) { TreeNode o = (TreeNode) path.getLastPathComponent(); if (o.isLeaf() || !o.children().hasMoreElements()) actionListener.actionPerformed(new ActionEvent(directoryChooser, 0, null)); } } } });
public boolean isNextChapterAvailable(final boolean _do) { final TreeNode n = getChapter((DefaultMutableTreeNode) trIndex_.getLastSelectedPathComponent()); if (n != null) { final TreeNode root = (TreeNode) trIndex_.getModel().getRoot(); final int idx = root.getIndex(n); final boolean r = idx >= 0 && ((idx + 1) < root.getChildCount()); if (r && _do) { trIndex_.setSelectionPath(new TreePath(new Object[] { root, root.getChildAt(idx + 1) })); } return r; } return false; }
private static TreePath getTreePath(TreeNode node) { List<TreeNode> list = new ArrayList<>(); list.add(node); TreeNode parent = node; while (parent.getParent() != null) { parent = parent.getParent(); list.add(parent); } Collections.reverse(list); return new TreePath(list.toArray(new TreeNode[list.size()])); }
@Override public void mousePressed(MouseEvent event) { boolean isClickCountMatches = (event.getClickCount() == 1 && luytenPrefs.isSingleClickOpenEnabled()) || (event.getClickCount() == 2 && !luytenPrefs.isSingleClickOpenEnabled()); if (!isClickCountMatches) return; if (!SwingUtilities.isLeftMouseButton(event)) return; final TreePath trp = tree.getPathForLocation(event.getX(), event.getY()); if (trp == null) return; Object lastPathComponent = trp.getLastPathComponent(); boolean isLeaf = (lastPathComponent instanceof TreeNode && ((TreeNode) lastPathComponent).isLeaf()); if (!isLeaf) return; new Thread() { public void run() { openEntryByTreePath(trp); } }.start(); } }
@Override public void collapsePathRecursive( final TreePath path ) { final TreeNode node = (TreeNode) path.getLastPathComponent(); // Going downward is faster because collapsing needs to update row indices of rows that follow // and this way there are less rows to follow when collapsing a node for ( int i = node.getChildCount() - 1; i >= 0; i-- ) collapsePathRecursive( path.pathByAddingChild( node.getChildAt( i ) ) ); collapsePath( path ); }
@Test public void testAppendDapNode() throws URISyntaxException { // preparation datasets.add(createDataset(catalog, "first", "OPENDAP")); // execution new CatalogTree(null, new DefaultAppContext(""), null).appendToNode(new JTree(), datasets, parentNode, true); // verification assertEquals(1, parentNode.getChildCount()); assertEquals(true, parentNode.getChildAt(0).isLeaf()); assertEquals(true, CatalogTreeUtils.isDapNode(parentNode.getChildAt(0))); }
/** * Expand the given tree to the given level, starting from the given node * and path. * * @param tree The tree to be expanded * @param node The node to start from * @param path The path to start from * @param level The number of levels to expand to */ private static void expandNode(final JTree tree, final TreeNode node, final TreePath path, final int level) { if (level <= 0) { return; } tree.expandPath(path); for (int i = 0; i < node.getChildCount(); ++i) { final TreeNode childNode = node.getChildAt(i); expandNode(tree, childNode, path.pathByAddingChild(childNode), level - 1); } }
public boolean isLeaf(TreePath nodeIdentifier) { TreeNode lastPathComponent = (TreeNode) nodeIdentifier.getLastPathComponent(); return lastPathComponent.isLeaf(); }
private void skip_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_skip_buttonActionPerformed if (deleteSelectedTreeItems(file_tree)) { _genDownloadLiks(); restore_button.setVisible(true); boolean root_childs = ((TreeNode) file_tree.getModel().getRoot()).getChildCount() > 0; dance_button.setEnabled(root_childs); skip_button.setEnabled(root_childs); skip_rest_button.setEnabled(root_childs); } }//GEN-LAST:event_skip_buttonActionPerformed
public void expandStandardPaths() { final TreeNode root = (TreeNode) getModel().getRoot(); final DefaultMutableTreeNode schemaNode = (DefaultMutableTreeNode) root.getChildAt(0); final DefaultMutableTreeNode libraryNode = (DefaultMutableTreeNode) root.getChildAt(1); expandPath(new TreePath(schemaNode.getPath())); expandPath(new TreePath(libraryNode.getPath())); }