Java Code Examples for javax.swing.tree.TreeNode#getChildCount()
The following examples show how to use
javax.swing.tree.TreeNode#getChildCount() .
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 |
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: OutlineComponent.java From MogwaiERDesignerNG with GNU General Public License v3.0 | 6 votes |
private void expandOrCollapseAllChildrenOfNode(TreePath aParentPath, boolean aExpand) { TreeNode node = (TreeNode) aParentPath.getLastPathComponent(); if (node.getChildCount() > 0) { for (Enumeration<TreeNode> en = (Enumeration<TreeNode>) node.children(); en .hasMoreElements(); ) { TreeNode n = en.nextElement(); TreePath path = aParentPath.pathByAddingChild(n); expandOrCollapseAllChildrenOfNode(path, aExpand); } } if (aExpand) { tree.expandPath(aParentPath); } else { tree.collapsePath(aParentPath); } }
Example 3
Source File: SdkListConfigurable.java From consulo with Apache License 2.0 | 6 votes |
@RequiredUIAccess @Override public void apply() throws ConfigurationException { boolean modifiedSdks = false; for (int i = 0; i < myRoot.getChildCount(); i++) { final TreeNode groupNode = myRoot.getChildAt(i); for (int k = 0; k < groupNode.getChildCount(); k++) { final MyNode sdkNode = (MyNode)groupNode.getChildAt(k); final NamedConfigurable configurable = sdkNode.getConfigurable(); if (configurable.isModified()) { configurable.apply(); modifiedSdks = true; } } } if (mySdksModel.isModified() || modifiedSdks) mySdksModel.apply(this); }
Example 4
Source File: RTree.java From marathonv5 with Apache License 2.0 | 6 votes |
@Override public void mousePressed(MouseEvent me) { // Ignore double clicks on non-leaf tree nodes if (me.getButton() == MouseEvent.BUTTON1 && me.getModifiersEx() == InputEvent.BUTTON1_DOWN_MASK && me.getClickCount() > 1) { TreePath path = ((JTree) component).getPathForRow(row); if (path != null) { Object lastPathComponent = path.getLastPathComponent(); if (lastPathComponent instanceof TreeNode) { TreeNode node = (TreeNode) lastPathComponent; if (node.getChildCount() != 0) { return; } } } } // Ignore Ctrl+Clicks used to select the nodes if (me.getButton() == MouseEvent.BUTTON1 && isMenuShortcutKeyDown(me)) { return; } if (me.getButton() != MouseEvent.BUTTON1) { focusLost(null); } super.mousePressed(me); }
Example 5
Source File: InspectorPanel.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void expandAll(JTree tree, TreePath parent, boolean expandProperties) { final TreeNode node = (TreeNode)parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (final Enumeration e = node.children(); e.hasMoreElements(); ) { final DefaultMutableTreeNode n = (DefaultMutableTreeNode)e.nextElement(); if (n.getUserObject() instanceof DiagnosticsNode) { final DiagnosticsNode diagonsticsNode = (DiagnosticsNode)n.getUserObject(); if (!diagonsticsNode.childrenReady() || (diagonsticsNode.isProperty() && !expandProperties)) { continue; } } expandAll(tree, parent.pathByAddingChild(n), expandProperties); } } tree.expandPath(parent); }
Example 6
Source File: TreeHelpers.java From binnavi with Apache License 2.0 | 6 votes |
private static void expandAll(final JTree tree, final TreePath parent, final boolean expand) { // Traverse children final TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (final Enumeration<?> e = node.children(); e.hasMoreElements();) { final TreeNode n = (TreeNode) e.nextElement(); final 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 7
Source File: CheckTreeNode.java From netbeans with Apache License 2.0 | 6 votes |
private boolean areSiblingsUnchecked() { TreeNode parent = getParent(); for (int i = 0; i < parent.getChildCount(); i++) { TreeNode node = parent.getChildAt(i); if (node == this) { continue; } if (!(node instanceof CheckTreeNode) || (((CheckTreeNode) node).getCheckState() != STATE_UNCHECKED)) { return false; } } return true; }
Example 8
Source File: RevertDeletedAction.java From netbeans with Apache License 2.0 | 5 votes |
private List<StoreEntryNode> getSelectedNodes(TreeNode node) { List<StoreEntryNode> ret = new LinkedList<StoreEntryNode>(); int count = node.getChildCount(); for (int i = 0; i < count; i++) { TreeNode child = node.getChildAt(i); if(child instanceof StoreEntryNode) { StoreEntryNode sen = (StoreEntryNode) child; if(sen.isSelected()) { ret.add(sen); } } ret.addAll(getSelectedNodes(child)); } return ret; }
Example 9
Source File: DErrorDetail.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
private void expandTree(JTree tree, TreePath parent) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration<?> children = node.children(); children.hasMoreElements();) { TreeNode subNode = (TreeNode) children.nextElement(); TreePath path = parent.pathByAddingChild(subNode); expandTree(tree, path); } } tree.expandPath(parent); }
Example 10
Source File: XTree.java From scelight with Apache License 2.0 | 5 votes |
@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 ); }
Example 11
Source File: XpathGenerator.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private static String getPosition(IOSTreeNode node) { int count = 0; TreeNode parent = node.getParent(); String nodeName = node.getAttribute("tag"); for (int i = 0; i < parent.getChildCount(); i++) { IOSTreeNode currNode = (IOSTreeNode) parent.getChildAt(i); if (currNode.getAttribute("tag").equals(nodeName)) { count++; if (currNode.equals(node)) { return nodeName + "[" + count + "]"; } } } return nodeName; }
Example 12
Source File: MainWindow.java From jadx with Apache License 2.0 | 5 votes |
public static void getExpandedPaths(JTree tree, TreePath path, List<TreePath> list) { if (tree.isExpanded(path)) { list.add(path); TreeNode node = (TreeNode) path.getLastPathComponent(); for (int i = node.getChildCount() - 1; i >= 0; i--) { TreeNode n = node.getChildAt(i); TreePath child = path.pathByAddingChild(n); getExpandedPaths(tree, child, list); } } }
Example 13
Source File: TreeUtil.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 5 votes |
public static TreePath buildTreePath(JTree tree, TreePath parent, String[] nodes, int startdepth, boolean expandable) { TreeNode node = (TreeNode) parent.getLastPathComponent(); String o = node.toString(); // If equal, go down the branch if (o.equals(nodes[startdepth])) { // If at end, return match if (startdepth == 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); if (n.isLeaf() && expandable) { return parent; } TreePath result = buildTreePath(tree, path, nodes, startdepth + 1,expandable); // Found a match if (result != null) { return result; } } } } // No match at this branch return null; }
Example 14
Source File: JFrameRTStats.java From mts with GNU General Public License v3.0 | 5 votes |
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 15
Source File: PreferencesPanel.java From importer-exporter with Apache License 2.0 | 5 votes |
private void performActionOnNodes(TreePath parent, boolean expand, boolean recursive) { TreeNode node = (TreeNode)parent.getLastPathComponent(); if (recursive) for (int i = 0; i < node.getChildCount(); ++i) performActionOnNodes(parent.pathByAddingChild(node.getChildAt(i)), expand, recursive); if (expand) menuTree.expandPath(parent); else menuTree.collapsePath(parent); }
Example 16
Source File: SdkListConfigurable.java From consulo with Apache License 2.0 | 5 votes |
@Override protected void onItemDeleted(Object item) { for (int i = 0; i < myRoot.getChildCount(); i++) { final TreeNode childAt = myRoot.getChildAt(i); if (childAt instanceof MyNode) { if (childAt.getChildCount() == 0) { myRoot.remove((MutableTreeNode)childAt); ((DefaultTreeModel)myTree.getModel()).reload(myRoot); } } } }
Example 17
Source File: DProperties.java From keystore-explorer with GNU General Public License v3.0 | 5 votes |
private String getNodeContents(TreeNode node, int level) { StringBuffer strBuff = new StringBuffer(); strBuff.append(INDENT.toString(level)); strBuff.append(node.toString().trim()); strBuff.append(NEWLINE); for (int i = 0; i < node.getChildCount(); i++) { strBuff.append(getNodeContents(node.getChildAt(i), level + 1)); } return strBuff.toString(); }
Example 18
Source File: IndexTreePathState.java From consulo with Apache License 2.0 | 5 votes |
public TreePath getRestoredPath() { int aliveIndex = findLowestAliveNodeIndex(mySelectionPath); if (aliveIndex == mySelectionPath.getPathCount() - 1) return mySelectionPath; TreeNode aliveAncestor = (TreeNode) mySelectionPath.getPathComponent(aliveIndex); TreePath newSelection = TreeUtil.getPathFromRoot(aliveAncestor); int childrenLeft = aliveAncestor.getChildCount(); if (childrenLeft != 0) { int newSelectedChildIndex = Math.min(myIndicies[aliveIndex + 1], childrenLeft - 1); newSelection = newSelection.pathByAddingChild(aliveAncestor.getChildAt(newSelectedChildIndex)); } return newSelection; }
Example 19
Source File: PreferencesPanel.java From importer-exporter with Apache License 2.0 | 4 votes |
private void nodesChanged(DefaultTreeModel model, TreeNode node) { model.nodeChanged(node); for (int i = 0; i < node.getChildCount(); i++) nodesChanged(model, node.getChildAt(i)); }
Example 20
Source File: SwingExtensions.java From groovy with Apache License 2.0 | 2 votes |
/** * Provide the standard Groovy <code>size()</code> method for <code>TreeNode</code>. * * @param self a TreeNode * @return the child count of the treeNode * @since 1.6.4 */ public static int size(TreeNode self) { return self.getChildCount(); }