Search in sources :

Example 11 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 12 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project processing by processing.

the class Base method addSketches.

public boolean addSketches(DefaultMutableTreeNode node, File folder, boolean examples) throws IOException {
    // skip .DS_Store files, etc (this shouldn't actually be necessary)
    if (!folder.isDirectory()) {
        return false;
    }
    final String folderName = folder.getName();
    // Don't look inside the 'libraries' folders in the sketchbook
    if (folderName.equals("libraries")) {
        return false;
    }
    // to be named 'examples'.
    if (!examples && folderName.equals("examples")) {
        return false;
    }
    //    // Conversely, when looking for examples, ignore the other folders
    //    // (to avoid going through hoops with the tree node setup).
    //    if (examples && !folderName.equals("examples")) {
    //      return false;
    //    }
    //    // Doesn't quite work because the parent will be 'examples', and we want
    //    // to walk inside that, but the folder itself will have a different name
    String[] fileList = folder.list();
    // If a bad folder or unreadable or whatever, this will come back null
    if (fileList == null) {
        return false;
    }
    // Alphabetize the list, since it's not always alpha order
    Arrays.sort(fileList, String.CASE_INSENSITIVE_ORDER);
    boolean found = false;
    for (String name : fileList) {
        if (name.charAt(0) == '.') {
            // Skip hidden files
            continue;
        }
        File subfolder = new File(folder, name);
        if (subfolder.isDirectory()) {
            File entry = checkSketchFolder(subfolder, name);
            if (entry != null) {
                DefaultMutableTreeNode item = new DefaultMutableTreeNode(new SketchReference(name, entry));
                node.add(item);
                found = true;
            } else {
                // not a sketch folder, but maybe a subfolder containing sketches
                DefaultMutableTreeNode subnode = new DefaultMutableTreeNode(name);
                // needs to be separate var otherwise would set ifound to false
                boolean anything = addSketches(subnode, subfolder, examples);
                if (anything) {
                    node.add(subnode);
                    found = true;
                }
            }
        }
    }
    return found;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 13 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project processing by processing.

the class ExamplesFrame method expandTree.

void expandTree(JTree tree, Object object, String[] items, DefaultMutableTreeNode[] nodes, int index) {
    //    if (object == null) {
    //      object = model.getRoot();
    //    }
    TreeModel model = tree.getModel();
    if (index == 0) {
        nodes[0] = (DefaultMutableTreeNode) model.getRoot();
        expandTree(tree, nodes[0], items, nodes, 1);
    } else if (index < items.length) {
        //    String item = items[0];
        //    TreeModel model = object.getModel();
        //    System.out.println(object.getClass().getName());
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) object;
        int count = model.getChildCount(node);
        //    System.out.println("child count is " + count);
        for (int i = 0; i < count; i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) model.getChild(node, i);
            if (items[index].equals(child.getUserObject())) {
                nodes[index] = child;
                expandTree(tree, child, items, nodes, index + 1);
            }
        }
    } else {
        // last one
        //      PApplet.println(nodes);
        tree.expandPath(new TreePath(nodes));
    }
}
Also used : TreeModel(javax.swing.tree.TreeModel) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath)

Example 14 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project processing by processing.

the class ExamplesFrame method updateExpanded.

protected void updateExpanded(JTree tree) {
    Enumeration en = tree.getExpandedDescendants(new TreePath(tree.getModel().getRoot()));
    //en.nextElement();  // skip the root "Examples" node
    StringBuilder s = new StringBuilder();
    while (en.hasMoreElements()) {
        //System.out.println(en.nextElement());
        TreePath tp = (TreePath) en.nextElement();
        Object[] path = tp.getPath();
        for (Object o : path) {
            DefaultMutableTreeNode p = (DefaultMutableTreeNode) o;
            String name = (String) p.getUserObject();
            //System.out.print(p.getUserObject().getClass().getName() + ":" + p.getUserObject() + " -> ");
            //System.out.print(name + " -> ");
            s.append(name);
            s.append(File.separatorChar);
        }
        //System.out.println();
        s.setCharAt(s.length() - 1, File.pathSeparatorChar);
    }
    // nix that last separator
    s.setLength(s.length() - 1);
    String pref = "examples." + getClass().getName() + ".visible";
    Preferences.set(pref, s.toString());
    Preferences.save();
//    System.out.println(s);
//    System.out.println();
}
Also used : Enumeration(java.util.Enumeration) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 15 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project processing by processing.

the class ExamplesFrame method buildTree.

protected DefaultMutableTreeNode buildTree() {
    //"Examples");
    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    try {
        // Get the list of Mode-specific examples, in the order the Mode wants
        // to present them (i.e. Basics, then Topics, then Demos...)
        File[] examples = mode.getExampleCategoryFolders();
        for (File subFolder : examples) {
            DefaultMutableTreeNode subNode = new DefaultMutableTreeNode(subFolder.getName());
            if (base.addSketches(subNode, subFolder, true)) {
                root.add(subNode);
            }
        }
        DefaultMutableTreeNode foundationLibraries = new DefaultMutableTreeNode(Language.text("examples.core_libraries"));
        // Get examples for core libraries
        for (Library lib : mode.coreLibraries) {
            if (lib.hasExamples()) {
                DefaultMutableTreeNode libNode = new DefaultMutableTreeNode(lib.getName());
                if (base.addSketches(libNode, lib.getExamplesFolder(), true)) {
                    foundationLibraries.add(libNode);
                }
            }
        }
        if (foundationLibraries.getChildCount() > 0) {
            root.add(foundationLibraries);
        }
        // Get examples for third party libraries
        DefaultMutableTreeNode contributedLibExamples = new DefaultMutableTreeNode(Language.text("examples.libraries"));
        for (Library lib : mode.contribLibraries) {
            if (lib.hasExamples()) {
                DefaultMutableTreeNode libNode = new DefaultMutableTreeNode(lib.getName());
                base.addSketches(libNode, lib.getExamplesFolder(), true);
                contributedLibExamples.add(libNode);
            }
        }
        if (contributedLibExamples.getChildCount() > 0) {
            root.add(contributedLibExamples);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    DefaultMutableTreeNode contributedExamplesNode = buildContribTree();
    if (contributedExamplesNode.getChildCount() > 0) {
        root.add(contributedExamplesNode);
    }
    return root;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Library(processing.app.Library) IOException(java.io.IOException) File(java.io.File)

Aggregations

DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)605 TreePath (javax.swing.tree.TreePath)162 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)85 Nullable (org.jetbrains.annotations.Nullable)50 ArrayList (java.util.ArrayList)44 TreeNode (javax.swing.tree.TreeNode)42 Test (org.junit.Test)39 JTree (javax.swing.JTree)34 NotNull (org.jetbrains.annotations.NotNull)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 JScrollPane (javax.swing.JScrollPane)25 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)21 TreeSelectionListener (javax.swing.event.TreeSelectionListener)21 Module (com.intellij.openapi.module.Module)20 Tree (com.intellij.ui.treeStructure.Tree)19 Enumeration (java.util.Enumeration)18 MProduct (org.compiere.model.MProduct)17 MouseEvent (java.awt.event.MouseEvent)15 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)14 List (java.util.List)13