Search in sources :

Example 56 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project jphp by jphp-compiler.

the class WrapTreeNode method insertAfter.

@Signature({ @Arg(value = "child", typeClass = NAME), @Arg(value = "node", typeClass = NAME) })
public Memory insertAfter(Environment env, Memory... args) {
    DefaultMutableTreeNode child = args[0].toObject(WrapTreeNode.class).getNode();
    DefaultMutableTreeNode node = args[1].toObject(WrapTreeNode.class).getNode();
    int childIndex = node.getIndex(child);
    if (childIndex <= 0 || childIndex == this.node.getChildCount() - 1)
        this.node.add(node);
    else {
        this.node.insert(node, childIndex + 1);
    }
    return Memory.NULL;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 57 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project jphp by jphp-compiler.

the class JTreeXEventProvider method register.

@Override
public void register(final Environment env, final JTreeX component, final ComponentProperties properties) {
    final ObjectMemory self = new ObjectMemory(new UITree(env, component));
    component.getContent().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(final TreeSelectionEvent e) {
            trigger(env, properties, "selected", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    Memory oldNode = Memory.NULL;
                    if (e.getOldLeadSelectionPath() != null) {
                        oldNode = new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) e.getOldLeadSelectionPath().getLastPathComponent()));
                    }
                    Memory node = Memory.NULL;
                    if (e.getNewLeadSelectionPath() != null) {
                        node = new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) e.getNewLeadSelectionPath().getLastPathComponent()));
                    }
                    return new Memory[] { self, node, oldNode, TrueMemory.valueOf(e.isAddedPath()) };
                }
            });
        }
    });
    component.getContent().addTreeWillExpandListener(new TreeWillExpandListener() {

        @Override
        public void treeWillExpand(final TreeExpansionEvent event) {
            trigger(env, properties, "willExpand", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }

        @Override
        public void treeWillCollapse(final TreeExpansionEvent event) {
            trigger(env, properties, "willCollapse", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }
    });
    component.getContent().addTreeExpansionListener(new TreeExpansionListener() {

        @Override
        public void treeExpanded(final TreeExpansionEvent event) {
            trigger(env, properties, "expanded", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }

        @Override
        public void treeCollapsed(final TreeExpansionEvent event) {
            trigger(env, properties, "collapsed", new Function<Memory[]>() {

                @Override
                public Memory[] call() {
                    return new Memory[] { self, new ObjectMemory(new WrapTreeNode(env, (DefaultMutableTreeNode) event.getPath().getLastPathComponent())) };
                }
            });
        }
    });
}
Also used : Function(php.runtime.common.Function) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ObjectMemory(php.runtime.memory.ObjectMemory) TrueMemory(php.runtime.memory.TrueMemory) Memory(php.runtime.Memory) ObjectMemory(php.runtime.memory.ObjectMemory) WrapTreeNode(org.develnext.jphp.swing.classes.components.tree.WrapTreeNode) UITree(org.develnext.jphp.swing.classes.components.tree.UITree)

Example 58 with DefaultMutableTreeNode

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

the class QualifiedSpellTreeCellRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean focus) {
    Object obj = ((DefaultMutableTreeNode) value).getUserObject();
    if (//$NON-NLS-1$
    "".equals(obj)) {
        //$NON-NLS-1$
        obj = LanguageBundle.getString("in_none");
    }
    super.getTreeCellRendererComponent(tree, obj, sel, expanded, leaf, row, focus);
    if (obj instanceof SpellNode) {
        SpellNode spellNode = (SpellNode) obj;
        SpellFacade spell = spellNode.getSpell();
        ClassFacade pcClass = spellNode.getSpellcastingClass();
        if (!character.isQualifiedFor(spell, pcClass)) {
            setForeground(UIPropertyContext.getNotQualifiedColor());
        }
    }
    if (obj instanceof InfoFacade && ((InfoFacade) obj).isNamePI()) {
        setFont(FontManipulation.bold_italic(getFont()));
    } else {
        setFont(FontManipulation.plain(getFont()));
    }
    return this;
}
Also used : SpellNode(pcgen.facade.core.SpellSupportFacade.SpellNode) ClassFacade(pcgen.facade.core.ClassFacade) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) InfoFacade(pcgen.facade.core.InfoFacade) SpellFacade(pcgen.facade.core.SpellFacade)

Example 59 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode 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 60 with DefaultMutableTreeNode

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

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)692 TreePath (javax.swing.tree.TreePath)185 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)98 ArrayList (java.util.ArrayList)51 Nullable (org.jetbrains.annotations.Nullable)50 TreeNode (javax.swing.tree.TreeNode)42 Test (org.junit.Test)39 JTree (javax.swing.JTree)38 NotNull (org.jetbrains.annotations.NotNull)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 JScrollPane (javax.swing.JScrollPane)25 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)23 TreeSelectionListener (javax.swing.event.TreeSelectionListener)23 Module (com.intellij.openapi.module.Module)20 File (java.io.File)20 Tree (com.intellij.ui.treeStructure.Tree)19 Enumeration (java.util.Enumeration)19 MouseEvent (java.awt.event.MouseEvent)18 IOException (java.io.IOException)17 MProduct (org.compiere.model.MProduct)17