Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#isRoot()
The following examples show how to use
javax.swing.tree.DefaultMutableTreeNode#isRoot() .
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: ElementSelectionListener.java From niftyeditor with Apache License 2.0 | 6 votes |
@Override public void valueChanged(TreeSelectionEvent e) { TreePath path = e.getNewLeadSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); if (!node.isRoot()) { try { SelectCommand command = CommandProcessor.getInstance().getCommand(SelectCommand.class); command.setElement((GElement) node.getUserObject()); CommandProcessor.getInstance().excuteCommand(command); } catch (Exception ex) { Logger.getLogger(ElementSelectionListener.class.getName()).log(Level.SEVERE, null, ex); } } final JTree temp = (JTree) e.getSource(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { temp.updateUI(); } }); } }
Example 2
Source File: VimDasaView.java From Astrosoft with GNU General Public License v2.0 | 6 votes |
public void nodeSelected(DefaultMutableTreeNode node, TreePath path) { Dasa dasa = (Dasa) node.getUserObject(); boolean isRoot = node.isRoot(); if (node.isLeaf()){ updateDasaTable(dasa.getParent(), isRoot); }else{ updateDasaTable(dasa, isRoot); } if (!isRoot && node.isLeaf()){ setRowSelected(node.getParent(), node); } String title; if (isRoot){ title = DisplayStrings.VIM_DASA_STR.toString(); }else{ title = path.getPathComponent(1).toString() + " " + DisplayStrings.DASA_STR.toString(); } dasaTitle.setText(title); }
Example 3
Source File: DasaTreeListener.java From Astrosoft with GNU General Public License v2.0 | 6 votes |
public void valueChanged(TreeSelectionEvent e) { JTree tree = (JTree) e.getSource(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null){ boolean isRoot = node.isRoot(); Dasa dasa = (Dasa) node.getUserObject(); //Add sub dasas only if not present already. if (!isRoot && node.isLeaf()){ for(Dasa d : dasa.subDasas()){ node.add(new DefaultMutableTreeNode(d, true)); } DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); model.reload(node); } handler.nodeSelected(node, e.getNewLeadSelectionPath()); } //tree.collapsePath(e.getOldLeadSelectionPath()); }
Example 4
Source File: DasaTreeCellRenderer.java From Astrosoft with GNU General Public License v2.0 | 6 votes |
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { renderer.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (value != null) { DefaultMutableTreeNode n = (DefaultMutableTreeNode) value; Dasa d = (Dasa)(n.getUserObject()); if (!n.isRoot()){ renderer.setToolTipText(d.getStartDate()); }else{ renderer.setToolTipText(""); } if (d.isRunning() && !selected){ renderer.setForeground(Color.RED); } } return renderer; }
Example 5
Source File: TableTreeData.java From JPPF with Apache License 2.0 | 5 votes |
/** * Get the list of selected nodes in depth-first traversal order. * @param handler the selection handler. * @param currentNode the node current being explored. * @param treeNodes the selected tree nodes. */ private void exploreTreeSelection(final SelectionHandler handler, final DefaultMutableTreeNode currentNode, final List<DefaultMutableTreeNode> treeNodes) { if (!currentNode.isRoot()) { final AbstractComponent<?> data = (AbstractComponent<?>) currentNode.getUserObject(); if (handler.isSelected(data.getUuid())) treeNodes.add(currentNode); } for (int i=0; i<currentNode.getChildCount(); i++) exploreTreeSelection(handler, (DefaultMutableTreeNode) currentNode.getChildAt(i), treeNodes); }
Example 6
Source File: AlertReportExportMenuItem.java From zap-extensions with Apache License 2.0 | 5 votes |
@Override public boolean isEnableForComponent(Component invoker) { if (invoker.getName() != null && "treeAlert".equals(invoker.getName())) { JTree tree = (JTree) invoker; if (tree.getLastSelectedPathComponent() != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); this.treeAlert = tree; if (!node.isRoot()) { return true; } } } return false; }
Example 7
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 8
Source File: FilteredTree.java From swing_library with MIT License | 5 votes |
/** * * @param root * @return boolean bad leaves were returned */ private boolean removeBadLeaves(DefaultMutableTreeNode root) { // no bad leaves yet boolean badLeaves = false; // reference first leaf DefaultMutableTreeNode leaf = root.getFirstLeaf(); // if leaf is root then its the only node if (leaf.isRoot()) return false; int leafCount = root.getLeafCount(); // this get method changes if in for loop so have to define outside of it for (int i = 0; i < leafCount; i++) { DefaultMutableTreeNode nextLeaf = leaf.getNextLeaf(); // if it does not start with the text then snip it off its parent if (!leaf.getUserObject().toString().startsWith(textToMatch)) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) leaf.getParent(); if (parent != null) parent.remove(leaf); badLeaves = true; } leaf = nextLeaf; } return badLeaves; }
Example 9
Source File: FilterTreeModel.java From swing_library with MIT License | 5 votes |
/** * * @param root * @return boolean bad leaves were returned */ private boolean removeBadLeaves(DefaultMutableTreeNode root) { // no bad leaves yet boolean badLeaves = false; // reference first leaf DefaultMutableTreeNode leaf = root.getFirstLeaf(); // if leaf is root then its the only node if (leaf.isRoot()) return false; int leafCount = root.getLeafCount(); // this get method changes if in for loop so have to define outside of it for (int i = 0; i < leafCount; i++) { DefaultMutableTreeNode nextLeaf = leaf.getNextLeaf(); // if it does not start with the text then snip it off its parent if (!filter.accepts(filterText, leaf.getUserObject().toString())) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) leaf.getParent(); if (parent != null) parent.remove(leaf); badLeaves = true; } leaf = nextLeaf; } return badLeaves; }
Example 10
Source File: TableTreeHelper.java From JPPF with Apache License 2.0 | 4 votes |
/** * Recursively expand all non-leaf nodes in the specified table tree. * @param tableTree the table tree that renders the nodes. * @param node the root node to expand. */ public static void expand(final JPPFTableTree tableTree, final DefaultMutableTreeNode node) { if (node.isLeaf()) return; if (!node.isRoot()) tableTree.expand(node); for (int i=0; i<node.getChildCount(); i++) expand(tableTree, (DefaultMutableTreeNode) node.getChildAt(i)); }