Example usage for javax.swing.event TreeSelectionEvent getNewLeadSelectionPath

List of usage examples for javax.swing.event TreeSelectionEvent getNewLeadSelectionPath

Introduction

In this page you can find the example usage for javax.swing.event TreeSelectionEvent getNewLeadSelectionPath.

Prototype

public TreePath getNewLeadSelectionPath() 

Source Link

Document

Returns the current lead path.

Usage

From source file:SimpleClient.java

public void valueChanged(TreeSelectionEvent e) {
    TreePath path = e.getNewLeadSelectionPath();
    if (path != null) {
        Object o = path.getLastPathComponent();
        if (o instanceof FolderTreeNode) {
            FolderTreeNode node = (FolderTreeNode) o;
            Folder folder = node.getFolder();

            try {
                if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) {
                    SimpleClient.fv.setFolder(folder);
                }/*from   w w w  . j a  v a2 s.  c o m*/
            } catch (MessagingException me) {
            }
        }
    }
}

From source file:cz.lidinsky.editor.TableCellEditor.java

public void valueChanged(TreeSelectionEvent e) {
    TreePath selectedPath = e.getNewLeadSelectionPath();
    if (selectedPath != null)
        selected = selectedPath.getLastPathComponent();
    else/*w  w w.j a v a  2s  .  c o  m*/
        selected = null;
}

From source file:pl.piotrsukiennik.jbrain.gui.JBrainMainFrame.java

private void leftColumnMenuValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_leftColumnMenuValueChanged
    TreePath newPath = evt.getNewLeadSelectionPath();
    String lastComponent = (String) ((DefaultMutableTreeNode) newPath.getLastPathComponent()).getUserObject();
    switch (lastComponent) {
    case "model":
        appController.displayModelManagement();
        break;//w w w  .  j  a  v  a  2  s  .c om
    case "new simulation":
        appController.displayNewSimulation();
        break;
    case "history":
        appController.displaySimulationHistory();
        break;
    }

}

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  ww w .  jav a  2s  .  c  o m*/
}

From source file:com.orthancserver.SelectImageDialog.java

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

    tree_.addTreeWillExpandListener(new TreeWillExpandListener() {
        @Override//from   w  w w  . ja v  a  2 s.  com
        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:org.optaplanner.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.java

private CheckBoxTree createCheckBoxTree() {
    final CheckBoxTree resultCheckBoxTree = new CheckBoxTree(initBenchmarkHierarchy(true));
    resultCheckBoxTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override//from  www . j a v  a 2s.c om
        public void valueChanged(TreeSelectionEvent e) {
            TreePath treeSelectionPath = e.getNewLeadSelectionPath();
            if (treeSelectionPath != null) {
                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treeSelectionPath
                        .getLastPathComponent();
                MixedCheckBox checkBox = (MixedCheckBox) treeNode.getUserObject();
                detailTextArea.setText(checkBox.getDetail());
                detailTextArea.setCaretPosition(0);
                renameNodeButton.setEnabled(checkBox.getBenchmarkResult() instanceof PlannerBenchmarkResult
                        || checkBox.getBenchmarkResult() instanceof SolverBenchmarkResult);
            }
        }
    });
    resultCheckBoxTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            // Enable button if checked singleBenchmarkResults exist
            generateReportButton.setEnabled(!resultCheckBoxTree.getSelectedSingleBenchmarkNodes().isEmpty());
        }
    });
    checkBoxTree = resultCheckBoxTree;
    return resultCheckBoxTree;
}

From source file:se.nawroth.asciidoc.browser.AsciidocBrowserApplication.java

public AsciidocBrowserApplication(final String[] args) {
    super("Asciidoc Browser");
    setIconImage(Icons.APPLICATION.image());

    setSize(1200, 1024);//from   w  w w.j  a v a  2s .c o m

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(final WindowEvent e) {
            actionExit();
        }
    });

    JPanel buttonPanel = new JPanel();
    backButton = new JButton("");
    backButton.setIcon(Icons.BACK.icon());
    backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionBack();
        }
    });
    buttonPanel.setLayout(new MigLayout("", "[1px][][][][]", "[1px]"));

    JButton btnOptionsbutton = new JButton("");
    btnOptionsbutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            settingsDialog.setVisible(true);
        }
    });
    btnOptionsbutton.setIcon(Icons.OPTIONS.icon());
    buttonPanel.add(btnOptionsbutton, "flowx,cell 0 0");
    backButton.setEnabled(false);
    buttonPanel.add(backButton, "cell 0 0,grow");
    forwardButton = new JButton("");
    forwardButton.setIcon(Icons.FORWARD.icon());
    forwardButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionForward();
        }
    });
    forwardButton.setEnabled(false);
    buttonPanel.add(forwardButton, "cell 0 0,grow");
    getContentPane().setLayout(new MigLayout("", "[793.00px,grow]", "[44px][930px]"));
    getContentPane().add(buttonPanel, "cell 0 0,growx,aligny top");
    locationTextField = new JTextField(65);
    locationTextField.setText("");
    locationTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(final KeyEvent e) {
            int keyCode = e.getKeyCode();
            if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) {
                actionGo();
                refreshDocumentTree();
            }
        }
    });
    locationTextField.setTransferHandler(
            new TextFieldTransferHandler(locationTextField.getTransferHandler(), new Runnable() {
                @Override
                public void run() {
                    locationTextField.setText("");
                }
            }, new Runnable() {

                @Override
                public void run() {
                    actionGo();
                    refreshDocumentTree();
                }
            }));

    homebutton = new JButton("");
    homebutton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            locationTextField.setText(Settings.getHome());
            actionGo();
            refreshDocumentTree();
        }
    });

    refreshButton = new JButton("");
    refreshButton.setToolTipText("Refresh");
    refreshButton.setEnabled(false);
    refreshButton.setIcon(Icons.REFRESH.icon());
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            actionGo();
            refreshPreview();
        }
    });
    buttonPanel.add(refreshButton, "cell 1 0");

    homebutton.setIcon(Icons.HOME.icon());
    buttonPanel.add(homebutton, "cell 2 0");
    buttonPanel.add(locationTextField, "cell 3 0,grow");

    treeSourceSplitPane = new JSplitPane();
    treeSourceSplitPane.setResizeWeight(0.3);
    getContentPane().add(treeSourceSplitPane, "cell 0 1,grow");

    treeScrollPane = new JScrollPane();
    treeScrollPane.setMinimumSize(new Dimension(200, 200));
    treeSourceSplitPane.setLeftComponent(treeScrollPane);

    documentTree = new DocumentTree(documentModel);
    documentTree.setCellRenderer(new TooltipsTreeCellRenderer());
    ToolTipManager.sharedInstance().registerComponent(documentTree);
    ToolTipManager.sharedInstance().setInitialDelay(INITIAL_TOOLTIP_DELAY);
    ToolTipManager.sharedInstance().setReshowDelay(0);
    documentTree.addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(final TreeSelectionEvent tse) {
            TreePath newLeadSelectionPath = tse.getNewLeadSelectionPath();
            if (newLeadSelectionPath != null && !newLeadSelectionPath.equals(currentSelectionPath)) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) newLeadSelectionPath
                        .getLastPathComponent();
                FileWrapper file = (FileWrapper) node.getUserObject();
                showFile(file, true);
                refreshPreview();
            }
        }
    });
    treeScrollPane.setViewportView(documentTree);

    sourceEditorPane = new JEditorPane();
    sourceEditorPane.setContentType("text/html");
    sourceEditorPane.setEditable(false);
    sourceEditorPane.addHyperlinkListener(new HandleHyperlinkUpdate());
    JScrollPane fileScrollPane = new JScrollPane(sourceEditorPane);
    fileScrollPane.setMinimumSize(new Dimension(600, 600));

    documentTabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
    documentTabbedPane.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(final ChangeEvent ce) {
            refreshPreview();
        }
    });
    sourceLogSplitPane = new JSplitPane();
    sourceLogSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    treeSourceSplitPane.setRightComponent(sourceLogSplitPane);
    sourceLogSplitPane.setTopComponent(documentTabbedPane);
    documentTabbedPane.add(fileScrollPane);
    documentTabbedPane.setTitleAt(0, "Source");

    browserPane = new BrowserPane();

    previewScrollPane = new JScrollPane(browserPane);
    documentTabbedPane.addTab("Preview", null, previewScrollPane, null);

    console = new JConsole();
    System.setErr(console.getErr());
    System.setOut(console.getOut());
    sourceLogSplitPane.setBottomComponent(console);

    executor = new AsciidocExecutor();
}

From source file:view.MultipleValidationDialog.java

private void jtFilesValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jtFilesValueChanged
    jtValidation.setModel(null);/*from w ww  .  ja  va 2  s .  c om*/
    ArrayList<SignatureValidation> svList = null;

    if (jtFiles.getSelectionRows().length > 1) {
        jtFiles.setSelectionPath(evt.getOldLeadSelectionPath());
        return;
    }

    if (evt.getNewLeadSelectionPath() == null) {
        panelSignatureDetails.setVisible(false);
        return;
    }

    for (Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> entry : hmValidation.entrySet()) {
        int numSigs = CCInstance.getInstance().getNumberOfSignatures(entry.getKey().getFilename());
        if (String.valueOf(evt.getPath().getLastPathComponent())
                .equals("(" + numSigs + ") " + entry.getKey().getFilename())) {
            svList = entry.getValue();
            break;
        }
    }

    final DefaultMutableTreeNode top = new DefaultMutableTreeNode(null);

    if (svList == null) {
        return;
    }
    if (svList.isEmpty()) {
        panelSignatureDetails.setVisible(false);
        DefaultMutableTreeNode noSignatures = new TreeNodeWithState(Bundle.getBundle().getString("notSigned"),
                TreeNodeWithState.State.NOT_SIGNED);
        top.add(noSignatures);
        TreeModel tm = new DefaultTreeModel(top);
        jtValidation.setModel(tm);
        return;
    }

    for (SignatureValidation sv : svList) {
        DefaultMutableTreeNode sig = new DefaultMutableTreeNode(sv);

        TreeNodeWithState childChanged = null;
        if (sv.isCertification()) {
            if (sv.isValid()) {
                if (sv.isChanged() || !sv.isCoversEntireDocument()) {
                    childChanged = new TreeNodeWithState(
                            "<html>" + Bundle.getBundle().getString("tn.1") + "<br>"
                                    + Bundle.getBundle().getString("tn.2") + "</html>",
                            TreeNodeWithState.State.CERTIFIED_WARNING);
                } else {
                    childChanged = new TreeNodeWithState(Bundle.getBundle().getString("certifiedOk"),
                            TreeNodeWithState.State.CERTIFIED);
                }
            } else {
                childChanged = new TreeNodeWithState(Bundle.getBundle().getString("changedAfterCertified"),
                        TreeNodeWithState.State.INVALID);
            }
        } else if (sv.isValid()) {
            if (sv.isChanged()) {
                childChanged = new TreeNodeWithState(
                        "<html>" + Bundle.getBundle().getString("tn.3") + "<br>"
                                + Bundle.getBundle().getString("tn.4") + "</html>",
                        TreeNodeWithState.State.VALID_WARNING);
            } else {
                childChanged = new TreeNodeWithState(Bundle.getBundle().getString("signedOk"),
                        TreeNodeWithState.State.VALID);
            }
        } else {
            childChanged = new TreeNodeWithState(Bundle.getBundle().getString("signedChangedOrCorrupted"),
                    TreeNodeWithState.State.INVALID);
        }

        TreeNodeWithState childVerified = null;
        if (sv.getOcspCertificateStatus().equals(CertificateStatus.OK)
                || sv.getCrlCertificateStatus().equals(CertificateStatus.OK)) {
            childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certOK"),
                    TreeNodeWithState.State.VALID);
        } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.REVOKED)
                || sv.getCrlCertificateStatus().equals(CertificateStatus.REVOKED)) {
            childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certRevoked"),
                    TreeNodeWithState.State.INVALID);
        } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHECKED)
                && sv.getCrlCertificateStatus().equals(CertificateStatus.UNCHECKED)) {
            childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certNotVerified"),
                    TreeNodeWithState.State.WARNING);
        } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.UNCHAINED)) {
            childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certNotChained"),
                    TreeNodeWithState.State.WARNING);
        } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.EXPIRED)) {
            childVerified = new TreeNodeWithState(Bundle.getBundle().getString("certExpired"),
                    TreeNodeWithState.State.WARNING);
        } else if (sv.getOcspCertificateStatus().equals(CertificateStatus.CHAINED_LOCALLY)) {
            childVerified = new TreeNodeWithState(
                    "<html>" + Bundle.getBundle().getString("tn.5") + "<br>"
                            + Bundle.getBundle().getString("tn.6") + "</html>",
                    TreeNodeWithState.State.VALID_WARNING);
        }

        TreeNodeWithState childTimestamp = null;
        if (sv.isValidTimeStamp()) {
            childTimestamp = new TreeNodeWithState(Bundle.getBundle().getString("validTimestamp"),
                    TreeNodeWithState.State.VALID);
        } else {
            childTimestamp = new TreeNodeWithState(Bundle.getBundle().getString("signerDateTime"),
                    TreeNodeWithState.State.WARNING);
        }

        sig.add(childChanged);
        sig.add(childVerified);
        sig.add(childTimestamp);
        top.add(sig);
    }
    TreeModel tm = new DefaultTreeModel(top);
    jtValidation.setModel(tm);

    if (jtValidation.getRowCount() > 0) {
        jtValidation.setSelectionRow(jtValidation.getRowCount() - 1);
    }
}