Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#getNextSibling()

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode#getNextSibling() . 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 vote down vote up
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: GroupedBandChoosingStrategy.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private void removeEmptyGroups(DefaultMutableTreeNode root, Map<String, Integer> groupNodeMap) {
    DefaultMutableTreeNode rootChild = (DefaultMutableTreeNode) root.getFirstChild();
    while (rootChild != null) {
        DefaultMutableTreeNode nextChild = rootChild.getNextSibling();
        if (rootChild.getChildCount() == 0 && groupNodeMap.containsKey(rootChild.getUserObject().toString())) {
            root.remove(rootChild);
        }
        rootChild = nextChild;
    }
}
 
Example 3
Source File: IfStatementExpressionAnalyzer.java    From JDeodorant with MIT License 5 votes vote down vote up
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 4
Source File: StructurePanel.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private DefaultMutableTreeNode getBandRowInsertedTreeNode(String bandName, int bandRow, int row) {

    DefaultMutableTreeNode bandNode = getBandTreeNode(bandName);

    // tree must be traversed in preorder (band by band)        
    Enumeration en = rootNode.preorderEnumeration();
    String currentBandName = ReportLayout.HEADER_BAND_NAME;
    while (en.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
        Object userObject = node.getUserObject();
        if (userObject instanceof Band) {
            currentBandName = ((Band) userObject).getName();
        } else if (userObject instanceof ReportGridCell) {
            // increment rows for all report grid cells which are in the rows
            // following the inserted row
            ReportGridCell reportGridCell = (ReportGridCell) userObject;
            if (row <= reportGridCell.getRow()) {
                reportGridCell.setRow(reportGridCell.getRow() + 1);
            }
        } else if (userObject instanceof Integer) {
            // modify 'row' nodes in the tree (for the current band)
            if (bandName.equals(currentBandName)) {
                if ((Integer) userObject == bandRow) {
                    DefaultMutableTreeNode sibling = node.getNextSibling();
                    node.setUserObject(((Integer) node.getUserObject()).intValue() + 1);
                    while (sibling != null) {
                        sibling.setUserObject(((Integer) sibling.getUserObject()).intValue() + 1);
                        sibling = sibling.getNextSibling();
                    }
                }
            }
        }
    }

    DefaultMutableTreeNode rowNode = new StructureTreeNode(bandRow);
    bandNode.insert(rowNode, bandRow);

    return rowNode;
}
 
Example 5
Source File: StructurePanel.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
private void deleteBandRowTreeNode(String bandName, int bandRow, int row) {

        // tree must be traversed in preorder (band by band)
        Enumeration en = rootNode.preorderEnumeration();
        String currentBandName = ReportLayout.HEADER_BAND_NAME;
        DefaultMutableTreeNode nodeToDelete = null;
        while (en.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
            Object userObject = node.getUserObject();
            if (userObject instanceof Band) {
                currentBandName = ((Band) userObject).getName();
            } else if (userObject instanceof ReportGridCell) {
                // decrement rows for all report grid cells which are in the rows
                // following the inserted row
                ReportGridCell reportGridCell = (ReportGridCell) userObject;
                if (row <= reportGridCell.getRow()) {
                    reportGridCell.setRow(reportGridCell.getRow() - 1);
                }
            } else if (userObject instanceof Integer) {
                // modify 'row' nodes in the tree (for the current band)
                if (bandName.equals(currentBandName)) {
                    if ((Integer) userObject == bandRow) {
                        if (nodeToDelete == null) {
                            nodeToDelete = node;
                            DefaultMutableTreeNode sibling = node.getNextSibling();
                            while (sibling != null) {
                                sibling.setUserObject(((Integer) sibling.getUserObject()).intValue() - 1);
                                sibling = sibling.getNextSibling();
                            }
                        }

                    }
                }
            }
        }
        if (nodeToDelete != null) {
            structureTreeModel.removeNodeFromParent(nodeToDelete);
        }
    }