Java JTree Node listTree(TreeNode node, String prefix, String lineSeparator)

Here you can find the source of listTree(TreeNode node, String prefix, String lineSeparator)

Description

list Tree

License

Open Source License

Declaration

public static String listTree(TreeNode node, String prefix,
            String lineSeparator) 

Method Source Code

//package com.java2s;
/**//from w  w w  .j a v  a2 s .  co  m
 *    Copyright Masao Nagasaki
 *    Nagasaki Lab
 *    Laboratory of Biomedical Information Analysis,
 *    Department of Integrative Genomics,
 *    Tohoku Medical Megabank Organization, Tohoku University 
 *    @since 2013
 *
 *    This file is part of SUGAR (Subtile-based GUI-Assisted Refiner).
 *    SUGAR is an extension of FastQC (copyright 2010-12 Simon Andrews)
 *
 *    SUGAR is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    SUGAR is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with SUGAR; if not, write to the Free Software
 *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import javax.swing.tree.TreeNode;

public class Main {
    public static final String LEVEL_SEPARATOR = "- ";

    public static String listTree(TreeNode node) {
        return listTree(node, "", "\n");
    }

    public static String listTree(TreeNode node, String prefix,
            String lineSeparator) {
        String result = prefix
                + ((node.toString() != null) ? node.toString() : "")
                + lineSeparator;
        if (!node.isLeaf()) {
            for (int i = 0; i < node.getChildCount(); i++) {
                result += listTree(node.getChildAt(i), prefix
                        + LEVEL_SEPARATOR, lineSeparator);
            }
        }
        return result;
    }
}

Related

  1. isChildNode(DefaultMutableTreeNode parent, DefaultMutableTreeNode child)
  2. isMovingUp(DefaultMutableTreeNode ntarget, DefaultMutableTreeNode nsource)
  3. isNodeAsStrChild(DefaultMutableTreeNode parent, String child)
  4. isNodeOrChildSelected(JTree tree, DefaultMutableTreeNode node)
  5. isReflectanceType(TreeNode productTypeNode, String type)
  6. printTree(final DefaultMutableTreeNode tree, final String indent)
  7. recursiveTreeNode(DefaultMutableTreeNode node)
  8. refreshNode(final JTree tree, final TreeNode node)
  9. RemoveChildren(DefaultMutableTreeNode node)