Example usage for javax.swing.tree DefaultMutableTreeNode getClass

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

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:ubic.basecode.dataStructure.graph.DirectedGraph.java

/**
 * Generate a JTree corresponding to this graph.
 * //  w  w  w.j  a  va  2  s . c  o  m
 * @param nodeClass The class to be used for TreeNodes. Defaults to DefaultMutableTreeNode.
 * @return javax.swing.JTree
 */
@SuppressWarnings("unchecked")
public JTree treeView(Class<? extends DefaultMutableTreeNode> nodeClass) {
    log.debug("Constructing tree view of graph");
    DirectedGraphNode<K, V> root = getRoot();
    Constructor<DefaultMutableTreeNode> constructor;
    DefaultMutableTreeNode top = null;
    treeView = null;
    try {
        constructor = (Constructor<DefaultMutableTreeNode>) nodeClass
                .getConstructor(new Class[] { root.getClass() });
        top = constructor.newInstance(new Object[] { root });
        log.debug("Starting tree with: " + top.getClass().getName());
        root.mark();
        addJTreeNode(top, root, constructor);
        dtm = new DefaultTreeModel(top);
        treeView = new JTree(dtm);

    } catch (Exception e) {
        log.error(e, e);
    }
    return treeView;
}