Example usage for javax.swing.tree TreeNode getChildAt

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

Introduction

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

Prototype

TreeNode getChildAt(int childIndex);

Source Link

Document

Returns the child TreeNode at index childIndex.

Usage

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getAllConcept(TreeNode node, Set<Concept> conceptSet) {
    for (int i = 0; i < node.getChildCount(); i++) {
        ConceptTreeNode childNode = (ConceptTreeNode) node.getChildAt(i);
        conceptSet.add(childNode.getConcept());
        getAllConcept(childNode, conceptSet);
    }/*  w  ww . ja  v a  2 s .c  om*/
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getAllUserObject(TreeNode node, Set userObjectSet) {
    for (int i = 0; i < node.getChildCount(); i++) {
        DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) node.getChildAt(i);
        userObjectSet.add(childNode.getUserObject());
        getAllUserObject(childNode, userObjectSet);
    }/*from  ww  w . j a  va  2  s .  com*/
}

From source file:net.sourceforge.doddle_owl.utils.Utils.java

private static void getChildCntAverage(TreeNode node, List<Integer> childNodeCntList) {
    if (0 < node.getChildCount()) {
        childNodeCntList.add(node.getChildCount());
    }/*from w ww.j  a v a2s . co m*/
    for (int i = 0; i < node.getChildCount(); i++) {
        ConceptTreeNode childNode = (ConceptTreeNode) node.getChildAt(i);
        getChildCntAverage(childNode, childNodeCntList);
    }
}

From source file:it.unibas.spicygui.controllo.window.operator.ProjectTreeGenerator.java

private void analisiRicorsivaAggiuntaIstanza(Object root, Scenario scenario, DefaultTreeModel model,
        String stringa) {/*  ww w.j av a  2  s. com*/
    int indice = model.getChildCount(root);
    for (int i = 0; i < indice; i++) {
        analisiRicorsivaAggiuntaIstanza(model.getChild(root, i), scenario, model, stringa);
    }
    //        if (indice == 2) {
    TreeTopComponentAdapter componentAdapter = (TreeTopComponentAdapter) ((DefaultMutableTreeNode) root)
            .getUserObject();
    TopComponent tc = componentAdapter.getTopComponent();
    if (tc != null && tc == scenario.getMappingTaskTopComponent()) {

        TreeTopComponentAdapter ttca = new TreeTopComponentAdapter(null, false, false, true);
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(ttca);
        TreeNode treeNode = ((TreeNode) root).getParent();
        TreeNode nodeInstancesFather = treeNode.getChildAt(2);
        //            if (stringa.equals(Costanti.SOURCE)) {
        TreeNode nodeInstacesSource = nodeInstancesFather.getChildAt(0);
        TreeNode nodeInstacesTarget = nodeInstancesFather.getChildAt(1);
        List<String> sourceInstancesName = (List<String>) scenario.getMappingTask().getSourceProxy()
                .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
        List<String> targetInstancesName = (List<String>) scenario.getMappingTask().getTargetProxy()
                .getAnnotation(SpicyEngineConstants.XML_INSTANCE_FILE_LIST);
        int place = 0;
        String name = "xxx";
        if (sourceInstancesName.size() != nodeInstacesSource.getChildCount()) {
            place = nodeInstacesSource.getChildCount();
            name = findTitle(sourceInstancesName.get(sourceInstancesName.size() - 1));
            model.insertNodeInto(newNode, (DefaultMutableTreeNode) nodeInstacesSource, place);
        } else if (targetInstancesName.size() != nodeInstacesTarget.getChildCount()) {
            place = nodeInstacesTarget.getChildCount();
            name = findTitle(targetInstancesName.get(targetInstancesName.size() - 1));
            model.insertNodeInto(newNode, (DefaultMutableTreeNode) nodeInstacesTarget, place);
        }
        ttca.setName(name);
        scenario.getXQueryTopComponent().update();

        //                return;
        //            }

    }
    //            return;
    //        }

}

From source file:dotaSoundEditor.Controls.EditorPanel.java

/**
 * @param oldTree The tree that was previously in use
 * @param scriptFilePath A File object pointing to or containing a script.
 * @return The merged tree.//from  ww w .j a v a  2  s.co m
 */
TreeModel mergeNewChanges(TreeModel oldTree, File scriptFilePath) {
    //Look for any modified wavestrings. Save their nodes, and note their indices.
    //Parse in updated script tree, replace nodes at indices with saved nodes.   
    //Return merged tree
    System.out.println("Running a merge operation!");

    TreeNode oldRoot = (TreeNode) oldTree.getRoot();
    ArrayList<DefaultMutableTreeNode> savedNodeList = new ArrayList<>();
    for (Enumeration e = ((DefaultMutableTreeNode) oldRoot).depthFirstEnumeration(); e.hasMoreElements()
            && oldRoot != null;) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
        if (node.getUserObject().toString().contains("custom\\")
                || node.getUserObject().toString().contains("custom/")) {
            savedNodeList.add(node);
        }
    }
    ScriptParser parser = new ScriptParser(scriptFilePath);
    TreeModel newTree = parser.getTreeModel();
    TreeNode newRoot = (TreeNode) newTree.getRoot();
    for (DefaultMutableTreeNode savedNode : savedNodeList) {
        int rndwaveIndex = -1;
        int childIndex = -1;
        int parentIndex = -1;
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) savedNode.getParent();
        if (parent.getUserObject().toString().contains("rndwave")) {
            rndwaveIndex = parent.getParent().getIndex(parent);
            childIndex = parent.getIndex(savedNode);
            parent = (DefaultMutableTreeNode) parent.getParent();
            parentIndex = parent.getParent().getIndex(parent);
        } else {
            parentIndex = parent.getParent().getIndex(parent);
            childIndex = parent.getIndex(savedNode);
        }

        TreeNode newParentNode = newRoot.getChildAt(parentIndex);
        TreeNode newChildNode;
        if (rndwaveIndex != -1) {
            newChildNode = newParentNode.getChildAt(rndwaveIndex);
            newChildNode = newChildNode.getChildAt(childIndex);
        } else {
            newChildNode = newParentNode.getChildAt(childIndex);
        }
        newChildNode = savedNode;
    }
    return newTree;
}

From source file:org.artifactory.webapp.wicket.actionable.tree.ActionableItemsTree.java

public TreeNode getNextTreeNode(TreeNode node) {
    ITreeState state = getTreeState();//from  www  .j a v  a2s . c om
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    if (parent == null) {
        return null;
    }
    if (!node.isLeaf() && node.getAllowsChildren() && state.isNodeExpanded(node)) {
        return node.getChildAt(0);
    }

    TreeNode nextNode = parent.getChildAfter(node);
    if (nextNode == null) {
        return getNextParent(parent);
    }
    return nextNode;
}

From source file:org.artifactory.webapp.wicket.actionable.tree.ActionableItemsTree.java

public TreeNode getPrevTreeNode(TreeNode node) {
    DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
    if (parent == null) {
        return null;
    }/*from   w ww.ja va  2s  . c  o  m*/

    TreeNode prevNode = parent.getChildBefore(node);
    if (prevNode != null) {
        ITreeState state = getTreeState();
        node = prevNode;
        while (!node.isLeaf() && node.getAllowsChildren() && state.isNodeExpanded(node)) {
            node = node.getChildAt(node.getChildCount() - 1);
        }
        return node;
    }

    DefaultTreeModel treeModel = getTreeModel();
    if (parent == treeModel.getRoot()) {
        return null;
    }
    return parent;
}

From source file:org.carewebframework.help.javahelp.HelpView.java

/**
 * Duplicates JavaHelp topic tree into HelpTopicNode-based tree.
 * /*from   ww w .  j a  v a2 s  .  c  o  m*/
 * @param htnParent Current parent for HelpTopicNode-based tree.
 * @param ttnParent Current parent for JavaHelp TreeNode-based tree.
 */
private void initTopicTree(HelpTopicNode htnParent, TreeNode ttnParent) {

    for (int i = 0; i < ttnParent.getChildCount(); i++) {
        TreeNode ttnChild = ttnParent.getChildAt(i);
        HelpTopic ht = getTopic(ttnChild);
        HelpTopicNode htnChild = new HelpTopicNode(ht);
        htnParent.addChild(htnChild);
        initTopicTree(htnChild, ttnChild);
    }

}

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelPropertyEditor.java

/**
 * Appends given {@link TreeNode} and its children to the {@link StringBuffer}.
 *//*  www.ja v a 2s.c o  m*/
private static void getText_appendNodes(StringBuffer buffer, TreeNode node, String prefix) {
    // append separator
    if (buffer.length() != 0) {
        buffer.append(", ");
    }
    // append current node
    buffer.append(prefix);
    if (node instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode mutableTreeNode = (DefaultMutableTreeNode) node;
        buffer.append(mutableTreeNode.getUserObject());
    }
    // append children
    String newPrefix = prefix + "+";
    for (int i = 0; i < node.getChildCount(); i++) {
        getText_appendNodes(buffer, node.getChildAt(i), newPrefix);
    }
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelPropertyEditor.java

/**
 * Appends given {@link TreeNode} and its children to the {@link StringBuffer}.
 *//*from w  ww .  j ava  2s . c  o  m*/
private static void getTooltip_appendNodes(StringBuffer buffer, TreeNode node, String prefix) {
    // append separator
    if (buffer.length() != 0) {
        buffer.append("\n");
    }
    // append current node
    buffer.append(prefix);
    if (node instanceof DefaultMutableTreeNode) {
        DefaultMutableTreeNode mutableTreeNode = (DefaultMutableTreeNode) node;
        buffer.append(mutableTreeNode.getUserObject());
    }
    // append children
    String newPrefix = prefix + "    ";
    for (int i = 0; i < node.getChildCount(); i++) {
        getTooltip_appendNodes(buffer, node.getChildAt(i), newPrefix);
    }
}