List of usage examples for javax.swing.tree TreeNode getChildCount
int getChildCount();
TreeNode
s the receiver contains. From source file:com.mirth.connect.client.ui.components.MirthTree.java
/** * Get the index of a node in relation to other nodes with the same name. Returns -1 if there * isn't an index.//from w ww. ja va 2s. co m * * @param node * @return */ public static int getIndexOfNode(TreeNode node) { String nodeName = node.toString().replaceAll(" \\(.*\\)", ""); // Get the node name without the vocab TreeNode parent = node.getParent(); // The parent will be null for the root node if (parent != null) { Enumeration children = parent.children(); int indexCounter = 0; int foundIndex = -1; // Look through all of the children of the parent to see if there // are multiple children with the same name. while (children.hasMoreElements()) { TreeNode child = (TreeNode) children.nextElement(); // Ignore the draggable nodes that have no children if (child.getChildCount() > 0) { if (nodeName.equals(child.toString().replaceAll(" \\(.*\\)", ""))) { if (child != node) { indexCounter++; } else { foundIndex = indexCounter; indexCounter++; } } } } // If there were multiple children, add the index to the nodeQ. if (indexCounter > 1) { return foundIndex; } } return -1; }
From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java
private static void expandAll(JTree tree, TreePath treePath, boolean expand, int maxLevel, int currentLevel) { if (maxLevel != -1 && currentLevel >= maxLevel - 1) { return;//from w w w . j ava2s. c o m } TreeNode node = (TreeNode) treePath.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) { TreeNode n = e.nextElement(); TreePath path = treePath.pathByAddingChild(n); expandAll(tree, path, expand, maxLevel, currentLevel + 1); } } // Expansion or collapse must be done bottom-up if (expand) { tree.expandPath(treePath); } else { tree.collapsePath(treePath); } }
From source file:Main.java
private 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);/*from w w w . ja v a 2 s . co m*/ } } tree.expandPath(parent); // tree.collapsePath(parent); }
From source file:Main.java
public void getPaths(JTree tree, TreePath parent, boolean expanded, List<TreePath> list) { if (expanded && !tree.isVisible(parent)) { return;//from w w w . ja va 2s. co m } list.add(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); getPaths(tree, path, expanded, list); } } }
From source file:gdt.jgui.entity.JEntityStructurePanel.java
private void expandAll(JTree tree, TreePath path, boolean expand) { TreeNode node = (TreeNode) path.getLastPathComponent(); if (node.getChildCount() >= 0) { Enumeration enumeration = node.children(); while (enumeration.hasMoreElements()) { TreeNode n = (TreeNode) enumeration.nextElement(); TreePath p = path.pathByAddingChild(n); expandAll(tree, p, expand);/*from www . j av a2 s . com*/ } } if (expand) { tree.expandPath(path); } else { tree.collapsePath(path); } }
From source file:dotaSoundEditor.Controls.EditorPanel.java
protected TreeModel buildSoundListTree(TreeModel scriptTree) { TreeNode rootNode = (TreeNode) scriptTree.getRoot(); int childCount = rootNode.getChildCount(); TreeModel soundListTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode("root")); ArrayList<String> wavePathsList = new ArrayList<>(); for (int i = 0; i < childCount; i++) { String nodeValue = scriptTree.getChild(rootNode, i).toString(); if (nodeValue.trim().startsWith("//")) { continue; }/*from w ww . ja v a 2s. co m*/ wavePathsList = getWavePathsAsList((TreeNode) scriptTree.getChild(rootNode, i)); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(nodeValue); for (String s : wavePathsList) { DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(s); newNode.add(tempNode); } ((DefaultMutableTreeNode) soundListTreeModel.getRoot()).add(newNode); } return soundListTreeModel; }
From source file:gdt.jgui.entity.JEntityDigestDisplay.java
private void expandAll(JTree tree, TreePath path, boolean expand) { TreeNode node = (TreeNode) path.getLastPathComponent(); if (node.getChildCount() >= 0) { Enumeration enumeration = node.children(); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode n = (DefaultMutableTreeNode) enumeration.nextElement(); TreePath p = path.pathByAddingChild(n); expandAll(tree, p, expand);/*from w ww .ja v a 2 s . co m*/ } } if (expand) { tree.expandPath(path); } else { tree.collapsePath(path); } }
From source file:com.imaginea.betterdocs.BetterDocsAction.java
private TreeSelectionListener getTreeSelectionListener(final TreeNode root) { return new TreeSelectionListener() { @Override/*from w w w . j ava 2 s . c om*/ public void valueChanged(TreeSelectionEvent treeSelectionEvent) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent(); if (selectedNode == null) { } else if (selectedNode.isLeaf() && root.getChildCount() > 0) { final CodeInfo codeInfo = (CodeInfo) selectedNode.getUserObject(); final Document windowEditorDocument = windowEditor.getDocument(); writeToDocument(codeInfo, windowEditorDocument); final List<Integer> linesForFolding = codeInfo.getLineNumbers(); linesForFolding.add(windowEditorDocument.getLineCount() + 1); java.util.Collections.sort(linesForFolding); addFoldings(windowEditorDocument, linesForFolding); } } }; }
From source file:de.erdesignerng.visual.common.OutlineComponent.java
private void expandOrCollapseAllChildrenOfNode(TreePath aParentPath, boolean aExpand) { TreeNode node = (TreeNode) aParentPath.getLastPathComponent(); if (node.getChildCount() > 0) { for (Enumeration<TreeNode> en = node.children(); en.hasMoreElements();) { TreeNode n = en.nextElement(); TreePath path = aParentPath.pathByAddingChild(n); expandOrCollapseAllChildrenOfNode(path, aExpand); }//w w w. j av a2 s . com } if (aExpand) { tree.expandPath(aParentPath); } else { tree.collapsePath(aParentPath); } }
From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java
private void analisiRicorsivaAggiuntaIstanza(Object root, Scenario scenario, DefaultTreeModel model, String stringa) {//from www.j a v a2 s .c o m int indice = model.getChildCount(root); for (int i = 0; i < indice; i++) { analisiRicorsivaAggiuntaIstanza(model.getChild(root, i), scenario, model, stringa); } // if (indice == 2) { TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) root) .getUserObject(); TopComponent tc = componentAdapter.getTopComponent(); if (tc != null && tc == scenario.getMappingTaskTopComponent()) { TreeTopComponentAdapter ttca = new TreeTopComponentAdapter(null, false, false, true); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(ttca); TreeNode treeNode = ((TreeNode) root).getParent(); TreeNode nodeInstancesFather = treeNode.getChildAt(2); // if (stringa.equals(Costanti.SOURCE)) { TreeNode nodeInstacesSource = nodeInstancesFather.getChildAt(0); TreeNode nodeInstacesTarget = nodeInstancesFather.getChildAt(1); List<String> sourceInstancesName = (List<String>) scenario.getMappingTask().getSourceProxy() .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST); List<String> targetInstancesName = (List<String>) scenario.getMappingTask().getTargetProxy() .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST); int place = 0; String name = "xxx"; if (sourceInstancesName.size() != nodeInstacesSource.getChildCount()) { place = nodeInstacesSource.getChildCount(); name = findTitle(sourceInstancesName.get(sourceInstancesName.size() - 1)); model.insertNodeInto(newNode, (DefaultMutableTreeNode) nodeInstacesSource, place); } else if (targetInstancesName.size() != nodeInstacesTarget.getChildCount()) { place = nodeInstacesTarget.getChildCount(); name = findTitle(targetInstancesName.get(targetInstancesName.size() - 1)); model.insertNodeInto(newNode, (DefaultMutableTreeNode) nodeInstacesTarget, place); } ttca.setName(name); scenario.getXQueryTopComponent().update(); // return; // } } // return; // } }