Search in sources :

Example 41 with DefaultMutableTreeNode

use of javax.swing.tree.DefaultMutableTreeNode in project binnavi by google.

the class CAddressSpaceNodeTest method setUp.

@Before
public void setUp() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException, FileReadException, CouldntLoadDataException, CouldntSaveDataException, LoadCancelledException {
    ConfigManager.instance().read();
    m_database = new MockDatabase(m_provider);
    m_project = new CProject(1, "Mock Project", "Mock Project Description", new Date(), new Date(), 0, new ArrayList<DebuggerTemplate>(), m_provider);
    m_project.load();
    m_addressSpace = m_project.getContent().createAddressSpace("Address Space");
    final CProjectTreeModel model = new CProjectTreeModel(m_tree);
    model.setRoot(new DefaultMutableTreeNode());
    m_tree.setModel(model);
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_database, "listeners"), "m_listeners")) == null);
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_project, "m_listeners"), "m_listeners")) == null);
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(m_addressSpace, "m_listeners"), "m_listeners")) == null);
    assertTrue(((LinkedHashSet<?>) ReflectionHelpers.getField(ReflectionHelpers.getField(ZyGraphBuilderManager.instance(), "m_listeners"), "m_listeners")) == null);
    m_container = new CProjectContainer(m_database, m_project, m_addressSpace);
}
Also used : CProject(com.google.security.zynamics.binnavi.disassembly.CProject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) CProjectTreeModel(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.CProjectTreeModel) CProjectContainer(com.google.security.zynamics.binnavi.disassembly.CProjectContainer) ArrayList(java.util.ArrayList) MockDatabase(com.google.security.zynamics.binnavi.Database.MockClasses.MockDatabase) Date(java.util.Date) Before(org.junit.Before)

Example 42 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 43 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 44 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 45 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)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