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.ucla.stat.SOCR.chart.ChartTree.java

/**
 * Creates a sub-tree for the time series charts.
 * //from  www . j a  va  2 s.co  m
 * @return The root node for the subtree.
 */
private MutableTreeNode createTimeSeriesChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Time Series Charts");

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo1", "TimeSeriesDemo1"));
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo2", "TimeSeriesDemo2"));
    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo3", "TimeSeriesDemo3"));
    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo4", "TimeSeriesDemo4"));
    DefaultMutableTreeNode n5 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo5", "TimeSeriesDemo5"));
    DefaultMutableTreeNode n6 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo6", "TimeSeriesDemo6"));
    DefaultMutableTreeNode n7 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo7", "TimeSeriesDemo7"));
    DefaultMutableTreeNode n8 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo8", "TimeSeriesDemo8"));
    DefaultMutableTreeNode n9 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo9", "TimeSeriesDemo9"));
    DefaultMutableTreeNode n10 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo10", "TimeSeriesDemo10"));
    DefaultMutableTreeNode n11 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo11", "TimeSeriesDemo11"));
    DefaultMutableTreeNode n12 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo12", "TimeSeriesDemo12"));
    DefaultMutableTreeNode n13 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.TimeSeriesDemo13", "TimeSeriesDemo13"));
    DefaultMutableTreeNode n14 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PeriodAxisDemo1", "PeriodAxisDemo1"));
    DefaultMutableTreeNode n15 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.PeriodAxisDemo2", "PeriodAxisDemo2"));
    DefaultMutableTreeNode n16 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.DynamicDataDemo1", "DynamicDataDemo1"));
    DefaultMutableTreeNode n17 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.DynamicDataDemo2", "DynamicDataDemo2"));
    DefaultMutableTreeNode n18 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.DynamicDataDemo3", "DynamicDataDemo3"));

    root.add(n1);
    root.add(n2);
    root.add(n3);
    root.add(n4);
    root.add(n5);
    root.add(n6);
    root.add(n7);
    root.add(n8);
    root.add(n9);
    root.add(n10);
    root.add(n11);
    root.add(n12);
    root.add(n13);
    root.add(n14);
    root.add(n15);
    root.add(n16);
    root.add(n17);
    root.add(n18);

    return root;
}

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

private void refresh() throws ExceptionLP, Throwable {
    List<DocNodeBase> parts = fullDocPath.getDeepCopy().asDocNodeList();
    boolean isSuche = wtfSuche.getText() != null && !"".equals(wtfSuche.getText());

    DefaultMutableTreeNode dmtNode = null;
    Object[] toSelect = new Object[parts.size()];
    if (parts.size() > 0) {
        dmtNode = new DefaultMutableTreeNode(parts.get(0));
        toSelect[0] = dmtNode;/* w ww  . j  av a 2  s  . co  m*/
        treeModel = new DefaultTreeModel(dmtNode);
        treeModel.addTreeModelListener(this);
    }
    for (int i = 1; i < parts.size() && !isSuche; i++) {
        DefaultMutableTreeNode toAdd = new DefaultMutableTreeNode(parts.get(i));
        toSelect[i] = toAdd;
        treeModel.insertNodeInto(toAdd, dmtNode, dmtNode.getChildCount());
        dmtNode = toAdd;
    }
    TreePath treePath = new TreePath(toSelect);
    TreePath treePathOld = null;
    if (toSelect.length >= 2) {
        treePathOld = new TreePath(toSelect[toSelect.length - 2]);
    } else {
        treePathOld = new TreePath(toSelect);
    }
    // Value Changed damit die Buttons korrekt angezeigt werden
    valueChanged(new TreeSelectionEvent(tree, treePath, true, treePathOld, treePath));
    if (isSuche) {
        setSearchedDocumentsOnTree(dmtNode,
                DelegateFactory.getInstance().getJCRDocDelegate().searchDocNodes(wtfSuche.getText()));
        for (int i = tree.getRowCount(); i > 0; i--) {
            tree.collapseRow(i);
        }
    } else if (dmtNode.getChildCount() == 0) {
        List<DocNodeBase> childDocNodes = DelegateFactory.getInstance().getJCRDocDelegate()
                .getDocNodeChildrenFromNode(fullDocPath);
        if (childDocNodes != null) {
            setDocNodesOnTree(dmtNode, childDocNodes, fullDocPath);
            tree.expandPath(treePath);
        }
    }
    tree.setSelectionPath(treePath);
}

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

/**
 * check threads in given thread dump and add appropriate
 * custom categories (if any defined).// w  ww  .  j a va  2s  .c  o 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:de.erdesignerng.visual.common.OutlineComponent.java

private void initialize() {

    tree = new DefaultTree();
    tree.setCellRenderer(new OutlineTreeCellRenderer());
    tree.addMouseListener(new OutlineMouseListener());
    tree.addTreeSelectionListener(new OutlineSelectionListener());
    tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(TreeGroupingElement.MODEL)));

    setLayout(new BorderLayout());
    add(tree.getScrollPane(), BorderLayout.CENTER);

    filterField = new DefaultTextField();
    filterField.setColumns(255);/*from ww  w  . j a va2  s .  c  om*/
    filterField.addKeyListener(new OutlineKeyAdapter());
    DefaultButton disableFilterButton = new DefaultButton();
    disableFilterButton.setIcon(IconFactory.getCancelIcon());
    disableFilterButton.setMaximumSize(new Dimension(21, 21));
    disableFilterButton.setMinimumSize(new Dimension(21, 21));
    disableFilterButton.setPreferredSize(new Dimension(21, 21));
    disableFilterButton.addActionListener(new OutlineDisableFilterActionListener());

    JPanel theFilterPanel = new JPanel();
    theFilterPanel.setLayout(new BorderLayout());
    theFilterPanel.add(filterField, BorderLayout.CENTER);
    theFilterPanel.add(disableFilterButton, BorderLayout.EAST);

    add(theFilterPanel, BorderLayout.NORTH);

    tree.addTreeExpansionListener(new OutlineTreeExpansionListener());
}

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

public DefaultMutableTreeNode addNode(PatientData node, DefaultMutableTreeNode parent) {
    // QueryInstanceData rundata = (QueryInstanceData)
    // parent.getUserObject();

    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    // QueryInstanceData tmpData = new QueryInstanceData();
    // 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 w w  w .j av  a2  s  .c om*/
    // Make sure the user can see the lovely new node.

    DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) parent.getChildAt(0);
    QueryData tmpdata = (QueryData) tmpnode.getUserObject();
    if (tmpdata.name().equalsIgnoreCase("working ......")) {
        treeModel.removeNodeFromParent(tmpnode);
    }

    return childNode;
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

public DefaultMutableTreeNode addNode(QueryMasterData node) {
    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, top, top.getChildCount());
    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }/*w w  w.  jav  a  2 s.c  om*/

    jTree1.expandPath(new TreePath(top.getPath()));

    return childNode;
}

From source file:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java

/**
 * Add folder node./*from   w  w w .java  2s  .  c om*/
 *
 * @param uri
 *            folder URI.
 * @return the node.
 */
public DefaultMutableTreeNode addFolderNode(String uri) {
    DefaultMutableTreeNode parent = null;

    // get label from URI
    FolderResource resource = new FolderResource(MindRaider.labelCustodian.get(uri));
    Object child = resource.getLabel();
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(child);

    // store node to map to be able to get URI from node object
    treeNodeToResourceUriMap.put(childNode, uri);

    if (parent == null) {
        parent = rootNode;
    }

    treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
    return childNode;
}

From source file:gov.nih.nci.ncicb.cadsr.contexttree.service.impl.CDEBrowserTreeServiceImpl.java

public Map getAllPublishingNode(TreeFunctions treeFunctions, TreeIdGenerator idGen,
        boolean showFormsAlphebetically) throws Exception {
    CSITransferObject publishFormCSI = null, publishTemplateCSI = null;

    DefaultMutableTreeNode publishNode = null;
    Map formPublishCSCSIMap = new HashMap();
    Map templatePublishCSCSIMap = new HashMap();
    Map publishNodeByContextMap = new HashMap();

    Map formCSMap = getFormClassificationNodes(treeFunctions, idGen, CaDSRConstants.FORM_CS_TYPE,
            CaDSRConstants.FORM_CSI_TYPE);
    Map templateCSMap = getFormClassificationNodes(treeFunctions, idGen, CaDSRConstants.TEMPLATE_CS_TYPE,
            CaDSRConstants.TEMPLATE_CSI_TYPE);

    FormDAO dao = daoFactory.getFormDAO();
    List formCSIs = dao.getAllPublishingCSCSIsForForm();

    Iterator formIter = formCSIs.iterator();

    while (formIter.hasNext()) {
        publishFormCSI = (CSITransferObject) formIter.next();

        formPublishCSCSIMap.put(publishFormCSI.getCsConteIdseq(), publishFormCSI);
    }/*from ww  w  .  j a  v  a  2s.c  o m*/

    List templateCSIs = dao.getAllPublishingCSCSIsForTemplate();

    Iterator templateIter = templateCSIs.iterator();

    while (templateIter.hasNext()) {
        publishTemplateCSI = (CSITransferObject) templateIter.next();

        templatePublishCSCSIMap.put(publishTemplateCSI.getCsConteIdseq(), publishTemplateCSI);
    }

    // get all form publishing context
    Collection formPublishingContexts = formPublishCSCSIMap.keySet();
    Iterator contextIter = formPublishingContexts.iterator();
    Map treeNodeMap = new HashMap();

    while (contextIter.hasNext()) {
        String currContextId = (String) contextIter.next();
        treeNodeMap.clear();

        publishFormCSI = (CSITransferObject) formPublishCSCSIMap.get(currContextId);
        publishNode = new DefaultMutableTreeNode(
                new WebNode(idGen.getNewId(), publishFormCSI.getClassSchemeLongName()));
        publishNodeByContextMap.put(currContextId, publishNode);

        List publishedProtocols = null;
        List publishedForms = null;

        publishedProtocols = dao.getAllProtocolsForPublishedForms(currContextId);

        publishedForms = new ArrayList();

        if (showFormsAlphebetically)
            publishedForms = dao.getAllPublishedForms(currContextId);

        if (!publishedProtocols.isEmpty() || !publishedForms.isEmpty()) {
            DefaultMutableTreeNode publishFormNode = new DefaultMutableTreeNode(
                    new WebNode(idGen.getNewId(), publishFormCSI.getClassSchemeItemName()));

            publishNode.add(publishFormNode);

            if (!publishedForms.isEmpty() && showFormsAlphebetically) {
                DefaultMutableTreeNode listedAlphabetically = new DefaultMutableTreeNode(
                        new WebNode(idGen.getNewId(), "Listed Alphabetically"));

                Iterator formsIt = publishedForms.iterator();

                while (formsIt.hasNext()) {
                    Form currForm = (Form) formsIt.next();

                    listedAlphabetically.add(getFormNode(idGen.getNewId(), currForm, treeFunctions, true));
                }

                publishFormNode.add(listedAlphabetically);
            }

            //starting here
            if (!publishedProtocols.isEmpty()) {
                DefaultMutableTreeNode listedByProtocol = new DefaultMutableTreeNode(
                        new WebNode(idGen.getNewId(), "Listed by Protocol"));

                Iterator protocolIt = publishedProtocols.iterator();

                while (protocolIt.hasNext()) {
                    Protocol currProto = (Protocol) protocolIt.next();

                    // first create protocol node for each protocol
                    DefaultMutableTreeNode currProtoNode = getProtocolNode(idGen.getNewId(), currProto,
                            currContextId, treeFunctions);

                    // then add all form nodes
                    List formsForProtocol = dao.getAllPublishedFormsForProtocol(currProto.getIdseq());

                    Iterator protocolFormsIt = formsForProtocol.iterator();

                    while (protocolFormsIt.hasNext()) {
                        Form currProtocolForm = (Form) protocolFormsIt.next();

                        //TODO - tree for multiple form/protocols
                        //currProtocolForm.setProtocol(currProto);

                        Collection formCSes = currProtocolForm.getClassifications();

                        if (formCSes == null || formCSes.size() == 0) {
                            currProtoNode.add(
                                    this.getFormNode(idGen.getNewId(), currProtocolForm, treeFunctions, true));
                        } else {
                            //add formNode to csTree
                            Iterator csIter = formCSes.iterator();
                            while (csIter.hasNext()) {
                                ClassSchemeItem currCSI = (ClassSchemeItem) csIter.next();

                                Map currCSMap = (Map) formCSMap.get(currCSI.getCsConteIdseq());
                                this.copyCSTree(currProtocolForm, currCSMap, treeNodeMap,
                                        getFormNode(idGen.getNewId(), currProtocolForm, treeFunctions, true),
                                        currProtoNode, idGen);
                            }
                        }

                        listedByProtocol.add(currProtoNode);
                    }

                    publishFormNode.add(listedByProtocol);
                }
            }
        }
    }
    // get all publishing template context
    Collection templatePublishingContexts = templatePublishCSCSIMap.keySet();
    contextIter = templatePublishingContexts.iterator();

    while (contextIter.hasNext()) {
        List publishedTemplates = null;
        treeNodeMap.clear();

        String currContextId = (String) contextIter.next();
        publishTemplateCSI = (CSITransferObject) templatePublishCSCSIMap.get(currContextId);
        publishNode = (DefaultMutableTreeNode) publishNodeByContextMap.get(currContextId);

        if (publishNode == null) {
            publishNode = new DefaultMutableTreeNode(
                    new WebNode(idGen.getNewId(), publishTemplateCSI.getClassSchemeLongName()));

            publishNodeByContextMap.put(currContextId, publishNode);
        }

        publishedTemplates = dao.getAllPublishedTemplates(currContextId);

        if (publishedTemplates != null && !publishedTemplates.isEmpty()) {
            DefaultMutableTreeNode publishTemplateNode = new DefaultMutableTreeNode(
                    new WebNode(idGen.getNewId(), publishTemplateCSI.getClassSchemeItemName()));

            Iterator templateIt = publishedTemplates.iterator();

            while (templateIt.hasNext()) {
                Form currTemplate = (Form) templateIt.next();

                if (currTemplate.getClassifications() == null
                        || currTemplate.getClassifications().size() == 0) {
                    publishTemplateNode.add(getTemplateNode(idGen.getNewId(), currTemplate, treeFunctions));
                } else {
                    //add template node to csTree(s)
                    Iterator csIter = currTemplate.getClassifications().iterator();
                    while (csIter.hasNext()) {
                        ClassSchemeItem currCSI = (ClassSchemeItem) csIter.next();

                        Map currCSMap = (Map) templateCSMap.get(currCSI.getCsConteIdseq());
                        this.copyCSTree(currTemplate, currCSMap, treeNodeMap,
                                getTemplateNode(idGen.getNewId(), currTemplate, treeFunctions),
                                publishTemplateNode, idGen);
                    }

                }

            }

            publishNode.add(publishTemplateNode);
        }
    }

    return publishNodeByContextMap;
}

From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java

/**
 * Update the component based on the node selected from the
 * ResultViewComponent tree./*w  ww .j  a v a 2 s . c om*/
 */
public void updateResult() {
    if (recognisedRenderersForMimeType == null)
        recognisedRenderersForMimeType = new ArrayList<>();
    if (otherRenderers == null)
        otherRenderers = new ArrayList<>();

    // Enable the combo box
    renderersComboBox.setEnabled(true);

    /*
     * Update the 'save result' buttons appropriately as the result node had
     * changed
     */
    for (int i = 0; i < saveButtonsPanel.getComponents().length; i++) {
        JButton saveButton = (JButton) saveButtonsPanel.getComponent(i);
        SaveIndividualResultSPI action = (SaveIndividualResultSPI) saveButton.getAction();
        // Update the action with the new result reference
        action.setResultReference(path);
        saveButton.setEnabled(true);
    }

    if (DataBundles.isValue(path) || DataBundles.isReference(path)) {
        // Enable refresh button
        refreshButton.setEnabled(true);

        List<MimeType> mimeTypes = new ArrayList<>();
        try (InputStream inputstream = getInputStream(path)) {
            mimeTypes.addAll(getMimeTypes(inputstream));
        } catch (IOException e) {
            logger.warn("Error getting mimetype", e);
        }

        if (mimeTypes.isEmpty())
            // If MIME types is empty - add "plain/text" MIME type
            mimeTypes.add(new MimeType("text/plain"));
        else if (mimeTypes.size() == 1 && mimeTypes.get(0).toString().equals("chemical/x-fasta")) {
            /*
             * If MIME type is recognised as "chemical/x-fasta" only then
             * this might be an error from MIME magic (i.e., sometimes it
             * recognises stuff that is not "chemical/x-fasta" as
             * "chemical/x-fasta" and then Seq Vista renderer is used that
             * causes errors) - make sure we also add the renderers for
             * "text/plain" and "text/xml" as it is most probably just
             * normal xml text and push the "chemical/x-fasta" to the bottom
             * of the list.
             */
            mimeTypes.add(0, new MimeType("text/plain"));
            mimeTypes.add(1, new MimeType("text/xml"));
        }

        for (MimeType mimeType : mimeTypes) {
            List<Renderer> renderersList = rendererRegistry.getRenderersForMimeType(mimeType.toString());
            for (Renderer renderer : renderersList)
                if (!recognisedRenderersForMimeType.contains(renderer))
                    recognisedRenderersForMimeType.add(renderer);
        }
        // if there are no renderers then force text/plain
        if (recognisedRenderersForMimeType.isEmpty())
            recognisedRenderersForMimeType = rendererRegistry.getRenderersForMimeType("text/plain");

        /*
         * Add all other available renderers that are not recognised to be
         * able to handle the MIME type of the result
         */
        otherRenderers = new ArrayList<>(rendererRegistry.getRenderers());
        otherRenderers.removeAll(recognisedRenderersForMimeType);

        mimeList = new String[recognisedRenderersForMimeType.size() + otherRenderers.size()];
        rendererList = new ArrayList<>();

        /*
         * First add the ones that can handle the MIME type of the result
         * item
         */
        for (int i = 0; i < recognisedRenderersForMimeType.size(); i++) {
            mimeList[i] = recognisedRenderersForMimeType.get(i).getType();
            rendererList.add(recognisedRenderersForMimeType.get(i));
        }
        // Then add the other renderers just in case
        for (int i = 0; i < otherRenderers.size(); i++) {
            mimeList[recognisedRenderersForMimeType.size() + i] = otherRenderers.get(i).getType();
            rendererList.add(otherRenderers.get(i));
        }

        renderersComboBox.setModel(new DefaultComboBoxModel<String>(mimeList));

        if (mimeList.length > 0) {
            int index = 0;

            // Find the index of the current MIME type for this output port.
            for (int i = 0; i < mimeList.length; i++)
                if (mimeList[i].equals(lastUsedMIMEtype)) {
                    index = i;
                    break;
                }

            int previousindex = renderersComboBox.getSelectedIndex();
            renderersComboBox.setSelectedIndex(index);
            /*
             * force rendering as setSelectedIndex will not fire an
             * itemstatechanged event if previousindex == index and we still
             * need render the result as we may have switched from a
             * different result item in a result list but the renderer index
             * stayed the same
             */
            if (previousindex == index)
                renderResult(); // draw the rendered result component
        }

    } else if (DataBundles.isError(path)) {
        // Disable refresh button
        refreshButton.setEnabled(false);

        // Hide wrap text check box - only works for actual data
        wrapTextCheckBox.setVisible(false);

        // Reset the renderers as we have an error item
        recognisedRenderersForMimeType = null;
        otherRenderers = null;

        DefaultMutableTreeNode root = new DefaultMutableTreeNode("Error Trace");

        try {
            ErrorDocument errorDocument = DataBundles.getError(path);
            try {
                buildErrorDocumentTree(root, errorDocument);
            } catch (IOException e) {
                logger.warn("Error building error document tree", e);
            }
        } catch (IOException e) {
            logger.warn("Error getting the error document", e);
        }

        JTree errorTree = new JTree(root);
        errorTree.setCellRenderer(new DefaultTreeCellRenderer() {
            @Override
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected,
                    boolean expanded, boolean leaf, int row, boolean hasFocus) {
                Component renderer = null;
                if (value instanceof DefaultMutableTreeNode) {
                    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) value;
                    Object userObject = treeNode.getUserObject();
                    if (userObject instanceof ErrorDocument)
                        renderer = renderErrorDocument(tree, selected, expanded, leaf, row, hasFocus,
                                (ErrorDocument) userObject);
                }
                if (renderer == null)
                    renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row,
                            hasFocus);
                if (renderer instanceof JLabel) {
                    JLabel label = (JLabel) renderer;
                    label.setIcon(null);
                }
                return renderer;
            }

            private Component renderErrorDocument(JTree tree, boolean selected, boolean expanded, boolean leaf,
                    int row, boolean hasFocus, ErrorDocument errorDocument) {
                return super.getTreeCellRendererComponent(tree,
                        "<html>" + escapeHtml(errorDocument.getMessage()) + "</html>", selected, expanded, leaf,
                        row, hasFocus);
            }
        });

        renderersComboBox.setModel(new DefaultComboBoxModel<>(new String[] { ERROR_DOCUMENT }));
        renderedResultPanel.removeAll();
        renderedResultPanel.add(errorTree, CENTER);
        repaint();
    }
}

From source file:com.tascape.qa.th.android.driver.App.java

private DefaultMutableTreeNode createNode(UIANode uiNode) {
    Rect bounds = uiNode.getBounds();//from w  w w. j  a v a 2 s .  c  o m
    String s = uiNode.getKlass() + " " + uiNode.getContentDescription() + " "
            + String.format("[%d,%d][%d,%d]", bounds.left, bounds.top, bounds.right, bounds.bottom);
    DefaultMutableTreeNode tNode = new DefaultMutableTreeNode(s);
    tNode.setUserObject(uiNode);

    for (UIANode n : uiNode.nodes()) {
        tNode.add(createNode(n));
    }
    return tNode;
}