Example usage for javax.swing.tree DefaultMutableTreeNode getChildAt

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

Introduction

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

Prototype

public TreeNode getChildAt(int index) 

Source Link

Document

Returns the child at the specified index in this node's child array.

Usage

From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java

/**
 * Tells the tree model that a node hash changed.
 * @param parentNode the parent node/*w ww. j av  a2 s  . c o  m*/
 * @param model the tree model
 * @param updateChildren update kids
 */
protected void updateTreeNodes(final DefaultMutableTreeNode parentNode, final DefaultTreeModel model,
        final boolean updateChildren) {
    model.nodeChanged(parentNode);
    if (updateChildren) {
        for (int i = 0; i < parentNode.getChildCount(); i++) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) parentNode.getChildAt(i);
            updateTreeNodes(node, model, true);
        }
    }
}

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

private void loadChromosome(final Element gaSettingsElement, final List<ParameterInfo> params)
        throws WizardLoadingException {
    final int childCount = getChromosomeTree().getChildCount(getChromosomeTree().getRoot());
    if (childCount > 0) {
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) getChromosomeTree().getRoot();
        for (int i = childCount - 1; i >= 0; --i) {
            final MutableTreeNode node = (MutableTreeNode) root.getChildAt(i);
            getChromosomeTree().removeNodeFromParent(node);
        }//from   www .  java  2  s  .c om
        genes = null;
    }

    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) getChromosomeTree().getRoot();

    NodeList nl = gaSettingsElement.getElementsByTagName(CHROMOSOME);
    if (nl != null && nl.getLength() > 0) {
        final Element chromosomeElement = (Element) nl.item(0);

        nl = chromosomeElement.getElementsByTagName(GENE);
        loadGene(nl, params, root);

        nl = chromosomeElement.getElementsByTagName(PARAMETER);
        loadParameter(nl, params, root);
    } else {
        throw new WizardLoadingException(true, "missing node: " + CHROMOSOME);
    }
}

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

private void loadChromosome(final eu.crisis_economics.abm.dashboard.generated.Chromosome chromosome,
        final List<ParameterInfo> parameters) throws ModelInformationException {
    final int childCount = getChromosomeTree().getChildCount(getChromosomeTree().getRoot());
    if (childCount > 0) {
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) getChromosomeTree().getRoot();
        for (int i = childCount - 1; i >= 0; --i) {
            final MutableTreeNode node = (MutableTreeNode) root.getChildAt(i);
            getChromosomeTree().removeNodeFromParent(node);
        }/*from  ww  w . ja  v a  2  s .c  o  m*/
        genes = null;
    }

    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) getChromosomeTree().getRoot();
    loadChromosomeTreeLevel(root, parameters, chromosome.getParameterList(),
            chromosome.getSubmodelParameterList(), chromosome.getGeneList());
}

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

public boolean alterParameterTree(final IIntelliContext ctx) {

    // create initial population
    final DefaultMutableTreeNode root = ctx.getParameterTreeRootNode();
    final DefaultMutableTreeNode newRoot = getAlteredParameterTreeRootNode(ctx);
    root.removeAllChildren();/*from   w w w  .  java 2 s  .  co m*/
    final int count = newRoot.getChildCount();

    for (int i = 0; i < count; ++i)
        root.add((DefaultMutableTreeNode) newRoot.getChildAt(0));

    return true;
}

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

public void setRecordableVariables(final DefaultMutableTreeNode root) {
    final List<RecordableInfo> newList = new ArrayList<RecordableInfo>();

    if (root.getChildCount() > 0) {
        final DefaultMutableTreeNode recorder = (DefaultMutableTreeNode) root.getChildAt(0);
        final ResultInfo resultInfo = (ResultInfo) recorder.getFirstLeaf().getUserObject();
        workspace = new File(resultInfo.getFile()).getParentFile();
        //first two children contains recorder meta data
        for (int j = 2; j < recorder.getChildCount(); ++j) {
            final RecordableElement re = (RecordableElement) ((DefaultMutableTreeNode) recorder.getChildAt(j))
                    .getUserObject();//from w ww . j av a 2  s  . co m
            final RecordableInfo recInfo = new RecordableInfo(
                    re.getAlias() != null ? re.getAlias() : re.getInfo().getName(), re.getInfo().getJavaType(),
                    re.getInfo().getName());
            if (!newList.contains(recInfo) && re.getInfo().isNumeric()) {
                newList.add(recInfo);
            }
        }
    }

    final RecordableInfo oldSelectedFunction = selectedFunction;
    removeAllFitnessFunctions();
    fitnessFunctions.addAll(newList);

    if (listeners != null) {
        for (final ModelListener listener : listeners) {
            listener.fitnessFunctionAdded();
        }
    }

    if (oldSelectedFunction != null) {
        RecordableInfo selectedFunctionInTheList = null;
        for (final RecordableInfo ri : fitnessFunctions) {
            if (ri.equals(oldSelectedFunction)) {
                // accessible name equality
                selectedFunctionInTheList = ri;
            }
        }

        if (selectedFunctionInTheList != null) {
            selectedFunction = selectedFunctionInTheList;
            if (listeners != null) {
                for (final ModelListener listener : listeners) {
                    listener.fitnessFunctionSelected(selectedFunction);
                }
            }
        }

    }

}

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

public void treeExpanded(TreeExpansionEvent event) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryData data = (QueryData) node.getUserObject();
    jTree1.scrollPathToVisible(new TreePath(node));

    System.out.println("Node expanded: " + data.name());

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }//w w w. j a va 2  s  .  c om

    // check to see if child is a placeholder ('working...')
    //   if so, make Web Service call to update children of node
    if (node.getChildCount() == 1) {
        final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryData) node1.getUserObject()).visualAttribute().equals("LAO")
                && ((QueryData) node1.getUserObject()).name().equals("working ......")) {
            final DefaultMutableTreeNode anode = node;
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    populateChildNodes(anode);
                }
            });
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryData adata = (QueryData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

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

public boolean alterParameterTree(final IIntelliContext ctx) {
    // create initial population
    final DefaultMutableTreeNode root = ctx.getParameterTreeRootNode();
    final DefaultMutableTreeNode newRoot = getAlteredParameterTreeRootNode(ctx);

    if (root != null) {
        root.removeAllChildren();//from w ww. ja v a 2 s.c o m
        final int count = newRoot.getChildCount();

        for (int i = 0; i < count; ++i)
            root.add((DefaultMutableTreeNode) newRoot.getChildAt(0));
    }

    return true;
}

From source file:edu.harvard.i2b2.query.ui.ConceptTreePanel.java

private void populateChildNodes(DefaultMutableTreeNode node) {

    List concepts = getConceptsFromChildren((QueryConceptTreeNodeData) node.getUserObject(),
            (DefaultMutableTreeNode) node.getChildAt(0));
    if (concepts != null) {
        addNodesFromOntXML(concepts, node);
        DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
        treeModel.removeNodeFromParent(tmpnode);
        jTree1.scrollPathToVisible(new TreePath(node.getPath()));
    }//w  w w.j a v a 2  s  .co m

}

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

private void setSearchedDocumentsOnTree(DefaultMutableTreeNode top, ArrayList<DocPath> docPaths)
        throws ExceptionLP, RepositoryException, Throwable {
    if (docPaths.size() == 0)
        treeModel.insertNodeInto(new DefaultMutableTreeNode("..."), top, 0);

    DefaultMutableTreeNode treeNode;
    for (DocPath path : docPaths) {
        treeNode = top;/*from   w w w  .j  ava 2  s . co m*/
        boolean firstNode = true;
        for (DocNodeBase node : path.asDocNodeList()) {
            if (firstNode) {
                firstNode = false;
            } else {
                int i = getDocNodeChildPos(node, treeNode);
                if (i == -1) {
                    DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(node);
                    treeModel.insertNodeInto(newNode, treeNode, treeNode.getChildCount());
                    treeNode = newNode;
                } else {
                    treeNode = (DefaultMutableTreeNode) treeNode.getChildAt(i);
                }
            }
        }
    }
    tree.setModel(treeModel);
}

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

public DefaultMutableTreeNode addNode(QueryResultData 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  ava  2  s . co  m*/
    //Make sure the user can see the lovely new node.
    jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

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

    return childNode;
}