本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.breadthFirstEnumeration方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.breadthFirstEnumeration方法的具体用法?Java DefaultMutableTreeNode.breadthFirstEnumeration怎么用?Java DefaultMutableTreeNode.breadthFirstEnumeration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultMutableTreeNode
的用法示例。
在下文中一共展示了DefaultMutableTreeNode.breadthFirstEnumeration方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterNodeByKey
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Filter node by key.
*
* @param node the node
* @param key the key
*/
private void filterNodeByKey(DefaultMutableTreeNode node, String key){
Vector<DefaultMutableTreeNode> toDeleteVect= new Vector<DefaultMutableTreeNode>();
@SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> e = node.breadthFirstEnumeration();
if(e != null){
while (e.hasMoreElements()){
DefaultMutableTreeNode actualElement = e.nextElement();
if (actualElement.isLeaf() == true && key.isEmpty() == false && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == false) {
//--- immediate removal invalidates the enumeration ---
// actualElement.removeFromParent();
// --- remember for later removal ---
toDeleteVect.add(actualElement);
}
if(actualElement.isLeaf() == true && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == true){
//--- (re)expand collapsed parent if search string matches ---
int level = actualElement.getLevel() -1;
StringBuilder sb = new StringBuilder();
sb.append(level -1).append(",");
String levelString = sb.toString();
if(expansionState.contains(levelString) == false){
levelString = sb.append(level).append(",").toString();
expansionState = expansionState.concat(levelString);
}
}
}
}
//--- delete nodes ---
for( int i=0; i < toDeleteVect.size(); i++){
toDeleteVect.get(i).removeFromParent();
}
}
示例2: sortThreads
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
public void sortThreads() {
DefaultMutableTreeNode tempNode = (DefaultMutableTreeNode) copyNode((DefaultMutableTreeNode) getModel().getRoot());
// --- save expansion state ---
expansionState = saveExpansionState();
// --- sort and update ---
@SuppressWarnings("rawtypes")
Enumeration e = tempNode.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (node.isLeaf() == true) {
sortNodesDescending((DefaultMutableTreeNode) node.getParent(),
(DefaultTreeModel) getModel());
}
}
((DefaultTreeModel) getModel()).setRoot(tempNode);
// --- restore expansion ---
restoreExpansionState(expansionState);
}
示例3: pathExists
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private DefaultMutableTreeNode pathExists(DefaultMutableTreeNode parent, String path) {
if (parent == null) {
parent = rootNode;
}
for (Enumeration node = parent.breadthFirstEnumeration(); node.hasMoreElements(); ) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.nextElement();
PwnBackNode usrNode = (PwnBackNode) child.getUserObject();
if (usrNode.getPath().equals(path)) {
return child;
}
}
return null;
}
示例4: expandTree
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private void expandTree(JTree tree) {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel()
.getRoot();
Enumeration e = root.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (node.isLeaf()) {
continue;
}
int row = tree.getRowForPath(new TreePath(node.getPath()));
tree.expandRow(row);
}
}