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:au.org.ala.delta.editor.ui.CharacterTree.java

public CharacterTree() {

    setToggleClickCount(0);/*from www .ja v a2s  . c o  m*/
    _characterListBehaviour = new CharacterListBehaviour();
    _stateListBehaviour = new StateListBehaviour();

    ToolTipManager.sharedInstance().registerComponent(this);

    addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            if (_doubleProcessingMouseEvent) {
                return;
            }
            if (!isEditing()) {
                int selectedRow = getClosestRowForLocation(e.getX(), e.getY());

                if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) {
                    Action action = getActionMap().get(SELECTION_ACTION_KEY);
                    if (action != null) {
                        action.actionPerformed(new ActionEvent(this, -1, ""));
                    }
                }
            }
        }
    });

    addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

            TreePath selection = e.getNewLeadSelectionPath();
            if (selection != null) {
                Object lastComponent = selection.getLastPathComponent();
                if (lastComponent instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent;

                    if (node.isLeaf()) {
                        CharacterTree.super.setTransferHandler(_stateTransferHandler);
                    } else {
                        CharacterTree.super.setTransferHandler(_characterTransferHandler);
                    }
                }
            }
        }
    });

    ActionMap actionMap = Application.getInstance().getContext().getActionMap(this);

    javax.swing.Action find = actionMap.get("find");
    if (find != null) {
        getActionMap().put("find", find);
    }

    javax.swing.Action findNext = actionMap.get("findNext");
    if (findNext != null) {
        getActionMap().put("findNext", findNext);
    }

    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY);

}

From source file:io.bibleget.BibleGetHelp.java

private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked
    // TODO add your handling code here:
    int tp = jTree1.getRowForLocation(evt.getX(), evt.getY());
    //System.out.println(tp);
    if (tp != -1 && tp < 4) {
        switch (tp) {
        case 0://  w  w w .ja v  a  2 s.c  om
            jTextPane2.setDocument(doc);
            jTextPane2.setText(HTMLStr0);
            jTextPane2.setCaretPosition(0);
            break;
        case 1:
            jTextPane2.setDocument(doc);
            jTextPane2.setText(HTMLStr1);
            jTextPane2.setCaretPosition(0);
            break;
        case 2:
            jTextPane2.setDocument(doc);
            jTextPane2.setText(HTMLStr2);
            jTextPane2.setCaretPosition(0);
            break;
        case 3:
            String curLang = Locale.getDefault().getDisplayLanguage().toUpperCase();
            //System.out.println(curLang);
            jTextPane2.setDocument(doc);
            jTextPane2.setText(MessageFormat.format(HTMLStr3, booksAndAbbreviations.get(curLang), curLang));
            jTextPane2.setCaretPosition(0);
            break;
        default:
            jTextPane2.setDocument(doc);
            jTextPane2.setText(HTMLStr0);
            jTextPane2.setCaretPosition(0);
        }
    } else if (tp > 3) {
        TreePath treePath = jTree1.getPathForLocation(evt.getX(), evt.getY());
        String curPath = treePath.getLastPathComponent().toString().toUpperCase(Locale.ENGLISH);
        //System.out.println(curPath);
        if (booksAndAbbreviations.get(curPath) != null) {
            jTextPane2.setDocument(doc);
            jTextPane2.setText(MessageFormat.format(HTMLStr3, booksAndAbbreviations.get(curPath), curPath));
            jTextPane2.setCaretPosition(0);
        }
    }
    //jTextPane2.setText("<span>"+tp+"</span>");
    //else
    //jtf.setText("");
}

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

private void addButtonClicked() {
    final TreePath selectionPath = tree.getSelectionPath();
    if (selectionPath == null || selectionPath.getPathCount() < 3) {
        return;//from w ww. j ava 2s .c om
    }

    final ITreeNode selected = (ITreeNode) selectionPath.getLastPathComponent();
    if (selected.getValue() instanceof InventoryType) {
        selectedItemsModel.addItem((InventoryType) selected.getValue());
    }
}

From source file:mobac.gui.components.JMapSourceTree.java

@Override
public String getToolTipText(MouseEvent event) {
    if (getRowForLocation(event.getX(), event.getY()) == -1)
        return "";
    TreePath curPath = getPathForLocation(event.getX(), event.getY());
    Object lastPathComponent = curPath.getLastPathComponent();
    if (lastPathComponent == null)
        return null;

    Object userObject = ((ComparableTreeNode) lastPathComponent).getUserObject();
    if (userObject.getClass().equals(folderClass)) {
        return null;
    }/*w w  w.  j a  v a2 s. c o m*/
    return generateMapSourceTooltip((MapSource) userObject);
}

From source file:com.orthancserver.SelectImageDialog.java

public SelectImageDialog() {
    tree_ = new JTree();

    tree_.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override//ww w  .  j av a  2 s.  co  m
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
            TreePath path = event.getPath();
            if (path.getLastPathComponent() instanceof MyTreeNode) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                node.LoadChildren((DefaultTreeModel) tree_.getModel());
            }
        }

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

    tree_.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            TreePath path = e.getNewLeadSelectionPath();
            if (path != null) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                if (node.UpdatePreview(preview_)) {
                    selectedType_ = node.GetResourceType();
                    selectedUuid_ = node.GetUuid();
                    selectedConnection_ = node.GetConnection();
                    okButton_.setEnabled(true);
                }

                removeServer_.setEnabled(node.GetResourceType() == ResourceType.SERVER);
            }
        }
    });

    tree_.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            TreePath path = tree_.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                MyTreeNode node = (MyTreeNode) path.getLastPathComponent();
                if (e.getClickCount() == 2 && node.GetResourceType() == ResourceType.INSTANCE) {
                    // Double click on an instance, close the dialog
                    isSuccess_ = true;
                    setVisible(false);
                }
            }
        }
    });

    final JPanel contentPanel = new JPanel();
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        JSplitPane splitPane = new JSplitPane();
        splitPane.setResizeWeight(0.6);
        contentPanel.add(splitPane);

        splitPane.setLeftComponent(new JScrollPane(tree_));
        splitPane.setRightComponent(preview_);
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton btnAddServer = new JButton("Add server");
            btnAddServer.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    OrthancConfigurationDialog dd = new OrthancConfigurationDialog();
                    dd.setLocationRelativeTo(null); // Center dialog on screen

                    OrthancConnection orthanc = dd.ShowModal();
                    if (orthanc != null) {
                        AddOrthancServer(orthanc);
                        ((DefaultTreeModel) tree_.getModel()).reload();
                    }
                }
            });
            buttonPane.add(btnAddServer);
        }

        {
            buttonPane.add(removeServer_);
            removeServer_.setEnabled(false);

            removeServer_.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    MyTreeNode selected = (MyTreeNode) tree_.getLastSelectedPathComponent();
                    if (selected.GetResourceType() == ResourceType.SERVER && JOptionPane.showConfirmDialog(null,
                            "Remove server \"" + selected.getUserObject() + "\"?", "WARNING",
                            JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                        ((DefaultTreeModel) tree_.getModel()).removeNodeFromParent(selected);
                    }
                }
            });
        }

        {
            okButton_.setEnabled(false);
            okButton_.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    isSuccess_ = true;
                    setVisible(false);
                }
            });
            buttonPane.add(okButton_);
            getRootPane().setDefaultButton(okButton_);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg) {
                    setVisible(false);
                }
            });
            buttonPane.add(cancelButton);
        }
    }

    setUndecorated(false);
    setSize(500, 500);
    setTitle("Select some series or some instance in Orthanc");
    setModal(true);
}

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

protected ITreeNode getCurrentlySelectedTreeNode() {
    final TreePath selection = tree.getSelectionPath();

    if (selection == null || !(selection.getLastPathComponent() instanceof ITreeNode)) {
        return null;
    }/*from   w  ww. j  ava2s  . c o  m*/

    return (ITreeNode) selection.getLastPathComponent();
}

From source file:com.mirth.connect.client.ui.alert.AlertChannelPane.java

private void toggleSelectedRows(boolean enabled) {
    int[] selectedRows = channelTreeTable.getSelectedModelRows();

    for (int i = 0; i < selectedRows.length; i++) {
        TreePath path = channelTreeTable.getPathForRow(selectedRows[i]);
        AbstractChannelTreeTableNode node = (AbstractChannelTreeTableNode) path.getLastPathComponent();

        node.setEnabled(enabled);/*from w  ww . ja v  a  2  s .c o m*/

        for (int j = 0; j < node.getChildCount(); j++) {
            ((AbstractChannelTreeTableNode) node.getChildAt(j)).setEnabled(enabled);
        }
    }

    channelTreeTable.repaint();
}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void buildInstallingPane() {

    getNextButton().setEnabled(false);// w  w  w . jav a  2  s  .co  m
    getCancelButton().setEnabled(false);
    getMainPane().removeAll();
    getMainPane().setLayout(new MigLayout(new LC().fill()));
    final JTextArea text = new JTextArea();
    text.setEditable(false);
    getMainPane().add(new JScrollPane(text), new CC().grow().spanY().wrap());
    getMainPane().validate();
    getMainPane().repaint();
    SwingWorker<Object, String> worker = new SwingWorker<Object, String>() {

        @Override
        protected Object doInBackground() throws Exception {
            try {
                List<String> mods = new ArrayList<String>();
                CheckBoxTreeSelectionModel select = getModTree().getCheckBoxTreeSelectionModel();
                TreePath[] paths = select.getSelectionPaths();
                if (paths != null && paths.length > 0) {
                    for (TreePath path : paths) {
                        DefaultMutableTreeNode node = ((DefaultMutableTreeNode) path.getLastPathComponent());
                        String mod = (String) node.getUserObject();
                        if (mod == null) {
                            for (int i = 0; i < node.getChildCount(); i++) {
                                DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
                                mods.add((String) child.getUserObject());
                            }
                        } else {
                            mods.add(mod);
                        }
                    }
                }
                InstallScript.guiInstall(mods, text, getProgressBar());
            } catch (Exception e) {
                LOGGER.error("Error while trying to install mods", e);
                JOptionPane.showMessageDialog(Installer.this,
                        "Unexpected error while installing mods:\n" + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                setVisible(false);
                dispose();
            }
            return null;
        }

        @Override
        public void done() {
            getNextButton().removeActionListener(Installer.this);
            getNextButton().setText("Done");
            getNextButton().addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                    dispose();
                }
            });
            getNextButton().setEnabled(true);
        }
    };

    worker.execute();
}

From source file:uk.co.petertribble.jangle.SnmpTreePanel.java

public void valueChanged(TreeSelectionEvent e) {
    TreePath tpth = e.getNewLeadSelectionPath();
    if (tpth != null) {
        setPanel((SnmpTreeNode) tpth.getLastPathComponent());
    }/*from w w w .j  a  v a2 s  . co  m*/
}

From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java

@SuppressWarnings("unchecked")
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

    DefaultTableModel dtm = (DefaultTableModel) getJTableFields().getModel();

    TreePath[] paths = jTree1.getSelectionPaths();
    if (paths == null)
        return;/* w w  w . j a  v a2 s .  co  m*/
    for (int i = 0; i < paths.length; ++i) {
        boolean valid = true;
        TreePath tp = paths[i];

        TreeJRField tjrf = (TreeJRField) ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject();
        String returnType = Misc.getJRFieldType(tjrf.getObj().getName());

        JRDesignField field = new JRDesignField();
        field.setName(tjrf.getField().getName());
        field.setValueClassName(returnType);

        field.setDescription(tjrf.getField().getDescription());
        Vector row = new Vector();
        row.addElement(field);
        row.addElement(field.getValueClassName());
        row.addElement(field.getDescription());

        if (isComboVisible() && jComboBox1.getSelectedItem() instanceof FieldClassWrapper) {
            FieldClassWrapper cw = (FieldClassWrapper) jComboBox1.getSelectedItem();
            field.setName(cw.getFieldName() + "." + field.getDescription());
            field.setDescription(field.getName());
        }

        // Check for duplicates fields...
        boolean found = fieldAlreadyExists(field);
        String baseName = field.getName();
        for (int j = 1; isPathOnDescription() && found; ++j) {
            field.setName(baseName + "_" + j);
            found = fieldAlreadyExists(field);
        }

        if (!found) {
            dtm.addRow(row);
            getJTableFields().getSelectionModel().addSelectionInterval(getJTableFields().getRowCount() - 1,
                    getJTableFields().getRowCount() - 1);
        }
    }
}