Example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

List of usage examples for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode DefaultMutableTreeNode.

Prototype

public DefaultMutableTreeNode(Object userObject) 

Source Link

Document

Creates a tree node with no parent, no children, but which allows children, and initializes it with the specified user object.

Usage

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

public DefaultMutableTreeNode addNode(QueryMasterData node, DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("working ......");
    tmpData.tooltip("A tmp node");
    tmpData.visualAttribute("LAO");
    DefaultMutableTreeNode tmpNode = new DefaultMutableTreeNode(tmpData);

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }//from  www  .j  a v a2s.c om

    return childNode;
}

From source file:de.rub.syssec.saaf.gui.editor.FileTree.java

/** Add nodes from under "dir" into curTop. Highly recursive. */
DefaultMutableTreeNode addNodes(DefaultMutableTreeNode curTop, File dir) {

    // String curPath = dir.getPath();
    String curPath = dir.getName();
    DefaultMutableTreeNode curDir = new DefaultMutableTreeNode(curPath);

    if (curTop != null) {
        // should only be null at root
        curTop.add(curDir);/*from w w w  . j  av a2 s. c  o m*/
    }

    // ignore some files
    IOFileFilter fileFilter = new NotFileFilter(
            new SuffixFileFilter(new String[] { ".class", ".java", ".DS_Store", ".yml" }));

    LinkedList<File> files = new LinkedList<File>(FileUtils.listFiles(dir, fileFilter, null));
    // FIXME: How the hell can directories be listed?!
    // LinkedList<File> directories = new
    // LinkedList<File>(FileUtils.listFiles(dir, FalseFileFilter.INSTANCE,
    // DirectoryFileFilter.INSTANCE));
    LinkedList<File> directories = new LinkedList<File>(
            Arrays.asList(dir.listFiles((FileFilter) DirectoryFileFilter.DIRECTORY)));

    Collections.sort(files);
    Collections.sort(directories);

    // Recursively add directories
    for (File directory : directories) {
        addNodes(curDir, directory);
    }
    // Add files
    for (File file : files) {
        if (file.getAbsolutePath().endsWith(".png") && file.getAbsolutePath().contains("/bytecode/smali")) {
            /*
             * Skipping generated PNG CFGs in bytecode folder. Other PNG
             * files will be shown in the tree, eg, /res/drawable-hdpi This
             * might not be necessary b/c no PNGs are currently not created
             * at startup.
             */
            continue;
        }
        curDir.add(new DefaultMutableTreeNode(new FileNode(file.getName(), file)));
    }
    return curDir;
}

From source file:kr.ac.kaist.swrc.jhannanum.demo.GUIDemo.java

/**
 * Setting of the each plug-in which is in the tree view.
 * @param top - default top tree node//ww  w.ja v a  2 s  .  c  o  m
 */
private void createPluginNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode phase = null;
    DefaultMutableTreeNode type = null;

    phase = new DefaultMutableTreeNode("Phase1 Plug-in. Plain Text Processing");
    type = new DefaultMutableTreeNode("Supplement Plugin");
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("InformalSentenceFilter", PluginInfo.PHASE1, PluginInfo.SUPPLEMENT)));
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("SentenceSegmentor", PluginInfo.PHASE1, PluginInfo.SUPPLEMENT)));
    phase.add(type);
    top.add(phase);

    phase = new DefaultMutableTreeNode("Phase2 Plug-in. Morphological Analysis");
    type = new DefaultMutableTreeNode("Major Plug-in");
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("ChartMorphAnalyzer", PluginInfo.PHASE2, PluginInfo.MAJOR)));
    phase.add(type);
    type = new DefaultMutableTreeNode("Supplement Plug-in");
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("UnknownMorphProcessor", PluginInfo.PHASE2, PluginInfo.SUPPLEMENT)));
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("SimpleMAResult09", PluginInfo.PHASE2, PluginInfo.SUPPLEMENT)));
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("SimpleMAResult22", PluginInfo.PHASE2, PluginInfo.SUPPLEMENT)));

    phase.add(type);
    top.add(phase);

    phase = new DefaultMutableTreeNode("Phase3 Plug-in. Part Of Speech Tagging");
    type = new DefaultMutableTreeNode("Major Plug-in");
    type.add(new DefaultMutableTreeNode(new PluginInfo("HmmPosTagger", PluginInfo.PHASE3, PluginInfo.MAJOR)));
    phase.add(type);
    type = new DefaultMutableTreeNode("Supplement Plug-in");
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("NounExtractor", PluginInfo.PHASE3, PluginInfo.SUPPLEMENT)));
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("SimplePOSResult09", PluginInfo.PHASE3, PluginInfo.SUPPLEMENT)));
    type.add(new DefaultMutableTreeNode(
            new PluginInfo("SimplePOSResult22", PluginInfo.PHASE3, PluginInfo.SUPPLEMENT)));
    phase.add(type);
    top.add(phase);
}

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private void analisiRicorsivaAggiuntaTC(Object root, Scenario scenario, DefaultTreeModel model,
        TopComponent topComponentAdded) {
    int indice = model.getChildCount(root);
    for (int i = 0; i < indice; i++) {
        analisiRicorsivaAggiuntaTC(model.getChild(root, i), scenario, model, topComponentAdded);
    }//from w  w  w.  j a v  a  2  s.  c om
    //        if (indice == 2) {
    TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) root)
            .getUserObject();
    TopComponent tc = componentAdapter.getTopComponent();
    if (tc != null && tc == scenario.getMappingTaskTopComponent()) {
        TreeNode treeNode = (TreeNode) root;
        int place = model.getChildCount(treeNode.getParent());
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                new TreeTopComponentAdapter(topComponentAdded, false, false, false));
        model.insertNodeInto(newNode, (DefaultMutableTreeNode) treeNode.getParent(), place);
    }
    //            return;
    //        }

}

From source file:gdt.jgui.entity.JEntityStructurePanel.java

/**
 * Create the context.//from   w  ww.j a  va 2  s  .co m
 * @param console the main console.
 * @param locator$ the locator.
 * @return the structure panel.
 */
@Override
public JContext instantiate(JMainConsole console, String locator$) {
    this.console = console;
    this.locator$ = locator$;
    Properties locator = Locator.toProperties(locator$);
    entihome$ = locator.getProperty(Entigrator.ENTIHOME);
    entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
    entityLabel$ = locator.getProperty(EntityHandler.ENTITY_LABEL);
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(entityLabel$);
    locator = new Properties();
    locator.setProperty(Locator.LOCATOR_TITLE, STRUCTURE);
    String icon$ = Support.readHandlerIcon(null, getClass(), "tree.png");
    locator.setProperty(Locator.LOCATOR_ICON, icon$);
    root.setUserObject(Locator.toString(locator));
    DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode(entityLabel$);
    root.add(parentNode);
    Entigrator entigrator = console.getEntigrator(entihome$);
    Sack parent = entigrator.getEntityAtKey(entityKey$);
    String parentLocator$ = EntityHandler.getEntityLocator(entigrator, parent);
    parentNode.setUserObject(parentLocator$);
    addChildren(parentNode);
    tree = new JTree(root);
    tree.addTreeSelectionListener(new SelectionListener());
    tree.setShowsRootHandles(true);
    tree.setCellRenderer(new NodeRenderer());
    tree.addMouseListener(new MousePopupListener());
    scrollPane.getViewport().add(tree);
    expandTree(tree, true);
    return this;
}

From source file:EditorPaneExample16.java

public TreeNode buildHeadingTree(Document doc) {
    String title = (String) doc.getProperty(Document.TitleProperty);
    if (title == null) {
        title = "[No title]";
    }//from ww  w .j  av a 2s.c o  m
    Heading rootHeading = new Heading(title, 0, 0);
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(rootHeading);

    DefaultMutableTreeNode lastNode[] = new DefaultMutableTreeNode[7];
    int lastLevel = 0;
    lastNode[lastLevel] = rootNode;

    if (doc instanceof HTMLDocument) {
        Element elem = doc.getDefaultRootElement();
        ElementIterator iterator = new ElementIterator(elem);
        Heading heading;

        while ((heading = getNextHeading(doc, iterator)) != null) {
            // Add the node to the tree
            DefaultMutableTreeNode hNode = new DefaultMutableTreeNode(heading);
            int level = heading.getLevel();

            if (level > lastLevel) {
                for (int i = lastLevel + 1; i < level; i++) {
                    lastNode[i] = null;
                }
                lastNode[lastLevel].add(hNode);
            } else {
                int prevLevel = level - 1;
                while (prevLevel >= 0) {
                    if (lastNode[prevLevel] != null) {
                        break;
                    }
                    lastNode[prevLevel] = null;
                    prevLevel--;
                }
                lastNode[prevLevel].add(hNode);
            }
            lastNode[level] = hNode;
            lastLevel = level;
        }
    }
    return rootNode;
}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

private void setSearchedDocumentsOnTree(DefaultMutableTreeNode top, ArrayList<DocPath> docPaths)
        throws ExceptionLP, RepositoryException, Throwable {
    if (docPaths.size() == 0)
        treeModel.insertNodeInto(new DefaultMutableTreeNode("..."), top, 0);

    DefaultMutableTreeNode treeNode;
    for (DocPath path : docPaths) {
        treeNode = top;//  ww w  .  java  2  s.com
        boolean firstNode = true;
        for (DocNodeBase node : path.asDocNodeList()) {
            if (firstNode) {
                firstNode = false;
            } else {
                int i = getDocNodeChildPos(node, treeNode);
                if (i == -1) {
                    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node);
                    treeModel.insertNodeInto(newNode, treeNode, treeNode.getChildCount());
                    treeNode = newNode;
                } else {
                    treeNode = (DefaultMutableTreeNode) treeNode.getChildAt(i);
                }
            }
        }
    }
    tree.setModel(treeModel);
}

From source file:ca.sqlpower.architect.swingui.enterprise.SecurityPanel.java

private void refreshTree() {
    tree.setModel(new DefaultTreeModel(rootNode));
    usersNode.removeAllChildren();/*from w ww.ja v  a 2 s  . c o  m*/
    for (User user : securityWorkspace.getChildren(User.class)) {
        usersNode.add(new DefaultMutableTreeNode(user));
    }
    groupsNode.removeAllChildren();
    for (Group group : securityWorkspace.getChildren(Group.class)) {
        groupsNode.add(new DefaultMutableTreeNode(group));
    }
    tree.expandPath(new TreePath(usersNode.getPath()));
    tree.expandPath(new TreePath(groupsNode.getPath()));
}

From source file:SAXTreeValidator.java

/**
 * <p>//  w  w w .  j  a  v  a2  s  .c om
 *   This reports character data (within an element).
 * </p>
 *
 * @param ch <code>char[]</code> character array with character data
 * @param start <code>int</code> index in array where data starts.
 * @param length <code>int</code> index in array where data ends.
 * @throws <code>SAXException</code> when things go wrong
 */
public void characters(char[] ch, int start, int length) throws SAXException {

    String s = new String(ch, start, length);
    DefaultMutableTreeNode data = new DefaultMutableTreeNode("Character Data: '" + s + "'");
    current.add(data);
}

From source file:edu.ucla.stat.SOCR.chart.ChartTree.java

/**
 * A node for various area charts.//from   w w w.  java2s  .c  o  m
 * 
 * @return The node.
 */
private MutableTreeNode createAreaChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Area Charts");

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.AreaChartDemo1", "AreaChartDemo1"));
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.StackedXYAreaChartDemo1", "StackedXYAreaChartDemo1"));
    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.StackedXYAreaChartDemo2", "StackedXYAreaChartDemo2"));
    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.XYAreaChartDemo1", "XYAreaChartDemo1"));
    DefaultMutableTreeNode n5 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.XYAreaChartDemo2", "XYAreaChartDemo2"));

    root.add(n1);
    root.add(n2);
    root.add(n3);
    root.add(n4);
    root.add(n5);

    return root;
}