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:org.olivier.ihm.FramePUMLCleanerControler.java

/**
 * Analyse une ligne et dtermine si elle est imprimable ou pas
 *
 * @param line La ligne  analyser//  w w w. jav  a2  s . co  m
 * @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

/**
 * Slectionne les noeuds dans l'arbre de filtrage corespondant au motif
 * @param motif Le motif pour slectionner les noeuds
 * @param jTreeFiltre L'arbre de filtrage
 *///from  w w w.  j  a  v a2  s.  co  m
public void selectionnerNoeud(String motif, JTree jTreeFiltre) {
    // TODO :  finir

    TreePath[] allPath = Util.getPaths(jTreeFiltre, true);
    // parcours des categories
    for (TreePath path : allPath) {
        // recup de la racine
        final DefaultMutableTreeNode root = (DefaultMutableTreeNode) path.getLastPathComponent();

        // parcours des catgories
        for (int j = 0; j < root.getChildCount(); j++) {
            final TreeNode categ = root.getChildAt(j);

            // parcours des noeuds
            for (j = 0; j < categ.getChildCount(); j++) {
                final TreeNode unNoeudSelectionner = categ.getChildAt(j);
                if (!unNoeudSelectionner.toString().contains(motif)) {

                }
            }
        }
    }
    checkTreeManager.getSelectionModel().setSelectionPaths(allPath);
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Searches all children of the currentNode and adds the node to it.
 * /*from  w w w  . j a  v  a2s . c  om*/
 * @param addNode
 * @param currentNode
 * @return
 */
public int addNodeToModel(TreeNode addNode, TreeNode currentNode) {

    int chInt = currentNode.getChildCount();
    int i = 0;

    for (; i < chInt; i++) {

        String currentNodeIdentifier = ((OIDObject) ((DefaultMutableTreeNode) currentNode.getChildAt(i))
                .getUserObject()).getIdentifier();

        String pathNodeIdentifer = ((OIDObject) ((DefaultMutableTreeNode) addNode).getUserObject())
                .getIdentifier();

        if (currentNodeIdentifier.equals(pathNodeIdentifer)) {
            return -1; //Already added, scenario never occurs.
        } else if (containsOID(currentNodeIdentifier, pathNodeIdentifer)) {
            i = addNodeToModel(addNode, currentNode.getChildAt(i));
            //currentNode and pathNode share OID, continue search one level below
        }
    }
    //None of the children of the current node have a child sharing the OID, add node to the current Node
    if (i <= chInt) {
        ((DefaultMutableTreeNode) currentNode).add((DefaultMutableTreeNode) addNode);
        return chInt + 2;
    }
    return i + chInt;
}

From source file:org.openehealth.coms.cc.web_frontend.consentcreator.service.ConsentCreatorUtilities.java

/**
 * Searches all children of the currentNode and adds the path to it.
 * /*from  w  w w .j  a  v a2 s .c  o m*/
 * @param path
 * @param currentNode
 * @param depth
 * @return
 */
public int addNodeToModel(TreeNode[] path, TreeNode currentNode, int depth) {

    int chInt = currentNode.getChildCount();
    int i = 0;

    for (; i < chInt; i++) {

        String currentNodeIdentifier = ((OIDObject) ((DefaultMutableTreeNode) currentNode.getChildAt(i))
                .getUserObject()).getIdentifier();

        String pathNodeIdentifer = ((OIDObject) ((DefaultMutableTreeNode) path[depth]).getUserObject())
                .getIdentifier();

        if (currentNodeIdentifier.equals(pathNodeIdentifer)) {
            if (depth == path.length) {
                return -1; //Already added, scenario never occurs.
            } else {
                addNodeToModel(path, currentNode.getChildAt(i), depth + 1);
                return -1;
            }
        } else if (containsOID(currentNodeIdentifier, pathNodeIdentifer)) {
            i = addNodeToModel(path, currentNode.getChildAt(i), depth + 1);
            //currentNode and pathNode share OID, continue search one level below
        }
    }
    //None of the children of the current node have a child sharing the OID, add the remaining path to the current Node
    if (i <= chInt) {
        int k = depth;
        DefaultMutableTreeNode nodeToAddTo = (DefaultMutableTreeNode) currentNode;

        for (; k < path.length; k++) {
            DefaultMutableTreeNode newNode = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) path[k])
                    .clone();
            nodeToAddTo.add(newNode);
            nodeToAddTo = newNode;
        }
        return chInt + 2;
    }
    return i + chInt;

}

From source file:phex.gui.tabs.library.LibraryTab.java

private JPanel createTreePanel(MouseHandler mouseHandler) {
    JPanel panel = new JPanel();
    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("fill:d:grow", // columns
            "fill:d:grow, 1dlu, p"); //rows
    PanelBuilder tabBuilder = new PanelBuilder(layout, panel);

    sharingTreeModel = new SharingTreeModel();
    mainTree = new JTree(sharingTreeModel);
    mainTree.setMinimumSize(new Dimension(0, 0));
    mainTree.setRowHeight(0);//from  w w w . j a va 2  s .co m
    mainTree.setCellRenderer(new SharingTreeRenderer());
    mainTree.addMouseListener(mouseHandler);

    mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler());
    ToolTipManager.sharedInstance().registerComponent(mainTree);

    // open up first level of nodes
    TreeNode root = (TreeNode) sharingTreeModel.getRoot();
    int count = root.getChildCount();
    for (int i = 0; i < count; i++) {
        mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) }));
    }

    JScrollPane treeScrollPane = new JScrollPane(mainTree);
    tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1));

    FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL);
    shareToolbar.setBorderPainted(false);
    shareToolbar.setFloatable(false);
    tabBuilder.add(shareToolbar, cc.xy(1, 3));

    FWAction action = new AddShareFolderAction();
    addTabAction(ADD_SHARE_FOLDER_ACTION_KEY, action);
    shareToolbar.addAction(action);

    action = new RemoveShareFolderAction();
    addTabAction(REMOVE_SHARE_FOLDER_ACTION_KEY, action);
    shareToolbar.addAction(action);

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        action = new ExploreFolderAction();
        addTabAction(EXPLORE_FOLDER_ACTION_KEY, action);
    }

    return panel;
}

From source file:phex.gui.tabs.library.LibraryTreePane.java

private void prepareComponent() {
    CellConstraints cc = new CellConstraints();
    FormLayout layout = new FormLayout("fill:d:grow", // columns
            "fill:d:grow, 1dlu, p"); //rows
    PanelBuilder tabBuilder = new PanelBuilder(layout, this);

    sharingTreeModel = new SharingTreeModel();
    mainTree = new JTree(sharingTreeModel);
    mainTree.setMinimumSize(new Dimension(0, 0));
    mainTree.setRowHeight(0);/*from  ww w  .ja  v a2  s .  c om*/
    mainTree.setCellRenderer(new SharingTreeRenderer());
    mainTree.addMouseListener(new MouseHandler());

    mainTree.getSelectionModel().addTreeSelectionListener(new SelectionHandler());
    ToolTipManager.sharedInstance().registerComponent(mainTree);

    // open up first level of nodes
    TreeNode root = (TreeNode) sharingTreeModel.getRoot();
    int count = root.getChildCount();
    for (int i = 0; i < count; i++) {
        mainTree.expandPath(new TreePath(new Object[] { root, root.getChildAt(i) }));
    }

    JScrollPane treeScrollPane = new JScrollPane(mainTree);
    tabBuilder.add(treeScrollPane, cc.xywh(1, 1, 1, 1));

    FWToolBar shareToolbar = new FWToolBar(FWToolBar.HORIZONTAL);
    shareToolbar.setBorderPainted(false);
    shareToolbar.setFloatable(false);
    tabBuilder.add(shareToolbar, cc.xy(1, 3));

    addShareFolderAction = new AddShareFolderAction();
    shareToolbar.addAction(addShareFolderAction);

    removeShareFolderAction = new RemoveShareFolderAction();
    shareToolbar.addAction(removeShareFolderAction);

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        exploreFolderAction = new ExploreFolderAction();
    }

    fileTreePopup = new FWPopupMenu();
    fileTreePopup.addAction(addShareFolderAction);
    fileTreePopup.addAction(removeShareFolderAction);

    if (SystemUtils.IS_OS_WINDOWS || SystemUtils.IS_OS_MAC_OSX) {
        fileTreePopup.addAction(exploreFolderAction);
    }
}