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:TreeUtil.java

/** Creates the menus by using recursion */
public JMenuItem getMenus(DefaultMutableTreeNode node, JMenu parentMenu) {
    String name = node.getUserObject().toString();
    int numChild = node.getChildCount();
    if (numChild < 1) {
        JMenuItem tempMenu = new JMenuItem(name);
        tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name);
        tempMenu.addActionListener(this);
        return tempMenu;
    }/*from www  . ja v  a2  s  . com*/
    JMenu tempMenu = new JMenu(name);
    tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name);
    tempMenu.addActionListener(this);
    for (int i = 0; i < numChild; i++) {
        tempMenu.add(getMenus((DefaultMutableTreeNode) node.getChildAt(i), tempMenu));
    }
    return tempMenu;
}

From source file:com.enderville.enderinstaller.ui.Installer.java

private void buildInstallingPane() {

    getNextButton().setEnabled(false);/* www  .j a v  a2s . co m*/
    getCancelButton().setEnabled(false);
    getMainPane().removeAll();
    getMainPane().setLayout(new MigLayout(new LC().fill()));
    final JTextArea text = new JTextArea();
    text.setEditable(false);
    getMainPane().add(new JScrollPane(text), new CC().grow().spanY().wrap());
    getMainPane().validate();
    getMainPane().repaint();
    SwingWorker<Object, String> worker = new SwingWorker<Object, String>() {

        @Override
        protected Object doInBackground() throws Exception {
            try {
                List<String> mods = new ArrayList<String>();
                CheckBoxTreeSelectionModel select = getModTree().getCheckBoxTreeSelectionModel();
                TreePath[] paths = select.getSelectionPaths();
                if (paths != null && paths.length > 0) {
                    for (TreePath path : paths) {
                        DefaultMutableTreeNode node = ((DefaultMutableTreeNode) path.getLastPathComponent());
                        String mod = (String) node.getUserObject();
                        if (mod == null) {
                            for (int i = 0; i < node.getChildCount(); i++) {
                                DefaultMutableTreeNode child = (DefaultMutableTreeNode) node.getChildAt(i);
                                mods.add((String) child.getUserObject());
                            }
                        } else {
                            mods.add(mod);
                        }
                    }
                }
                InstallScript.guiInstall(mods, text, getProgressBar());
            } catch (Exception e) {
                LOGGER.error("Error while trying to install mods", e);
                JOptionPane.showMessageDialog(Installer.this,
                        "Unexpected error while installing mods:\n" + e.getMessage(), "Error",
                        JOptionPane.ERROR_MESSAGE);
                setVisible(false);
                dispose();
            }
            return null;
        }

        @Override
        public void done() {
            getNextButton().removeActionListener(Installer.this);
            getNextButton().setText("Done");
            getNextButton().addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                    dispose();
                }
            });
            getNextButton().setEnabled(true);
        }
    };

    worker.execute();
}

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

private void updateHierarchy(DefaultMutableTreeNode parentNode, Hierarchy hierarchy,
        HierarchyNode hierarchyNode) {/*  w  w w  . j  a v a 2 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:com.pironet.tda.SunJDKParser.java

private void renormalizeMonitorDepth(DefaultMutableTreeNode monitorNode, int index) {
    // First, remove all duplicates of the item at index "index"
    DefaultMutableTreeNode threadNode1 = (DefaultMutableTreeNode) monitorNode.getChildAt(index);
    ThreadInfo mi1 = (ThreadInfo) threadNode1.getUserObject();
    int i = index + 1;
    while (i < monitorNode.getChildCount()) {
        DefaultMutableTreeNode threadNode2 = (DefaultMutableTreeNode) monitorNode.getChildAt(i);
        ThreadInfo mi2 = (ThreadInfo) threadNode2.getUserObject();
        if (mi1.getName().equals(mi2.getName())) {
            if (threadNode2.getChildCount() > 0) {
                threadNode1.add((DefaultMutableTreeNode) threadNode2.getFirstChild());
                monitorNode.remove(i);/*from ww  w.  ja  v a 2s  .  com*/
                continue;
            }
        }
        i++;
    }

    // Second, recurse into item "index"
    renormalizeThreadDepth(threadNode1);
}

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  av 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;
}

From source file:SuitaDetails.java

public void setComboTBs() {
    if (parent == null)
        return;/*from   w w  w  .j  av  a 2 s.  c o  m*/
    for (ListSelectionListener l : combo.getListSelectionListeners()) {
        combo.removeListSelectionListener(l);
    }
    StringBuilder b = new StringBuilder();
    DefaultMutableTreeNode root = RunnerRepository.window.mainpanel.p4.getSut().sut.root;
    int sutsnr = root.getChildCount();
    for (int i = 0; i < sutsnr; i++) {
        b.append(root.getChildAt(i).toString());
        b.append(";");
    }

    //         StringBuilder b = new StringBuilder();

    //         Node parentnode = RunnerRepository.window.mainpanel.p4.getTB().getParentNode();
    //         HashMap children =  parentnode.getChildren();
    //         if(children!=null&&children.size()!=0){
    //             Set keys = children.keySet();
    //             Iterator iter = keys.iterator();
    //             while(iter.hasNext()){
    //                 String n = iter.next().toString();
    //                 String name = parentnode.getChild(n).getName();
    //                 b.append(name);
    //                 b.append(";");
    //             }
    //         }
    String[] vecresult = b.toString().split(";");

    combo.setModel(new DefaultComboBoxModel(vecresult));

    String[] strings = parent.getEpId();
    ArrayList<String> array = new ArrayList<String>(Arrays.asList(vecresult));
    int[] sel = new int[strings.length];
    for (int i = 0; i < strings.length; i++) {
        sel[i] = array.indexOf(strings[i]);
    }
    combo.setSelectedIndices(sel);
    combo.addListSelectionListener(new MyListSelectionListener());

}

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

public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    QueryConceptTreeNodeData data = (QueryConceptTreeNodeData) node.getUserObject();

    //System.out.println("Node will expand: "+data.dimcode());   

    if (data.visualAttribute().equals("FA")) {
        data.visualAttribute("FAO");
    } else if (data.visualAttribute().equals("CA")) {
        data.visualAttribute("CAO");
    }/*from   www. j a  v a2 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
            && !(node.getChildAt(0).toString().equalsIgnoreCase("Over 300 child nodes"))) {
        DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) node.getChildAt(0);
        if (((QueryConceptTreeNodeData) node1.getUserObject()).visualAttribute().equals("LAO")) {
            populateChildNodes(node);
        }
    } else {
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode anode = (DefaultMutableTreeNode) node.getChildAt(0);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

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

private void reNormalizeBlockingThreadTree(final MonitorMap mmap,
        final Map<String, DefaultMutableTreeNode> directChildMap) {
    Map<String, DefaultMutableTreeNode> allBlockingThreadsMap = new HashMap<>(directChildMap); // All threads that are blocking at least one other thread

    // First, re-normalize based on monitors to get our unique tree
    // Tree will be unique as long as there are no deadlocks aka monitor loops
    for (Iterator iter = mmap.iterOfKeys(); iter.hasNext();) {
        String monitor1 = (String) iter.next();
        Map<String, String>[] threads1 = mmap.getFromMonitorMap(monitor1);

        final DefaultMutableTreeNode thread1Node = allBlockingThreadsMap.get(monitor1);
        if (thread1Node == null) {
            continue;
        }/*from  w w w.j a  v a  2 s . c  om*/

        // Get information on the one thread holding this lock
        Iterator it = threads1[MonitorMap.LOCK_THREAD_POS].keySet().iterator();
        if (!it.hasNext()) {
            continue;
        }
        String threadLine1 = (String) it.next();

        for (Iterator iter2 = mmap.iterOfKeys(); iter2.hasNext();) {
            String monitor2 = (String) iter2.next();
            if (monitor1 == monitor2) {
                continue;
            }

            Map<String, String>[] threads2 = mmap.getFromMonitorMap(monitor2);
            if (threads2[MonitorMap.WAIT_THREAD_POS].containsKey(threadLine1)) {
                // Get the node of the thread that is holding this lock
                DefaultMutableTreeNode thread2Node = (DefaultMutableTreeNode) allBlockingThreadsMap
                        .get(monitor2);
                // Get the node of the monitor itself
                DefaultMutableTreeNode monitor2Node = (DefaultMutableTreeNode) thread2Node.getFirstChild();

                // If a redundant node for thread2 exists with no children, remove it
                // To compare, we have to remove "Thread - " from the front of display strings
                for (int i = 0; i < monitor2Node.getChildCount(); i++) {
                    DefaultMutableTreeNode child2 = (DefaultMutableTreeNode) monitor2Node.getChildAt(i);
                    if (child2.toString().substring(9).equals(threadLine1) && child2.getChildCount() == 0) {
                        monitor2Node.remove(i);
                        break;
                    }
                }

                // Thread1 is blocked by monitor2 held by thread2, so move thread1 under thread2
                monitor2Node.insert(thread1Node, 0);
                directChildMap.remove(monitor1);
                break;
            }
        }
    }

    allBlockingThreadsMap.clear();

    // Second, re-normalize top level based on threads for cases where one thread holds multiple monitors
    boolean changed;
    do {
        changed = false;
        for (final Object o : directChildMap.entrySet()) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) ((Map.Entry) o).getValue();
            if (checkForDuplicateThreadItem(directChildMap, node)) {
                changed = true;
                break;
            }
        }
    } while (changed);

    // Third, renormalize lower levels of the tree based on threads for cases where one thread holds multiple monitors
    for (final Object o : directChildMap.entrySet()) {
        renormalizeThreadDepth((DefaultMutableTreeNode) ((Map.Entry) o).getValue());
    }
}

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

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

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

    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  .  com

    // 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 (((QueryConceptTreeNodeData) node1.getUserObject()).name().equalsIgnoreCase("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);
            QueryConceptTreeNodeData adata = (QueryConceptTreeNodeData) anode.getUserObject();
            if (adata.visualAttribute().equals("FAO")) {
                adata.visualAttribute("FA");
            } else if (adata.visualAttribute().equals("CAO")) {
                adata.visualAttribute("CA");
            }
        }
    }
}

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

private void addNotExistingNodes(DocPath pathToAdd, DefaultMutableTreeNode top) {
    if (pathToAdd == null || pathToAdd.size() == 0) {
        treeModel.insertNodeInto(new DefaultMutableTreeNode(MUST_LOAD_CHILDREN), top, 0);
        return;/*w  w  w . j a  v a 2 s  .co  m*/
    }
    boolean exists = false;
    DefaultMutableTreeNode node = null;
    for (int i = 0; i < top.getChildCount(); i++) {
        node = (DefaultMutableTreeNode) top.getChildAt(i);
        if (pathToAdd.asDocNodeList().get(0).toString().equals(node.getUserObject().toString())) {
            exists = true;
            break;
        }
    }
    if (!exists) {
        node = new DefaultMutableTreeNode(pathToAdd.asDocNodeList().get(0));
        treeModel.insertNodeInto(node, top, top.getChildCount());
    }
    DocPath subPath = pathToAdd.getDeepCopy();
    subPath.asDocNodeList().remove(0);
    addNotExistingNodes(subPath, node);
}