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:com.lp.client.frame.component.PanelDokumentenablage.java

@Override
public void treeExpanded(TreeExpansionEvent event) {
    if (treeInProgress)
        return;//from w ww.j  a  v a  2  s  .  c  om
    setBusy(true);

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) node.getFirstChild();
    TreePath selectionPath = tree.getSelectionPath();
    if (MUST_LOAD_CHILDREN.equals(firstChild.getUserObject())) {

        node.removeAllChildren();
        DocPath expandPath = new DocPath();

        for (Object obj : node.getUserObjectPath()) {
            try {
                expandPath.add((DocNodeBase) obj);
            } catch (ClassCastException ex) {
                expandPath.add(new DocNodeLiteral(obj.toString()));
            }
        }

        List<DocNodeBase> childList;
        try {
            childList = DelegateFactory.getInstance().getJCRDocDelegate()
                    .getDocNodeChildrenFromNode(expandPath);
            setDocNodesOnTree(node, childList, expandPath);
        } catch (Throwable e) {
            treeModel.insertNodeInto(new DefaultMutableTreeNode(e), node, 0);
        }
        tree.expandPath(new TreePath(node.getPath()));
        tree.setSelectionPath(selectionPath);
    }
    setBusy(false);
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createLegendNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Legends");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("LegendWrapperDemo1", "LegendWrapperDemo1.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    return defaultmutabletreenode;
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createMarkersNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Markers");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("CategoryMarkerDemo1", "CategoryMarkerDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("CategoryMarkerDemo2", "CategoryMarkerDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("MarkerDemo1", "MarkerDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("MarkerDemo2", "MarkerDemo2.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    return defaultmutabletreenode;
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createOrientationNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Plot Orientation");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("PlotOrientationDemo1", "PlotOrientationDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("PlotOrientationDemo2", "PlotOrientationDemo2.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    return defaultmutabletreenode;
}

From source file:ai.aitia.meme.paramsweep.intellisweepPlugin.JgapGAPlugin.java

private void loadParameter(final NodeList parameterList, final List<ParameterInfo> params,
        final DefaultMutableTreeNode root) throws WizardLoadingException {
    if (parameterList != null) {
        for (int i = 0; i < parameterList.getLength(); ++i) {
            final Element parameterElement = (Element) parameterList.item(i);
            final String paramName = parameterElement.getAttribute(WizardSettingsManager.NAME);

            if (paramName == null || paramName.trim().isEmpty()) {
                throw new WizardLoadingException(true,
                        "missing attribute '" + WizardSettingsManager.NAME + "' at node: " + PARAMETER);
            }//from  ww w .  j ava 2s .c  om

            final ParameterInfo info = findParameterInfo(params, paramName.trim());
            if (info != null) {
                final NodeList content = parameterElement.getChildNodes();
                if (content == null || content.getLength() == 0) {
                    throw new WizardLoadingException(true, "missing content at node: " + PARAMETER);
                }
                final String parameterValue = ((Text) content.item(0)).getNodeValue().trim();
                Object value;
                if (info.getType().equals("File") && parameterValue.isEmpty()) {
                    value = new File("");
                } else {
                    value = ParameterInfo.getValue(parameterValue, info.getJavaType());
                }
                info.setValue(value);

                final ParameterOrGene userObj = new ParameterOrGene(info);
                final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObj);
                getChromosomeTree().insertNodeInto(newNode, root, root.getChildCount());
            } else {
                throw new WizardLoadingException(false, "Unrecognized gene: " + paramName + " (ignored)");
            }
        }
    }
}

From source file:it.imtech.metadata.MetaUtility.java

/**
 * Aggiunge il pannello delle classificazioni all'interfaccia dei metadati
 *
 * @param innerPanel Pannello sul quale aggiungere i metadati
 * @param kv Valori dei metadati/*from www .  j  a va 2s .com*/
 */
private void addClassification(JPanel innerPanel, Integer kv, final String sequence, final String panelname)
        throws Exception {
    try {
        ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                Globals.loader);

        DefaultMutableTreeNode hierarchy = new DefaultMutableTreeNode("root");
        selected = null;
        String selectedPath = "";

        String link = selectedClassificationList.get(panelname + "---" + sequence);

        recursiveOefosTreeviewBuild(hierarchy, oefos.get(link), sequence, panelname);
        DefaultTreeModel model = new DefaultTreeModel(hierarchy);

        final JTree tree = new JTree(model);
        tree.setRootVisible(false);

        if (selected != null) {
            TreePath selpath = new TreePath(selected.getPath());
            tree.setSelectionPath(selpath);

            Object[] nodes = selpath.getPath();

            for (int i = 1; i < nodes.length; i++) {
                selectedPath += nodes[i].toString();
                selectedPath += (i != nodes.length - 1) ? "/" : "";
            }
        }

        tree.setName("MID_" + Integer.toString(kv) + "---" + sequence);
        tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

        tree.addTreeSelectionListener(new TreeSelectionListener() {

            public void valueChanged(TreeSelectionEvent e) {
                try {
                    setOEFOS(tree, sequence, panelname);
                } catch (Exception ex) {
                    logger.error(ex.getMessage());
                }
            }
        });

        javax.swing.JScrollPane tree_scroller = new javax.swing.JScrollPane();
        tree_scroller
                .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        tree_scroller.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        tree_scroller.setViewportView(tree);
        tree_scroller.setBorder(null);

        innerPanel.add(tree_scroller, "wrap, width 100:800:800");

        JPanel iPanel = new JPanel(new MigLayout());
        iPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                Utility.getBundleString("choose2", bundle), TitledBorder.LEFT, TitledBorder.TOP));
        JLabel label = new JLabel();
        label.setName("classification_path" + "---" + sequence);
        label.setText(selectedPath);
        iPanel.add(label, "wrap, growx, height 30:30:30");

        innerPanel.add(iPanel, "wrap, width 100:800:800");

        findLastClassification(panelname);

    } catch (Exception ex) {
        logger.error(ex.getMessage());
        throw new Exception("Exception in addClassification: " + ex.getStackTrace() + "\n");
    }
}

From source file:lcmc.gui.ClusterBrowser.java

/** Updates networks. */
private void updateNetworks() {
    if (networksNode != null) {
        DefaultMutableTreeNode resource;
        final Network[] networks = cluster.getCommonNetworks();
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                networksNode.removeAllChildren();
            }//from w  ww . j  a  va2  s . c om
        });
        for (int i = 0; i < networks.length; i++) {
            resource = new DefaultMutableTreeNode(new NetworkInfo(networks[i].getName(), networks[i], this));
            setNode(resource);
            addNode(networksNode, resource);
        }
        reload(networksNode, false);
    }
}

From source file:org.jfree.chart.demo.SuperDemo.java

private MutableTreeNode createExperimentalNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Experimental");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("DialDemo1", "DialDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("DialDemo2", "DialDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("DialDemo3", "DialDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("DialDemo4", "DialDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("DialDemo5", "DialDemo5.java"));
    DefaultMutableTreeNode defaultmutabletreenode6 = new DefaultMutableTreeNode(
            new DemoDescription("LogAxisDemo1", "LogAxisDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode7 = new DefaultMutableTreeNode(
            new DemoDescription("XYTitleAnnotationDemo1", "XYTitleAnnotationDemo1.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    defaultmutabletreenode.add(defaultmutabletreenode6);
    defaultmutabletreenode.add(defaultmutabletreenode7);
    return defaultmutabletreenode;
}

From source file:GUI.MainWindow.java

private void AddToPersonalVulnsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddToPersonalVulnsActionPerformed

    System.out.println("Add to personal vulns section");

    DefaultTreeModel dtm = (DefaultTreeModel) VulnTree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) dtm.getRoot();
    TreePath[] paths = VulnTree.getSelectionPaths();

    // If there are no paths then no nodes have been selected, ignore the request
    if (paths == null) {
        return;/*from   ww w .ja v a 2  s . c o m*/
    }

    DefaultTreeModel personaldtm = (DefaultTreeModel) this.personal_vulns_window.PersonalVulnsTree.getModel();
    DefaultMutableTreeNode personalroot = (DefaultMutableTreeNode) personaldtm.getRoot();

    // For each selected node
    for (int i = 0; i < paths.length; i++) {
        TreePath path = paths[i]; // Get the node
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        Object obj = node.getUserObject();
        // Make sure it has an object of type Vulnerability
        if (obj != null && obj instanceof Vulnerability) {
            Vulnerability vuln = (Vulnerability) obj;
            if (vuln.containsIdentifier("24d459a81449d721c8f9a86c2913034", "ReportCompiler")) {
                JOptionPane.showMessageDialog(null,
                        "Attempting to add a personal vuln with the title 'NEW' has a dangerous identifier, please change the title first\n"
                                + vuln.getTitle());
                return;
            }
            // Clone that vulnerability so it isn't the same object that is in the main tree
            Vulnerability newvuln = new Vulnerability();
            newvuln.setTitle(vuln.getTitle());
            newvuln.setRecommendation(vuln.getRecommendation());
            newvuln.setDescription(vuln.getDescription());
            newvuln.cloneReferences(vuln);
            newvuln.cloneRisk(vuln);
            newvuln.cloneIdentifiers(vuln);
            // Add the clone to the personal vulns database
            // TODO do something clever where a vuln exists that has an ID in this one.
            if (new TreeUtils().OkToaddToPersonalVulns(personalroot, newvuln)) {
                personalroot.add(new DefaultMutableTreeNode(newvuln));
                System.out.println("Added to personal vulns: " + newvuln);
                System.out.println("Hosts: " + newvuln.getAffectedHosts().size());
            } else {
                JOptionPane.showMessageDialog(null, "A personal vuln exists that may match that already");
            }

        }
    }

    // Sort the tree
    personalroot = new TreeUtils().sortVulns(personalroot);
    // Update the model
    personaldtm.setRoot(personalroot);

    try {

        // Save the tree again
        new SaveFileExporter().save(this.personal_vulns_window.person_vulns_file, personalroot);
        System.out.println(
                "Personal Vulns Saved: " + this.personal_vulns_window.person_vulns_file.getAbsolutePath());
    } catch (Exception ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:it.isislab.dmason.tools.batch.BatchWizard.java

private void createNodes(DefaultMutableTreeNode top, ArrayList<Param> paramList) {

    //generalParams = new DefaultMutableTreeNode("General Params");
    //simParams = new DefaultMutableTreeNode("Simulation Params");

    top.add(generalParams);//ww w. ja v  a2 s.  c om
    top.add(simParams);

    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("Width", "int", 1, "100")));
    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("Height", "int", 1, "100")));
    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("MaxDistance", "int", 1, "100")));
    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("NumAgents", "int", 1, "15")));
    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("Rows", "int", 1, "1")));
    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("Columns", "int", 1, "2")));
    generalParams.add(new DefaultMutableTreeNode(new ParamFixed("MaxStep", "long", 1, "1000")));

    for (Param param : paramList) {

        //p = new DefaultMutableTreeNode(param);
        // p.add(new DefaultMutableTreeNode(param));
        simParams.add(new DefaultMutableTreeNode(param));
    }

}