001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.util;
019
020 import java.io.PrintWriter;
021
022 /**
023 * A helper class for printing indented text
024 *
025 * @version $Revision: 1.1.1.1 $
026 */
027 public class IndentPrinter {
028
029 private int indentLevel;
030 private String indent;
031 private PrintWriter out;
032
033 public IndentPrinter() {
034 this(new PrintWriter(System.out), " ");
035 }
036
037 public IndentPrinter(PrintWriter out) {
038 this(out, " ");
039 }
040
041 public IndentPrinter(PrintWriter out, String indent) {
042 this.out = out;
043 this.indent = indent;
044 }
045
046 public void println(Object value) {
047 out.print(value.toString());
048 out.println();
049 }
050
051 public void println(String text) {
052 out.print(text);
053 out.println();
054 }
055
056 public void print(String text) {
057 out.print(text);
058 }
059
060 public void printIndent() {
061 for (int i = 0; i < indentLevel; i++) {
062 out.print(indent);
063 }
064 }
065
066 public void println() {
067 out.println();
068 }
069
070 public void incrementIndent() {
071 ++indentLevel;
072 }
073
074 public void decrementIndent() {
075 --indentLevel;
076 }
077
078 public int getIndentLevel() {
079 return indentLevel;
080 }
081
082 public void setIndentLevel(int indentLevel) {
083 this.indentLevel = indentLevel;
084 }
085
086 public void flush() {
087 out.flush();
088 }
089 }