Search in sources :

Example 66 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project JMRI by JMRI.

the class CombinedLocoSelTreePane method layoutDecoderSelection.

/**
     * Create the panel used to select the decoder
     */
@Override
protected JPanel layoutDecoderSelection() {
    JPanel pane1a = new JPanel(new BorderLayout());
    pane1a.add(new JLabel(Bundle.getMessage("LabelDecoderInstalled")), BorderLayout.NORTH);
    // create the list of manufacturers; get the list of decoders, and add elements
    dRoot = new DecoderTreeNode("Root");
    dModel = new InvisibleTreeModel(dRoot);
    dTree = new JTree(dModel) {

        @Override
        public String getToolTipText(MouseEvent evt) {
            if (getRowForLocation(evt.getX(), evt.getY()) == -1) {
                return null;
            }
            TreePath curPath = getPathForLocation(evt.getX(), evt.getY());
            return ((DecoderTreeNode) curPath.getLastPathComponent()).getToolTipText();
        }
    };
    dTree.setToolTipText("");
    createDecoderTypeContents();
    // build the tree GUI
    pane1a.add(new JScrollPane(dTree), BorderLayout.CENTER);
    dTree.expandPath(new TreePath(dRoot));
    dTree.setRootVisible(false);
    dTree.setShowsRootHandles(true);
    dTree.setScrollsOnExpand(true);
    dTree.setExpandsSelectedPaths(true);
    dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
    // tree listener
    dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            log.debug("selection changed " + dTree.isSelectionEmpty() + " " + dTree.getSelectionPath());
            if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // can't be just a mfg, has to be at least a family
            dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
            dTree.getSelectionCount() < 2) {
                // decoder selected - reset and disable loco selection
                log.debug("Selection event with " + dTree.getSelectionPath().toString());
                if (locoBox != null) {
                    locoBox.setSelectedIndex(0);
                }
                go2.setEnabled(true);
                go2.setRequestFocusEnabled(true);
                go2.requestFocus();
                go2.setToolTipText(Bundle.getMessage("TipClickToOpen"));
            } else {
                // decoder not selected - require one
                go2.setEnabled(false);
                go2.setToolTipText(Bundle.getMessage("TipSelectLoco"));
            }
        }
    });
    //      Mouselistener for doubleclick activation of programmer   
    dTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent me) {
            // Clear any status messages and ensure the tree is in single path select mode
            if (_statusLabel != null) {
                _statusLabel.setText(Bundle.getMessage("StateIdle"));
            }
            dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
            if (me.getClickCount() == 2) {
                if (go2.isEnabled() && ((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
                    go2.doClick();
                }
            }
        }
    });
    viewButtons = new JPanel();
    iddecoder = addDecoderIdentButton();
    if (iddecoder != null) {
        viewButtons.add(iddecoder);
    }
    showAll = new JRadioButton(Bundle.getMessage("LabelAll"));
    showAll.setSelected(true);
    showMatched = new JRadioButton(Bundle.getMessage("LabelMatched"));
    if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
        ButtonGroup group = new ButtonGroup();
        group.add(showAll);
        group.add(showMatched);
        viewButtons.add(showAll);
        viewButtons.add(showMatched);
        pane1a.add(viewButtons, BorderLayout.SOUTH);
        showAll.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (dModel.isActivatedFilter()) {
                    dModel.activateFilter(false);
                    dModel.reload();
                    for (TreePath path : selectedPath) {
                        dTree.expandPath(path);
                        dTree.addSelectionPath(path);
                        dTree.scrollPathToVisible(path);
                    }
                }
            }
        });
        showMatched.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (!dModel.isActivatedFilter()) {
                    dModel.activateFilter(true);
                    dModel.reload();
                    for (TreePath path : selectedPath) {
                        log.debug("action selects path: " + path);
                        dTree.expandPath(path);
                        dTree.addSelectionPath(path);
                        dTree.scrollPathToVisible(path);
                    }
                }
            }
        });
    }
    return pane1a;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) JTree(javax.swing.JTree) BorderLayout(java.awt.BorderLayout) TreePath(javax.swing.tree.TreePath) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 67 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project n2a by frothga.

the class FixedParameterSpacePanel method buildDomainTab.

private void buildDomainTab(ParameterDomain domain) {
    TNode nRoot = new TNode(new NodeSimpleLabel(domain.getName()));
    populate(nRoot, domain);
    FilterableParameterTreePanel pnlFilterableTree = new FilterableParameterTreePanel(nRoot);
    final ParameterTree treParams = pnlFilterableTree.getTree();
    treParams.addMouseMotionListener(new MouseMotionAdapter() {

        @Override
        public void mouseMoved(MouseEvent e) {
            TreePath path = treParams.getPathForLocation(e.getX(), e.getY());
            if (path == null || ((TNode) path.getLastPathComponent()).getUserObject() instanceof NodeSubdomain) {
                treParams.setCursor(Cursor.getDefaultCursor());
            } else {
                treParams.setCursor(DragCursors.getOpenhandcursor());
            }
        }
    });
    treParams.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            updateDetailsPanelFromTree(treParams);
        }
    });
    treParams.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1 && treParams.getSelectionCount() != 0) {
                List<ParameterBundle> bundles = getSelectedParamsAsBundles(treParams.getSelectionPaths());
                if (bundles != null) {
                    dropIntoGroups(bundles, dropEmphasis);
                }
            }
        }
    });
    DragSource ds = new DragSource();
    ds.createDefaultDragGestureRecognizer(treParams, DnDConstants.ACTION_LINK, this);
    int existingIndex = tabParamDomains.indexOfTabByKey(domain.getName());
    if (existingIndex != -1) {
        tabParamDomains.remove(existingIndex);
    }
    tabParamDomains.add(domain.getName(), pnlFilterableTree);
    int index = tabParamDomains.getTabCount();
    tabParamDomains.setIconAt(index - 1, domain.getIcon());
    tabParamDomains.setUseBorderAt(index - 1, true);
}
Also used : MouseEvent(java.awt.event.MouseEvent) ParameterTree(gov.sandia.umf.platform.ui.ensemble.tree.ParameterTree) MouseAdapter(java.awt.event.MouseAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DragSource(java.awt.dnd.DragSource) NodeSimpleLabel(replete.gui.controls.simpletree.NodeSimpleLabel) NodeSubdomain(gov.sandia.umf.platform.ui.ensemble.tree.NodeSubdomain) FilterableParameterTreePanel(gov.sandia.umf.platform.ui.ensemble.tree.FilterableParameterTreePanel) TNode(replete.gui.controls.simpletree.TNode) MouseMotionAdapter(java.awt.event.MouseMotionAdapter) TreePath(javax.swing.tree.TreePath) List(java.util.List) ParameterSetList(gov.sandia.umf.platform.ensemble.params.ParameterSetList) ArrayList(java.util.ArrayList) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 68 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project JWildfire by thargor6.

the class FlameBrowserInternalFrame method getFlameBrowserTree.

JTree getFlameBrowserTree() {
    if (flameBrowserTree == null) {
        flameBrowserTree = new JTree();
        flameBrowserTree.addTreeSelectionListener(new TreeSelectionListener() {

            public void valueChanged(TreeSelectionEvent e) {
                if (tinaController != null) {
                    tinaController.getFlameBrowserController().flamesTree_changed();
                }
            }
        });
    }
    return flameBrowserTree;
}
Also used : JTree(javax.swing.JTree) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 69 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project freeplane by freeplane.

the class SelectMenuItemDialog method createTree.

private JTree createTree() {
    final DefaultMutableTreeNode treeRoot = MenuUtils.createMenuEntryTree(SELECTION_ROOT_KEY);
    if (treeRoot.getUserObject() == null)
        treeRoot.setUserObject(new MenuEntry(null, TextUtils.getText("select_menu_item_root_node")));
    JTree jTree = new JTree(treeRoot);
    jTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    // replace the standard icons
    jTree.setCellRenderer(new MenuIconRenderer());
    jTree.addTreeSelectionListener(new TreeSelectionListener() {

        public void valueChanged(final TreeSelectionEvent e) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
            btnOK.setEnabled(node != null && nodeIsSelectable(node));
        }
    });
    jTree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                if (btnOK.isEnabled())
                    btnOK.doClick();
            }
        }
    });
    return jTree;
}
Also used : JTree(javax.swing.JTree) MenuEntry(org.freeplane.core.util.MenuUtils.MenuEntry) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MouseAdapter(java.awt.event.MouseAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 70 with TreeSelectionListener

use of javax.swing.event.TreeSelectionListener in project sirix by sirixdb.

the class TreeView method dispose.

@Override
public void dispose() {
    mTree.clearSelection();
    mTree.setModel(null);
    mTree.setCellRenderer(null);
    for (final FocusListener listener : mTree.getFocusListeners()) {
        mTree.removeFocusListener(listener);
    }
    for (final ComponentListener listener : mTree.getComponentListeners()) {
        mTree.removeComponentListener(listener);
    }
    for (final TreeSelectionListener listener : mTree.getTreeSelectionListeners()) {
        mTree.removeTreeSelectionListener(listener);
    }
    for (final ContainerListener listener : mTree.getContainerListeners()) {
        mTree.removeContainerListener(listener);
    }
}
Also used : ComponentListener(java.awt.event.ComponentListener) ContainerListener(java.awt.event.ContainerListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) FocusListener(java.awt.event.FocusListener)

Aggregations

TreeSelectionListener (javax.swing.event.TreeSelectionListener)87 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)36 TreePath (javax.swing.tree.TreePath)33 JTree (javax.swing.JTree)27 JScrollPane (javax.swing.JScrollPane)25 ActionEvent (java.awt.event.ActionEvent)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 MouseEvent (java.awt.event.MouseEvent)16 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)16 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)14 GridBagConstraints (java.awt.GridBagConstraints)12 GridBagLayout (java.awt.GridBagLayout)12 Insets (java.awt.Insets)12 JButton (javax.swing.JButton)11 Tree (com.intellij.ui.treeStructure.Tree)10 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9