Example usage for javax.swing.tree DefaultMutableTreeNode toString

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the result of sending toString() to this node's user object, or the empty string if the node has no user object.

Usage

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Analyser le fichier PUML et initialiser le filtre
 *
 * @param jTextAreaFichier Le contenu du fichier PUML
 * @param jTreeFiltre Le filtre  initialiser
 *//*  w w w .  j  a v  a2  s . c om*/
private void analyserFichier(JTextArea jTextAreaFichier, JTree jTreeFiltre) {
    lines = jTextAreaFichier.getText().split("[\\r\\n]+");

    final DefaultMutableTreeNode newFilter = initaliserNodes();

    // parcours de chaque ligne du fichier pour analyse
    for (String line : lines) {
        if (line.contains(">")) {
            break;
        } else {
            String categ = "";
            String noeud = null;
            // recherche de la catgorie
            for (String categorie : categories) {
                if (line.contains(categorie)) {
                    categ = categorie;
                    noeud = line.replaceFirst(categorie, "").replaceAll(" ", "");
                    // ajout du noeud dans la bonne catgorie de l'arbre
                    for (int i = 0; i < newFilter.getChildCount(); i++) {
                        final DefaultMutableTreeNode dmtr = (DefaultMutableTreeNode) newFilter.getChildAt(i);
                        if (dmtr.toString().equals(categ)) {
                            final DefaultMutableTreeNode node = new DefaultMutableTreeNode(new NodeInfo(noeud));
                            dmtr.add(node);
                        }
                    }
                    break;
                }
            }
        }
    }
    jTreeFiltre.setModel(new DefaultTreeModel(newFilter));
    jTextAreaFichier.requestFocus();
}

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Analyse une ligne et dtermine si elle est imprimable ou pas
 *
 * @param line La ligne  analyser/*from   www  .  jav  a 2 s  .  com*/
 * @param nodeToDelete Liste des noeuds  supprimer
 * @return True si la ligne doit etre imprime, false sinon
 */
private boolean isLinePrintable(String line, DefaultMutableTreeNode nodeToDelete) {
    boolean isPrintable = true;

    // parcours des catgories
    for (int i = 0; i < nodeToDelete.getChildCount(); i++) {
        final TreeNode categ = nodeToDelete.getChildAt(i);
        // parcours des noeuds  supprimer
        for (int j = 0; j < categ.getChildCount(); j++) {
            final DefaultMutableTreeNode noeudToDelete = (DefaultMutableTreeNode) categ.getChildAt(j);
            final String nomNoeudToDelete = noeudToDelete.toString();

            if (line.contains(nomNoeudToDelete)) {
                isPrintable = false;
                break;
            }
        }
        if (!isPrintable) {
            break;
        }
    }
    return isPrintable;
}

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Renvoi la liste des noeuds non slectionns
 *
 * @param allTreeNode Liste de tous les noeuds
 * @param selectedPath Chemins slectionns
 * @return Liste des noeuds non slectionns
 *///  w w  w  .  j av a2s  .  c o m
private DefaultMutableTreeNode getNodeToDelete(DefaultMutableTreeNode allTreeNode, TreePath[] selectedPath) {
    final DefaultMutableTreeNode nodeToDelete = new DefaultMutableTreeNode("Node to delete");
    // Parcours de l'arbre pour supprimer les noeuds slectionns
    // Parcours des catgories  
    for (int i = 0; i < allTreeNode.getChildCount(); i++) {
        final DefaultMutableTreeNode tnCateg = (DefaultMutableTreeNode) allTreeNode.getChildAt(i);
        // les catgories sont systmatiquement ajoutes
        final DefaultMutableTreeNode newTnCateg = new DefaultMutableTreeNode(tnCateg.toString());//) allTreeNode.getChildAt(i);
        nodeToDelete.add(newTnCateg);
        // parcours des noeuds
        for (int j = 0; j < tnCateg.getChildCount(); j++) {
            final DefaultMutableTreeNode tnNoeud = (DefaultMutableTreeNode) tnCateg.getChildAt(j);
            // Ajout du noeud s'il n'est pas slectionn
            if (!isNoeudSelected(tnNoeud, selectedPath)) {
                /* 
                 Il est impratif de crer un nouveau noeud !
                 Si on se contente d'ajouter tnNoeud dans newTnCateg, celui-ci est supprim de tnCateg !
                 Visiblement, un noeud ne peut pas appartenir  2 arbres diffrents. Cela semble logique 
                 car la dfinition des anctres risque de poser problme.
                 A approfondir quand j'aurai le temps ...
                 */
                final DefaultMutableTreeNode newTnNoeud = new DefaultMutableTreeNode(
                        new NodeInfo(tnNoeud.toString()));
                newTnCateg.add(newTnNoeud);
            }
        }
    }
    return nodeToDelete;
}

From source file:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Indique si un noeud est slectionn ou pas
 *
 * @param noeudATester Le noeud  tester//  ww w.j  a v  a  2 s . co  m
 * @param selectedPath La liste des noeuds slectionns
 * @return True si le noeud est slectionn, false sinon
 */
private boolean isNoeudSelected(final DefaultMutableTreeNode noeudATester, final TreePath[] selectedPath) {
    boolean isSelected = false;

    // parcours des categories
    for (TreePath path : selectedPath) {
        try {
            // Cette ligne plante quand on slectionne une catgorie complte d'ou le try-catch !
            final DefaultMutableTreeNode unNoeudSelectionner = (DefaultMutableTreeNode) path.getPath()[2];
            isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString());
        } catch (ArrayIndexOutOfBoundsException ex) {
            // Quand on choisit une catgorie complte, il faut parcourir les noeuds de cette manire :
            // recup de la categorie
            final DefaultMutableTreeNode categ = (DefaultMutableTreeNode) path.getLastPathComponent();
            // parcours des noeuds dans la catgorie
            for (int j = 0; j < categ.getChildCount(); j++) {
                final TreeNode unNoeudSelectionner = categ.getChildAt(j);
                isSelected = noeudATester.toString().equals(unNoeudSelectionner.toString());
                if (isSelected) {
                    break;
                }
            }
        }
        // on sort de la boucle ds qu'on a la rponse
        if (isSelected) {
            break;
        }
    }

    return isSelected;
}

From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java

private void insertReports(final TreeModel model, final Object currentLevel, final XulMenupopup popup)
        throws XulException {
    final int childCount = model.getChildCount(currentLevel);
    for (int i = 0; i < childCount; i += 1) {
        final ReportDesignerView frame = context.getView();

        final Object child = model.getChild(currentLevel, i);
        if (model.isLeaf(child)) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) child;
            final File file = new File(String.valueOf(node.getUserObject()));
            final OpenSampleReportAction action = new OpenSampleReportAction(file, node.toString());
            action.setReportDesignerContext(context);
            popup.addChild(frame.createMenuItem(action));
        } else {/*from www . j  av a 2 s .  c o  m*/
            final XulMenupopup childPopup = frame.createPopupMenu(String.valueOf(child), popup);
            insertReports(model, child, childPopup);
        }
    }
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * Get the TreePath to this Artifact clause given a String rule and clause
 * name//from w ww  .  ja v  a 2  s .c o m
 *
 * @param ruleName   the rule name to find
 * @param clauseName the clause name to find
 *
 * @return
 */
private TreePath findTreePathByRuleAndArtifactClauseName(String ruleName, String clauseName) {
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> enumeration = rootNode.preorderEnumeration();
    boolean insideRule = false;
    while (enumeration.hasMoreElements()) {
        DefaultMutableTreeNode node = enumeration.nextElement();
        Item item = (Item) node.getUserObject();
        if (item.getItemType() == ItemType.RULE) {
            insideRule = node.toString().equalsIgnoreCase(ruleName);
        }

        if ((insideRule == true) && (item.getItemType() == ItemType.ARTIFACT_CLAUSE)
                && (item.getName().compareTo(clauseName) == 0)) {
            return new TreePath(node.getPath());
        }
    }
    return null;
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * Get the TreePath to this rule, given a String rule name.
 *
 * @param ruleName the name of the rule to find
 *
 * @return the TreePath to this rule, given a String rule name.
 *///from  ww  w .j ava 2 s  .co  m
private TreePath findTreePathByRuleName(String ruleName) {
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> enumeration = rootNode.depthFirstEnumeration();
    while (enumeration.hasMoreElements()) {
        DefaultMutableTreeNode node = enumeration.nextElement();
        if (node.toString().equalsIgnoreCase(ruleName)) {
            return new TreePath(node.getPath());
        }
    }
    return null;
}

From source file:ropes.MainWindow.java

private DefaultMutableTreeNode findNode(DefaultMutableTreeNode root, String s) {
    //reutrn node if exist in jtree
    @SuppressWarnings("unchecked")
    Enumeration<DefaultMutableTreeNode> e = root.depthFirstEnumeration();
    while (e.hasMoreElements()) {
        DefaultMutableTreeNode node = e.nextElement();
        if (node.toString().equalsIgnoreCase(s)) {
            return node;
        }/* w  w  w .  j av  a  2  s  . c  o m*/
    }
    return null;
}

From source file:UserInterface.CustomerRole.CustomerOrderSchedulingJPanel.java

private void jTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeValueChanged
    // TODO add your handling code here:
    DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) jTree.getLastSelectedPathComponent();
    if (selectedNode != null) {
        seletedFlag = 1;//from  w  w w .  ja va 2  s.  c  o  m
        selectedEnterpriseJLabel.setText(selectedNode.toString());
    }
}