本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.depthFirstEnumeration方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.depthFirstEnumeration方法的具体用法?Java DefaultMutableTreeNode.depthFirstEnumeration怎么用?Java DefaultMutableTreeNode.depthFirstEnumeration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultMutableTreeNode
的用法示例。
在下文中一共展示了DefaultMutableTreeNode.depthFirstEnumeration方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Removes non-agents from DefaultMutableTreeNode.
*
* @param node the node
* @param key the key
*/
private void filterNode(DefaultMutableTreeNode node){
Vector<DefaultMutableTreeNode> toDeleteVect= new Vector<DefaultMutableTreeNode>();
@SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> e = node.depthFirstEnumeration();
if(e != null){
while (e.hasMoreElements()){
DefaultMutableTreeNode actualElement = e.nextElement();
if (actualElement.isLeaf() == true && matchAgentClass(actualElement) == false) {
//--- immediate removal invalidates the enumeration ---
// actualElement.removeFromParent();
// --- remember for later removal ---
toDeleteVect.add(actualElement);
}
}
}
//--- delete nodes ---
for( int i=0; i < toDeleteVect.size(); i++){
toDeleteVect.get(i).removeFromParent();
}
}
示例2: getAllItems
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private List<Item> getAllItems() {
List<Item> result = new LinkedList<FmtSpaces.Item>();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((FmtSpaces) panel).model.getRoot();
Enumeration children = root.depthFirstEnumeration();
while( children.hasMoreElements() ) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
Object o = node.getUserObject();
if (o instanceof Item) {
Item item = (Item) o;
if ( item.items == null || item.items.length == 0 ) {
result.add( item );
}
}
}
return result;
}
示例3: sortTree
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static void sortTree(PnlGuiConfig pnlGuiConfig, DefaultMutableTreeNode root, JTree treeTypes) {
if (root != null) {
Enumeration e = root.depthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (!node.isLeaf()) {
sort(node); //selection sort
}
}
//Atualizando a arvore
if (updateTree) {
TreePath treePath = treeTypes.getSelectionPath();
DefaultTreeModel model = (DefaultTreeModel) treeTypes.getModel();
model.reload();
treeTypes.setSelectionPath(treePath);
updateTree = false;
}
pnlGuiConfig.getPnlFieldCondition().ckDynamicClick();
}
}
示例4: findNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
public DefaultMutableTreeNode findNode(DefaultMutableTreeNode root, int id) {
Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = e.nextElement();
if (node.getUserObject() instanceof HTTP2SampleResult){
HTTP2SampleResult http2NodeResult= (HTTP2SampleResult) node.getUserObject();
if (http2NodeResult.getId()==id) {
return node;
}
}
}
return null;
}
示例5: buildTree
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Builds the JTree which represents the navigation menu and then returns it
*
* @return The navigation tree.
*/
private JTree buildTree() {
String name = Messages.message("colopedia");
DefaultMutableTreeNode root
= new DefaultMutableTreeNode(new ColopediaTreeItem(null, null, name, null));
FreeColClient fcc = getFreeColClient();
new TerrainDetailPanel(fcc, this).addSubTrees(root);
new ResourcesDetailPanel(fcc, this).addSubTrees(root);
new GoodsDetailPanel(fcc, this).addSubTrees(root);
new UnitDetailPanel(fcc, this).addSubTrees(root);
new BuildingDetailPanel(fcc, this).addSubTrees(root);
new FatherDetailPanel(fcc, this).addSubTrees(root);
new NationDetailPanel(fcc, this).addSubTrees(root);
new NationTypeDetailPanel(fcc, this).addSubTrees(root);
new ConceptDetailPanel(fcc, this).addSubTrees(root);
DefaultTreeModel treeModel = new DefaultTreeModel(root);
tree = new JTree(treeModel) {
@Override
public Dimension getPreferredSize() {
return new Dimension(
(int)(200 * getImageLibrary().getScaleFactor()),
super.getPreferredSize().height);
}
};
tree.setRootVisible(false);
tree.setCellRenderer(new ColopediaTreeCellRenderer());
tree.setOpaque(false);
tree.addTreeSelectionListener(this);
listPanel.add(tree);
Enumeration allNodes = root.depthFirstEnumeration();
while (allNodes.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) allNodes.nextElement();
ColopediaTreeItem item = (ColopediaTreeItem) node.getUserObject();
nodeMap.put(item.getId(), node);
}
return tree;
}
示例6: select
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private boolean select(DefaultMutableTreeNode parent, Predicate<IEntity> selectionPredicate) {
if (parent.getChildCount() == 0) {
return false;
}
Enumeration en = parent.depthFirstEnumeration();
while (en.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) en.nextElement();
IEntity ent = null;
if (node.getUserObject() instanceof IconTreeListItem) {
IconTreeListItem iconItem = (IconTreeListItem) node.getUserObject();
if (iconItem.getUserObject() instanceof IEntity) {
ent = (IEntity) iconItem.getUserObject();
}
} else if (node.getUserObject() instanceof IEntity) {
ent = (IEntity) node.getUserObject();
}
if (ent == null) {
continue;
}
if (selectionPredicate.test(ent)) {
final TreePath newSelection = new TreePath(node.getPath());
if (this.tree.getSelectionPath() != null && this.tree.getSelectionPath().equals(newSelection)) {
continue;
}
this.tree.setSelectionPath(newSelection);
TreePath path = this.tree.getSelectionPath();
if (path == null || !this.tree.isVisible()) {
return false;
}
Rectangle bounds = this.tree.getPathBounds(path);
if (bounds == null) {
return false;
}
// set the height to the visible height to force the node to top
bounds.height = this.tree.getVisibleRect().height;
this.tree.scrollRectToVisible(bounds);
return true;
}
}
return false;
}