Array binary tree toString() – output like a tree

How to output a binary tree like this:

tree

/**
     * a String representation of a binary tree
     */
    public String toString(){          

        String output = "";  
        int depth = 0;
        int arraySpots = tree.length;

        while (arraySpots > 0){
        	arraySpots /= 2;
        	++depth;
        }

        int maxWidth = (int) (Math.pow(2, depth));
    	int charWidth = 4*maxWidth;
    	int idx = 0;
    	for (int i = 0; i < depth; ++i) {
    		int level = (int) Math.pow(2, i);
    		for (int j = 0; j < level; ++j) {
    			int preSpace = (int) ((charWidth/(Math.pow(2,(i + 1))) - 1));

    			for (int k = 0; k < preSpace; ++k) {
    				output += " ";
    			}

    			output +=tree[idx];
    			++idx;
    			if (idx >= size()) {
    				output += "\n";
    				break;
    			}
    			for (int k = 0; k < preSpace; ++k) {
    				output +=" ";
    			}
    		}
    		output += "\n\n";
    	}
    	return output;
    }

ArrayBinarySearchTree.java

package jsjf;

@SuppressWarnings("rawtypes")
public class ArrayBinarySearchTree<T extends Object & Comparable<T>>extends ArrayBinaryTree implements BinarySearchTreeADT{
private int temp;

	/**
	 * Starts addElement process
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void addElement(Object e) {
		Comparable<T> element = (Comparable) e;
		if (tree[0] == null){
			findSpot(element, 0);
		}
		else if (element.compareTo((T) tree[0]) >= 0){
			findSpot(element, 2);
		}
		else if(element.compareTo((T) tree[0]) < 0){
			findSpot(element, 1);
		}   
	}

	/**
	 * @param e target element
	 * @paramidx index
	 */
	public void findSpot(Comparable e, int idx){
		Comparable<T> temp = (Comparable<T>) e;
		if(idx*2+2 < count)
			expandCapacity();
		if(tree[idx] == null){
			tree[idx] = temp;
			count++;
		}
		else if (temp.compareTo((T) tree[idx]) >= 0){
			findSpot(temp, idx*2+2);
		}
		else if (temp.compareTo((T) tree[idx]) < 0){
			findSpot(temp, idx*2+1);
		}

	}

	/**
	 * @paramtargetElement Element we want to remove
	 * @return the element we removed
	 */
	@Override
	public Object removeElement(Object targetElement) {

		int idx = 0;
		T e = (T) targetElement;
		boolean found = false;

		int location = findIndex((T) targetElement, 0);
		removeElement(e, location);		

		return targetElement;

	}

	/**
	 * 
	 * @param e target element
	 * @paramidx index of the node
	 */
	private void removeElement(T e, int idx){

		// Leaf
		if(tree[idx*2+1] == null&&tree[idx*2+2] == null){
			tree[idx] = null;
			count--;
		}

		else if(tree[idx*2+1] != null || tree[idx*2+2] != null){
			int replacement = 0;

			// Single right Child
			if(tree[idx*2+2] != null&&tree[idx*2+1] == null){ 
				replacement = getInOrderSuccessor(idx*2+2, idx);
				tree[idx] = tree[replacement];
				tree[replacement] = null;
				count--;
			}

			// Single left Child
			if(tree[idx*2+2] == null&&tree[idx*2+1] != null){ 
				replacement = getInOrderPreDecessor(idx*2+1, idx);
				tree[idx] = tree[replacement];
				tree[replacement] = null;
				count--;
			}

			// 2 Children
			if (tree[idx*2+1] != null&&tree[idx*2+2] != null){

				if(e.compareTo((T) tree[0]) < 0){
					replacement = getInOrderSuccessor(idx*2+1, idx);

				}
				else if (e.compareTo((T) tree[0]) >= 0){
					replacement = getInOrderSuccessor(idx*2+2, idx);
				}

				tree[idx] = tree[replacement];
				removeElement(e, replacement);
				count --;
			}
		}

	/**
	 * 	Gets the In Order PreDecessor for removing elements
	*  @returnint index of the IOPD
	 */
	}
	private int getInOrderPreDecessor(int idx, int oldRoot){

		if(tree[idx*2+2] == null){	
			temp = idx;
		}
		if(tree[idx*2+2] != null)
			getInOrderPreDecessor(idx*2+2, oldRoot);

		return temp;
	}

	/**
	 * 
	 * @param idx get IO Successor for this index
	 * @param oldRoot the node we want to replace
	 * @return the IOSuccessor index
	 */
	private int getInOrderSuccessor(int idx, int oldRoot){

		// Go right
		if(((Comparable<T>) tree[oldRoot]).compareTo((T) tree[0]) >= 0){
			if(tree[idx*2+1] == null){
				temp = idx;	
			}			
			else if(tree[idx*2+1] != null)
				getInOrderSuccessor(idx*2+1, oldRoot);
		}

		// Go left
		else if (((Comparable<T>) tree[oldRoot]).compareTo((T) tree[0]) < 0){

			if(tree[idx*2+2] == null){
				temp = idx;
			}
			if(tree[idx*2+2] != null)
				getInOrderSuccessor(idx*2+2, oldRoot);
		}
		return temp;
	}

	/**
	 * @param e element we're looking for
	 * @param idx index to start looking
	 * @return if found, return its index
	 */
	private int findIndex(T e, int idx){
		if (idx*2+2 < tree.length){
			temp = -1;

			if (e.equals(tree[idx])){
				temp = idx;
			}
			else if (tree[idx] != null){
				if (e.compareTo((T) tree[idx]) < 0){
					findIndex(e, idx*2+1);
				}
				 else if (e.compareTo((T) tree[idx]) >= 0){
					findIndex(e, idx*2+2);
				}
			}

		}

		return temp;

	}
	/**
	 * Remove all occurrences of a node
	 */
	@Override
	public void removeAllOccurrences(Object targetElement) {
		if (count > 0)
			if(findIndex((T) targetElement, 0) > -1){
				removeElement(targetElement);
				removeAllOccurrences(targetElement);
			}
			else
				return;

	}

	/**
	 * Remove the smallest element and return it
	 * @return max element
	 */
	public Object removeMin() {
		int idx = 0;
		boolean found = false;
		while(idx*2+2 <count&& !found){
			if(tree[idx*2+1] == null){
				found = true;

			}else{
				idx=idx*2+1;
			}
		}
		removeElement(tree[idx]);
		return tree[idx];
	}

	/**
	 * Remove the largest element and return it
	 * @return max element
	 */
	public Object removeMax() {
		int idx = 0;
		boolean found = false;
		while(idx*2+2 < count && !found){
			if(tree[idx*2+2] == null){
				found = true;
			}else{
				idx=idx*2+2;
			}
		}

		removeElement(tree[idx]);
		return tree[idx];

	}

	/**
	 * @return smallest element
	 */
	public Object findMin() {

		int idx = 0;
		boolean found = false;
		while(!found){
			if(tree[idx*2+1] == null){
				found = true;
			}else{
				idx=idx*2+1;
			}
		}

		return tree[idx];
	}

	/**
	 * @return largest element
	 */
	public Object findMax() {

		int idx = 0;
		boolean found = false;
		while(!found){
			if(tree[idx*2+2] == null){
				found = true;
			}else{
				idx=idx*2+2;
			}
		}

		return tree[idx];
	}

}