Search in sources :

Example 36 with TreePath

use of javax.swing.tree.TreePath in project pcgen by PCGen.

the class SpellsPreparedTab method getCurrentSpellListName.

/**
	 * Identify the current spell list, being the spell list that spell should
	 * be added to. If no lists exist then a default one will be created.
	 *
	 * @param character The character qwe are checking for.
	 * @return The name of the 'current' spell list.
	 */
String getCurrentSpellListName(CharacterFacade character) {
    String spellList = "";
    Object selectedObject = selectedTable.getSelectedObject();
    if (selectedObject != null) {
        if (selectedObject instanceof SpellNode) {
            spellList = ((SpellNode) selectedObject).getRootNode().toString();
        } else {
            JTree tree = selectedTable.getTree();
            TreePath path = tree.getSelectionPath();
            while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) {
                path = path.getParentPath();
            }
            spellList = path.getLastPathComponent().toString();
        }
    }
    if (StringUtils.isEmpty(spellList)) {
        spellList = spellListField.getText();
    }
    if (StringUtils.isEmpty(spellList)) {
        ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel();
        if (!data.isEmpty()) {
            Object firstElem = data.getElementAt(0);
            if (firstElem instanceof SpellNode) {
                spellList = ((SpellNode) firstElem).getRootNode().toString();
            }
        }
    }
    if (StringUtils.isEmpty(spellList)) {
        // No lists exist, so create a default one!
        spellList = "Prepared Spells";
        character.getSpellSupport().addSpellList(spellList);
    }
    return spellList;
}
Also used : SpellNode(pcgen.facade.core.SpellSupportFacade.SpellNode) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath)

Example 37 with TreePath

use of javax.swing.tree.TreePath in project pcgen by PCGen.

the class ClassInfoHandler method valueChanged.

@Override
public void valueChanged(ListSelectionEvent e) {
    if (!e.getValueIsAdjusting()) {
        TreePath path;
        if (e.getSource() == availableTable.getSelectionModel()) {
            path = availableTable.getTree().getSelectionPath();
        } else {
            path = selectedTable.getTree().getSelectionPath();
        }
        if (path == null) {
            return;
        }
        ClassFacade c = null;
        DefaultMutableTreeNode treenode = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object[] objs = treenode.getUserObjectPath();
        for (Object object : objs) {
            if (object instanceof ClassFacade) {
                c = (ClassFacade) object;
                break;
            }
        }
        if (c != null) {
            text = character.getSpellSupport().getClassInfo(c);
            classPane.setText(text);
        }
    }
}
Also used : ClassFacade(pcgen.facade.core.ClassFacade) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 38 with TreePath

use of javax.swing.tree.TreePath 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 39 with TreePath

use of javax.swing.tree.TreePath in project intellij-plugins by StepicOrg.

the class NavigationUtils method collapseNonSelected.

private static void collapseNonSelected(@NotNull PsiFileSystemItem file) {
    ProjectView projectView = ProjectView.getInstance(file.getProject());
    if (projectView == null) {
        return;
    }
    AbstractProjectViewPane projectViewPane = projectView.getCurrentProjectViewPane();
    if (projectViewPane == null) {
        return;
    }
    JTree tree = projectViewPane.getTree();
    Set<TreePath> paths = new HashSet<>(TreeUtil.collectExpandedPaths(tree));
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
    DefaultMutableTreeNode selectionNode = findNodeWithObject(root, file);
    if (selectionNode != null) {
        List<TreePath> toCollapse = new ArrayList<>();
        TreePath selectedPath = getPathFromRoot(selectionNode);
        for (TreePath treePath : paths) {
            if (treePath.isDescendant(selectedPath)) {
                continue;
            }
            TreePath currPath = treePath;
            TreePath parent = treePath.getParentPath();
            while (parent != null) {
                if (parent.isDescendant(selectedPath)) {
                    toCollapse.add(currPath);
                    break;
                }
                currPath = parent;
                parent = parent.getParentPath();
            }
        }
        for (TreePath path : toCollapse) {
            tree.collapsePath(path);
            tree.fireTreeCollapsed(path);
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) ProjectView(com.intellij.ide.projectView.ProjectView) AbstractProjectViewPane(com.intellij.ide.projectView.impl.AbstractProjectViewPane) HashSet(java.util.HashSet)

Example 40 with TreePath

use of javax.swing.tree.TreePath 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)

Aggregations

TreePath (javax.swing.tree.TreePath)641 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)201 ArrayList (java.util.ArrayList)65 TreeNode (javax.swing.tree.TreeNode)64 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)53 Nullable (org.jetbrains.annotations.Nullable)49 JTree (javax.swing.JTree)43 NotNull (org.jetbrains.annotations.NotNull)32 Point (java.awt.Point)26 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)23 TreeSelectionListener (javax.swing.event.TreeSelectionListener)23 BioModelNode (cbit.vcell.desktop.BioModelNode)22 MouseEvent (java.awt.event.MouseEvent)22 Test (org.junit.Test)22 Tree (com.intellij.ui.treeStructure.Tree)21 ActionEvent (java.awt.event.ActionEvent)19 KeyEvent (java.awt.event.KeyEvent)12 File (java.io.File)12 List (java.util.List)12 EVTask (net.sourceforge.processdash.ev.EVTask)12