Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#getIndex()
The following examples show how to use
javax.swing.tree.DefaultMutableTreeNode#getIndex() .
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: IfStatementExpressionAnalyzer.java From IntelliJDeodorant with MIT License | 5 votes |
public DefaultMutableTreeNode getRemainingExpression(PsiExpression expressionToBeRemoved) { DefaultMutableTreeNode newRoot = new DefaultMutableTreeNode(); processExpression(newRoot, completeExpression); DefaultMutableTreeNode leaf = newRoot.getFirstLeaf(); while (leaf != null) { PsiExpression expression = (PsiExpression) leaf.getUserObject(); if (expression.equals(expressionToBeRemoved)) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) leaf.getParent(); if (parent != null) { DefaultMutableTreeNode grandParent = (DefaultMutableTreeNode) parent.getParent(); DefaultMutableTreeNode sibling = null; if (leaf.getNextSibling() != null) { sibling = leaf.getNextSibling(); } else if (leaf.getPreviousSibling() != null) { sibling = leaf.getPreviousSibling(); } if (grandParent != null) { int parentIndex = grandParent.getIndex(parent); grandParent.remove(parent); grandParent.insert(sibling, parentIndex); } else { newRoot = sibling; } } else { newRoot = null; } break; } leaf = leaf.getNextLeaf(); } return newRoot; }
Example 2
Source File: UMLModelASTReader.java From RefactoringMiner with MIT License | 5 votes |
private String getAnonymousBinaryName(DefaultMutableTreeNode node) { StringBuilder name = new StringBuilder(); TreeNode[] path = node.getPath(); for(int i=0; i<path.length; i++) { DefaultMutableTreeNode tmp = (DefaultMutableTreeNode)path[i]; if(tmp.getUserObject() != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode)tmp.getParent(); int index = parent.getIndex(tmp); name.append(index+1); if(i < path.length-1) name.append("."); } } return name.toString(); }
Example 3
Source File: IfStatementExpressionAnalyzer.java From JDeodorant with MIT License | 5 votes |
private void processExpression(DefaultMutableTreeNode parent, Expression expression) { if(expression instanceof InfixExpression) { InfixExpression infixExpression = (InfixExpression)expression; InfixExpression.Operator operator = infixExpression.getOperator(); if(operator.equals(InfixExpression.Operator.CONDITIONAL_AND) || operator.equals(InfixExpression.Operator.CONDITIONAL_OR)) { parent.setUserObject(operator); DefaultMutableTreeNode leftOperandNode = new DefaultMutableTreeNode(); DefaultMutableTreeNode rightOperandNode = new DefaultMutableTreeNode(); parent.add(leftOperandNode); parent.add(rightOperandNode); processExpression(leftOperandNode, infixExpression.getLeftOperand()); processExpression(rightOperandNode, infixExpression.getRightOperand()); if(infixExpression.hasExtendedOperands()) { DefaultMutableTreeNode grandParent = (DefaultMutableTreeNode)parent.getParent(); int parentIndex = -1; if(grandParent != null) parentIndex = grandParent.getIndex(parent); DefaultMutableTreeNode newParent = processExtendedOperands(parent, infixExpression.extendedOperands()); if(grandParent != null) grandParent.insert(newParent, parentIndex); else root = newParent; } } else { parent.setUserObject(infixExpression); } } else { parent.setUserObject(expression); } }
Example 4
Source File: IfStatementExpressionAnalyzer.java From JDeodorant with MIT License | 5 votes |
public DefaultMutableTreeNode getRemainingExpression(Expression expressionToBeRemoved) { DefaultMutableTreeNode newRoot = new DefaultMutableTreeNode(); processExpression(newRoot, completeExpression); DefaultMutableTreeNode leaf = newRoot.getFirstLeaf(); while(leaf != null) { Expression expression = (Expression)leaf.getUserObject(); if(expression.equals(expressionToBeRemoved)) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode)leaf.getParent(); if(parent != null) { DefaultMutableTreeNode grandParent = (DefaultMutableTreeNode)parent.getParent(); DefaultMutableTreeNode sibling = null; if(leaf.getNextSibling() != null) { sibling = leaf.getNextSibling(); } else if(leaf.getPreviousSibling() != null) { sibling = leaf.getPreviousSibling(); } if(grandParent != null) { int parentIndex = grandParent.getIndex(parent); grandParent.remove(parent); grandParent.insert(sibling, parentIndex); } else { newRoot = sibling; } break; } else { newRoot = null; break; } } leaf = leaf.getNextLeaf(); } return newRoot; }
Example 5
Source File: ProjectTree.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** Implements the "Duplicate, link and send to next/previous layer" functionality. The 'position' can be zero (before) or 1 (after). The profile has no layer assigned. */ public Profile duplicateChild(Profile original, int position, Layer layer) { Utils.log2("ProjectTree: Called duplicateChild " + System.currentTimeMillis() + " for original id = " + original.getId() + " at position " + position); // find the Thing that holds it Thing child = project.findProjectThing(original); if (null == child) { Utils.log("ProjectTree.duplicateChild: node not found for original " + original); return null; } Profile copy = (Profile)original.clone(); copy.setLayer(layer); // for the Z ordering ProjectThing new_thing = null; try { new_thing = new ProjectThing(((ProjectThing)child.getParent()).getChildTemplate(child.getType()), original.getProject(), copy); } catch (Exception e) { IJError.print(e); return null; } DefaultMutableTreeNode child_node = (DefaultMutableTreeNode)findNode(child, this); DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode)child_node.getParent(); ProjectThing parent_thing = (ProjectThing)parent_node.getUserObject(); //sanity check: if (position < 0) position = 0; else if (position > 1) position = 1; int index = parent_node.getIndex(child_node) + position; if (index < 0) index = 0; if (index > parent_node.getChildCount()) index = parent_node.getChildCount() -1; if (!parent_thing.addChild(new_thing, index)) return null; DefaultMutableTreeNode new_node = new DefaultMutableTreeNode(new_thing); ((DefaultTreeModel)this.getModel()).insertNodeInto(new_node, parent_node, index /*parent_node.getIndex(child_node) + position*/); // relist properly the nodes updateList(parent_node); TreePath treePath = new TreePath(new_node.getPath()); this.scrollPathToVisible(treePath); this.setSelectionPath(treePath); return copy; }
Example 6
Source File: CalculationTreeEditor.java From swing_library with MIT License | 4 votes |
public Object getCellEditorValue() { System.out.println("getCellEditorValue"); Double i = (Double) emptyNodeEditor.getCellEditorValue(); ValueNode vn = new ValueNode(i); editedNode.setUserObject(new ValueNode(i)); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) editedNode .getParent(); int index = parent.getIndex(editedNode); if (editedNode.getUserObject() instanceof MultiEmptyNode) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) editedNode .getParent(); DefaultMutableTreeNode newMultiEmpty = new DefaultMutableTreeNode(); newMultiEmpty.setUserObject(new MultiEmptyNode()); parentNode.add(newMultiEmpty); } else if (parent.getUserObject() instanceof BinaryOperator) { System.out.println("parent user object is BinaryOperator"); // inserting into the actual object model BinaryOperator bo = (BinaryOperator) parent.getUserObject(); if (index == 0) { System.out.println("setting first operand type = " + vn.getClass()); bo.setFirstOperand(vn); } else if (index == 1) { System.out.println("setting second operand type = " + vn.getClass()); bo.setSecondOperand(vn); } } else if (parent.getUserObject() instanceof FunctionInput) { System.out.println("parent user object is FunctionInput"); FunctionInput fi = (FunctionInput) parent.getUserObject(); fi.setValue(vn); } // this System.out.println("<<< get cell editor value >>>>"); System.out.println("editedNode.getUserObject() = " + editedNode.getUserObject()); calculationPanel.updateCalculationText(); return editedNode.getUserObject(); }
Example 7
Source File: EditorRootPane.java From libGDX-Path-Editor with Apache License 2.0 | 4 votes |
private int getSelectedNodeIndex(DefaultMutableTreeNode node) { DefaultMutableTreeNode root = getTreeRoot(); if (root == null) { return -1; } if (node == null) { return -1; } return root.getIndex(node); }