DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement(); if(node.isLeaf()) continue; int row = tree.getRowForPath(new TreePath(node.getPath())); tree.expandRow(row);
//Where the tree is initialized: tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); //Listen for when the selection changes. tree.addTreeSelectionListener(this); public void valueChanged(TreeSelectionEvent e) { //Returns the last path element of the selection. //This method is useful only when the selection model allows a single selection. DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) //Nothing is selected. return; Object nodeInfo = node.getUserObject(); if (node.isLeaf()) { BookInfo book = (BookInfo) nodeInfo; displayURL(book.bookURL); } else { displayURL(helpURL); } }
public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
if (node == null || node.isLeaf()) { return null;
TreeModel model = tree.getModel(); DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) model.getRoot(); // Just changing enumeration kind here Enumeration<DefaultMutableTreeNode> en = rootNode.preorderEnumeration(); while (en.hasMoreElements()) { DefaultMutableTreeNode node = en.nextElement(); TreeNode[] path = node.getPath(); System.out.println((node.isLeaf() ? " - " : "+ ") + path[path.length - 1]); }
@Override public void run() { try { Queue<DefaultMutableTreeNode> q = new LinkedList<>(); q.add(node); while (!q.isEmpty()) { final DefaultMutableTreeNode n = q.poll(); expand(n); @SuppressWarnings("unchecked") Enumeration<TreeNode> children = n.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); if (!child.isLeaf() && child.getChildCount() > 0) { q.offer(child); } } } } finally { executor.shutdownNow(); } } });
/** * Removes any inactive nodes from the Category tree. */ protected int removeUnusedNodes() { int count = 0; CategoryNode root = _categoryModel.getRootCategoryNode(); Enumeration enumeration = root.depthFirstEnumeration(); while (enumeration.hasMoreElements()) { CategoryNode node = (CategoryNode) enumeration.nextElement(); if (node.isLeaf() && node.getNumberOfContainedRecords() == 0 && node.getParent() != null) { _categoryModel.removeNodeFromParent(node); count++; } } return count; }
if (node.isLeaf()) { ChartInfo chartInfo = (ChartInfo) nodeInfo;
if (node.isLeaf()) { if (!(nodeInfo instanceof ExampleChartInfo)) { return;
/** * Test if node is leaf. * @return True, if is leaf. */ public boolean isLeaf() { return leaf!=null? leaf.booleanValue(): super.isLeaf(); }
public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
public void handleClick( DefaultMutableTreeNode node ) { if (node == null) return; if (!node.isLeaf()) return; AppInfo info = (AppInfo)node.getUserObject(); System.out.println("clicked "+info); launch(info); }
public boolean shouldSelectCell(EventObject e) { boolean rv = false; // only mouse events if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; TreePath path = tree.getPathForLocation(me.getX(), me.getY()); CategoryNode node = (CategoryNode) path.getLastPathComponent(); rv = node.isLeaf() /*|| !inCheckBoxHitRegion(me)*/; } return rv; }
public List<DefaultMutableTreeNode> getLeaves(DefaultMutableTreeNode node) { Enumeration<?> e = node.breadthFirstEnumeration(); List<DefaultMutableTreeNode> leaves = new ArrayList<DefaultMutableTreeNode>(); while (e.hasMoreElements()) { DefaultMutableTreeNode element = (DefaultMutableTreeNode) e.nextElement(); if (element.isLeaf()) { leaves.add(element); } } return leaves; }
public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) { Enumeration e = root.depthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); if (!node.isLeaf()) { _sortTreeNode(node); } } return root; }
@Override public void mouseClicked(MouseEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) arvoreExemplos.getLastSelectedPathComponent(); if (e.getClickCount() == 2 && node.isLeaf()) { botaoAbrirExemplo.doClick(); } } });
public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) return; Object nodeInfo = node.getUserObject(); if (node.isLeaf() && nodeInfo instanceof GCTestStep) { GCTestStep testStep = (GCTestStep) nodeInfo; updatePane(testStep); } }
public void mouseDragged(MouseEvent e) { int selRow = pTree.getRowForLocation(e.getX(), e.getY()); if(selRow!=-1) { if(((DefaultMutableTreeNode)pTree.getLastSelectedPathComponent()).isLeaf()) return; pFrame.setCursor(new Cursor(Cursor.MOVE_CURSOR)); isDragging = true; } } });
@Override public boolean isLeaf() { // there is two behaviours for the test : // 1 - when the node is static, then can directly use his number of child // to determine if node is a leaf (no child) // 2 - when the node is dynamic, then ALWAYS says the node is NOT a leaf until // it was loaded, otherwise the WillExpand listener will not load the childs... // Once the node is loaded, use back the normal behaviour (count number of childs) return isStaticNode() ? super.isLeaf() : isLoaded() && getChildCount() == 0; }
private void collapseChildren(DefaultMutableTreeNode node, JTree tree) { DefaultMutableTreeNode child; int nrChildren = node.getChildCount(); for (int i = 0; i < nrChildren; i++) { child = (DefaultMutableTreeNode) node.getChildAt(i); if (!child.isLeaf()) { tree.collapsePath(new TreePath(child.getPath())); collapseChildren(child, tree); } } } }