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:ser321.media.MediaJavaClient.java

public void valueChanged(TreeSelectionEvent e) {
    try {/*from   ww  w  .j a v a2 s .  c  om*/
        tree.removeTreeSelectionListener(this);
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

        if (node != null) {
            String nodeLabel = (String) node.getUserObject();
            debug("In valueChanged. Selected node labelled: " + nodeLabel);
            // is this a terminal node?
            if (node.getChildCount() == 0 && (node != (DefaultMutableTreeNode) tree.getModel().getRoot())) {
                JSONObject jObj = new JSONObject();
                jObj = cc.get(nodeLabel);

                titleJTF.setText(nodeLabel);
                albumJTF.setText(jObj.getString("album"));
                authorJTF.setText(jObj.getString("author"));
                genreJTF.setText(jObj.getString("genre"));
                fileNameJTF.setText(jObj.getString("filename"));
                if (jObj.getString("mediaType").equals("0"))
                    typeJCB.setSelectedIndex(0);
                else
                    typeJCB.setSelectedIndex(1);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    tree.addTreeSelectionListener(this);
}

From source file:streamme.visuals.Main.java

/**
 * Creates new form Main/*from  ww w .j  a  va  2s  . c o m*/
 */
public Main() {
    player = Player.getInstance();
    player.setListener(this);

    setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getClassLoader().getResource("res/icon32.png")));
    loadTray();

    hotkeyProvider = Provider.getCurrentProvider(false);
    hotkeyProvider.register(KeyStroke.getKeyStroke("alt UP"), new HotKeyListener() {
        public void onHotKey(HotKey hotKey) {
            btn_playPauseActionPerformed(null);
        }
    });
    hotkeyProvider.register(KeyStroke.getKeyStroke("alt RIGHT"), new HotKeyListener() {
        public void onHotKey(HotKey hotKey) {
            btn_nextActionPerformed(null);
        }
    });
    hotkeyProvider.register(KeyStroke.getKeyStroke("alt LEFT"), new HotKeyListener() {
        public void onHotKey(HotKey hotKey) {
            btn_prevActionPerformed(null);
        }
    });
    hotkeyProvider.register(KeyStroke.getKeyStroke("alt DOWN"), new HotKeyListener() {
        public void onHotKey(HotKey hotKey) {
            btn_stopActionPerformed(null);
        }
    });

    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Windows".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }

    initComponents();
    //getContentPane().setBackground(new java.awt.Color(123,161,214));
    PlaylistManager.get().setFrame(this);

    this.setLocationRelativeTo(null);

    treeMenu = new JPopupMenu();

    JMenuItem itemOpenToNew = new JMenuItem("Open to a new playlist");
    itemOpenToNew.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree_files.getLastSelectedPathComponent();
            if (node == null)
                return;
            DataNode dn = (DataNode) node.getUserObject();
            int idx = PlaylistManager.get().addPlaylist(dn.getName());
            addToPlaylist(node, idx, true);
        }
    });

    JMenuItem itemAdd = new JMenuItem("Add to selected playlist...");
    itemAdd.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree_files.getLastSelectedPathComponent();
            if (node == null)
                return;
            addToPlaylist(node, playlistsPanel.getSelectedIndex(), true);
        }
    });

    treeMenu.add(itemOpenToNew);
    treeMenu.add(itemAdd);
    //tree_files.setComponentPopupMenu(menu);

    renamePlaylistKeyListener = new KeyListener() {
        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == 113) { // F2
                int idx = playlistsPanel.getSelectedIndex();
                if (idx < 0)
                    return;
                String oldTitle = playlistsPanel.getTitleAt(idx);
                String s = (String) JOptionPane.showInputDialog(Main.this, "Rename playlist:",
                        "Rename playlist", JOptionPane.PLAIN_MESSAGE, null, null, oldTitle);
                if (s != null) {
                    PlaylistManager.get().renameTab(idx, s);
                }
            }
        }
    };

    playlistsPanel.addKeyListener(renamePlaylistKeyListener);
}

From source file:streamme.visuals.Main.java

public void playNodes() {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree_files.getLastSelectedPathComponent();
    if (node != null && node.isLeaf()) {
        DataNode dn = (DataNode) node.getUserObject();
        if (!dn.isFolder()) {
            PlaylistManager pm = PlaylistManager.get();
            DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
            pm.clearPlaylist(-1);/*from w  w  w. jav a  2 s  .  co m*/

            // Get Path:
            javax.swing.tree.TreeNode[] tree = parent.getPath();
            String path = StreamMe.OPTIONS.getOutputPath();
            for (int i = 1; i < tree.length; i++) {
                path += "\\" + ((DataNode) ((DefaultMutableTreeNode) tree[i]).getUserObject()).getName();
            }

            Enumeration ch = parent.children();
            DefaultMutableTreeNode child = null;
            while (ch.hasMoreElements()) {
                child = (DefaultMutableTreeNode) ch.nextElement();
                if (child.isLeaf())
                    break;
            }
            int songIdx = 0, i = 0;
            while (child != null) {
                DataNode childnode = (DataNode) child.getUserObject();

                if (child == node) {
                    songIdx = i;
                }
                pm.addToPlaylist(-1, childnode.toFileLink(path + "\\" + childnode.getName()));
                child = child.getNextSibling();
                i++;
            }
            playSong(pm.getDefaultModelIdx(), songIdx);
        }
    }
}

From source file:streamme.visuals.Main.java

public void addToPlaylist(DefaultMutableTreeNode node, int listIdx, boolean recursive) {
    DefaultMutableTreeNode leaf = node.getFirstLeaf();
    while (node.isNodeDescendant(leaf)) {
        DataNode dn = (DataNode) leaf.getUserObject();
        javax.swing.tree.TreeNode[] tree = leaf.getPath();
        String path = StreamMe.OPTIONS.getOutputPath();
        for (int i = 1; i < tree.length; i++) {
            path += "\\" + ((DataNode) ((DefaultMutableTreeNode) tree[i]).getUserObject()).getName();
        }//from w w w. ja  v  a 2s. c o m
        PlaylistManager.get().addToPlaylist(listIdx, dn.toFileLink(path));
        leaf = leaf.getNextLeaf();
    }
}

From source file:tk.tomby.tedit.plugins.explorer.Explorer.java

/**
 * Creates a new Explorer object./*from w w w  .  j a  v  a  2 s.  c  om*/
 */
public Explorer() {
    super("Explorer");

    File rootDir = new File(PreferenceManager.getString("explorer.directory", System.getProperty("user.home")));

    JPanel internalPanel = new JPanel();
    internalPanel.setLayout(new BorderLayout());

    topPanel = new TopPanel(rootDir.getAbsolutePath());
    topPanel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            JComboBox combo = (JComboBox) evt.getSource();
            TaskManager.execute(new ReadDirectoryWorker(combo));
        }
    });

    internalPanel.add(BorderLayout.NORTH, topPanel);

    DefaultMutableTreeNode directoryRoot = new DefaultMutableTreeNode(rootDir);

    directoryTreeModel = new ShortedTreeModel(directoryRoot, new ToStringComparator());
    directoryTree = new JTree(directoryTreeModel);
    directoryTree.setCellRenderer(new DirectoryCellRenderer());
    directoryTree.setRootVisible(true);
    directoryTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    directoryTree.setEnabled(true);
    directoryTree.setEditable(false);
    directoryTree.setShowsRootHandles(true);
    directoryTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getPath();
            TreePath leadPath = evt.getNewLeadSelectionPath();

            if ((path != null) && (leadPath != null)) {
                TaskManager.execute(new RefreshWorker(leadPath, false));
            }
        }
    });
    directoryTree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) directoryTree
                        .getLastSelectedPathComponent();

                if (!node.isRoot()) {
                    File dir = (File) node.getUserObject();

                    topPanel.setDirectory(dir.getAbsolutePath());
                }
            }
        }
    });

    JScrollPane directoryScroll = new JScrollPane(directoryTree);
    directoryScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    directoryScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    directoryScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    fileListModel = new ShortedListModel(new ToStringComparator());
    fileList = new JList(fileListModel);
    fileList.setDragEnabled(true);
    fileList.setCellRenderer(new FileCellRenderer());
    fileList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                final int index = fileList.locationToIndex(evt.getPoint());

                TaskManager.execute(new Runnable() {
                    public void run() {
                        File file = (File) fileListModel.getElementAt(index);

                        if (log.isDebugEnabled()) {
                            log.debug(file);
                        }

                        IBuffer buffer = new BufferFactory().createBuffer();
                        buffer.open(file);

                        WorkspaceManager.addBuffer(buffer);
                    }
                });
            }
        }
    });

    JScrollPane filesScroll = new JScrollPane(fileList);
    filesScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    filesScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    filesScroll.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE);

    splitPane = new StrippedSplitPane(JSplitPane.VERTICAL_SPLIT, directoryScroll, filesScroll);
    splitPane.setBorder(BorderFactory.createEmptyBorder());
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerSize(5);
    splitPane.setDividerLocation(PreferenceManager.getInt("explorer.divider", 0));

    List<MutableTreeNode> dirs = openDirectory(rootDir);
    directoryTreeModel.insertAllInto(dirs, directoryRoot);

    List<File> files = getFiles(rootDir);
    fileListModel.addAll(files);

    directoryTree.expandRow(0);

    internalPanel.add(splitPane, BorderLayout.CENTER);

    setContent(internalPanel);
}

From source file:tufts.vue.OutlineViewTree.java

/** Creates a new instance of OverviewTree */
public OutlineViewTree() {
    setModel(null);//  w w w .  jav a 2s.c  o  m
    setEditable(true);
    setFocusable(true);
    getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    setCellRenderer(new OutlineViewTreeRenderer());
    //setCellRenderer(new DefaultTreeCellRenderer());
    setCellEditor(new OutlineViewTreeEditor());
    setInvokesStopCellEditing(true); // so focus-loss during edit triggers a save instead of abort edit

    setRowHeight(-1); // ahah: must do this to force variable row height

    //tree selection listener to keep track of the selected node 
    addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            ArrayList selectedComponents = new ArrayList();
            TreePath[] paths = getSelectionPaths();

            //if there is no selected nodes
            if (paths == null) {
                valueChangedState = false;
                selectionFromVUE = false;

                return;
            }

            for (int i = 0; i < paths.length; i++) {
                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
                Object o = treeNode.getUserObject();
                if (DEBUG.FOCUS)
                    System.out.println(this + " valueChanged in treeNode[" + treeNode + "] userObject="
                            + o.getClass() + "[" + o + "]");
                tufts.oki.hierarchy.HierarchyNode hierarchyNode = (tufts.oki.hierarchy.HierarchyNode) o;

                LWComponent component = hierarchyNode.getLWComponent();

                //if it is not LWMap, add to the selected components list
                if (!(component instanceof LWMap)) {
                    selectedComponents.add(component);
                }
            }

            if (!selectionFromVUE) {
                valueChangedState = true;

                //                         if(selectedComponents.size() != 0)
                //                           VUE.getSelection().setTo(selectedComponents.iterator());
                //                         else
                //                           VUE.getSelection().clear();
            }

            valueChangedState = false;
            selectionFromVUE = false;
        }
    });
}

From source file:unikn.dbis.univis.navigation.tree.VTree.java

/**
 * TODO: document me!!!/*from  ww w.java2 s .  c  o m*/
 *
 * @param p
 */
public void showPopupMenu(Point p) {

    // Remove all items from popup menu.
    popupMenu.removeAll();

    Object o = getLastSelectedPathComponent();

    if (o instanceof DefaultMutableTreeNode) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;

        Object userObject = node.getUserObject();

        if (userObject instanceof VDimension) {

            VDimension dimension = (VDimension) userObject;

            try {
                Point p2 = new Point(p);
                SwingUtilities.convertPointToScreen(p2, this);

                final FilterItemContainer container = createFilterContainer(dimension, p2);

                if (!container.isEmpty()) {
                    /*
                    JLabel header = new JLabel(MessageResolver.getMessage("data_reference." + dimension.getI18nKey()));
                    Font font = header.getFont();
                    header.setFont(new Font(font.getFontName(), Font.BOLD, font.getSize() + 2));
                    popupMenu.add(header);
                    popupMenu.add(new JPopupMenu.Separator());
                    */

                    popupMenu = new FilterPopupMenu(
                            MessageResolver.getMessage("data_reference." + dimension.getI18nKey()));

                    final JCheckBox button = new JCheckBox("Check/Uncheck all");

                    button.setSelected(container.isAllChecked());

                    button.addActionListener(new ActionListener() {
                        /**
                         * Invoked when an action occurs.
                         */
                        public void actionPerformed(ActionEvent e) {

                            for (Component c : container.getComponents()) {
                                if (c instanceof VBidirectionalBrowsingItem) {
                                    ((VBidirectionalBrowsingItem) c).getCheckBox()
                                            .setChecked(button.isSelected());
                                }
                            }
                        }
                    });

                    popupMenu.add(button);

                    popupMenu.add(new JPopupMenu.Separator());

                    popupMenu.add(container);

                    JButton view = new JButton(MessageResolver.getMessage("filtering"), VIcons.FILTER);
                    view.addActionListener(new ActionListener() {

                        /**
                         * Invoked when an action occurs.
                         */
                        public void actionPerformed(ActionEvent e) {
                            popupMenu.setVisible(false);
                        }
                    });

                    popupMenu.add(new JPopupMenu.Separator());

                    popupMenu.add(view);

                    popupMenu.show(VTree.this, (int) p.getX(), (int) p.getY());
                } else {
                    JOptionPane.showMessageDialog(VTree.this.getParent().getParent().getParent(),
                            MessageResolver.getMessage("no_items_found"),
                            MessageResolver.getMessage("error_message"), JOptionPane.ERROR_MESSAGE);
                }
            } catch (SQLException sqle) {
                VExplorer.publishException(sqle);

                if (LOG.isErrorEnabled()) {
                    LOG.error(sqle.getMessage(), sqle);
                }
            }
        }
    }
}

From source file:view.MultipleValidationDialog.java

private void jtValidationValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jtValidationValueChanged
    if (jtValidation.getSelectionRows().length == 0) {
        showSignatureValidationDetails(null);
    } else if (jtValidation.getSelectionRows().length == 1) {
        DefaultMutableTreeNode dtn = (DefaultMutableTreeNode) jtValidation.getLastSelectedPathComponent();
        SignatureValidation sv = null;/* w  w  w.ja  va2s  .  c  o m*/
        if (dtn.isLeaf()) {
            DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) dtn.getParent();
            sv = (SignatureValidation) dmtn.getUserObject();
        } else {
            sv = (SignatureValidation) dtn.getUserObject();
            jtValidation.expandRow(jtValidation.getSelectionRows()[0]);
        }
        showSignatureValidationDetails(sv);
    } else {
        jtValidation.setSelectionPath(evt.getOldLeadSelectionPath());
    }
}

From source file:view.MultipleValidationDialog.java

private void btnShowCertificateDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowCertificateDetailsActionPerformed
    DefaultMutableTreeNode dtn = (DefaultMutableTreeNode) jtValidation.getLastSelectedPathComponent();
    SignatureValidation sv = null;//from  w ww  .  ja  va  2 s .  c  om
    if (dtn.isLeaf()) {
        DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) dtn.getParent();
        sv = (SignatureValidation) dmtn.getUserObject();
    } else {
        sv = (SignatureValidation) dtn.getUserObject();
    }
    CertificatePropertiesDialog cpd = new CertificatePropertiesDialog((MainWindow) this.getParent(), true,
            sv.getSignature().getSignCertificateChain());
    cpd.setLocationRelativeTo(null);
    cpd.setVisible(true);
}

From source file:view.MultipleValidationDialog.java

private void lblRevisionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblRevisionMouseClicked
    if (SwingUtilities.isLeftMouseButton(evt)) {
        DefaultMutableTreeNode dtn = (DefaultMutableTreeNode) jtValidation.getLastSelectedPathComponent();
        SignatureValidation sv = null;/*from  w  ww.j  a  va2  s . c o  m*/
        if (dtn.isLeaf()) {
            DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) dtn.getParent();
            sv = (SignatureValidation) dmtn.getUserObject();
        } else {
            sv = (SignatureValidation) dtn.getUserObject();
        }
        try {
            File f = CCInstance.getInstance().extractRevision(sv.getFilename(), sv.getName());
            openPdfReaderFromFile(f);
        } catch (IOException | RevisionExtractionException ex) {
            Logger.getLogger(WorkspacePanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}