Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getUserObject.

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:Main.java

public static JComponent makeUI() {
    JTree tree = new JTree();
    TreeModel model = tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    Enumeration e = root.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        Object o = node.getUserObject();
        if (o instanceof String) {
            node.setUserObject(new CheckBoxNode((String) o, false));
        }/*from w ww .java 2 s . com*/
    }
    tree.setEditable(true);
    tree.setCellRenderer(new CheckBoxNodeRenderer());
    tree.setCellEditor(new CheckBoxNodeEditor());
    tree.expandRow(0);
    return new JScrollPane(tree);
}

From source file:Main.java

private static Node extractNode(Object value) {
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        Object userObject = node.getUserObject();
        if (userObject instanceof Node) {
            return (Node) userObject;
        }/*ww w .ja v a 2s.com*/
    }
    return null;
}

From source file:Main.java

public static DefaultMutableTreeNode buscarNodeByNombre(JTree jtree, String nodeStr) {
    DefaultMutableTreeNode node = null;
    TreeNode root = (TreeNode) jtree.getModel().getRoot();
    Enumeration<?> e = root.children();
    while (e.hasMoreElements()) {
        node = (DefaultMutableTreeNode) e.nextElement();
        if ((node.getUserObject().toString()).contains(nodeStr)) {
            return node;
        }/*from w ww .j  a  v a 2 s.c  o  m*/
    }
    return null;
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

public static int getUserObjectNum(DefaultMutableTreeNode rootNode) {
    Set userObjectSet = new HashSet();
    userObjectSet.add(rootNode.getUserObject());
    getAllUserObject(rootNode, userObjectSet);
    return userObjectSet.size();
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getAllUserObject(TreeNode node, Set userObjectSet) {
    for (int i = 0; i < node.getChildCount(); i++) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i);
        userObjectSet.add(childNode.getUserObject());
        getAllUserObject(childNode, userObjectSet);
    }/*w w  w  .j  a v  a2 s.co  m*/
}

From source file:org.spf4j.ui.TSDBViewJInternalFrame.java

@edu.umd.cs.findbugs.annotations.SuppressWarnings("CLI_CONSTANT_LIST_INDEX")
private static List<String> getSelectedTables(@Nullable final TreePath[] selectionPaths) {
    if (selectionPaths == null) {
        return Collections.EMPTY_LIST;
    }/*from www . j a va2s. co m*/
    List<String> result = new ArrayList<String>();
    for (TreePath path : selectionPaths) {
        Object[] pathArr = path.getPath();
        if (pathArr.length < 2) {
            continue;
        }
        DefaultMutableTreeNode colNode = (DefaultMutableTreeNode) pathArr[1];
        int depth = colNode.getDepth();
        String tableName;
        if (depth == 1) {
            result.add((String) colNode.getUserObject());
        } else {
            Enumeration childEnum = colNode.children();
            while (childEnum.hasMoreElements()) {
                DefaultMutableTreeNode child = (DefaultMutableTreeNode) childEnum.nextElement();
                tableName = Pair.of((String) colNode.getUserObject(), (String) child.getUserObject())
                        .toString();
                result.add(tableName);
            }
        }
    }
    return result;
}

From source file:com.openbravo.pos.admin.RolesViewTree.java

public static DefaultMutableTreeNode sortTree(DefaultMutableTreeNode root) {
    for (int i = 0; i < root.getChildCount() - 1; i++) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) root.getChildAt(i);
        String nt = node.getUserObject().toString();
        for (int j = i + 1; j <= root.getChildCount() - 1; j++) {
            DefaultMutableTreeNode prevNode = (DefaultMutableTreeNode) root.getChildAt(j);
            String np = prevNode.getUserObject().toString();
            if (nt.compareToIgnoreCase(np) > 0) {
                root.insert(node, j);//from  w  w  w .  j a  v a 2 s .co m
                root.insert(prevNode, i);
            }
        }
        if (node.getChildCount() > 0) {
            node = sortTree(node);
        }
    }
    return root;
}

From source file:Main.java

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    checkbox.setSelected((Boolean) node.getUserObject());
    checkbox.setText("Row:" + row);
    return checkbox;
}

From source file:Main.java

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (value instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        if (node.getUserObject() instanceof String) {
            setIcon(UIManager.getIcon("FileView.computerIcon"));
        } else if (node.getUserObject() instanceof Contact) {
            Contact contact = (Contact) node.getUserObject();
            if (contact.isSomeProperty()) {
                setIcon(UIManager.getIcon("FileView.hardDriveIcon"));
            } else {
                setIcon(UIManager.getIcon("FileChooser.homeFolderIcon"));
            }//from   ww w  .  jav  a2s.  c om
        }
    }
    return this;
}

From source file:MainClass.java

protected void fillModel(SortTreeModel model, DefaultMutableTreeNode current) {
    MyFile pf = (MyFile) current.getUserObject();
    File f = pf.getFile();//  w w  w  .ja va 2  s. co m
    if (f.isDirectory()) {
        String files[] = f.list();
        for (int i = 0; i < files.length; i++) {
            if (files[i].startsWith("."))
                continue;
            MyFile tmp = new MyFile(pf, files[i]);
            DefaultMutableTreeNode node = new DefaultMutableTreeNode(tmp);
            model.insertNodeInto(node, current);
            if (tmp.getFile().isDirectory()) {
                fillModel(model, node);
            }
        }
    }
}