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 node for the tree model that contains financial charts.
 * /*from   ww w. j  a  v a 2s . c  o  m*/
 * @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.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

public DefaultMutableTreeNode insertNode(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);

    if (ascending) {
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
    } else {//w ww  . j a va2 s. c  o m
        treeModel.insertNodeInto(childNode, top, 0);
    }

    if (!(node.visualAttribute().startsWith("L") || node.visualAttribute().equalsIgnoreCase("MA"))) {
        treeModel.insertNodeInto(tmpNode, childNode, childNode.getChildCount());
    }

    jTree1.expandPath(new TreePath(top.getPath()));
    previousQueries.add(node);

    return childNode;
}

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

public void buildErrorDocumentTree(DefaultMutableTreeNode node, ErrorDocument errorDocument)
        throws IOException {
    DefaultMutableTreeNode child = new DefaultMutableTreeNode(errorDocument);
    String trace = errorDocument.getTrace();
    if (trace != null && !trace.isEmpty())
        for (String line : trace.split("\n"))
            child.add(new DefaultMutableTreeNode(line));
    node.add(child);//from   ww  w.jav  a2  s .  c  om

    List<Path> causes = errorDocument.getCausedBy();
    for (Path cause : causes)
        if (DataBundles.isError(cause)) {
            ErrorDocument causeErrorDocument = DataBundles.getError(cause);
            if (causes.size() == 1)
                buildErrorDocumentTree(node, causeErrorDocument);
            else
                buildErrorDocumentTree(child, causeErrorDocument);
        } else if (DataBundles.isList(cause)) {
            List<ErrorDocument> errorDocuments = getErrorDocuments(cause);
            if (errorDocuments.size() == 1)
                buildErrorDocumentTree(node, errorDocuments.get(0));
            else
                for (ErrorDocument errorDocument2 : errorDocuments)
                    buildErrorDocumentTree(child, errorDocument2);
        }
}

From source file:dotaSoundEditor.Controls.EditorPanel.java

protected TreeModel buildSoundListTree(TreeModel scriptTree) {
    TreeNode rootNode = (TreeNode) scriptTree.getRoot();
    int childCount = rootNode.getChildCount();
    TreeModel soundListTreeModel = new DefaultTreeModel(new DefaultMutableTreeNode("root"));
    ArrayList<String> wavePathsList = new ArrayList<>();
    for (int i = 0; i < childCount; i++) {
        String nodeValue = scriptTree.getChild(rootNode, i).toString();
        if (nodeValue.trim().startsWith("//")) {
            continue;
        }//from w  w w.  ja  va 2 s  .co  m
        wavePathsList = getWavePathsAsList((TreeNode) scriptTree.getChild(rootNode, i));
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(nodeValue);
        for (String s : wavePathsList) {
            DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(s);
            newNode.add(tempNode);
        }
        ((DefaultMutableTreeNode) soundListTreeModel.getRoot()).add(newNode);
    }
    return soundListTreeModel;
}

From source file:edu.harvard.i2b2.previousquery.QueryPreviousRunsPanel.java

/** This method is called from within the constructor to
 * initialize the form.//from  ww w .j a v a2s. c o  m
 */
private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jTree1 = new javax.swing.JTree();

    setLayout(new java.awt.BorderLayout());

    QueryMasterData tmpData = new QueryMasterData();
    tmpData.name("Queries by " + System.getProperty("user"));
    tmpData.tooltip("Previous query runs");
    tmpData.visualAttribute("CA");
    top = new DefaultMutableTreeNode(tmpData);
    //top = new DefaultMutableTreeNode("Root Node");
    treeModel = new DefaultTreeModel(top);
    //treeModel.addTreeModelListener(new MyTreeModelListener());

    jTree1 = new JTree(treeModel);
    jTree1.setEditable(false);

    //jTree1.getSelectionModel().setSelectionMode
    //        (TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setShowsRootHandles(true);
    //JScrollPane treeView = new JScrollPane(jTree1);
    jTree1.setRootVisible(false);
    jTree1.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    jTree1.setCellRenderer(new MyRenderer());
    ToolTipManager.sharedInstance().registerComponent(jTree1);

    if (cellStatus.equalsIgnoreCase("CellDown")) {
        DefaultMutableTreeNode childNode = new DefaultMutableTreeNode("Data Repository Cell is unavailable");
        treeModel.insertNodeInto(childNode, top, top.getChildCount());
        // Make sure the user can see the lovely new node.
        jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));
    }

    ArrayList<QueryMasterData> queries = previousQueries;
    if (queries != null) {
        for (int i = 0; i < queries.size(); i++) {
            addNode(queries.get(i));
        }
    }

    jScrollPane1.setViewportView(jTree1);
    add(jScrollPane1, java.awt.BorderLayout.CENTER);

    jTree1.setTransferHandler(new NodeCopyTransferHandler());
    jTree1.addTreeExpansionListener(this);
}

From source file:de.erdesignerng.visual.common.OutlineComponent.java

public void setModel(Model aModel) {

    userObjectMap.clear();/*from w ww .j a  v a  2  s  . c  o  m*/
    expandedUserObjects.clear();

    DefaultMutableTreeNode theRoot = new DefaultMutableTreeNode(TreeGroupingElement.MODEL);

    Comparator<OwnedModelItem> theComparator = new BeanComparator("name");

    // Add the user-defined datatypes
    if (aModel.getDialect() != null) {
        if (aModel.getDialect().isSupportsCustomTypes()) {
            List<CustomType> theCustomTypes = new ArrayList<>();
            theCustomTypes.addAll(aModel.getCustomTypes());
            Collections.sort(theCustomTypes, theComparator);
            buildCustomTypesChildren(aModel, theRoot, theCustomTypes);
        }

        // Add the domains
        List<Domain> theDomains = new ArrayList<>();
        theDomains.addAll(aModel.getDomains());
        Collections.sort(theDomains, theComparator);
        buildDomainsChildren(aModel, theRoot, theDomains);
    }

    // Add the Tables
    List<Table> theTables = new ArrayList<>();
    theTables.addAll(aModel.getTables());
    Collections.sort(theTables, theComparator);
    buildTablesChildren(aModel, theRoot, theTables);

    // Add the Views
    List<View> theViews = new ArrayList<>();
    theViews.addAll(aModel.getViews());
    Collections.sort(theTables, theComparator);
    buildViewsChildren(aModel, theRoot, theViews);

    // Add the Relations
    List<Relation> theRelations = new ArrayList<>();
    theRelations.addAll(aModel.getRelations());
    Collections.sort(theRelations, theComparator);
    buildRelationChildren(theRoot, theRelations);

    // Add the Indexes
    List<Index> theIndexes = new ArrayList<>();
    for (Table theTable : aModel.getTables()) {
        theIndexes.addAll(theTable.getIndexes());
    }
    Collections.sort(theIndexes, theComparator);
    buildIndexChildren(theRoot, theIndexes);

    // Add the subject areas
    List<SubjectArea> theSAList = new ArrayList<>();
    theSAList.addAll(aModel.getSubjectAreas());
    Collections.sort(theSAList, theComparator);
    buildSubjectAreasChildren(aModel, theRoot, theSAList);

    tree.setModel(new DefaultTreeModel(theRoot));

    // if (aExpandAll) {
    for (int row = 0; row < tree.getRowCount(); row++) {
        TreePath thePath = tree.getPathForRow(row);
        DefaultMutableTreeNode theNode = (DefaultMutableTreeNode) thePath.getLastPathComponent();
        Object theUserObject = theNode.getUserObject();
        if (theUserObject instanceof TreeGroupingElement) {
            tree.expandRow(row);
        }
    }
    // }
}

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

/**
 * Adds all institutions as nodes to the navigation tree. Adds children nodes recursively (divisions,
 * disciplines, collections, user groups, and users).
 * @param session Data provider session to be used to retrieve data objects 
 * @param root Root of the tree to add children (institutions) to
 *//* w  w w.j a v a  2s.co  m*/
private void addInstitutionsRecursively(final DataProviderSessionIFace session,
        final DefaultMutableTreeNode root) {
    // initialize hash of users that will be used to avoid creation of multiple instances of the same persisted user
    spUsers = new HashSet<SpecifyUser>();

    // XXX Room for performance improvement: fetch all tree in the same query using HQL with OUTER LEFT JOIN FETCH
    List<Institution> institutions = session.getDataList(Institution.class);
    Collections.sort(institutions, new ComparatorByStringRepresentation<Institution>());
    for (Institution institution : institutions) {
        DefaultMutableTreeNode instNode = new DefaultMutableTreeNode(new DataModelObjBaseWrapper(institution));
        root.add(instNode);
        addDivisionsRecursively(session, instNode, institution);
        addGroup(session, instNode, institution);
    }
}

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);/*  ww w.j  a  va 2  s .c om*/
    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  . jav  a2s .  c om*/
 * @param instNode
 * @param institution
 */
private void addDivisionsRecursively(final DataProviderSessionIFace session,
        final DefaultMutableTreeNode instNode, final Institution institution) {
    // sort divisions
    TreeSet<Division> divisions = new TreeSet<Division>(institution.getDivisions());
    for (Division division : divisions) {
        //log.debug("Adding Division "+division.getName());
        for (Discipline discipline : division.getDisciplines()) {
            //log.debug("  Adding Discipline "+discipline.getName());
            DataModelObjBaseWrapper dmob = new DataModelObjBaseWrapper(discipline);
            DefaultMutableTreeNode discNode = new DefaultMutableTreeNode(dmob);
            instNode.add(discNode);
            addCollectionsRecursively(session, discNode, discipline);
            addGroup(session, discNode, discipline);
        }
    }
}

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

/**
 * Creates a node for the tree model that contains "meter" charts.
 * //from w ww .  j av a 2s .  co m
 * @return The tree node.
 */
private MutableTreeNode createMeterChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Meter Charts");

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.MeterChartDemo1", "MeterChartDemo1"));

    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.MeterChartDemo2", "MeterChartDemo2"));

    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.MeterChartDemo4", "MeterChartDemo4"));

    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
            new DemoDescription("edu.ucla.stat.SOCR.chart.demo.ThermometerDemo1", "ThermometerDemo1"));

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