Example usage for javax.swing.tree DefaultMutableTreeNode add

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

Introduction

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

Prototype

public void add(MutableTreeNode newChild) 

Source Link

Document

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.

Usage

From source file:jeplus.JEPlusProject.java

/**
 * Add a list of parameter items as a branch at the given root node
 * @param root Root where the new branch is attached
 * @param list The list of parameter items
 *//*from  w  w w.ja  v  a2s.c o m*/
public void addParameterListAsBranch(DefaultMutableTreeNode root, List<ParameterItem> list) {
    if (list != null && list.size() > 0) {
        if (root == null) { // replace current tree
            ParamTree = new DefaultMutableTreeNode(list.get(0));
            DefaultMutableTreeNode current = ParamTree;
            for (int i = 1; i < list.size(); i++) {
                DefaultMutableTreeNode newnode = new DefaultMutableTreeNode(list.get(i));
                current.add(newnode);
                current = newnode;
            }
        } else {
            DefaultMutableTreeNode current = root;
            for (ParameterItem item : list) {
                DefaultMutableTreeNode newnode = new DefaultMutableTreeNode(item);
                current.add(newnode);
                current = newnode;
            }
        }
    }
}

From source file:it.cnr.icar.eric.client.ui.swing.ConceptsTreeModel.java

/** 
 * Implementation for expandTree. Option to fire no events.
 *///ww w  . j  a  va  2  s.  c om
private void expandTree(final DefaultMutableTreeNode node, final int depth, boolean quiet) {
    // Warning: this method should be executed by a SwingWorker

    Object userObj = node.getUserObject();

    if (!(userObj instanceof NodeInfo)) {
        return;
    }

    final NodeInfo nodeInfo = (NodeInfo) userObj;
    if (nodeInfo.loaded) {
        return;
    }

    nodeInfo.loaded = true;
    Collection<?> childConcepts = null;
    try {
        childConcepts = getChildConcepts(nodeInfo.obj);
    } catch (JAXRException e) {
        log.error(e);
    }

    if (childConcepts != null) {
        Iterator<?> iter = childConcepts.iterator();
        int newDepth = depth - 1;

        while (iter.hasNext()) { // expandTree()
            NodeInfo newNodeInfo = new NodeInfo();
            Concept childConcept = (Concept) iter.next();
            newNodeInfo.obj = childConcept;
            newNodeInfo.loaded = false;
            ConceptsTreeNode newNode = new ConceptsTreeNode(newNodeInfo);

            // insertNodeInto(newNode, node, node.getChildCount());
            node.add(newNode);

            if (newDepth != 0) {
                expandTree(newNode, newDepth, quiet);
            }
        }
        if (!quiet) {
            nodeStructureChanged(node);
        }
    }
}

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

private void addChildren(DefaultMutableTreeNode parentNode) {
    try {/*from   w  w  w .  j  ava  2  s  . co m*/
        String locator$ = (String) parentNode.getUserObject();
        Properties locator = Locator.toProperties(locator$);
        String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
        String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
        Entigrator entigrator = console.getEntigrator(entihome$);
        Sack parent = entigrator.getEntityAtKey(entityKey$);
        String[] sa = entigrator.ent_listComponents(parent);
        if (sa != null) {
            Sack child;
            String childLocator$;
            DefaultMutableTreeNode childNode;
            for (String aSa : sa) {
                child = entigrator.getEntityAtKey(aSa);
                childLocator$ = EntityHandler.getEntityLocator(entigrator, child);
                childNode = new DefaultMutableTreeNode();
                childNode.setUserObject(childLocator$);
                parentNode.add(childNode);
                addChildren(childNode);
            }
        }
    } catch (Exception e) {
        Logger.getLogger(JEntityStructurePanel.class.getName()).severe(e.toString());
    }
}

From source file:com.pironet.tda.AbstractDumpParser.java

/**
 * check threads in given thread dump and add appropriate
 * custom categories (if any defined)./*from  w  w  w.  j  av a  2s .  co m*/
 *
 * @param threadDump the thread dump info object.
 */
public void addCustomCategories(DefaultMutableTreeNode threadDump) {
    ThreadDumpInfo tdi = (ThreadDumpInfo) threadDump.getUserObject();
    Category threads = tdi.getThreads();
    ListModel cats = PrefManager.get().getCategories();
    for (int i = 0; i < cats.getSize(); i++) {
        final Category cat = new TableCategory(((CustomCategory) cats.getElementAt(i)).getName(),
                IconFactory.CUSTOM_CATEGORY);
        for (int j = 0; j < threads.getNodeCount(); j++) {
            Iterator filterIter = ((CustomCategory) cats.getElementAt(i)).iterOfFilters();
            boolean matches = true;
            ThreadInfo ti = (ThreadInfo) threads.getNodeAt(j).getUserObject();
            while (matches && filterIter.hasNext()) {
                Filter filter = (Filter) filterIter.next();
                matches = filter.matches(ti, true);
            }

            if (matches) {
                cat.addToCatNodes(new DefaultMutableTreeNode(ti));
            }
        }
        if (cat.getNodeCount() > 0) {
            cat.setName(cat.getName() + " (" + cat.getNodeCount() + " Threads overall)");
            threadDump.add(new DefaultMutableTreeNode(cat));
        }
    }
}

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

private MutableTreeNode createXYChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("XY Charts");

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.XYLineAndShapeRendererDemo1", "XYLineAndShapeRendererDemo1"));
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.XYSeriesDemo1", "XYSeriesDemo1"));
    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.XYSeriesDemo2", "XYSeriesDemo2"));
    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.XYSeriesDemo3", "XYSeriesDemo3"));
    DefaultMutableTreeNode n5 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.WindChartDemo1", "WindChartDemo1"));

    root.add(n1);
    root.add(n2);/* w w  w . j a  va2 s.  c  o m*/
    root.add(n3);
    root.add(n4);
    root.add(n5);

    return root;
}

From source file:org.dcm4chee.dashboard.ui.filesystem.FileSystemPanel.java

@Override
public void onBeforeRender() {
    super.onBeforeRender();

    try {//from w w  w  .  ja  v  a 2  s.c  om
        DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new FileSystemModel());
        for (String groupname : DashboardDelegator
                .getInstance(
                        (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName")))
                .listAllFileSystemGroups()) {
            FileSystemModel group = new FileSystemModel();

            int index = groupname.indexOf("group=");
            if (index < 0)
                continue;
            group.setDirectoryPath(groupname.substring(index + 6));
            group.setDescription(groupname + ",AET=" + DashboardDelegator.getInstance(
                    (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName")))
                    .getDefaultRetrieveAETitle(groupname));
            group.setGroup(true);
            DefaultMutableTreeNode groupNode;
            rootNode.add(groupNode = new DefaultMutableTreeNode(group));

            File[] fileSystems = null;
            try {
                fileSystems = DashboardDelegator.getInstance(
                        (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName")))
                        .listFileSystemsOfGroup(groupname);
            } catch (MBeanException mbe) {
            }

            if (!((fileSystems == null) || (fileSystems.length == 0))) {
                long minBytesFree = DashboardDelegator.getInstance(
                        (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName")))
                        .getMinimumFreeDiskSpaceOfGroup(groupname);

                for (File file : fileSystems) {
                    FileSystemModel fsm = new FileSystemModel();
                    fsm.setDirectoryPath(file.getName());
                    fsm.setDescription(
                            file.getName().startsWith("tar:") ? file.getName() : file.getAbsolutePath());
                    fsm.setOverallDiskSpace(file.getTotalSpace() / FileSystemModel.MEGA);
                    fsm.setUsedDiskSpace(
                            Math.max((file.getTotalSpace() - file.getUsableSpace()) / FileSystemModel.MEGA, 0));
                    fsm.setFreeDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0));
                    fsm.setMinimumFreeDiskSpace(
                            fsm.getOverallDiskSpaceLong() == 0 ? 0 : minBytesFree / FileSystemModel.MEGA);
                    fsm.setUsableDiskSpace(
                            Math.max((file.getUsableSpace() - minBytesFree) / FileSystemModel.MEGA, 0));
                    fsm.setRemainingTime(Math.max((file.getUsableSpace() - minBytesFree) / DashboardDelegator
                            .getInstance((((BaseWicketApplication) getApplication())
                                    .getInitParameter("DashboardServiceName")))
                            .getExpectedDataVolumePerDay(groupname), 0));

                    group.setOverallDiskSpace(group.getOverallDiskSpaceLong() + fsm.getOverallDiskSpaceLong());
                    group.setUsedDiskSpace(group.getUsedDiskSpaceLong() + fsm.getUsedDiskSpaceLong());
                    group.setFreeDiskSpace(group.getFreeDiskSpaceLong() + fsm.getFreeDiskSpaceLong());
                    group.setMinimumFreeDiskSpace(
                            group.getMinimumFreeDiskSpaceLong() + fsm.getMinimumFreeDiskSpaceLong());
                    group.setUsableDiskSpace(group.getUsableDiskSpaceLong() + fsm.getUsableDiskSpaceLong());
                    group.setRemainingTime(group.getRemainingTime() + fsm.getRemainingTime());
                    groupNode.add(new DefaultMutableTreeNode(fsm));
                }
            }
        }

        String[] otherFileSystems = DashboardDelegator
                .getInstance(
                        (((BaseWicketApplication) getApplication()).getInitParameter("DashboardServiceName")))
                .listOtherFileSystems();
        if (otherFileSystems != null && otherFileSystems.length > 0) {

            FileSystemModel group = new FileSystemModel();
            group.setDirectoryPath(
                    new ResourceModel("dashboard.filesystem.group.other").wrapOnAssignment(this).getObject());
            group.setGroup(true);
            group.setRemainingTime(-1);
            DefaultMutableTreeNode groupNode;
            rootNode.add(groupNode = new DefaultMutableTreeNode(group));

            for (String otherFileSystem : otherFileSystems) {
                File file = new File(otherFileSystem);
                FileSystemModel fsm = new FileSystemModel();
                fsm.setDirectoryPath(file.getAbsolutePath());
                fsm.setDescription(file.getName().startsWith("tar:") ? file.getName() : file.getAbsolutePath());
                fsm.setOverallDiskSpace(file.getTotalSpace() / FileSystemModel.MEGA);
                fsm.setUsedDiskSpace(
                        Math.max((file.getTotalSpace() - file.getUsableSpace()) / FileSystemModel.MEGA, 0));
                fsm.setFreeDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0));
                fsm.setMinimumFreeDiskSpace(fsm.getOverallDiskSpaceLong() / FileSystemModel.MEGA);
                fsm.setUsableDiskSpace(Math.max(file.getUsableSpace() / FileSystemModel.MEGA, 0));
                fsm.setRemainingTime(-1);

                group.setOverallDiskSpace(group.getOverallDiskSpaceLong() + fsm.getOverallDiskSpaceLong());
                group.setUsedDiskSpace(group.getUsedDiskSpaceLong() + fsm.getUsedDiskSpaceLong());
                group.setFreeDiskSpace(group.getFreeDiskSpaceLong() + fsm.getFreeDiskSpaceLong());
                group.setMinimumFreeDiskSpace(
                        group.getMinimumFreeDiskSpaceLong() + fsm.getMinimumFreeDiskSpaceLong());
                group.setUsableDiskSpace(group.getUsableDiskSpaceLong() + fsm.getUsableDiskSpaceLong());
                group.setVisible(false);
                groupNode.add(new DefaultMutableTreeNode(fsm));
            }
        }

        FileSystemTreeTable fileSystemTreeTable = new FileSystemTreeTable("filesystem-tree-table",
                new DefaultTreeModel(rootNode),
                new IColumn[] {
                        new PropertyTreeColumn(new ColumnLocation(Alignment.LEFT, 25, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.name")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.directoryPath"),
                        new ImageRenderableColumn(new ColumnLocation(Alignment.MIDDLE, 30, Unit.PROPORTIONAL),
                                new ResourceModel("dashboard.filesystem.table.column.image")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.directoryPath"),
                        new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.overall")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.overallDiskSpaceString"),
                        new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.used")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.usedDiskSpaceString"),
                        new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.free")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.freeDiskSpaceString"),
                        new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.minimumfree")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.minimumFreeDiskSpaceString"),
                        new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 7, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.usable")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.usableDiskSpaceString"),
                        new PropertyRenderableColumn(new ColumnLocation(Alignment.RIGHT, 10, Unit.PERCENT),
                                new ResourceModel("dashboard.filesystem.table.column.remainingtime")
                                        .wrapOnAssignment(this).getObject(),
                                "userObject.remainingTimeString") });
        fileSystemTreeTable.getTreeState().setAllowSelectMultiple(true);
        fileSystemTreeTable.getTreeState().collapseAll();
        fileSystemTreeTable.setRootLess(true);
        addOrReplace(fileSystemTreeTable);
    } catch (Exception e) {
        log.error(this.getClass().toString() + ": " + "onBeforeRender: " + e.getMessage());
        log.debug("Exception: ", e);
        throw new WicketRuntimeException(e.getLocalizedMessage(), e);
    }
}

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

/**
 * Creates a node for the tree model that contains financial charts.
 * //  w w  w .j av a  2 s  .c om
 * @return The tree node.
 */
private MutableTreeNode createFinancialChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Financial Charts");

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.CandlestickChartDemo1", "CandlestickChartDemo1"));
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.HighLowChartDemo1", "HighLowChartDemo1"));
    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.HighLowChartDemo2", "HighLowChartDemo2"));
    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PriceVolumeDemo1", "PriceVolumeDemo1"));
    DefaultMutableTreeNode n5 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.YieldCurveDemo", "YieldCurveDemo"));

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

From source file:edu.ku.brc.specify.tasks.subpane.security.SecurityAdminPane.java

/**
 * @param session//from   w  ww.  j a  v  a 2  s  .co  m
 * @param divNode
 * @param division
 */
@SuppressWarnings("unused")
private void addDisciplinesRecursively(final DataProviderSessionIFace session,
        final DefaultMutableTreeNode divNode, final Division division) {
    // sort disciplines
    TreeSet<Discipline> disciplines = new TreeSet<Discipline>(division.getDisciplines());
    for (Discipline discipline : disciplines) {
        log.debug("    Adding Discipline " + discipline.getName());
        DefaultMutableTreeNode discNode = new DefaultMutableTreeNode(new DataModelObjBaseWrapper(discipline));
        divNode.add(discNode);
        addCollectionsRecursively(session, discNode, discipline);
        addGroup(session, discNode, discipline);
    }
}

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

/**
 * A node for various area charts./*ww  w . ja v  a  2  s. 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;
}

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;
}