Example usage for javax.swing.tree DefaultMutableTreeNode setUserObject

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

Introduction

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

Prototype

public void setUserObject(Object userObject) 

Source Link

Document

Sets the user object for this node to userObject.

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 ww w.j a va2s  . c  o m
    }
    tree.setEditable(true);
    tree.setCellRenderer(new CheckBoxNodeRenderer());
    tree.setCellEditor(new CheckBoxNodeEditor());
    tree.expandRow(0);
    return new JScrollPane(tree);
}

From source file:com.autentia.wuija.widget.TreeComponent.java

private static DefaultMutableTreeNode createSingleNode(String nodeName, boolean isLeaf, boolean expanded) {
    final DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode();
    final IceUserObject branchObject = new IceUserObject(branchNode);
    branchObject.setText(nodeName);/*from   w  ww  .  j  a  va  2s  .c om*/
    branchObject.setExpanded(expanded);
    branchObject.setLeaf(isLeaf);

    branchNode.setUserObject(branchObject);
    return branchNode;
}

From source file:fxts.stations.util.preferences.PreferencesNode.java

public PreferencesNode addNode(String aNameResID) {
    PreferencesNode childNode;//from   ww w . j  a  va  2  s.  co  m
    for (int i = 0; i < mTreeNode.getChildCount(); i++) {
        childNode = (PreferencesNode) ((DefaultMutableTreeNode) mTreeNode.getChildAt(i)).getUserObject();
        if (childNode.getName().equals(aNameResID)) {
            return childNode;
        }
    }
    //Same node not found.
    childNode = new PreferencesNode(aNameResID);
    DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode();
    newTreeNode.setUserObject(childNode);
    mTreeNode.add(newTreeNode);
    childNode.setTreeNode(newTreeNode);
    return childNode;
}

From source file:gdt.jgui.entity.contact.JContactFacetOpenItem.java

@Override
public DefaultMutableTreeNode[] getDigest() {
    try {/*from  w  w w  .java2 s  . c  o m*/
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack entity = entigrator.getEntityAtKey(entityKey$);
        contact$ = entity.getProperty("contact");
        String locator$ = getLocator();
        locator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, contact$);
        DefaultMutableTreeNode contactNode = new DefaultMutableTreeNode();
        contactNode.setUserObject(locator$);
        return new DefaultMutableTreeNode[] { contactNode };

    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }
    return null;
}

From source file:gdt.jgui.entity.email.JEmailFacetOpenItem.java

@Override
public DefaultMutableTreeNode[] getDigest() {
    try {//from  w  w  w .ja v  a 2  s.c o  m
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack entity = entigrator.getEntityAtKey(entityKey$);
        String email$ = entity.getProperty("email");
        String locator$ = getLocator();
        locator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, email$);
        DefaultMutableTreeNode emailNode = new DefaultMutableTreeNode();
        emailNode.setUserObject(locator$);
        return new DefaultMutableTreeNode[] { emailNode };

    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }
    return null;
}

From source file:gdt.jgui.entity.phone.JPhoneFacetOpenItem.java

@Override
public DefaultMutableTreeNode[] getDigest() {
    try {/*from w ww.j a va 2s.  com*/
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack entity = entigrator.getEntityAtKey(entityKey$);
        String phone$ = entity.getProperty("phone");
        String locator$ = getLocator();
        locator$ = Locator.append(locator$, Locator.LOCATOR_TITLE, phone$);
        DefaultMutableTreeNode phoneNode = new DefaultMutableTreeNode();
        phoneNode.setUserObject(locator$);
        return new DefaultMutableTreeNode[] { phoneNode };

    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }
    return null;
}

From source file:com.tascape.qa.th.android.driver.App.java

private DefaultMutableTreeNode createNode(UIANode uiNode) {
    Rect bounds = uiNode.getBounds();//from  w  w w  .  j av  a2 s.  c  om
    String s = uiNode.getKlass() + " " + uiNode.getContentDescription() + " "
            + String.format("[%d,%d][%d,%d]", bounds.left, bounds.top, bounds.right, bounds.bottom);
    DefaultMutableTreeNode tNode = new DefaultMutableTreeNode(s);
    tNode.setUserObject(uiNode);

    for (UIANode n : uiNode.nodes()) {
        tNode.add(createNode(n));
    }
    return tNode;
}

From source file:gtu._work.ui.LoadJspCheckTagUI.java

private void setTreeNode(Map<Tag, Set<File>> map) {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = null;
    DefaultMutableTreeNode childchild = null;
    List<Tag> list = new ArrayList<Tag>(map.keySet());
    List<File> childList = null;
    Collections.sort(list);//from ww  w .  j  a v a 2  s. c  om
    for (Tag tagName : list) {
        child = new DefaultMutableTreeNode();
        child.setUserObject(tagName);
        root.add(child);
        childList = new ArrayList<File>(map.get(tagName));
        Collections.sort(childList);
        for (File chfile : childList) {
            childchild = new DefaultMutableTreeNode();
            childchild.setUserObject(new ChieldNode(chfile));
            child.add(childchild);
        }
    }
    jTree1.setModel(new DefaultTreeModel(root));
}

From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java

/**
 * Load the data files into the tree./*from  ww  w  .j  a v a2s. co  m*/
 *
 * @throws LoadDirectoryException - when the directory is empty!
 */
private void loadDataIntoTree() throws LoadDirectoryException {
    DefaultTreeModel model = (DefaultTreeModel) loadTracksPanel.getDirectoryTree().getModel();
    DefaultMutableTreeNode rootNote = (DefaultMutableTreeNode) model.getRoot();
    // change name (user object) of root node
    rootNote.setUserObject(directory.getName());
    File[] listFiles = directory.listFiles();
    if (listFiles.length != 0) {
        for (File file : listFiles) {
            if (!file.isDirectory()) {
                DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(file.getName(), Boolean.FALSE);
                rootNote.add(fileNode);
            } else {
                // reset the directory to null
                directory = null;
                throw new LoadDirectoryException("This directory has a wrong structure!");
            }
        }
    } else {
        // reset the directory to null
        directory = null;
        throw new LoadDirectoryException("This directory seems to be empty!");
    }
    model.reload();
    loadTracksPanel.getChosenDirectoryTextArea().setText(directory.getAbsolutePath());
    cellCoordController.showMessage("Directory successful loaded!\nYou can now select the files to import!", "",
            JOptionPane.INFORMATION_MESSAGE);
    loadTracksPanel.getImportFilesButton().setEnabled(true);
}

From source file:gdt.jgui.entity.bookmark.JBookmarksFacetOpenItem.java

/**
 * Get children nodes of the facet node for the digest view.
 * @return the children nodes of the facet node.
 *//*from  w ww.java2 s . c  om*/
@Override
public DefaultMutableTreeNode[] getDigest() {
    try {
        //         System.out.println("JBookmarksFacetOpenItem:getDigest:locator="+locator$);
        Properties locator = Locator.toProperties(locator$);
        entihome$ = locator.getProperty(Entigrator.ENTIHOME);
        entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack entity = entigrator.getEntityAtKey(entityKey$);
        Core[] ca = entity.elementGet("jbookmark");
        if (ca == null)
            return null;
        DefaultMutableTreeNode bookmarkNode;
        ArrayList<DefaultMutableTreeNode> nl = new ArrayList<DefaultMutableTreeNode>();
        String itemLocator$;
        for (Core aCa : ca) {
            bookmarkNode = new DefaultMutableTreeNode();
            itemLocator$ = aCa.value;
            itemLocator$ = Locator.append(itemLocator$, BaseHandler.HANDLER_CLASS, getClass().getName());
            bookmarkNode.setUserObject(itemLocator$);
            nl.add(bookmarkNode);
        }
        //      System.out.println("JBookmarkFacetOpenItem:getDigest:nl="+nl.size());
        return nl.toArray(new DefaultMutableTreeNode[0]);
    } catch (Exception e) {
        Logger.getLogger(getClass().getName()).severe(e.toString());
    }
    return null;
}