Here you can find the source of getTreeIndents(TreeModel in)
Parameter | Description |
---|---|
in | - the tree model |
public static int[] getTreeIndents(TreeModel in)
//package com.java2s; //License from project: Apache License import javax.swing.tree.*; public class Main { /**// www. ja va 2 s . co m return the size of a tree starting at a specific root @param in - the tree model @return - the indents 0 = root */ public static int[] getTreeIndents(TreeModel in) { int[] ret = new int[getTreeModelSize(in)]; setTreeIndents(in, in.getRoot(), ret, 0, 0); return (ret); } /** return the size of a tree model @param in - the tree model @return - the size >= 0 */ public static int getTreeModelSize(TreeModel in) { Object root = in.getRoot(); if (root == null) return (0); return (getTreeModelSize(in, root)); } /** return the size of a tree starting at a specific root @param in - the tree model @parem root - starting node - non-null @return - the size >= 1 */ protected static int getTreeModelSize(TreeModel in, Object root) { int ret = 1; // add one for root for (int i = 0; i < in.getChildCount(root); i++) ret += getTreeModelSize(in, in.getChild(root, i)); return (ret); } /** return array of indents for a tree @param in - the tree model @parem root - starting node - non-null @parem items - array of indents @parem level - current indent level 0 = root @parem index - index on entry @return - index of first unused access */ protected static int setTreeIndents(TreeModel in, Object root, int[] items, int level, int index) { items[index++] = level; for (int i = 0; i < in.getChildCount(root); i++) index = setTreeIndents(in, in.getChild(root, i), items, level + 1, index); return (index); } }