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

The following examples show how to use javax.swing.tree.DefaultMutableTreeNode#depthFirstEnumeration() . 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: FmtSpaces.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: FmtSpaces.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: FmtSpaces.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: FmtSpaces.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private List<Item> getAllItems() {
    List<Item> result = new LinkedList<>();
    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;
}
 
Example 5
Source File: SortTreeHelper.java    From ISO8583 with GNU General Public License v3.0 6 votes vote down vote up
@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;
		}
	}
}
 
Example 6
Source File: FuzzerPayloadGeneratorUIHandler.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private void setSelectedFuzzers(List<FuzzerPayloadSource> fileFuzzers) {
    resetFileFuzzersCheckBoxTree();

    if (fileFuzzers.isEmpty()) {
        return;
    }

    List<FuzzerPayloadSource> selections = new ArrayList<>(fileFuzzers);
    DefaultMutableTreeNode root =
            (DefaultMutableTreeNode) getFileFuzzersCheckBoxTree().getModel().getRoot();
    @SuppressWarnings("unchecked")
    Enumeration<TreeNode> nodes = root.depthFirstEnumeration();
    while (!selections.isEmpty() && nodes.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
        if (selections.remove(node.getUserObject())) {
            TreePath path = new TreePath(node.getPath());
            getFileFuzzersCheckBoxTree().check(path, true);
            getFileFuzzersCheckBoxTree().expandPath(path.getParentPath());
        }
    }
}
 
Example 7
Source File: MainView.java    From HiJson with Apache License 2.0 6 votes vote down vote up
private void findTreeChildValue(String findText,List<TreePath> treePathLst) {
        JTree tree = getTree();
        DefaultMutableTreeNode root = (DefaultMutableTreeNode)tree.getModel().getRoot();
        Enumeration e = root.depthFirstEnumeration();
        treePathLst.clear();
        curPos = 0;
        while (e.hasMoreElements()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
            if (node.isLeaf()) {
                String str = node.toString();
                if (str.substring(2).indexOf(findText) >= 0) {
                    tree.expandPath(new TreePath(node.getPath()));
                    TreePath tp = expandTreeNode(tree,node.getPath(), true);
                    treePathLst.add(tp);
                }
            }
        }
        if(!treePathLst.isEmpty()){
            tree.setSelectionPath(treePathLst.get(0));
            tree.scrollPathToVisible(treePathLst.get(0));
        }
//        return treePathLst;
    }
 
Example 8
Source File: AnalyzeSizeToolWindowTest.java    From size-analyzer with Apache License 2.0 5 votes vote down vote up
private TreePath getTreePathWithString(Tree tree, String searchTarget) {
  DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) tree.getModel().getRoot();
  for (Enumeration<?> treeEnumeration = rootNode.depthFirstEnumeration();
      treeEnumeration.hasMoreElements(); ) {
    Object node = treeEnumeration.nextElement();
    if (node instanceof DefaultMutableTreeNode) {
      Object value = ((DefaultMutableTreeNode) node).getUserObject();
      if (value.toString().equals(searchTarget)) {
        return new TreePath(((DefaultMutableTreeNode) node).getPath());
      }
    }
  }
  return null;
}
 
Example 9
Source File: DNDTree.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public String getInfo() {
	DefaultMutableTreeNode node = (DefaultMutableTreeNode)this.getModel().getRoot();
	int n_basic = 0, n_abstract = 0;
	for (Enumeration<?> e = node.depthFirstEnumeration(); e.hasMoreElements(); ) {
		DefaultMutableTreeNode child = (DefaultMutableTreeNode)e.nextElement();
		Object ob = child.getUserObject();
		if (ob instanceof Thing && Project.isBasicType(((Thing)ob).getType())) n_basic++;
		else n_abstract++;
	}
	return this.getClass().getName() + ": \n\tAbstract nodes: " + n_abstract + "\n\tBasic nodes: " + n_basic + "\n";
}
 
Example 10
Source File: TreeTestBase.java    From jenetics with Apache License 2.0 5 votes vote down vote up
@Test
public void depthFirstIterator() {
	final T tree = newTree(5, new Random(123));
	final DefaultMutableTreeNode stree = newSwingTree(5, new Random(123));

	final Iterator<T> treeIt = tree.depthFirstIterator();
	final Enumeration<?> streeIt = stree.depthFirstEnumeration();

	while (treeIt.hasNext()) {
		final T node = treeIt.next();
		final DefaultMutableTreeNode snode = (DefaultMutableTreeNode)streeIt.nextElement();

		Assert.assertEquals(node.value(), snode.getUserObject());
	}
}
 
Example 11
Source File: ProcessingComponent.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
private boolean nodeContains(@Nonnull DefaultMutableTreeNode node,
    @Nonnull DefaultMutableTreeNode comp) {
  Enumeration<?> e = node.depthFirstEnumeration();
  while (e.hasMoreElements()) {
    DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
    if (n.toString().equalsIgnoreCase(comp.toString())) {
      return true;
    }
  }
  return false;
}
 
Example 12
Source File: CategoryModel.java    From opencards with BSD 2-Clause "Simplified" License 5 votes vote down vote up
DefaultMutableTreeNode getNode(Object userValue) {
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.getRoot();

    for (Enumeration e = root.depthFirstEnumeration(); e.hasMoreElements(); ) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();

        if (node.getUserObject() == userValue) {
            return node;
        }
    }

    return null;
}
 
Example 13
Source File: ColopediaPanel.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: ProcessingComponent.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private boolean nodeContains(@Nonnull DefaultMutableTreeNode node,
    @Nonnull DefaultMutableTreeNode comp) {
  Enumeration<?> e = node.depthFirstEnumeration();
  while (e.hasMoreElements()) {
    DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement();
    if (n.toString().equalsIgnoreCase(comp.toString())) {
      return true;
    }
  }
  return false;
}
 
Example 15
Source File: MiscTools.java    From megabasterd with GNU General Public License v3.0 4 votes vote down vote up
public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) {

        Enumeration e = root.depthFirstEnumeration();

        while (e.hasMoreElements()) {

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();

            if (!node.isLeaf()) {

                _sortTreeNode(node);

            }
        }

        return root;

    }
 
Example 16
Source File: ObjectSelector.java    From jaamsim with Apache License 2.0 4 votes vote down vote up
@Override
public void setEntity(Entity ent) {

	if (ent == currentEntity)
		return;
	currentEntity = ent;

	if (tree == null)
		return;

	JaamSimModel simModel = GUIFrame.getJaamSimModel();
	if (simModel == null || simModel.getSimulation() == null)
		return;

	long curSequence = simModel.getEntitySequence();
	if (entSequence != curSequence) {
		entSequence = curSequence;
		updateTree(simModel);
	}

	if (currentEntity == null) {
		tree.setSelectionPath(null);
		tree.setEditable(false);
		return;
	}

	tree.setEditable(true);

	DefaultMutableTreeNode root = (DefaultMutableTreeNode)tree.getModel().getRoot();
	Enumeration<?> e = root.depthFirstEnumeration();
	while (e.hasMoreElements()) {
		DefaultMutableTreeNode aNode = (DefaultMutableTreeNode)e.nextElement();
		if (aNode.getUserObject() == currentEntity) {
			TreePath path = new TreePath(aNode.getPath());
			tree.scrollPathToVisible(path);
			tree.setSelectionPath(path);
			return;
		}
	}

	// Entity not found in the tree
	tree.setSelectionPath(null);
	tree.setEditable(false);
}
 
Example 17
Source File: FileGrabberDialog.java    From megabasterd with GNU General Public License v3.0 2 votes vote down vote up
private void _genFileList() {

        _files.clear();

        _total_space = 0L;

        DefaultTreeModel tree_model = (DefaultTreeModel) swingInvokeAndWaitForReturn((Callable) file_tree::getModel);

        DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree_model.getRoot();

        Enumeration files_tree = root.depthFirstEnumeration();

        while (files_tree.hasMoreElements()) {

            DefaultMutableTreeNode node = (DefaultMutableTreeNode) files_tree.nextElement();

            if (node.isLeaf() && node != root) {

                String path = "";

                Object[] object_path = node.getUserObjectPath();

                for (Object p : object_path) {

                    path += File.separator + p;
                }

                path = path.replaceAll("^/+", "/").replaceAll("^\\+", "\\").trim().replaceAll(" \\[[0-9,.]+ [A-Z]+\\]$", "");

                File file = new File(path);

                if (file.isFile()) {

                    _total_space += file.length();

                    _files.add(file);
                }
            }
        }

        swingInvoke(() -> {
            total_file_size_label.setText("[" + formatBytes(_total_space) + "]");
        });

    }