Example usage for javax.swing.tree TreePath getLastPathComponent

List of usage examples for javax.swing.tree TreePath getLastPathComponent

Introduction

In this page you can find the example usage for javax.swing.tree TreePath getLastPathComponent.

Prototype

public Object getLastPathComponent() 

Source Link

Document

Returns the last element of this path.

Usage

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private GroupTreeNodeViewModel getFirstSelectedNode() {
    TreePath path = groupsTree.getSelectionPath();
    if (path != null) {
        return (GroupTreeNodeViewModel) path.getLastPathComponent();
    }/*from w  w  w. ja  va  2s  .  c om*/
    return null;
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Creates the tree view, that holds the data structure. <br>
 * <br>/*from www  .j av  a  2  s  .  com*/
 * Initially, the root node is <b>not</b> visible, so that the tree appears empty at the beginning.
 */
private void createTree() {

    /**
     * Mouse listener to listen for mouse events on the tree. <br>
     * This will mark the selected tree entry as "selected" or "unselected",
     * which will cause this nodes checkbox to appear as either "checked" or
     * "unchecked".
     */
    treeMouseListener = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            int x = e.getX();
            int y = e.getY();

            int row = tree.getRowForLocation(x, y);

            TreePath path = tree.getPathForRow(row);
            if (path != null) {
                CheckableTreeNode node = (CheckableTreeNode) path.getLastPathComponent();
                if (e.getClickCount() == 2) {
                    Object userObject = node.getUserObject();
                    if ((userObject instanceof FileNodeWrapper) && node.isLeaf()) {
                        FileNodeWrapper fnw = (FileNodeWrapper) userObject;
                        try {
                            JabRefDesktop.openExternalViewer(
                                    JabRefGUI.getMainFrame().getCurrentBasePanel().getBibDatabaseContext(),
                                    fnw.file.getAbsolutePath(), "pdf");
                        } catch (IOException e1) {
                            LOGGER.info("Error opening file", e1);
                        }
                    }
                } else {
                    node.check();
                    tree.invalidate();
                    tree.repaint();
                }
            }
        }

    };

    CheckableTreeNode startNode = new CheckableTreeNode("ROOT");
    DefaultTreeModel model = new DefaultTreeModel(startNode);

    tree.setModel(model);
    tree.setRootVisible(false);

    DefaultTreeCellRenderer renderer = new CheckboxTreeCellRenderer();
    tree.setCellRenderer(renderer);

    tree.addMouseListener(treeMouseListener);

}

From source file:de.codesourcery.jasm16.ide.ui.views.WorkspaceExplorer.java

protected WorkspaceTreeNode getSelectedNode() {
    TreePath path = tree.getSelectionPath();
    if (path != null) {
        return (WorkspaceTreeNode) path.getLastPathComponent();
    }// www  .j  av a2 s .co m
    return null;
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * /*from  ww w . j a  va  2s  .  com*/
 */
protected void fillPropsTable() {
    TreePath path = tree.getSelectionPath();
    if (path != null) {
        RegProcEntry rpe = (RegProcEntry) path.getLastPathComponent();

        Vector<String> keys = new Vector<String>();
        for (Object obj : rpe.keySet()) {
            keys.add(obj.toString());
        }
        Collections.sort(keys);

        if (fullDescHash == null) {
            fullDescHash = rp.getAllDescPairsHash();
        }

        Object[][] rows = new Object[keys.size()][2];
        int inx = 0;
        for (Object key : keys) {
            String titleStr = fullDescHash.get(key);
            if (titleStr == null) {
                titleStr = key.toString();
            }
            rows[inx][0] = titleStr;

            rows[inx][1] = rpe.get(key.toString());
            inx++;
        }
        propsTable.setModel(new DefaultTableModel(rows, new String[] { "Property", "Value" }));
    } else {
        propsTable.setModel(new DefaultTableModel());
    }
}

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Get URI of the selected concept./*  w w  w . ja va2s  .  c  o m*/
 */
public String getSelectedConceptUri() {
    TreePath treePath = treeTable.tree.getSelectionPath();

    if (treePath != null) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
        if (node != null) {
            return ((OutlineNode) node).getUri();
        }
    }
    return null;
}

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Get selected tree node./*from  ww w.ja v a2s .c o m*/
 *
 * @return
 */
public DefaultMutableTreeNode getSelectedTreeNode() {
    TreePath treePath = treeTable.tree.getSelectionPath();

    if (treePath == null) {
        return null;
    }
    return (DefaultMutableTreeNode) treePath.getLastPathComponent();
}

From source file:net.sf.jabref.gui.groups.GroupSelector.java

private void definePopup() {
    // These key bindings are just to have the shortcuts displayed
    // in the popup menu. The actual keystroke processing is in
    // BasePanel (entryTable.addKeyListener(...)).
    groupsContextMenu.add(editGroupPopupAction);
    groupsContextMenu.add(addGroupPopupAction);
    groupsContextMenu.add(addSubgroupPopupAction);
    groupsContextMenu.addSeparator();/*w ww.  j a  v a2  s.com*/
    groupsContextMenu.add(removeGroupAndSubgroupsPopupAction);
    groupsContextMenu.add(removeGroupKeepSubgroupsPopupAction);
    groupsContextMenu.add(removeSubgroupsPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(expandSubtreePopupAction);
    groupsContextMenu.add(collapseSubtreePopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(moveSubmenu);
    sortSubmenu.add(sortDirectSubgroupsPopupAction);
    sortSubmenu.add(sortAllSubgroupsPopupAction);
    groupsContextMenu.add(sortSubmenu);
    moveSubmenu.add(moveNodeUpPopupAction);
    moveSubmenu.add(moveNodeDownPopupAction);
    moveSubmenu.add(moveNodeLeftPopupAction);
    moveSubmenu.add(moveNodeRightPopupAction);
    groupsContextMenu.addSeparator();
    groupsContextMenu.add(addToGroup);
    groupsContextMenu.add(moveToGroup);
    groupsContextMenu.add(removeFromGroup);
    groupsTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showPopup(e);
            }
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
            if (path == null) {
                return;
            }
            GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent();
            // the root node is "AllEntries" and cannot be edited
            if (node.getNode().isRoot()) {
                return;
            }
            if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { // edit
                editGroupAction.actionPerformed(null); // dummy event
            } else if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) {
                annotationEvent(node);
            }
        }
    });
    // be sure to remove a possible border highlight when the popup menu
    // disappears
    groupsContextMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            // nothing to do
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            groupsTree.setHighlightBorderCell(null);
        }
    });
}

From source file:net.sf.jabref.groups.GroupSelector.java

private void updateSelections() {
    final MatcherSet searchRules = MatcherSets
            .build(andCb.isSelected() ? MatcherSets.MatcherType.AND : MatcherSets.MatcherType.OR);
    TreePath[] selection = groupsTree.getSelectionPaths();
    if (selection == null) {
        selection = new TreePath[0];
    }/*from w  ww  .  j  av  a 2 s .c  om*/

    for (TreePath aSelection : selection) {
        SearchMatcher searchRule = ((GroupTreeNode) aSelection.getLastPathComponent()).getSearchRule();
        searchRules.addRule(searchRule);
    }
    SearchMatcher searchRule = invCb.isSelected() ? new NotMatcher(searchRules) : searchRules;
    GroupingWorker worker = new GroupingWorker(searchRule);
    worker.getWorker().run();
    worker.getCallBack().update();
}

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

private void expandTreeAndSelect(final LoadProfileEntity selectedItem) {
    List<TreePath> paths = treeModel.getPaths();
    for (TreePath path : paths) {
        if (path.getLastPathComponent().equals(selectedItem)) {
            tree.setSelectionPath(path);
            tree.scrollPathToVisible(path);
        }/* w  ww  .  j a  v a  2s  .c  o  m*/
        tree.expandPath(path.getParentPath());
    }
}

From source file:gdt.jgui.entity.index.JIndexPanel.java

private void expandAll(JTree tree, TreePath parent, boolean expand) {

    TreeNode node = (TreeNode) parent.getLastPathComponent();

    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
        }//from w ww .j a  v a 2  s .  c  o  m
    }
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}