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:net.jradius.client.gui.JRadiusSimulator.java

/**
 * This method initializes attributeTree
 * //from   ww w.j  a  va 2  s .  com
 * @return javax.swing.JTree
 */
private JTree getAttributeTree() {
    if (attributeTree == null) {
        DefaultMutableTreeNode top = new DefaultMutableTreeNode("Attribute Dictionary");
        createAttributeTreeNodes(top);
        attributeTree = new JTree(top);
    }
    return attributeTree;
}

From source file:net.jradius.client.gui.JRadiusSimulator.java

private void createAttributeTreeNodes(DefaultMutableTreeNode top) {
    DefaultMutableTreeNode standardTree = new DefaultMutableTreeNode("Standard Attributes");
    DefaultMutableTreeNode vsaTree = new DefaultMutableTreeNode("Vendor Specific Attributes");
    addAttributesToTable(standardTree, AttributeFactory.getAttributeNameMap(), true);
    top.add(standardTree);//from www . j a  v  a2  s.  c o  m

    Map<Long, VendorValue> vendors = AttributeFactory.getVendorValueMap();
    LinkedHashMap<String, Map<String, Class<?>>> dictList = new LinkedHashMap<String, Map<String, Class<?>>>();
    for (Iterator<VendorValue> i = vendors.values().iterator(); i.hasNext();) {
        VendorValue vendor = i.next();
        try {
            VSADictionary dict = (VSADictionary) vendor.getDictClass().newInstance();
            String vendorName = dict.getVendorName();
            Map<String, Class<?>> map = vendor.getAttributeNameMap();
            System.out.println("Loading vendor " + vendorName + " with " + map.size() + " attributes.");
            dictList.put(vendorName, map);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    LinkedList<String> list = new LinkedList<String>(dictList.keySet());
    Collections.sort(list);
    for (Iterator<String> i = list.iterator(); i.hasNext();) {
        String vendorName = i.next();
        DefaultMutableTreeNode vsaNode = new DefaultMutableTreeNode(vendorName);
        addAttributesToTable(vsaNode, dictList.get(vendorName), false);
        vsaTree.add(vsaNode);
    }
    top.add(vsaTree);
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void addParameterToTree(final AvailableParameter[] parameters, final ParameterCombinationGUI pcGUI) {
    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();
    final DefaultTreeModel treeModel = (DefaultTreeModel) pcGUI.tree.getModel();
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();

    for (final AvailableParameter parameter : parameters) {
        listModel.removeElement(parameter);
        final ParameterInfo selectedInfo = parameter.info;
        final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(
                new ParameterInATree(selectedInfo, currentModelHandler.getModelClass()));
        treeModel.insertNodeInto(newNode, root, root.getChildCount());

        if (selectedInfo instanceof SubmodelInfo) {
            final SubmodelInfo sInfo = (SubmodelInfo) selectedInfo;
            if (sInfo.getActualType() != null) {
                addSubParametersToTree(sInfo, pcGUI.tree, newNode);
                pcGUI.tree.expandPath(new TreePath(treeModel.getPathToRoot(newNode)));
            }/*from w ww  .jav  a2s  .  c o m*/
        }
    }

    updateNumberOfRuns();
    pcGUI.tree.expandPath(new TreePath(treeModel.getPathToRoot(root)));
}

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

private MutableTreeNode createAnnotationsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Annotations");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("AnnotationDemo1", "AnnotationDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("AnnotationDemo2", "AnnotationDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("CategoryPointerAnnotationDemo1", "CategoryPointerAnnotationDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("XYBoxAnnotationDemo1", "XYBoxAnnotationDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("XYPolygonAnnotationDemo1", "XYPolygonAnnotationDemo1.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    return defaultmutabletreenode;
}

From source file:lcmc.gui.ClusterBrowser.java

/** Updates VM nodes. */
public void updateVMS() {
    Tools.debug(this, "VM status update", 1);
    final Set<String> domainNames = new TreeSet<String>();
    for (final Host host : getClusterHosts()) {
        final VMSXML vxml = getVMSXML(host);
        if (vxml != null) {
            domainNames.addAll(vxml.getDomainNames());
        }// ww w. j  a v a 2 s. c o  m
    }
    final List<DefaultMutableTreeNode> nodesToRemove = new ArrayList<DefaultMutableTreeNode>();
    boolean nodeChanged = false;
    final List<VMSVirtualDomainInfo> currentVMSVDIs = new ArrayList<VMSVirtualDomainInfo>();

    mVMSUpdateLock.lock();
    if (vmsNode != null) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> ee = vmsNode.children();
        while (ee.hasMoreElements()) {
            final DefaultMutableTreeNode node = ee.nextElement();
            final VMSVirtualDomainInfo vmsvdi = (VMSVirtualDomainInfo) node.getUserObject();
            if (domainNames.contains(vmsvdi.toString())) {
                /* keeping */
                currentVMSVDIs.add(vmsvdi);
                domainNames.remove(vmsvdi.toString());
                vmsvdi.updateParameters(); /* update old */
            } else {
                if (!vmsvdi.getResource().isNew()) {
                    /* remove not existing vms */
                    vmsvdi.setNode(null);
                    nodesToRemove.add(node);
                    nodeChanged = true;
                }
            }
        }
    }

    /* remove nodes */
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            for (final DefaultMutableTreeNode node : nodesToRemove) {
                node.removeFromParent();
            }
        }
    });

    if (vmsNode == null) {
        mVMSUpdateLock.unlock();
        return;
    }
    for (final String domainName : domainNames) {
        @SuppressWarnings("unchecked")
        final Enumeration<DefaultMutableTreeNode> e = vmsNode.children();
        int i = 0;
        while (e.hasMoreElements()) {
            final DefaultMutableTreeNode node = e.nextElement();
            final VMSVirtualDomainInfo vmsvdi = (VMSVirtualDomainInfo) node.getUserObject();
            final String name = vmsvdi.getName();
            if (domainName != null && name != null && domainName.compareTo(vmsvdi.getName()) < 0) {
                break;
            }
            i++;
        }
        /* add new vms nodes */
        final VMSVirtualDomainInfo vmsvdi = new VMSVirtualDomainInfo(domainName, this);
        currentVMSVDIs.add(vmsvdi);
        final DefaultMutableTreeNode resource = new DefaultMutableTreeNode(vmsvdi);
        setNode(resource);
        vmsvdi.updateParameters();
        final int index = i;
        Tools.invokeAndWait(new Runnable() {
            public void run() {
                vmsNode.insert(resource, index);
            }
        });
        nodeChanged = true;
    }
    mVMSUpdateLock.unlock();
    if (nodeChanged) {
        reload(vmsNode, false);
    }
    for (final ServiceInfo si : getExistingServiceList(null)) {
        final VMSVirtualDomainInfo vmsvdi = si.connectWithVMS();
        if (vmsvdi != null) {
            /* keep the not connected ones.*/
            currentVMSVDIs.remove(vmsvdi);
        }
    }
    for (final VMSVirtualDomainInfo vmsvdi : currentVMSVDIs) {
        vmsvdi.setUsedByCRM(false);
    }
    final VMSInfo vmsi = (VMSInfo) vmsNode.getUserObject();
    if (vmsi != null) {
        vmsi.updateTable(VMSInfo.MAIN_TABLE);
    }
}

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

private MutableTreeNode createCrosshairChartsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Crosshairs");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("CrosshairDemo1", "CrosshairDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("CrosshairDemo2", "CrosshairDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("CrosshairDemo3", "CrosshairDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("CrosshairDemo4", "CrosshairDemo4.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    return defaultmutabletreenode;
}

From source file:net.jradius.client.gui.JRadiusSimulator.java

private void addAttributesToTable(DefaultMutableTreeNode node, Map<String, Class<?>> map, boolean skipVSA) {
    LinkedHashMap<String, String> attributeList = new LinkedHashMap<String, String>();
    for (Iterator<Map.Entry<String, Class<?>>> i = map.entrySet().iterator(); i.hasNext();) {
        Map.Entry<String, Class<?>> entry = i.next();
        String type = entry.getKey();
        Class<?> clazz = entry.getValue();
        try {//  w w w .  j av  a  2 s . co m
            RadiusAttribute attribute = (RadiusAttribute) clazz.newInstance();
            if (!skipVSA || (!(attribute instanceof VSAttribute) && attribute.getType() <= 255)) {
                String attributeName = attribute.getAttributeName();
                if (attributeName.equals("Vendor-Specific"))
                    continue;
                if (attributeName.startsWith("X-Ascend-"))
                    continue;
                attributeList.put(type, attributeName);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    LinkedList<String> list = new LinkedList<String>(attributeList.keySet());
    Collections.sort(list);
    for (Iterator<String> i = list.iterator(); i.hasNext();) {
        node.add(new DefaultMutableTreeNode(attributeList.get(i.next())));
    }
}

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

private MutableTreeNode createDynamicChartsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Dynamic Charts");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("DynamicDataDemo1", "DynamicDataDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("DynamicDataDemo2", "DynamicDataDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("DynamicDataDemo3", "DynamicDataDemo3.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    return defaultmutabletreenode;
}

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

private MutableTreeNode createItemLabelsNode() {
    DefaultMutableTreeNode defaultmutabletreenode = new DefaultMutableTreeNode("Item Labels");
    DefaultMutableTreeNode defaultmutabletreenode1 = new DefaultMutableTreeNode(
            new DemoDescription("ItemLabelDemo1", "ItemLabelDemo1.java"));
    DefaultMutableTreeNode defaultmutabletreenode2 = new DefaultMutableTreeNode(
            new DemoDescription("ItemLabelDemo2", "ItemLabelDemo2.java"));
    DefaultMutableTreeNode defaultmutabletreenode3 = new DefaultMutableTreeNode(
            new DemoDescription("ItemLabelDemo3", "ItemLabelDemo3.java"));
    DefaultMutableTreeNode defaultmutabletreenode4 = new DefaultMutableTreeNode(
            new DemoDescription("ItemLabelDemo4", "ItemLabelDemo4.java"));
    DefaultMutableTreeNode defaultmutabletreenode5 = new DefaultMutableTreeNode(
            new DemoDescription("ItemLabelDemo5", "ItemLabelDemo5.java"));
    defaultmutabletreenode.add(defaultmutabletreenode1);
    defaultmutabletreenode.add(defaultmutabletreenode2);
    defaultmutabletreenode.add(defaultmutabletreenode3);
    defaultmutabletreenode.add(defaultmutabletreenode4);
    defaultmutabletreenode.add(defaultmutabletreenode5);
    return defaultmutabletreenode;
}

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

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

            if (geneName == null || geneName.trim().isEmpty()) {
                throw new WizardLoadingException(true,
                        "missing attribute '" + WizardSettingsManager.NAME + "' at node: " + GENE);
            }//from www.  ja v  a2  s . c  o m

            final ParameterInfo info = findParameterInfo(params, geneName.trim());
            if (info != null) {
                final ParameterOrGene userObj = initializeUserObjectFromGene(geneElement, info);
                final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(userObj);
                getChromosomeTree().insertNodeInto(newNode, root, root.getChildCount());
            } else {
                throw new WizardLoadingException(false, "Unrecognized gene: " + geneName + " (ignored)");
            }
        }
    }
}