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:AncestorTree.java

public boolean addAncestors(DefaultMutableTreeNode node) {
    if (node.getChildCount() > 0)
        return false;

    Object obj = node.getUserObject();
    if (obj == null)
        return false;
    node.add(new DefaultMutableTreeNode(new IconData(ICON_MALE, "Father of: " + obj.toString())));
    node.add(new DefaultMutableTreeNode(new IconData(ICON_FEMALE, "Mother of: " + obj.toString())));
    return true;// w  w w  .  j ava2s  . c om
}

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

private void jTreeListener(EventObject evt) {
    try {//from www  .j  a  v  a  2  s .c om
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((JTree) (evt.getSource()))
                .getLastSelectedPathComponent();
        Object userObj = node.getUserObject();
        if (userObj != null && userObj instanceof ChieldNode) {
            File file = ((ChieldNode) userObj).file;
            if (modifyFileBox.getSelectedItem().equals("??")) {
                File tempFile = File.createTempFile(file.getName().substring(0, file.getName().length() - 5),
                        ".java");
                byte[] content = FileUtil.loadFromFile(file);
                FileUtil.saveToFile(tempFile, content);
                Runtime.getRuntime().exec("cmd /c start " + tempFile.getAbsolutePath());
                tempFile.deleteOnExit();
            } else {
                Runtime.getRuntime().exec("cmd /c start " + file.getAbsolutePath());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(e.getMessage(), "error");
    }
}

From source file:MyTreeModelListener.java

public void treeNodesChanged(TreeModelEvent e) {
    DefaultMutableTreeNode node;
    node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent());

    try {/*from ww w . j  ava2 s .  c o  m*/
        int index = e.getChildIndices()[0];
        node = (DefaultMutableTreeNode) (node.getChildAt(index));
    } catch (NullPointerException exc) {
    }

    System.out.println("The user has finished editing the node.");
    System.out.println("New value: " + node.getUserObject());
}

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

@Override
public void treeNodesChanged(TreeModelEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getTreePath().getLastPathComponent();
    if (node.getUserObject() instanceof PeakList)
        rebuildPeakListSelector();/*from   w ww  . j a v  a 2  s . co m*/
}

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

@Override
public void treeNodesInserted(TreeModelEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getTreePath().getLastPathComponent();
    if (node.getUserObject() instanceof PeakList)
        rebuildPeakListSelector();/*from   www  . j  a va  2s.c  o  m*/
}

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

@Override
public void treeNodesRemoved(TreeModelEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getTreePath().getLastPathComponent();
    if (node.getUserObject() instanceof PeakList)
        rebuildPeakListSelector();/*w  w w  .  j a va2s  .co m*/
}

From source file:net.sf.mzmine.modules.visualization.ida.IDABottomPanel.java

@Override
public void treeStructureChanged(TreeModelEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getTreePath().getLastPathComponent();
    if (node.getUserObject() instanceof PeakList)
        rebuildPeakListSelector();/*  w  w w. java2  s .c om*/
}

From source file:FileTree3.java

public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
        boolean leaf, int row, boolean hasFocus)

{
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    Object obj = node.getUserObject();
    setText(obj.toString());/*from  w w  w  . jav  a2s. co  m*/

    if (obj instanceof Boolean)
        setText("Retrieving data...");

    if (obj instanceof IconData) {
        IconData idata = (IconData) obj;
        if (expanded)
            setIcon(idata.getExpandedIcon());
        else
            setIcon(idata.getIcon());
    } else
        setIcon(null);

    setFont(tree.getFont());
    setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor);
    setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor);
    m_selected = sel;
    return this;
}

From source file:TreeIconDemo2.java

/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

    if (node == null)
        return;/*w w w .  ja  va 2 s.  c om*/

    Object nodeInfo = node.getUserObject();
    if (node.isLeaf()) {
        BookInfo book = (BookInfo) nodeInfo;
        displayURL(book.bookURL);
        if (DEBUG) {
            System.out.print(book.bookURL + ":  \n    ");
        }
    } else {
        displayURL(helpURL);
    }
    if (DEBUG) {
        System.out.println(nodeInfo.toString());
    }
}

From source file:FileTree3.java

FileNode getFileNode(DefaultMutableTreeNode node) {
    if (node == null)
        return null;
    Object obj = node.getUserObject();
    if (obj instanceof IconData)
        obj = ((IconData) obj).getObject();
    if (obj instanceof FileNode)
        return (FileNode) obj;
    else/*from w ww.j av a 2s.  c o  m*/
        return null;
}