Example usage for javax.swing.tree DefaultMutableTreeNode insert

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

Introduction

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

Prototype

public void insert(MutableTreeNode newChild, int childIndex) 

Source Link

Document

Removes newChild from its present parent (if it has a parent), sets the child's parent to this node, and then adds the child to this node's child array at index childIndex.

Usage

From source file:TreeUtil.java

public void addNode(String name, Object obj) {
    itsMap.put(name, obj);/*ww w  .j  a v a 2  s  .c o m*/
    DefaultMutableTreeNode tempNode = itsRootNode;
    StringTokenizer tok = new StringTokenizer(name, ".");
    String currentName = null;
    while (tok.hasMoreTokens()) {
        String myTok = tok.nextToken();
        currentName = (currentName == null) ? myTok : currentName + "." + myTok;
        boolean createNew = true;
        for (int j = 0; j < tempNode.getChildCount(); j++) {
            DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) tempNode.getChildAt(j);
            if (childNode.toString().equals(myTok)) {
                tempNode = childNode;
                createNew = false;
                break;
            }
        }
        if (createNew) {
            DefaultMutableTreeNode aNode = new DefaultMutableTreeNode(myTok);
            itsTreeMap.put(currentName, aNode);
            // Let's give some consideration to where in the tree we place
            // the new node.
            // We want any nodes with children to be listed first, in
            // alphabetical order.
            // Then come nodes with no children, in alphabetical order.
            if (tok.hasMoreTokens()) {
                // This node is not a leaf node
                int targeti;
                for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) {
                    TreeNode bNode = tempNode.getChildAt(targeti);
                    if (bNode.isLeaf() || bNode.toString().compareToIgnoreCase(myTok) > 0) {
                        break;
                    }
                }
                tempNode.insert(aNode, targeti);
            } else {
                // This node is a leaf node
                int targeti;
                for (targeti = 0; targeti < tempNode.getChildCount(); targeti++) {
                    TreeNode bNode = tempNode.getChildAt(targeti);
                    if (bNode.isLeaf() && bNode.toString().compareToIgnoreCase(myTok) > 0) {
                        break;
                    }
                }
                tempNode.insert(aNode, targeti);
            }
            tempNode = aNode;
        }
    }
}

From source file:com.emental.mindraider.ui.outline.OutlineJPanel.java

/**
 * Up concept.//w w  w .ja v  a 2 s  .c  om
 */
public boolean conceptUp() {
    // move concept up in the tree
    DefaultMutableTreeNode node = getSelectedTreeNode();
    if (node != null) {
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
        if (parent != null) {
            DefaultMutableTreeNode previousSibling = node.getPreviousSibling();
            if (previousSibling != null) {
                // move it up in the model
                if (MindRaider.noteCustodian.up(MindRaider.outlineCustodian.getActiveOutlineResource(),
                        ((OutlineNode) parent).getUri(), ((OutlineNode) node).getUri())) {
                    int siblingIndex = parent.getIndex(previousSibling);
                    parent.remove(node);
                    parent.insert(node, siblingIndex);
                    treeTable.updateUI();
                    logger.debug(Messages.getString("NotebookOutlineJPanel.noMovedUp"));
                    return true;
                }
                // else it is the first concept in the sequence
            } else {
                logger.debug("No sibling!");
            }
        } else {
            logger.debug(Messages.getString("NotebookOutlineJPanel.noParent"));
        }
    } else {
        logger.debug(Messages.getString("NotebookOutlineJPanel.noNodeSelected"));
    }
    return false;
}

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  va  2s.  c o m*/

        // 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:UserInterface.CustomerRole.CustomerOrderSchedulingJPanel.java

public void populateTree() {
    DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
    ArrayList<Network> networkList = system.getNetworkList();
    ArrayList<Enterprise> enterpriseList;
    ArrayList<Organization> organizationList;

    Network network;/*ww w. j  a v  a2  s  .  c o  m*/
    Enterprise enterprise;
    Organization organization;

    DefaultMutableTreeNode networks = new DefaultMutableTreeNode("Networks");
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    root.removeAllChildren();
    root.insert(networks, 0);

    DefaultMutableTreeNode networkNode;
    DefaultMutableTreeNode enterpriseNode;

    DefaultMutableTreeNode organizationNode;

    for (int i = 0; i < networkList.size(); i++) {
        network = networkList.get(i);
        networkNode = new DefaultMutableTreeNode(network.getName());
        networks.insert(networkNode, i);

        enterpriseList = network.getEnterpriseDirectory().getEnterpriseList();

        for (int j = 0; j < enterpriseList.size(); j++) {
            enterprise = enterpriseList.get(j);
            enterpriseNode = new DefaultMutableTreeNode(enterprise.getName());
            networkNode.insert(enterpriseNode, j);

            organizationList = enterprise.getOrganizationDirectory().getOrganizationList();

            for (int k = 0; k < organizationList.size(); k++) {
                organization = organizationList.get(k);
                organizationNode = new DefaultMutableTreeNode(organization.getName());
                enterpriseNode.insert(organizationNode, k);
            }
        }
    }
    model.reload();
}

From source file:view.MultipleValidationDialog.java

/**
 * Creates new form MultipleValidationDialog
 *
 * @param parent// www  . j  a v  a  2 s.co  m
 * @param modal
 * @param files
 */
public MultipleValidationDialog(java.awt.Frame parent, boolean modal, final ArrayList<File> files) {
    super(parent, modal);
    initComponents();

    updateText();

    this.setSize(1024, 768);
    lblRevision.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    final DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(null);
    panelSignatureDetails.setVisible(false);
    btnSaveInFile.setEnabled(false);
    jtValidation.setModel(null);
    jtValidation.setVisible(false);
    progressBar.setString(Bundle.getBundle().getString("pb.validating") + " 1 "
            + Bundle.getBundle().getString("of") + " " + files.size());
    progressBar.setMaximum(files.size());
    final ValidationListener vl = new ValidationListener() {
        int numParsed = 1;

        @Override
        public void onValidationComplete(SignatureValidation sv) {
            Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> tempEntry = null;
            while (tempEntry == null) {
                for (Map.Entry<ValidationFileListEntry, ArrayList<SignatureValidation>> entry : hmValidation
                        .entrySet()) {
                    if (entry.getKey().getFilename().equals(sv.getFilename())) {
                        tempEntry = entry;
                        break;
                    }
                }
                if (sv.isCertification()) {
                    if (sv.isValid()) {
                        tempEntry.getKey()
                                .setValidationStatus(ValidationFileListEntry.ValidationStatus.CERTIFIED);
                    } else {
                        tempEntry.getKey()
                                .setValidationStatus(ValidationFileListEntry.ValidationStatus.INVALID);
                    }
                } else if (sv.isValid()) {
                    tempEntry.getKey().setValidationStatus(ValidationFileListEntry.ValidationStatus.ALL_OK);
                } else {
                    tempEntry.getKey().setValidationStatus(ValidationFileListEntry.ValidationStatus.INVALID);
                }
                tempEntry.getValue().add(sv);
            }
        }
    };

    Runnable r = new Runnable() {
        @Override
        public void run() {
            int numParsed = 0;
            for (File file : files) {
                try {
                    ArrayList<SignatureValidation> svList = new ArrayList<>();
                    int numSigs = CCInstance.getInstance().getNumberOfSignatures(file.getAbsolutePath());
                    ValidationFileListEntry vfle = new ValidationFileListEntry(file.getAbsolutePath(), numSigs,
                            ValidationFileListEntry.ValidationStatus.UNKNOWN);
                    hmValidation.put(vfle, svList);
                    CCInstance.getInstance().validatePDF(file.getAbsolutePath(), vl);
                    dmtn.insert(new DefaultMutableTreeNode(vfle), 0);
                } catch (IOException | DocumentException | GeneralSecurityException ex) {
                    if (ex.getLocalizedMessage().contains("keystore\\aCCinaPDF_cacerts")) {
                        JOptionPane.showMessageDialog(MultipleValidationDialog.this,
                                Bundle.getBundle().getString("errorDefaultKeystore"),
                                WordUtils.capitalize(Bundle.getBundle().getString("error")),
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        JOptionPane.showMessageDialog(MultipleValidationDialog.this,
                                Bundle.getBundle().getString("unknownErrorLog"),
                                WordUtils.capitalize(Bundle.getBundle().getString("error")),
                                JOptionPane.ERROR_MESSAGE);
                        controller.Logger.getLogger().addEntry(ex);
                    }
                    break;
                }
                numParsed++;
                progressBar.setValue(numParsed);
                progressBar.setString(Bundle.getBundle().getString("pb.validating") + " " + numParsed + " "
                        + Bundle.getBundle().getString("of") + " " + files.size());

                TreeModel tm = new DefaultTreeModel(dmtn);
                jtFiles.setModel(tm);
            }
            progressBar.setString(Bundle.getBundle().getString("pb.validationComplete"));
            if (numParsed > 0) {
                jtFiles.setSelectionRow(0);
                btnSaveInFile.setEnabled(true);
            }
        }
    };

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

    jtValidation.setVisible(true);

    FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer();
    jtFiles.setCellRenderer(renderer1);
    ToolTipManager.sharedInstance().registerComponent(jtFiles);
    ValidationTreeCellRenderer renderer = new ValidationTreeCellRenderer();
    jtValidation.setCellRenderer(renderer);
}