/** * 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(); }
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 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; }
final int indent, final String lineSeparator) { final int count = node.getChildCount(); if (count == 0) { if (node.isLeaf()) {
/** * 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); } }
private int getChildCountInternal(Object node) { if (node == null) { return 0; } return ((TreeNode) node).getChildCount(); }
public int getChildCount() { if (bean != null && bean instanceof TreeNode) { return ((TreeNode)bean).getChildCount(); } return 0; }
@Override public int getChildCount(Object parent) { if (m_filterIsActive) { if (parent instanceof InvisibleNode) { return ((InvisibleNode) parent).getChildCount(m_filterIsActive); } } return ((TreeNode) parent).getChildCount(); } }
protected TreeNode findChild(TreeNode parent, Integer simpleKey) { int childIdx = simpleKey.intValue(); if (childIdx < parent.getChildCount()) { return parent.getChildAt(childIdx); } return null; }
private String getNodeContents(TreeNode node, int level) { StringBuffer strBuff = new StringBuffer(); for (int i = 0; i < level; i++) { strBuff.append('\t'); } strBuff.append(node.toString()); strBuff.append('\n'); for (int i = 0; i < node.getChildCount(); i++) { strBuff.append(getNodeContents(node.getChildAt(i), level + 1)); } return strBuff.toString(); }
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(); }
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); }
private static void collapseAll(JTree tree, TreePath parent) { // Traverse children 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); collapseAll(tree, path); } } tree.collapsePath(parent); }
private void expandTree(JTree tree, TreePath parent) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration<?> enumNodes = node.children(); enumNodes.hasMoreElements();) { TreeNode subNode = (TreeNode) enumNodes.nextElement(); TreePath path = parent.pathByAddingChild(subNode); expandTree(tree, path); } } tree.expandPath(parent); }
@Override public ASTNodeValue geq(ASTNode left, ASTNode right) throws SBMLException { if (left != null && left.getParent().getChildCount() > 2 || left != null && left.getParent().getChildCount() < 2) { return function("geq", ((ASTNode) left.getParent()).getListOfNodes()); // TODO - still use ">=" when there are more than 2 children } return new ASTNodeValue(relation(left, ">=", right), this); }
@Override public ASTNodeValue eq(ASTNode left, ASTNode right) throws SBMLException { if (left != null && left.getParent().getChildCount() > 2 || left != null && left.getParent().getChildCount() < 2) { return function("eq", ((ASTNode) left.getParent()).getListOfNodes()); } return new ASTNodeValue(relation(left, "==", right), this); }
@Override public ASTNodeValue gt(ASTNode left, ASTNode right) throws SBMLException { if (left != null && left.getParent().getChildCount() > 2 || left != null && left.getParent().getChildCount() < 2) { return function("gt", ((ASTNode) left.getParent()).getListOfNodes()); } return new ASTNodeValue(relation(left, ">", right), this); }
@Override public ASTNodeValue leq(ASTNode left, ASTNode right) throws SBMLException { if (left != null && left.getParent().getChildCount() > 2 || left != null && left.getParent().getChildCount() < 2) { return function("leq", ((ASTNode) left.getParent()).getListOfNodes()); } return new ASTNodeValue(relation(left, "<=", right), this); }
private void setSelectionType(final TreeNode selectedNode, final int newSelectionType) { final TreeNodeInfo info = (TreeNodeInfo) ((DefaultMutableTreeNode) selectedNode).getUserObject(); if (info.getSelected() != newSelectionType) { info.setSelected(newSelectionType); treeModel.nodeChanged(selectedNode); } for (int i = 0; i < selectedNode.getChildCount(); i++) { setSelectionType(selectedNode.getChildAt(i), newSelectionType); } }