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.mzmine.desktop.impl.projecttree.ProjectTreeMouseHandler.java

private void handleDoubleClickEvent(MouseEvent e) {
    TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY());
    if (clickedPath == null)
        return;// ww w  .java 2s .  c  o  m
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent();
    Object clickedObject = node.getUserObject();

    if (clickedObject instanceof RawDataFile) {
        RawDataFile clickedFile = (RawDataFile) clickedObject;
        TICVisualizerModule.setupNewTICVisualizer(clickedFile);
    }

    if (clickedObject instanceof PeakList) {
        PeakList clickedPeakList = (PeakList) clickedObject;
        PeakListTableModule.showNewPeakListVisualizerWindow(clickedPeakList);
    }

    if (clickedObject instanceof Scan) {
        Scan clickedScan = (Scan) clickedObject;
        SpectraVisualizerModule.showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber());
    }

    if (clickedObject instanceof MassList) {
        MassList clickedMassList = (MassList) clickedObject;
        Scan clickedScan = clickedMassList.getScan();
        SpectraVisualizerWindow window = SpectraVisualizerModule
                .showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber());
        MassListDataSet dataset = new MassListDataSet(clickedMassList);
        window.addDataSet(dataset, Color.green);
    }

    if (clickedObject instanceof PeakListRow) {
        PeakListRow clickedPeak = (PeakListRow) clickedObject;
        PeakSummaryVisualizerModule.showNewPeakSummaryWindow(clickedPeak);
    }

}

From source file:au.org.ala.delta.editor.ui.CharacterTree.java

/**
 * This is a done to initiate a cell edit from a single click with drag and drop enabled.
 *///ww  w  . j  a v a 2  s . c om
protected void processMouseEvent(MouseEvent e) {

    super.processMouseEvent(e);
    _doubleProcessingMouseEvent = false;
    TreePath selectedPath = getSelectionPath();
    if (selectedPath != null) {
        Object lastComponent = selectedPath.getLastPathComponent();
        if (lastComponent instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;

            if (node.isLeaf()) {
                int row = getRowForPath(selectedPath);
                Rectangle bounds = getRowBounds(row);
                int pos = e.getX() - bounds.x;
                if (pos >= 0 && pos < 20) {
                    _doubleProcessingMouseEvent = true;
                    super.processMouseEvent(e);
                }
            }
        }
    }
}

From source file:au.org.ala.delta.editor.ui.CharacterTree.java

@Override
public String getToolTipText(MouseEvent event) {
    TreePath path = getClosestPathForLocation(event.getX(), event.getY());
    if (path != null) {
        Object node = path.getLastPathComponent();
        if (node instanceof CharacterTreeNode) {
            CharacterTreeNode chNode = (CharacterTreeNode) node;
            String desc = chNode.getCharacter().getDescription();
            int width = getGraphics().getFontMetrics(getFont()).stringWidth(desc);
            if (width > getParent().getWidth() - 70) {
                if (width > 400) {
                    return String.format("<html><body style=\"width: %dpx;\">%s</body></html>", 400,
                            StringEscapeUtils.escapeHtml(desc));
                } else {
                    return desc;
                }//from ww  w. jav  a 2s.  c o m
            }
        }
    }
    return null;
}

From source file:eu.europa.ec.markt.dss.applet.view.validationpolicy.EditView.java

private void registerMouseListener(final JTree tree) {

    MouseListener mouseAdapter = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            if (mouseEvent.getButton() == MouseEvent.BUTTON3) {
                final int selectedRow = tree.getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
                final TreePath selectedPath = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
                if (selectedRow != -1) {
                    final XmlDomAdapterNode clickedItem = (XmlDomAdapterNode) selectedPath
                            .getLastPathComponent();
                    final boolean isLeaf = tree.getModel().isLeaf(selectedPath.getLastPathComponent());
                    // Do nothing on root element
                    if (selectedPath.getPathCount() > 1) {
                        // find the allowed actions, to know if a popup menu should be displayed and the content of the popup menu + action handlers
                        if (clickedItem.node instanceof Element) {
                            nodeActionAdd(mouseEvent, selectedRow, selectedPath, clickedItem, tree);
                        } else if (isLeaf) {
                            valueLeafActionEdit(mouseEvent, selectedPath, clickedItem, tree);
                        }//from   w  w w .java2  s. c o  m
                    }
                }
            }
        }
    };
    tree.addMouseListener(mouseAdapter);
}

From source file:com.igormaznitsa.mindmap.model.MindMap.java

@Override
public void valueForPathChanged(@Nonnull final TreePath path, @Nullable final Object newValue) {
    if (newValue instanceof String) {
        ((Topic) path.getLastPathComponent()).setText((String) newValue);
        fireTopicChanged((Topic) path.getLastPathComponent());
    } else {/*from  w  w w .  j a  v  a 2s.c  o m*/
        LOGGER.warn("Attempt to set non string value to path : " + path); //NOI18N
    }
}

From source file:ObjectInspector.java

@Override
public String getToolTipText(MouseEvent me) {
    TreePath pathForLocation = getPathForLocation(me.getX(), me.getY());

    if (pathForLocation != null) {
        Object lastPathComponent = pathForLocation.getLastPathComponent();
        if (lastPathComponent instanceof ObjectNode) {
            ObjectNode on = (ObjectNode) lastPathComponent;

            return on.tooltip;
        }/*from   w  w  w  .j  ava  2s . co m*/
    }

    return null;
}

From source file:com.mgmtp.jfunk.core.ui.JFunkFrame.java

private void runScripts() {
    try {//from ww w  .ja  va  2s  .co m
        TreePath[] paths = tree.getSelectionPaths();

        if (paths == null) {
            JOptionPane.showMessageDialog(JFunkFrame.this, "No script(s) selected!", "Error",
                    JOptionPane.ERROR_MESSAGE);
            return;
        }

        String testSystem;
        boolean parallel = false;
        if (StringUtils.equals((String) parallelComboBox.getSelectedItem(), "yes")) {
            parallel = true;
        }
        testSystem = testSystemsModel.getSelectedItem();

        int threads = (Integer) threadCountComboBox.getSelectedItem();

        List<String> commandsList = new ArrayList<String>(paths.length + 5);
        commandsList.add("cmd.exe");
        commandsList.add("/X");
        commandsList.add("/C");
        commandsList.add("start");
        commandsList.add("run_testskript.bat");
        //Threadcount wird als argument weiter gereicht.
        commandsList.add("-threadcount=" + threads);
        //Flag parallel wird als Parameter weiter gereicht.
        if (parallel) {
            commandsList.add("-parallel");
        }

        if (paths.length == 1) {
            commandsList.add(((File) paths[0].getLastPathComponent()).getPath());
        } else {
            boolean hasScriptOrDir = false;
            for (TreePath path : paths) {
                File file = (File) path.getLastPathComponent();
                if (file.isFile()) {
                    commandsList.add(file.getPath());
                    hasScriptOrDir = true;
                }
            }
            if (!hasScriptOrDir) {
                // Es wurden nur Verzeichnisse ausgewhlt.
                // Erstes Verzeichnis nehmen!
                commandsList.add(((File) paths[0].getLastPathComponent()).getPath());
            }
        }

        final ProcessBuilder pb = new ProcessBuilder(commandsList);
        pb.environment().put("EXIT_AFTER_RUNNING", "true");
        StringBuilder opts = new StringBuilder(
                "-Djfunk.props.file=" + jFunkPropertyFilesModel.getSelectedItem());
        opts.append(" -Dtestsystem=" + testSystem);
        String mailConfig = mailConfigurationsModel.getSelectedItem();
        if (!StringUtils.equals(mailConfig, "default")) {
            opts.append(" -Dsystem.properties.mailconfig=email_accounts/" + mailConfig + "." + PROPS_SUFFIX);
        }
        pb.environment().put("APP_OPTS", opts.toString());
        pb.start();
    } catch (final Exception ex) {
        log.error(ex.getMessage(), ex);
        JOptionPane.showMessageDialog(JFunkFrame.this, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java

private void registerMouseListener(final JTree tree) {

    MouseListener mouseAdapter = new MouseAdapter() {
        @Override/*from w w w .  j  a va 2s.  co m*/
        public void mousePressed(MouseEvent mouseEvent) {
            if (mouseEvent.getButton() == MouseEvent.BUTTON3) {
                final int selectedRow = tree.getRowForLocation(mouseEvent.getX(), mouseEvent.getY());
                final TreePath selectedPath = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY());
                if (selectedRow != -1) {
                    final XmlDomAdapterNode clickedItem = (XmlDomAdapterNode) selectedPath
                            .getLastPathComponent();
                    final boolean isLeaf = tree.getModel().isLeaf(selectedPath.getLastPathComponent());
                    // Do nothing on root element
                    if (selectedPath.getPathCount() > 1) {
                        // find the allowed actions, to know if a popup menu should be displayed and the content of the popup menu + action handlers
                        if (clickedItem.node instanceof Element) {
                            nodeActionAdd(mouseEvent, selectedRow, selectedPath, clickedItem, tree);
                        } else if (isLeaf) {
                            valueLeafActionEdit(mouseEvent, selectedPath, clickedItem, tree);
                        }
                    }
                }
            }
        }
    };
    tree.addMouseListener(mouseAdapter);
}

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemChooserComponent.java

@Override
protected JPanel createPanelHook() {

    tree.setRootVisible(false);// ww w .  j av  a  2s . c o  m
    tree.setCellRenderer(treeRenderer);

    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() != 2 || e.isPopupTrigger()) {
                return;
            }

            final TreePath path = tree.getClosestPathForLocation(e.getX(), e.getY());
            final ITreeNode node = (ITreeNode) path.getLastPathComponent();

            if (node.getValue() instanceof InventoryType) {
                final InventoryType selectedItem = (InventoryType) node.getValue();
                selectedItemsModel.addItem(selectedItem);
                if (selectionMode == SelectionMode.SINGLE_SELECTION) {
                    okButtonClicked();
                } else if (selectionMode == SelectionMode.MULTIPLE_SELECTION) {
                    // ok
                } else {
                    throw new RuntimeException("Unhandled mode " + selectionMode);
                }
            }
        }
    });

    tree.addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
        }

        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            handleTreeExpansion(event);
        }
    });

    final JScrollPane pane = new JScrollPane(tree);
    pane.setPreferredSize(new Dimension(400, 400));

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());

    switch (selectionMode) {
    case SINGLE_SELECTION:
        result.add(pane, constraints().useRemainingSpace().resizeBoth().end());
        break;
    case MULTIPLE_SELECTION:
        result.add(pane, constraints(0, 0).useRelativeWidth().resizeBoth().end());
        result.add(createListViewPanel(), constraints(1, 0).useRemainingWidth().resizeBoth().end());
        break;
    default:
        throw new RuntimeException("Unhandled selection mode" + selectionMode);
    }

    return result;
}

From source file:gdt.jgui.entity.JEntityStructurePanel.java

private void expandAll(JTree tree, TreePath path, boolean expand) {
    TreeNode node = (TreeNode) path.getLastPathComponent();
    if (node.getChildCount() >= 0) {
        Enumeration enumeration = node.children();
        while (enumeration.hasMoreElements()) {
            TreeNode n = (TreeNode) enumeration.nextElement();
            TreePath p = path.pathByAddingChild(n);
            expandAll(tree, p, expand);/*w ww  .j a  v  a 2 s  . c om*/
        }
    }
    if (expand) {
        tree.expandPath(path);
    } else {
        tree.collapsePath(path);
    }
}