javax.swing.tree.DefaultMutableTreeNode#getNextSibling ( )源码实例Demo

下面列出了javax.swing.tree.DefaultMutableTreeNode#getNextSibling ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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;
}
 
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;
    }
}
 
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;
}
 
源代码4 项目: nextreports-designer   文件: StructurePanel.java
@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;
}
 
源代码5 项目: nextreports-designer   文件: StructurePanel.java
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);
        }
    }