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:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void addGoalMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addGoalMenuItemActionPerformed
    TreePath path = projectTree.getSelectionPath();
    if (path == null) {
        return;/*  www.  j  a  va  2  s  .c om*/
    }

    MavenGoalDialog dialog = new MavenGoalDialog(null, true);
    dialog.setTitle("Add goals");
    dialog.setLocationRelativeTo(addGoalMenuItem);
    dialog.setVisible(true);
    //String goals = JOptionPane.showInputDialog(null, "Please input maven goals", "Add", JOptionPane.QUESTION_MESSAGE);
    if (!dialog.isCancel) {
        try {
            String name = dialog.nameTextField.getText();
            if (name.trim().equals("")) {
                return;
            }
            String goals = dialog.goalsTextField.getText();
            String profile = dialog.profileTextField.getText();
            List<String> properties = Arrays.asList(dialog.propertiesTextArea.getText().split("\n"));
            boolean skipTests = dialog.skipTestsCheckBox.isSelected();

            MyTreeNode node = (MyTreeNode) ((MyTreeNode) path.getLastPathComponent());
            MyTreeNode goalNode = new MyTreeNode(name, goals, profile, properties, skipTests, "goal",
                    node.project, node.projectInformation);
            node.add(goalNode);
            projectTree.updateUI();

            String key = node.projectInformation.getDisplayName();
            ArrayList<PersistData> list = data.get(key);
            if (list == null) {
                list = new ArrayList<PersistData>();
                data.put(key, list);
            }
            list.add(new PersistData(goalNode.type, goalNode.projectInformation.getDisplayName(), goalNode.name,
                    goalNode.goals, goalNode.profile, goalNode.properties, goalNode.skipTests));
            NbPreferences.forModule(this.getClass()).put("data", toString(data));
        } catch (Exception ex) {
            log(ExceptionUtils.getStackTrace(ex));
        }
    }
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createTokenTreePanel() {
    final JTree tree = new JTree();
    tokenPanelTreeModel = new TokenPanelTreeModel(tree);
    tree.setModel(tokenPanelTreeModel);//w  w w  . j  av a  2s .c  om
    tree.setCellRenderer(new TokenPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.addMouseListener(new MouseAdapter() {
        // TODO: Make this a handler class, not an aic
        @Override
        public void mousePressed(MouseEvent e) {
            // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY()));
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);

                if (row instanceof Token) {
                    if (e.getClickCount() == 2) {
                        Token token = (Token) row;
                        getCurrentZoneRenderer().clearSelectedTokens();
                        getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY()));

                        // Pick an appropriate tool
                        getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class);
                        getCurrentZoneRenderer().setActiveLayer(token.getLayer());
                        getCurrentZoneRenderer().selectToken(token.getId());
                        getCurrentZoneRenderer().requestFocusInWindow();
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        Token firstToken = null;
                        Set<GUID> selectedTokenSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof Token) {
                                Token token = (Token) path.getLastPathComponent();
                                if (firstToken == null) {
                                    firstToken = token;
                                }
                                if (AppUtil.playerOwns(token)) {
                                    selectedTokenSet.add(token.getId());
                                }
                            }
                        }
                        if (!selectedTokenSet.isEmpty()) {
                            try {
                                if (firstToken.isStamp()) {
                                    new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                } else {
                                    new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(),
                                            firstToken).showPopup(tree);
                                }
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }
    });
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            tokenPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return tree;
}

From source file:net.rptools.maptool.client.ui.MapToolFrame.java

private JComponent createDrawTreePanel() {
    final JTree tree = new JTree();
    drawablesPanel = new DrawablesPanel();
    drawPanelTreeModel = new DrawPanelTreeModel(tree);
    tree.setModel(drawPanelTreeModel);//from  w w w . ja v a 2 s.c o  m
    tree.setCellRenderer(new DrawPanelTreeCellRenderer());
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPane.setContinuousLayout(true);

    splitPane.setTopComponent(new JScrollPane(tree));
    splitPane.setBottomComponent(drawablesPanel);
    splitPane.setDividerLocation(100);
    // Add mouse Event for right click menu
    tree.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path == null) {
                return;
            }
            Object row = path.getLastPathComponent();
            int rowIndex = tree.getRowForLocation(e.getX(), e.getY());
            if (SwingUtilities.isLeftMouseButton(e)) {
                if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) {
                    tree.clearSelection();
                }
                tree.addSelectionInterval(rowIndex, rowIndex);
                if (row instanceof DrawnElement) {
                    if (e.getClickCount() == 2) {
                        DrawnElement de = (DrawnElement) row;
                        getCurrentZoneRenderer()
                                .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(),
                                        (int) de.getDrawable().getBounds().getCenterY()));
                    }
                }

                int[] treeRows = tree.getSelectionRows();
                java.util.Arrays.sort(treeRows);
                drawablesPanel.clearSelectedIds();
                for (int i = 0; i < treeRows.length; i++) {
                    TreePath p = tree.getPathForRow(treeRows[i]);
                    if (p.getLastPathComponent() instanceof DrawnElement) {
                        DrawnElement de = (DrawnElement) p.getLastPathComponent();
                        drawablesPanel.addSelectedId(de.getDrawable().getId());
                    }
                }
            }
            if (SwingUtilities.isRightMouseButton(e)) {
                if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) {
                    tree.clearSelection();
                    tree.addSelectionInterval(rowIndex, rowIndex);
                    drawablesPanel.clearSelectedIds();
                }
                final int x = e.getX();
                final int y = e.getY();
                EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        DrawnElement firstElement = null;
                        Set<GUID> selectedDrawSet = new HashSet<GUID>();
                        for (TreePath path : tree.getSelectionPaths()) {
                            if (path.getLastPathComponent() instanceof DrawnElement) {
                                DrawnElement de = (DrawnElement) path.getLastPathComponent();
                                if (firstElement == null) {
                                    firstElement = de;
                                }
                                selectedDrawSet.add(de.getDrawable().getId());
                            }
                        }
                        if (!selectedDrawSet.isEmpty()) {
                            try {
                                new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(),
                                        firstElement).showPopup(tree);
                            } catch (IllegalComponentStateException icse) {
                                log.info(tree.toString(), icse);
                            }
                        }
                    }
                });
            }
        }

    });
    // Add Zone Change event
    MapTool.getEventDispatcher().addListener(new AppEventListener() {
        public void handleAppEvent(AppEvent event) {
            drawPanelTreeModel.setZone((Zone) event.getNewValue());
        }
    }, MapTool.ZoneEvent.Activated);
    return splitPane;
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateImportDialog.java

private void updateErrorsAndWarnings() {
    if (warningsPanel != null && warningsPanel != null) {
        errorsPanel.setVisible(false);//from   w w w . j  a va  2  s . c  o  m
        warningsPanel.setVisible(false);

        int selectedRow = importTreeTable.getSelectedRow();
        if (selectedRow >= 0) {
            TreePath selectedPath = importTreeTable.getPathForRow(selectedRow);

            if (selectedPath != null) {
                ImportTreeTableNode node = (ImportTreeTableNode) selectedPath.getLastPathComponent();

                if ((boolean) node.getValueAt(IMPORT_SELECTED_COLUMN)) {
                    String name = (String) node.getValueAt(IMPORT_NAME_COLUMN);
                    Boolean overwrite = (Boolean) node.getValueAt(IMPORT_OVERWRITE_COLUMN);
                    overwrite = overwrite != null && overwrite;

                    if (node instanceof ImportLibraryTreeTableNode) {
                        ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node;

                        if (libraryNode.getConflicts().isConflictByName()) {
                            errorsPanel.setVisible(true);
                            StringBuilder text = new StringBuilder();

                            if (libraryNode.getConflicts().getMatchingLibrary() != null
                                    && StringUtils.equalsIgnoreCase(
                                            libraryNode.getConflicts().getMatchingLibrary().getName(), name)
                                    && !overwrite) {
                                text.append(
                                        "The selected library already exists. Edit its name, or select overwrite.");
                            } else {
                                text.append(
                                        "Another library (with a different ID) is already using the name \"");
                                text.append(name);
                                text.append("\". Please enter a new name.");
                            }

                            errorsTextArea.setText(text.toString());
                        }
                    } else if (node instanceof ImportCodeTemplateTreeTableNode) {
                        ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node;

                        if (codeTemplateNode.getConflicts().isConflictByName()) {
                            errorsPanel.setVisible(true);
                            StringBuilder text = new StringBuilder();

                            if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null
                                    && StringUtils.equalsIgnoreCase(
                                            codeTemplateNode.getConflicts().getMatchingCodeTemplate().getName(),
                                            name)
                                    && !overwrite) {
                                if (unassignedCodeTemplates) {
                                    text.append(
                                            "The selected code template already exists. Edit its name, select overwrite, or switch the library.");
                                } else {
                                    text.append(
                                            "The selected code template already exists. Edit its name, or select overwrite.");
                                }
                            } else {
                                text.append(
                                        "Another code template (with a different ID) is already using the name \"");
                                text.append(name);
                                text.append("\". Please enter a new name");
                                if (unassignedCodeTemplates) {
                                    text.append(", or switch the library");
                                }
                                text.append('.');
                            }

                            errorsTextArea.setText(text.toString());
                        } else if (codeTemplateNode.getConflicts().isUnassignedConflict()) {
                            errorsPanel.setVisible(true);

                            if (unassignedCodeTemplates) {
                                errorsTextArea.setText(
                                        "Please select a parent library in order to import the selected code template.");
                            } else {
                                ImportTreeTableNode tableLibraryNode = (ImportTreeTableNode) codeTemplateNode
                                        .getParent();

                                StringBuilder text = new StringBuilder("The parent library \"");
                                text.append((String) tableLibraryNode.getValueAt(IMPORT_NAME_COLUMN));
                                text.append(
                                        "\" does not currently exist, so it must be imported in order to import the selected code template.");

                                errorsTextArea.setText(text.toString());
                            }
                        }

                        if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) {
                            warningsPanel.setVisible(true);
                            if (codeTemplateNode.getConflicts().getMatchingLibrary() != null) {
                                warningsTextArea
                                        .setText("The selected code template already exists in library \""
                                                + codeTemplateNode.getConflicts().getMatchingLibrary().getName()
                                                + "\".");
                            } else {
                                warningsTextArea.setText("The selected code template already exists.");
                            }
                        }
                    }
                }
            }
        } else {
            boolean errors = false;
            boolean warnings = false;

            for (int row = 0; row < importTreeTable.getRowCount(); row++) {
                TreePath path = importTreeTable.getPathForRow(row);

                if (path != null) {
                    ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent();

                    if ((boolean) node.getValueAt(IMPORT_SELECTED_COLUMN)) {
                        if (node instanceof ImportLibraryTreeTableNode) {
                            LibraryConflicts conflicts = ((ImportLibraryTreeTableNode) node).getConflicts();
                            if (conflicts.isConflictByName()) {
                                errors = true;
                                break;
                            }
                        } else if (node instanceof ImportCodeTemplateTreeTableNode) {
                            CodeTemplateConflicts conflicts = ((ImportCodeTemplateTreeTableNode) node)
                                    .getConflicts();
                            if (conflicts.isConflictByName() || conflicts.isUnassignedConflict()) {
                                errors = true;
                                break;
                            }

                            if (conflicts.getMatchingCodeTemplate() != null) {
                                warnings = true;
                            }
                        }
                    }
                }
            }

            if (errors) {
                errorsPanel.setVisible(true);
                if (unassignedCodeTemplates) {
                    errorsTextArea.setText(
                            "One or more libraries / code templates have name conflicts. Edit their names, select overwrite, or switch the library.");
                } else {
                    errorsTextArea.setText(
                            "One or more libraries / code templates have name conflicts. Edit their names, or select overwrite.");
                }
            } else if (warnings) {
                warningsPanel.setVisible(true);
                warningsTextArea.setText("One or more libraries / code templates have warnings.");
            }
        }
    }
}

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

private void showPopup(MouseEvent e) {
    final TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
    addGroupPopupAction.setEnabled(true);
    addSubgroupPopupAction.setEnabled(path != null);
    editGroupPopupAction.setEnabled(path != null);
    removeGroupAndSubgroupsPopupAction.setEnabled(path != null);
    removeGroupKeepSubgroupsPopupAction.setEnabled(path != null);
    moveSubmenu.setEnabled(path != null);
    expandSubtreePopupAction.setEnabled(path != null);
    collapseSubtreePopupAction.setEnabled(path != null);
    removeSubgroupsPopupAction.setEnabled(path != null);
    sortSubmenu.setEnabled(path != null);
    addToGroup.setEnabled(false);/*from   w  w w  . jav a2 s.  c o  m*/
    moveToGroup.setEnabled(false);
    removeFromGroup.setEnabled(false);
    if (path != null) { // some path dependent enabling/disabling
        GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent();
        editGroupPopupAction.setNode(node);
        addSubgroupPopupAction.setNode(node);
        removeGroupAndSubgroupsPopupAction.setNode(node);
        removeSubgroupsPopupAction.setNode(node);
        removeGroupKeepSubgroupsPopupAction.setNode(node);
        expandSubtreePopupAction.setNode(node);
        collapseSubtreePopupAction.setNode(node);
        sortDirectSubgroupsPopupAction.setNode(node);
        sortAllSubgroupsPopupAction.setNode(node);
        groupsTree.setHighlightBorderCell(node);
        if (node.canBeEdited()) {
            editGroupPopupAction.setEnabled(false);
            addGroupPopupAction.setEnabled(false);
            removeGroupAndSubgroupsPopupAction.setEnabled(false);
            removeGroupKeepSubgroupsPopupAction.setEnabled(false);
        } else {
            editGroupPopupAction.setEnabled(true);
            addGroupPopupAction.setEnabled(true);
            addGroupPopupAction.setNode(node);
            removeGroupAndSubgroupsPopupAction.setEnabled(true);
            removeGroupKeepSubgroupsPopupAction.setEnabled(true);
        }
        expandSubtreePopupAction
                .setEnabled(groupsTree.isCollapsed(path) || groupsTree.hasCollapsedDescendant(path));
        collapseSubtreePopupAction
                .setEnabled(groupsTree.isExpanded(path) || groupsTree.hasExpandedDescendant(path));
        sortSubmenu.setEnabled(!node.isLeaf());
        removeSubgroupsPopupAction.setEnabled(!node.isLeaf());
        moveNodeUpPopupAction.setEnabled(node.canMoveUp());
        moveNodeDownPopupAction.setEnabled(node.canMoveDown());
        moveNodeLeftPopupAction.setEnabled(node.canMoveLeft());
        moveNodeRightPopupAction.setEnabled(node.canMoveRight());
        moveSubmenu.setEnabled(moveNodeUpPopupAction.isEnabled() || moveNodeDownPopupAction.isEnabled()
                || moveNodeLeftPopupAction.isEnabled() || moveNodeRightPopupAction.isEnabled());
        moveNodeUpPopupAction.setNode(node);
        moveNodeDownPopupAction.setNode(node);
        moveNodeLeftPopupAction.setNode(node);
        moveNodeRightPopupAction.setNode(node);
        // add/remove entries to/from group
        List<BibEntry> selection = frame.getCurrentBasePanel().getSelectedEntries();
        if (!selection.isEmpty()) {
            if (node.canAddEntries(selection)) {
                addToGroup.setNode(node);
                addToGroup.setBasePanel(panel);
                addToGroup.setEnabled(true);
                moveToGroup.setNode(node);
                moveToGroup.setBasePanel(panel);
                moveToGroup.setEnabled(true);
            }
            if (node.canRemoveEntries(selection)) {
                removeFromGroup.setNode(node);
                removeFromGroup.setBasePanel(panel);
                removeFromGroup.setEnabled(true);
            }
        }
    } else {
        editGroupPopupAction.setNode(null);
        addGroupPopupAction.setNode(null);
        addSubgroupPopupAction.setNode(null);
        removeGroupAndSubgroupsPopupAction.setNode(null);
        removeSubgroupsPopupAction.setNode(null);
        removeGroupKeepSubgroupsPopupAction.setNode(null);
        moveNodeUpPopupAction.setNode(null);
        moveNodeDownPopupAction.setNode(null);
        moveNodeLeftPopupAction.setNode(null);
        moveNodeRightPopupAction.setNode(null);
        expandSubtreePopupAction.setNode(null);
        collapseSubtreePopupAction.setNode(null);
        sortDirectSubgroupsPopupAction.setNode(null);
        sortAllSubgroupsPopupAction.setNode(null);
    }
    groupsContextMenu.show(groupsTree, e.getPoint().x, e.getPoint().y);
}

From source file:dataviewer.DataViewer.java

/**
 * Creates new form DataViewer/*from w  w w  .  j  a va  2s.  c  o m*/
 */
public DataViewer() {
    try {
        for (Enum ee : THREAD.values()) {
            t[ee.ordinal()] = new Thread();
        }
        initComponents();
        DropTarget dropTarget = new DropTarget(tr_files, new DropTargetListenerImpl());
        TreeSelectionListener treeSelectionListener = new TreeSelectionListener() {

            @Override
            public void valueChanged(TreeSelectionEvent e) {
                javax.swing.JTree tree = (javax.swing.JTree) e.getSource();
                TreePath path = tree.getSelectionPath();
                Object[] pnode = (Object[]) path.getPath();
                String name = pnode[pnode.length - 1].toString();
                String ex = getExtension(name);
                if (ex.equals(".txt") || ex.equals(".dat") || ex.equals(".csv") || ex.equals(".tsv")) {
                    selected_file = name;
                } else {
                    selected_file = "";
                }
            }
        };
        tr_files.addTreeSelectionListener(treeSelectionListener);

        tr_files.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent evt) {
                if (evt.getClickCount() >= 2) {
                    if (!"".equals(selected_file)) {
                        //count_data();
                        read_data();
                    } else {
                        TreePath path = tr_files.getSelectionPath();
                        if (path.getLastPathComponent().toString().equals(cur_path)) {
                            cur_path = (new File(cur_path)).getParent();
                        } else {
                            cur_path = cur_path + File.separator + path.getLastPathComponent().toString();
                        }
                        fill_tree();
                    }
                }
            }
        });

        tr_files.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
                    cur_path = (new File(cur_path)).getParent();
                    fill_tree();
                } else if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
                    if (!"".equals(selected_file)) {
                        //count_data();
                        read_data();
                    } else {
                        TreePath path = tr_files.getSelectionPath();
                        if (path.getLastPathComponent().toString().equals(cur_path)) {
                            cur_path = (new File(cur_path)).getParent();
                        } else {
                            cur_path = cur_path + File.separator + path.getLastPathComponent().toString();
                        }
                        fill_tree();
                    }
                } else if (evt.getKeyCode() == KeyEvent.VK_DELETE) {

                    if (!"".equals(selected_file)) {
                        String name = cur_path + File.separator + selected_file;
                        if ((new File(name)).isFile()) {
                            int dialogResult = JOptionPane.showConfirmDialog(null,
                                    "Selected file [" + selected_file
                                            + "] will be removed and not recoverable.",
                                    "Are you sure?", JOptionPane.YES_NO_OPTION);
                            if (dialogResult == JOptionPane.YES_OPTION) {
                                (new File(name)).delete();
                                fill_tree();
                            }
                        }

                    } else {
                        JOptionPane.showMessageDialog(null,
                                "For safety concern, removing folder is not supported.", "Information",
                                JOptionPane.ERROR_MESSAGE);
                    }
                }
            }
        });

        tr_files.setCellRenderer(new MyTreeCellRenderer());
        p_count.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);

        //tp_menu.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ctrl1, "tab_read");
        //tp_menu.getActionMap().put("tab_read", (Action) new ActionListenerImpl());
        //tp_menu.setMnemonicAt(0, KeyEvent.VK_1);
        //tp_menu.setMnemonicAt(1, KeyEvent.VK_2);
        /*InputMap inputMap = tp_menu.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
         ActionMap actionMap = tp_menu.getActionMap();
                
         KeyStroke ctrl1 = KeyStroke.getKeyStroke("ctrl 1");
         inputMap.put(ctrl1, "tab_read");
         actionMap.put("tab_read", new AbstractAction() {
                
         @Override
         public void actionPerformed(ActionEvent arg0) {
         tp_menu.setSelectedIndex(0);
         }
         });
                
         KeyStroke ctrl2 = KeyStroke.getKeyStroke("ctrl 2");
         inputMap.put(ctrl2, "tab_analyze");
         actionMap.put("tab_analyze", new AbstractAction() {
                
         @Override
         public void actionPerformed(ActionEvent arg0) {
         tp_menu.setSelectedIndex(1);
         }
         });*/
        config();
    } catch (Exception e) {
        txt_count.setText(e.getMessage());
    }
}

From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateImportDialog.java

private void initComponents() {
    setBackground(UIConstants.BACKGROUND_COLOR);
    getContentPane().setBackground(getBackground());

    topPanel = new JPanel();
    topPanel.setBackground(getBackground());

    linkPanel = new JPanel();
    linkPanel.setBackground(topPanel.getBackground());

    linkLeftPanel = new JPanel();
    linkLeftPanel.setBackground(linkPanel.getBackground());

    linkLeftSelectAllLabel = new JLabel("<html><u>All</u></html>");
    linkLeftSelectAllLabel.setForeground(Color.BLUE);
    linkLeftSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    linkLeftSelectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            for (int row = 0; row < importTreeTable.getRowCount(); row++) {
                importTreeTable.getModel().setValueAt(true, row, IMPORT_SELECTED_COLUMN);
            }//from www . j ava2s . c o  m
        }
    });

    linkLeftDeselectAllLabel = new JLabel("<html><u>None</u></html>");
    linkLeftDeselectAllLabel.setForeground(Color.BLUE);
    linkLeftDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    linkLeftDeselectAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            for (int row = 0; row < importTreeTable.getRowCount(); row++) {
                importTreeTable.getModel().setValueAt(false, row, IMPORT_SELECTED_COLUMN);
            }
        }
    });

    linkRightPanel = new JPanel();
    linkRightPanel.setBackground(linkPanel.getBackground());

    linkRightOverwriteAllLabel = new JLabel("<html><u>All</u></html>");
    linkRightOverwriteAllLabel.setForeground(Color.BLUE);
    linkRightOverwriteAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    linkRightOverwriteAllLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            for (int row = 0; row < importTreeTable.getRowCount(); row++) {
                TreePath path = importTreeTable.getPathForRow(row);
                if (path != null) {
                    ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent();
                    if (node instanceof ImportLibraryTreeTableNode) {
                        ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node;
                        if (libraryNode.getConflicts().getMatchingLibrary() != null) {
                            importTreeTable.getModel().setValueAt(true, row, IMPORT_OVERWRITE_COLUMN);
                        }
                    } else if (node instanceof ImportCodeTemplateTreeTableNode) {
                        ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node;
                        if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) {
                            importTreeTable.getModel().setValueAt(true, row, IMPORT_OVERWRITE_COLUMN);
                        }
                    }
                }
            }
        }
    });

    linkRightOverwriteNoneLabel = new JLabel("<html><u>None</u></html>");
    linkRightOverwriteNoneLabel.setForeground(Color.BLUE);
    linkRightOverwriteNoneLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
    linkRightOverwriteNoneLabel.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent evt) {
            for (int row = 0; row < importTreeTable.getRowCount(); row++) {
                TreePath path = importTreeTable.getPathForRow(row);
                if (path != null) {
                    ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent();
                    if (node instanceof ImportLibraryTreeTableNode) {
                        ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node;
                        if (libraryNode.getConflicts().getMatchingLibrary() != null) {
                            importTreeTable.getModel().setValueAt(false, row, IMPORT_OVERWRITE_COLUMN);
                        }
                    } else if (node instanceof ImportCodeTemplateTreeTableNode) {
                        ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node;
                        if (codeTemplateNode.getConflicts().getMatchingCodeTemplate() != null) {
                            importTreeTable.getModel().setValueAt(false, row, IMPORT_OVERWRITE_COLUMN);
                        }
                    }
                }
            }
        }
    });

    final TableCellEditor templateCellEditor = new NameCellEditor();

    importTreeTable = new JXTreeTable() {
        @Override
        public boolean isCellEditable(int row, int column) {
            return (column == IMPORT_OVERWRITE_COLUMN || column == IMPORT_SELECTED_COLUMN
                    || column == IMPORT_NAME_COLUMN);
        }

        @Override
        public TableCellEditor getCellEditor(int row, int column) {
            if (isHierarchical(column)) {
                return templateCellEditor;
            } else {
                return super.getCellEditor(row, column);
            }
        }
    };

    importTreeTable.setLargeModel(true);
    DefaultTreeTableModel model = new ImportTreeTableModel();
    model.setColumnIdentifiers(Arrays.asList(new String[] { "", "Name", "Overwrite", "Conflicts", "Id" }));

    DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode();
    model.setRoot(rootNode);
    importTreeTable.setTreeTableModel(model);

    Set<String> addedCodeTemplateIds = new HashSet<String>();

    if (unassignedCodeTemplates) {
        ImportTreeTableNode libraryNode = new ImportUnassignedLibraryTreeTableNode("Select a library", "");
        CodeTemplateLibrary library = importLibraries.get(0);

        for (CodeTemplate codeTemplate : library.getCodeTemplates()) {
            if (!addedCodeTemplateIds.contains(codeTemplate.getId())) {
                libraryNode
                        .add(new ImportCodeTemplateTreeTableNode(codeTemplate.getName(), codeTemplate.getId()));
                addedCodeTemplateIds.add(codeTemplate.getId());
                importCodeTemplateMap.put(codeTemplate.getId(), codeTemplate);
            }
        }

        rootNode.add(libraryNode);
    } else {
        Set<String> addedLibraryIds = new HashSet<String>();

        for (CodeTemplateLibrary library : importLibraries) {
            if (!addedLibraryIds.contains(library.getId())) {
                ImportTreeTableNode libraryNode = new ImportLibraryTreeTableNode(library.getName(),
                        library.getId());
                importLibraryMap.put(library.getId(), library);

                for (CodeTemplate codeTemplate : library.getCodeTemplates()) {
                    if (!addedCodeTemplateIds.contains(codeTemplate.getId())) {
                        libraryNode.add(new ImportCodeTemplateTreeTableNode(codeTemplate.getName(),
                                codeTemplate.getId()));
                        addedCodeTemplateIds.add(codeTemplate.getId());
                        importCodeTemplateMap.put(codeTemplate.getId(), codeTemplate);
                    }
                }

                rootNode.add(libraryNode);
                addedLibraryIds.add(library.getId());
            }
        }
    }

    importTreeTable.setOpenIcon(null);
    importTreeTable.setClosedIcon(null);
    importTreeTable.setLeafIcon(null);
    importTreeTable.setRootVisible(false);
    importTreeTable.setDoubleBuffered(true);
    importTreeTable.setDragEnabled(false);
    importTreeTable.setRowSelectionAllowed(true);
    importTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    importTreeTable.setRowHeight(UIConstants.ROW_HEIGHT);
    importTreeTable.setFocusable(true);
    importTreeTable.setOpaque(true);
    importTreeTable.getTableHeader().setReorderingAllowed(false);
    importTreeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    importTreeTable.setEditable(true);
    importTreeTable.setSortable(false);
    importTreeTable.setAutoCreateColumnsFromModel(false);
    importTreeTable.setShowGrid(true, true);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        importTreeTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    importTreeTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent evt) {
            checkSelection(evt);
        }

        @Override
        public void mouseReleased(MouseEvent evt) {
            checkSelection(evt);
        }

        private void checkSelection(MouseEvent evt) {
            int row = importTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY()));

            if (row < 0) {
                importTreeTable.clearSelection();
            }
        }
    });

    importTreeTable.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override
        public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
        }

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

    importTreeTable.setTreeCellRenderer(new NameCellRenderer());

    importTreeTable.getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent evt) {
            if (evt.getColumn() != IMPORT_CONFLICTS_COLUMN) {
                for (int row = evt.getFirstRow(); row <= evt.getLastRow()
                        && row < importTreeTable.getRowCount(); row++) {
                    TreePath path = importTreeTable.getPathForRow(row);
                    if (path != null) {
                        ImportTreeTableNode node = (ImportTreeTableNode) path.getLastPathComponent();

                        if (path.getPathCount() == 2) {
                            if (node instanceof ImportUnassignedLibraryTreeTableNode) {
                                String libraryName = (String) node.getValueAt(IMPORT_NAME_COLUMN);
                                String libraryId = null;
                                for (CodeTemplateLibrary library : PlatformUI.MIRTH_FRAME.codeTemplatePanel
                                        .getCachedCodeTemplateLibraries().values()) {
                                    if (library.getName().equals(libraryName)) {
                                        libraryId = library.getId();
                                        break;
                                    }
                                }
                                node.setValueAt(libraryId, IMPORT_ID_COLUMN);
                            } else if (node instanceof ImportLibraryTreeTableNode) {
                                ImportLibraryTreeTableNode libraryNode = (ImportLibraryTreeTableNode) node;
                                libraryNode.setConflicts(getLibraryConflicts(node));
                            }

                            for (Enumeration<? extends TreeTableNode> codeTemplateNodes = node
                                    .children(); codeTemplateNodes.hasMoreElements();) {
                                ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) codeTemplateNodes
                                        .nextElement();
                                codeTemplateNode.setConflicts(getCodeTemplateConflicts(codeTemplateNode));
                            }

                            importTreeTable.updateUI();
                        } else if (path.getPathCount() == 3) {
                            ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) node;
                            codeTemplateNode.setConflicts(getCodeTemplateConflicts(node));
                        }
                    }
                }
            }

            updateImportButton();
            updateErrorsAndWarnings();
        }
    });

    importTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                updateImportButton();
                updateErrorsAndWarnings();
            }
        }
    });

    importTreeTable.expandAll();

    importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN).setMinWidth(20);
    importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN).setMaxWidth(20);
    importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN)
            .setCellRenderer(new ImportSelectedCellRenderer());
    importTreeTable.getColumnModel().getColumn(IMPORT_SELECTED_COLUMN)
            .setCellEditor(new ImportSelectedCellEditor());

    importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN).setMinWidth(60);
    importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN).setMaxWidth(60);
    importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN)
            .setCellRenderer(new OverwriteCellRenderer());
    importTreeTable.getColumnModel().getColumn(IMPORT_OVERWRITE_COLUMN)
            .setCellEditor(new OverwriteCellEditor());

    importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setMinWidth(60);
    importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setMaxWidth(60);
    importTreeTable.getColumnModel().getColumn(IMPORT_CONFLICTS_COLUMN).setCellRenderer(new IconCellRenderer());

    importTreeTable.getColumnModel().removeColumn(importTreeTable.getColumnModel().getColumn(IMPORT_ID_COLUMN));

    importTreeTableScrollPane = new JScrollPane(importTreeTable);
    importTreeTableScrollPane.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new Color(0x6E6E6E)));

    warningsPanel = new JPanel();
    warningsPanel.setBackground(getBackground());
    warningsPanel.setVisible(false);

    warningsLabel = new JLabel(UIConstants.ICON_WARNING);

    warningsTextArea = new JTextArea();
    warningsTextArea.setLineWrap(true);
    warningsTextArea.setWrapStyleWord(true);

    errorsPanel = new JPanel();
    errorsPanel.setBackground(getBackground());
    errorsPanel.setVisible(false);

    errorsLabel = new JLabel(UIConstants.ICON_ERROR);

    errorsTextArea = new JTextArea();
    errorsTextArea.setLineWrap(true);
    errorsTextArea.setWrapStyleWord(true);

    separator = new JSeparator();

    buttonPanel = new JPanel();
    buttonPanel.setBackground(getBackground());

    importButton = new JButton("Import");
    importButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                boolean warnings = false;
                for (Enumeration<? extends TreeTableNode> libraryNodes = ((TreeTableNode) importTreeTable
                        .getTreeTableModel().getRoot()).children(); libraryNodes.hasMoreElements();) {
                    for (Enumeration<? extends TreeTableNode> codeTemplateNodes = libraryNodes.nextElement()
                            .children(); codeTemplateNodes.hasMoreElements();) {
                        ImportCodeTemplateTreeTableNode codeTemplateNode = (ImportCodeTemplateTreeTableNode) codeTemplateNodes
                                .nextElement();

                        if ((boolean) codeTemplateNode.getValueAt(IMPORT_SELECTED_COLUMN)) {
                            CodeTemplateConflicts conflicts = codeTemplateNode.getConflicts();
                            if (conflicts.getMatchingCodeTemplate() != null) {
                                warnings = true;
                                break;
                            }
                        }
                    }

                    if (warnings) {
                        break;
                    }
                }

                if (!warnings || PlatformUI.MIRTH_FRAME.alertOption(CodeTemplateImportDialog.this,
                        "Some selected rows have warnings. Are you sure you wish to continue?")) {
                    save();
                    dispose();
                }
            } catch (Exception e) {
                PlatformUI.MIRTH_FRAME.alertThrowable(CodeTemplateImportDialog.this, e,
                        "Unable to import: " + e.getMessage());
            }
        }
    });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (confirmClose()) {
                dispose();
            }
        }
    });

    updateImportButton();
}

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

private void showPopup(MouseEvent e) {
    final TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y);
    addGroupPopupAction.setEnabled(true);
    addSubgroupPopupAction.setEnabled(path != null);
    editGroupPopupAction.setEnabled(path != null);
    removeGroupAndSubgroupsPopupAction.setEnabled(path != null);
    removeGroupKeepSubgroupsPopupAction.setEnabled(path != null);
    moveSubmenu.setEnabled(path != null);
    expandSubtreePopupAction.setEnabled(path != null);
    collapseSubtreePopupAction.setEnabled(path != null);
    removeSubgroupsPopupAction.setEnabled(path != null);
    sortSubmenu.setEnabled(path != null);
    addToGroup.setEnabled(false);/*from   w  w  w .j  a  va 2s . com*/
    moveToGroup.setEnabled(false);
    removeFromGroup.setEnabled(false);
    if (path != null) { // some path dependent enabling/disabling
        GroupTreeNode node = (GroupTreeNode) path.getLastPathComponent();
        editGroupPopupAction.setNode(node);
        addSubgroupPopupAction.setNode(node);
        removeGroupAndSubgroupsPopupAction.setNode(node);
        removeSubgroupsPopupAction.setNode(node);
        removeGroupKeepSubgroupsPopupAction.setNode(node);
        expandSubtreePopupAction.setNode(node);
        collapseSubtreePopupAction.setNode(node);
        sortDirectSubgroupsPopupAction.setNode(node);
        sortAllSubgroupsPopupAction.setNode(node);
        groupsTree.setHighlightBorderCell(node);
        AbstractGroup group = node.getGroup();
        if (group instanceof AllEntriesGroup) {
            editGroupPopupAction.setEnabled(false);
            addGroupPopupAction.setEnabled(false);
            removeGroupAndSubgroupsPopupAction.setEnabled(false);
            removeGroupKeepSubgroupsPopupAction.setEnabled(false);
        } else {
            editGroupPopupAction.setEnabled(true);
            addGroupPopupAction.setEnabled(true);
            addGroupPopupAction.setNode(node);
            removeGroupAndSubgroupsPopupAction.setEnabled(true);
            removeGroupKeepSubgroupsPopupAction.setEnabled(true);
        }
        expandSubtreePopupAction
                .setEnabled(groupsTree.isCollapsed(path) || groupsTree.hasCollapsedDescendant(path));
        collapseSubtreePopupAction
                .setEnabled(groupsTree.isExpanded(path) || groupsTree.hasExpandedDescendant(path));
        sortSubmenu.setEnabled(!node.isLeaf());
        removeSubgroupsPopupAction.setEnabled(!node.isLeaf());
        moveNodeUpPopupAction.setEnabled(node.canMoveUp());
        moveNodeDownPopupAction.setEnabled(node.canMoveDown());
        moveNodeLeftPopupAction.setEnabled(node.canMoveLeft());
        moveNodeRightPopupAction.setEnabled(node.canMoveRight());
        moveSubmenu.setEnabled(moveNodeUpPopupAction.isEnabled() || moveNodeDownPopupAction.isEnabled()
                || moveNodeLeftPopupAction.isEnabled() || moveNodeRightPopupAction.isEnabled());
        moveNodeUpPopupAction.setNode(node);
        moveNodeDownPopupAction.setNode(node);
        moveNodeLeftPopupAction.setNode(node);
        moveNodeRightPopupAction.setNode(node);
        // add/remove entries to/from group
        List<BibEntry> selection = frame.getCurrentBasePanel().getSelectedEntries();
        if (selection.size() > 0) {
            if (node.getGroup().supportsAdd() && !node.getGroup().containsAll(selection)) {
                addToGroup.setNode(node);
                addToGroup.setBasePanel(panel);
                addToGroup.setEnabled(true);
                moveToGroup.setNode(node);
                moveToGroup.setBasePanel(panel);
                moveToGroup.setEnabled(true);
            }
            if (node.getGroup().supportsRemove() && node.getGroup().containsAny(selection)) {
                removeFromGroup.setNode(node);
                removeFromGroup.setBasePanel(panel);
                removeFromGroup.setEnabled(true);
            }
        }
    } else {
        editGroupPopupAction.setNode(null);
        addGroupPopupAction.setNode(null);
        addSubgroupPopupAction.setNode(null);
        removeGroupAndSubgroupsPopupAction.setNode(null);
        removeSubgroupsPopupAction.setNode(null);
        removeGroupKeepSubgroupsPopupAction.setNode(null);
        moveNodeUpPopupAction.setNode(null);
        moveNodeDownPopupAction.setNode(null);
        moveNodeLeftPopupAction.setNode(null);
        moveNodeRightPopupAction.setNode(null);
        expandSubtreePopupAction.setNode(null);
        collapseSubtreePopupAction.setNode(null);
        sortDirectSubgroupsPopupAction.setNode(null);
        sortAllSubgroupsPopupAction.setNode(null);
    }
    groupsContextMenu.show(groupsTree, e.getPoint().x, e.getPoint().y);
}

From source file:com.pironet.tda.TDA.java

/**
 * expand or collapse all nodes of the specified tree
 *
 * @param catTree the tree to expand all/collapse all
 * @param parent  the parent to start with
 * @param expand  expand=true, collapse=false
 *///from  ww w.ja va 2s  .  c o  m
private void expandAll(JTree catTree, TreePath parent, boolean expand) {
    // Traverse children
    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(catTree, path, expand);
        }
    }

    if (parent.getPathCount() > 1) {
        // Expansion or collapse must be done bottom-up
        if (expand) {
            catTree.expandPath(parent);
        } else {
            catTree.collapsePath(parent);
        }
    }
}

From source file:com.pironet.tda.TDA.java

/**
 * navigate to child of currently selected node with the given prefix in name
 *
 * @param startsWith node name prefix (e.g. "Threads waiting")
 *///from   ww w .  j a v  a2  s .c  om
private void navigateToChild(String startsWith) {
    TreePath currentPath = tree.getSelectionPath();
    DefaultMutableTreeNode dumpNode = (DefaultMutableTreeNode) currentPath.getLastPathComponent();
    Enumeration childs = dumpNode.children();

    TreePath searchPath = null;
    while ((searchPath == null) && childs.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) childs.nextElement();
        String name = child.toString();
        if (name != null && name.startsWith(startsWith)) {
            searchPath = new TreePath(child.getPath());
        }
    }

    if (searchPath != null) {
        tree.makeVisible(searchPath);
        tree.setSelectionPath(searchPath);
        tree.scrollPathToVisible(searchPath);
    }
}