Example usage for javax.swing.tree DefaultMutableTreeNode getChildCount

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

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children of this node.

Usage

From source file:hr.fer.zemris.vhdllab.view.explorer.ProjectExplorerView.java

private void updateHierarchy(DefaultMutableTreeNode parentNode, Hierarchy hierarchy,
        HierarchyNode hierarchyNode) {/*from www  . j  a v a2  s  . c o  m*/
    Map<Object, DefaultMutableTreeNode> map = new HashMap<Object, DefaultMutableTreeNode>(
            parentNode.getChildCount());
    for (int i = 0; i < parentNode.getChildCount(); i++) {
        DefaultMutableTreeNode c = (DefaultMutableTreeNode) parentNode.getChildAt(i);
        map.put(c.getUserObject(), c);
    }

    Iterator<HierarchyNode> iterator = getHierarchyIterator(hierarchy, hierarchyNode);
    while (iterator.hasNext()) {
        HierarchyNode next = iterator.next();
        File file = next.getFile();
        DefaultMutableTreeNode nextParentNode;
        if (map.containsKey(file)) {
            nextParentNode = map.remove(file);
        } else {
            nextParentNode = (DefaultMutableTreeNode) insertNode(parentNode, file);
        }
        updateHierarchy(nextParentNode, hierarchy, next);
    }

    // model.nodesWereRemoved expected ordered indices
    Map<Integer, DefaultMutableTreeNode> sortedMap = new TreeMap<Integer, DefaultMutableTreeNode>();
    for (DefaultMutableTreeNode n : map.values()) {
        int index = parentNode.getIndex(n);
        sortedMap.put(Integer.valueOf(index), n);
    }

    // construct arguments for model.nodesWereRemoved
    int[] childIndices = new int[sortedMap.size()];
    Object[] removedChildren = new Object[sortedMap.size()];
    int i = 0;
    for (Entry<Integer, DefaultMutableTreeNode> entry : sortedMap.entrySet()) {
        childIndices[i] = entry.getKey();
        removedChildren[i] = entry.getValue();
        i++;
        parentNode.remove(entry.getValue());
    }
    model.nodesWereRemoved(parentNode, childIndices, removedChildren);
}

From source file:net.sf.xmm.moviemanager.commands.importexport.IMDbInfoUpdater.java

@SuppressWarnings("unchecked")
public void execute() {

    /* Setting the priority of the thread to 4 to give the GUI room to update more often */
    Thread.currentThread().setPriority(4);

    DefaultMutableTreeNode root = (DefaultMutableTreeNode) ((DefaultTreeModel) MovieManager.getDialog()
            .getMoviesList().getModel()).getRoot();
    final Enumeration<DefaultMutableTreeNode> enumeration = root.children();

    lengthOfTask = root.getChildCount();

    try {/*  www. j av a 2s .  c  om*/

        Runnable threadRunner = new Runnable() {

            public void run() {

                DefaultMutableTreeNode node;
                ModelEntry model;

                ModelMovieInfo modelInfo = new ModelMovieInfo();
                IMDb imdb;
                try {
                    imdb = IMDbLib.newIMDb(MovieManager.getConfig().getHttpSettings());

                    while (enumeration.hasMoreElements()) {

                        if (canceled)
                            break;

                        // Will start only threadCount number of threads
                        while (threadHandler.getThreadCount() > threadCount - 1) {
                            threadHandler.waitForNextDecrease();
                        }

                        node = enumeration.nextElement();
                        model = (ModelEntry) node.getUserObject();

                        if (!model.getHasGeneralInfoData()) {
                            model.updateGeneralInfoData();
                        }

                        if (!model.getHasAdditionalInfoData()) {
                            model.updateAdditionalInfoData();
                        }

                        /* wrapping each movie in a thread */
                        Thread t = new Thread(new GetInfo(modelInfo, model, imdb));
                        t.start();

                        // Wait till the new thread has started and increased the thread count.
                        threadHandler.waitForNextIncrease();
                    }

                    do {
                        threadHandler.waitForNextDecrease();

                        if (threadHandler.getNoAction()) {
                            log.debug("No threads have finished within timeout of " + threadHandler.getTimeout()
                                    + "ms.");

                            ArrayList<GetInfo> active = threadHandler.getActiveThreads();

                            log.debug("Active threads:");

                            for (GetInfo t : active) {
                                log.debug(t.getTitle());
                            }
                        }

                    } while (threadHandler.getThreadCount() > 0);

                    setDone();

                    log.debug("Done updating list!");

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        Thread t = new Thread(threadRunner);
        t.start();

    } catch (Exception e) {
        log.warn("Exception:" + e.getMessage());
    }
}

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

/**
 * Add discarded notebook node./* ww  w.  ja  va  2 s .co m*/
 *
 * @param uri
 *            notebook node.
 * @return the node.
 */
public DefaultMutableTreeNode addDiscardedNotebookNode(String label, String uri) {
    DefaultMutableTreeNode parent = null;

    Object child = label;
    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:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java

/**
 * Add notebook node.//from w  w  w  . ja va2s.com
 *
 * @param parent
 *            folder node.
 * @param uri
 *            notebook URI.
 * @param label
 *            notebook label.
 * @return the node.
 */
public DefaultMutableTreeNode addNotebookNode(DefaultMutableTreeNode parent, String uri, String label) {
    Object child = label;
    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:com.mindcognition.mindraider.ui.swing.trash.TrashJPanel.java

/**
 * Add folder node./*from   ww  w  .j  a v a2 s .co  m*/
 *
 * @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:uk.co.markfrimston.tasktree.TaskTree.java

protected void addTasksFromChildElements(Element parent, DefaultMutableTreeNode treeNode) throws Exception {
    Iterator<Element> i = getElementChildren(parent);
    while (i.hasNext()) {
        Element child = i.next();
        if (!child.getNodeName().equals("task")) {
            throw new Exception("Expected \"task\", found \"" + child.getNodeName() + "\"");
        }//from  w  ww.j  av  a 2s.  c  o m
        String name = child.getAttribute("label");
        if (name == null || name.length() == 0) {
            throw new Exception("No label attribute for task");
        }
        DefaultMutableTreeNode newNode = addTask(treeNode, treeNode.getChildCount(), name);
        addTasksFromChildElements(child, newNode);
    }
}

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

private void renormalizeThreadDepth(DefaultMutableTreeNode threadNode1) {
    for (Enumeration e = threadNode1.children(); e.hasMoreElements();) {
        DefaultMutableTreeNode monitorNode2 = (DefaultMutableTreeNode) e.nextElement();
        for (int ii = 0; ii < monitorNode2.getChildCount(); ii++) {
            renormalizeMonitorDepth(monitorNode2, ii);
        }//  w  ww.  j  a v  a  2 s .c o  m
    }
}

From source file:edu.harvard.i2b2.query.QueryConceptTreePanel.java

private DefaultMutableTreeNode addNode(QueryConceptTreeNodeData node, DefaultMutableTreeNode parent) {
    DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(node);

    QueryConceptTreeNodeData tmpData = new QueryConceptTreeNodeData();
    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  a  va 2  s .  co m
    //Make sure the user can see the lovely new node.
    //jTree1.scrollPathToVisible(new TreePath(childNode.getPath()));

    return childNode;
}

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

private boolean checkForDuplicateThreadItem(Map directChildMap, DefaultMutableTreeNode node1) {
    ThreadInfo mi1 = (ThreadInfo) node1.getUserObject();
    String name1 = mi1.getName();

    for (Iterator iter2 = directChildMap.entrySet().iterator(); iter2.hasNext();) {
        DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) ((Map.Entry) iter2.next()).getValue();
        if (node1 == node2) {
            continue;
        }/*from   w w  w. j  av a  2s .  c  o m*/

        ThreadInfo mi2 = (ThreadInfo) node2.getUserObject();
        if (name1.equals(mi2.getName()) && node2.getChildCount() > 0) {
            node1.add((MutableTreeNode) node2.getFirstChild());
            iter2.remove();
            return true;
        }
    }

    return false;
}

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

/**
 * Gibt -1 zur&uuml;ck wenn kein docNode kein child von treeNode, sonst dessen
 * Position (getChildAt(int i))/*ww w.j a v a  2  s .  co m*/
 * 
 * @param docNode
 * @param treeNode
 * @return
 */
private int getDocNodeChildPos(DocNodeBase docNode, DefaultMutableTreeNode treeNode) {
    for (int i = 0; i < treeNode.getChildCount(); i++) {
        if (docNode.toString()
                .equals(((DefaultMutableTreeNode) treeNode.getChildAt(i)).getUserObject().toString()))
            return i;
    }
    return -1;
}