Search in sources :

Example 1 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project pcgen by PCGen.

the class PreferencesPluginsPanel method getCenter.

@Override
protected JComponent getCenter() {
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root");
    DefaultMutableTreeNode characterNode;
    DefaultMutableTreeNode pcGenNode;
    DefaultMutableTreeNode appearanceNode;
    DefaultMutableTreeNode gameModeNode;
    panelList = new ArrayList<>(15);
    // Build the settings panel
    settingsPanel = new JPanel();
    settingsPanel.setLayout(new CardLayout());
    settingsPanel.setPreferredSize(new Dimension(780, 420));
    // Build the selection tree
    characterNode = new DefaultMutableTreeNode(in_character);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_charTip")), in_character);
    characterStatsPanel = new CharacterStatsPanel(this);
    addPanelToTree(characterNode, characterStatsPanel);
    hitPointsPanel = new HitPointsPanel();
    addPanelToTree(characterNode, hitPointsPanel);
    houseRulesPanel = new HouseRulesPanel();
    addPanelToTree(characterNode, houseRulesPanel);
    monsterPanel = new MonsterPanel();
    addPanelToTree(characterNode, monsterPanel);
    defaultsPanel = new DefaultsPanel();
    addPanelToTree(characterNode, defaultsPanel);
    rootNode.add(characterNode);
    appearanceNode = new DefaultMutableTreeNode(in_appearance);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_appearanceTip")), in_appearance);
    colorsPanel = new ColorsPanel();
    addPanelToTree(appearanceNode, colorsPanel);
    displayOptionsPanel = new DisplayOptionsPanel();
    addPanelToTree(appearanceNode, displayOptionsPanel);
    levelUpPanel = new LevelUpPanel();
    addPanelToTree(appearanceNode, levelUpPanel);
    lookAndFeelPanel = new LookAndFeelPanel(this);
    addPanelToTree(appearanceNode, lookAndFeelPanel);
    //		tabsPanel = new TabsPanel();
    //		addPanelToTree(appearanceNode, tabsPanel);
    rootNode.add(appearanceNode);
    pcGenNode = new DefaultMutableTreeNode(Constants.APPLICATION_NAME);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_pcgenTip")), Constants.APPLICATION_NAME);
    equipmentPanel = new EquipmentPanel();
    addPanelToTree(pcGenNode, equipmentPanel);
    languagePanel = new LanguagePanel();
    addPanelToTree(pcGenNode, languagePanel);
    locationPanel = new LocationPanel();
    addPanelToTree(pcGenNode, locationPanel);
    inputPanel = new InputPanel();
    addPanelToTree(pcGenNode, inputPanel);
    outputPanel = new OutputPanel();
    addPanelToTree(pcGenNode, outputPanel);
    sourcesPanel = new SourcesPanel();
    addPanelToTree(pcGenNode, sourcesPanel);
    rootNode.add(pcGenNode);
    String in_gamemode = LanguageBundle.getString("in_mnuSettingsCampaign");
    gameModeNode = new DefaultMutableTreeNode(in_gamemode);
    settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_mnuSettingsCampaignTip")), in_gamemode);
    copySettingsPanel = new CopySettingsPanel();
    addPanelToTree(gameModeNode, copySettingsPanel);
    rootNode.add(gameModeNode);
    DefaultMutableTreeNode pluginNode = new DefaultMutableTreeNode(//$NON-NLS-1$
    LanguageBundle.getString("in_Prefs_plugins"));
    addPluginPanes(rootNode, pluginNode);
    settingsModel = new DefaultTreeModel(rootNode);
    settingsTree = new JTree(settingsModel);
    settingsTree.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
    settingsTree.setRootVisible(false);
    settingsTree.setShowsRootHandles(true);
    settingsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    settingsScroll = new JScrollPane(settingsTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    // Turn off the icons
    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
    renderer.setLeafIcon(null);
    renderer.setOpenIcon(null);
    renderer.setClosedIcon(null);
    settingsTree.setCellRenderer(renderer);
    // Expand all of the branch nodes
    settingsTree.expandPath(new TreePath(characterNode.getPath()));
    settingsTree.expandPath(new TreePath(pcGenNode.getPath()));
    settingsTree.expandPath(new TreePath(appearanceNode.getPath()));
    settingsTree.expandPath(new TreePath(gameModeNode.getPath()));
    settingsTree.expandPath(new TreePath(pluginNode.getPath()));
    // Add the listener which switches panels when a node of the tree is selected
    settingsTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) settingsTree.getLastSelectedPathComponent();
            if (node == null) {
                return;
            }
            CardLayout cl = (CardLayout) (settingsPanel.getLayout());
            cl.show(settingsPanel, String.valueOf(node));
        }
    });
    // Build the split pane
    splitPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, settingsScroll, settingsPanel, "Prefs");
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerSize(10);
    return splitPane;
}
Also used : JPanel(javax.swing.JPanel) LocationPanel(pcgen.gui2.prefs.LocationPanel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) SourcesPanel(pcgen.gui2.prefs.SourcesPanel) OutputPanel(pcgen.gui2.prefs.OutputPanel) TreeSelectionListener(javax.swing.event.TreeSelectionListener) HitPointsPanel(pcgen.gui2.prefs.HitPointsPanel) CopySettingsPanel(pcgen.gui2.prefs.CopySettingsPanel) DefaultTreeCellRenderer(javax.swing.tree.DefaultTreeCellRenderer) HouseRulesPanel(pcgen.gui2.prefs.HouseRulesPanel) DisplayOptionsPanel(pcgen.gui2.prefs.DisplayOptionsPanel) LevelUpPanel(pcgen.gui2.prefs.LevelUpPanel) ColorsPanel(pcgen.gui2.prefs.ColorsPanel) LanguagePanel(pcgen.gui2.prefs.LanguagePanel) EquipmentPanel(pcgen.gui2.prefs.EquipmentPanel) JScrollPane(javax.swing.JScrollPane) CardLayout(java.awt.CardLayout) CharacterStatsPanel(pcgen.gui2.prefs.CharacterStatsPanel) InputPanel(pcgen.gui2.prefs.InputPanel) Dimension(java.awt.Dimension) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) JTree(javax.swing.JTree) DefaultsPanel(pcgen.gui2.prefs.DefaultsPanel) TreePath(javax.swing.tree.TreePath) MonsterPanel(pcgen.gui2.prefs.MonsterPanel) LookAndFeelPanel(pcgen.gui2.prefs.LookAndFeelPanel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 2 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.

the class MavenArtifactSearchPanel method initComponents.

private void initComponents(String initialText) {
    myResultList = new Tree();
    myResultList.setExpandableItemsEnabled(false);
    myResultList.getEmptyText().setText("Loading...");
    myResultList.setRootVisible(false);
    myResultList.setShowsRootHandles(true);
    myResultList.setModel(null);
    MyArtifactCellRenderer renderer = myClassMode ? new MyClassCellRenderer(myResultList) : new MyArtifactCellRenderer(myResultList);
    myResultList.setCellRenderer(renderer);
    myResultList.setRowHeight(renderer.getPreferredSize().height);
    mySearchField = new JTextField(initialText);
    mySearchField.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            int d;
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                d = 1;
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
                d = -1;
            } else {
                return;
            }
            int row = myResultList.getSelectionModel().getLeadSelectionRow();
            row += d;
            if (row >= 0 && row < myResultList.getRowCount()) {
                myResultList.setSelectionRow(row);
            }
        }
    });
    setLayout(new BorderLayout());
    add(mySearchField, BorderLayout.NORTH);
    JScrollPane pane = ScrollPaneFactory.createScrollPane(myResultList);
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    // Don't remove this line.
    pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // Without VERTICAL_SCROLLBAR_ALWAYS policy our custom layout
    // works incorrectly, see https://youtrack.jetbrains.com/issue/IDEA-72986
    add(pane, BorderLayout.CENTER);
    mySearchField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        protected void textChanged(DocumentEvent e) {
            scheduleSearch();
        }
    });
    myResultList.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (!myAlarm.isEmpty())
                return;
            boolean hasSelection = !myResultList.isSelectionEmpty();
            myListener.canSelectStateChanged(MavenArtifactSearchPanel.this, hasSelection);
        }
    });
    myResultList.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER && myResultList.getLastSelectedPathComponent() != null) {
                myListener.itemSelected();
                e.consume();
            }
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            final TreePath path = myResultList.getPathForLocation(e.getX(), e.getY());
            if (path != null && myResultList.isPathSelected(path)) {
                Object sel = path.getLastPathComponent();
                if (sel != null && myResultList.getModel().isLeaf(sel)) {
                    myListener.itemSelected();
                    return true;
                }
            }
            return false;
        }
    }.installOn(myResultList);
}
Also used : MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DocumentEvent(javax.swing.event.DocumentEvent) KeyEvent(java.awt.event.KeyEvent) TreePath(javax.swing.tree.TreePath) Tree(com.intellij.ui.treeStructure.Tree) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 3 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project pcgen by PCGen.

the class NotesView method initTree.

//Initialization methods
private void initTree() {
    dataDir.listFiles();
    root = new NotesTreeNode(dataDir.getName(), dataDir, notesTree);
    TreeModel model = new DefaultTreeModel(root);
    notesTree.setModel(model);
    notesTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent evt) {
            notesTreeActionPerformed();
        }
    });
    notesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    notesTree.setEditable(true);
    model.addTreeModelListener(new TreeModelListener() {

        @Override
        public void treeNodesChanged(TreeModelEvent e) {
            notesTreeNodesChanged();
        }

        @Override
        public void treeNodesInserted(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }

        @Override
        public void treeNodesRemoved(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }

        @Override
        public void treeStructureChanged(TreeModelEvent e) {
        // TODO:  Method does nothing?
        }
    });
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeModelEvent(javax.swing.event.TreeModelEvent) TreeModelListener(javax.swing.event.TreeModelListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent)

Example 4 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.

the class ChooseLibrariesDialogBase method createCenterPanel.

@Override
@Nullable
protected JComponent createCenterPanel() {
    myBuilder = new SimpleTreeBuilder(myTree, new DefaultTreeModel(new DefaultMutableTreeNode()), new MyStructure(getProject()), WeightBasedComparator.FULL_INSTANCE);
    myBuilder.initRootNode();
    myTree.setDragEnabled(false);
    myTree.setShowsRootHandles(true);
    UIUtil.setLineStyleAngled(myTree);
    myTree.setRootVisible(false);
    myTree.addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            updateOKAction();
        }
    });
    new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent e) {
            if (isOKActionEnabled()) {
                doOKAction();
                return true;
            }
            return false;
        }
    }.installOn(myTree);
    myTree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
    myTree.getActionMap().put("ENTER", getOKAction());
    final JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
    pane.setPreferredSize(JBUI.size(500, 400));
    return pane;
}
Also used : SimpleTreeBuilder(com.intellij.ui.treeStructure.SimpleTreeBuilder) MouseEvent(java.awt.event.MouseEvent) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DoubleClickListener(com.intellij.ui.DoubleClickListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with TreeSelectionEvent

use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.

the class XWatchesViewImpl method installEditListeners.

private void installEditListeners() {
    final XDebuggerTree watchTree = getTree();
    final Alarm quitePeriod = new Alarm();
    final Alarm editAlarm = new Alarm();
    final ClickListener mouseListener = new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent event, int clickCount) {
            if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
                return false;
            }
            boolean sameRow = isAboveSelectedItem(event, watchTree, false);
            if (!sameRow || clickCount > 1) {
                editAlarm.cancelAllRequests();
                return false;
            }
            final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
            Presentation presentation = editWatchAction.getTemplatePresentation().clone();
            DataContext context = DataManager.getInstance().getDataContext(watchTree);
            final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
            Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
            if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
                editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
            } else {
                editAlarm.cancelAllRequests();
            }
            return false;
        }
    };
    final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {

        @Override
        protected boolean onDoubleClick(MouseEvent event) {
            if (!isAboveSelectedItem(event, watchTree, true)) {
                myRootNode.addNewWatch();
                return true;
            }
            return false;
        }
    };
    ListenerUtil.addClickListener(watchTree, mouseListener);
    ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
    final FocusListener focusListener = new FocusListener() {

        @Override
        public void focusGained(@NotNull FocusEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }

        @Override
        public void focusLost(@NotNull FocusEvent e) {
            editAlarm.cancelAllRequests();
        }
    };
    ListenerUtil.addFocusListener(watchTree, focusListener);
    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(@NotNull TreeSelectionEvent e) {
            quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
        }
    };
    watchTree.addTreeSelectionListener(selectionListener);
    myDisposables.add(new Disposable() {

        @Override
        public void dispose() {
            ListenerUtil.removeClickListener(watchTree, mouseListener);
            ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
            ListenerUtil.removeFocusListener(watchTree, focusListener);
            watchTree.removeTreeSelectionListener(selectionListener);
        }
    });
}
Also used : CompositeDisposable(com.intellij.openapi.CompositeDisposable) Disposable(com.intellij.openapi.Disposable) MouseEvent(java.awt.event.MouseEvent) DoubleClickListener(com.intellij.ui.DoubleClickListener) TreeSelectionListener(javax.swing.event.TreeSelectionListener) XDebuggerTree(com.intellij.xdebugger.impl.ui.tree.XDebuggerTree) NotNull(org.jetbrains.annotations.NotNull) FocusEvent(java.awt.event.FocusEvent) Alarm(com.intellij.util.Alarm) EmptyRunnable(com.intellij.openapi.util.EmptyRunnable) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) FocusListener(java.awt.event.FocusListener) DoubleClickListener(com.intellij.ui.DoubleClickListener) ClickListener(com.intellij.ui.ClickListener)

Aggregations

TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)85 TreeSelectionListener (javax.swing.event.TreeSelectionListener)82 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)34 TreePath (javax.swing.tree.TreePath)32 JTree (javax.swing.JTree)27 ActionEvent (java.awt.event.ActionEvent)23 JScrollPane (javax.swing.JScrollPane)23 JPanel (javax.swing.JPanel)22 ActionListener (java.awt.event.ActionListener)20 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)18 MouseEvent (java.awt.event.MouseEvent)15 BorderLayout (java.awt.BorderLayout)14 Dimension (java.awt.Dimension)13 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)9 KeyAdapter (java.awt.event.KeyAdapter)9 KeyEvent (java.awt.event.KeyEvent)9