Search in sources :

Example 1 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project LogisticsPipes by RS485.

the class DebugHelper method handleItemTooltip.

@Override
public List<String> handleItemTooltip(GuiContainer gui, final ItemStack itemstack, int paramInt1, int paramInt2, List<String> currenttip) {
    if (Configs.TOOLTIP_INFO && itemstack != null) {
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) && Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) && Keyboard.isKeyDown(Keyboard.KEY_H)) {
            if (DebugHelper.lastTime + 1000 < System.currentTimeMillis()) {
                DebugHelper.lastTime = System.currentTimeMillis();
                new Thread(() -> {
                    while (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_H)) {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    DefaultMutableTreeNode node = new DefaultMutableTreeNode(ItemIdentifier.get(itemstack).getFriendlyName());
                    node.add(new DefaultMutableTreeNode("ItemId: " + Item.getIdFromItem(itemstack.getItem())));
                    node.add(new DefaultMutableTreeNode("ItemDamage: " + itemstack.getItemDamage()));
                    if (itemstack.hasTagCompound()) {
                        DefaultMutableTreeNode tag = new DefaultMutableTreeNode("Tag:");
                        try {
                            addNBTToTree(itemstack.getTagCompound(), tag);
                        } catch (Exception e) {
                            tag.add(new DefaultMutableTreeNode(e));
                        }
                        node.add(tag);
                    }
                    JTree tree = new JTree(node);
                    JScrollPane treeView = new JScrollPane(tree);
                    JFrame frame = new JFrame("Item Info");
                    frame.getContentPane().add(treeView, BorderLayout.CENTER);
                    frame.setLocationRelativeTo(null);
                    frame.pack();
                    frame.setVisible(true);
                }).start();
            }
        }
    }
    return currenttip;
}
Also used : JScrollPane(javax.swing.JScrollPane) JTree(javax.swing.JTree) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JFrame(javax.swing.JFrame)

Example 2 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 3 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 4 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 5 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)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1272 TreePath (javax.swing.tree.TreePath)316 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)205 ArrayList (java.util.ArrayList)91 TreeNode (javax.swing.tree.TreeNode)81 JTree (javax.swing.JTree)65 Test (org.junit.Test)64 Nullable (org.jetbrains.annotations.Nullable)51 JScrollPane (javax.swing.JScrollPane)47 Enumeration (java.util.Enumeration)44 File (java.io.File)43 IOException (java.io.IOException)43 MouseEvent (java.awt.event.MouseEvent)41 NotNull (org.jetbrains.annotations.NotNull)37 ActionEvent (java.awt.event.ActionEvent)36 TreeSelectionListener (javax.swing.event.TreeSelectionListener)35 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)34 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 MouseAdapter (java.awt.event.MouseAdapter)28 List (java.util.List)28