001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  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    package org.apache.activemq.util;
018    
019    import java.io.PrintWriter;
020    
021    /**
022     * A helper class for printing indented text
023     *
024     * 
025     */
026    public class IndentPrinter {
027    
028        private int indentLevel;
029        private String indent;
030        private PrintWriter out;
031    
032        public IndentPrinter() {
033            this(new PrintWriter(System.out), "  ");
034        }
035    
036        public IndentPrinter(PrintWriter out) {
037            this(out, "  ");
038        }
039    
040        public IndentPrinter(PrintWriter out, String indent) {
041            this.out = out;
042            this.indent = indent;
043        }
044    
045        public void println(Object value) {
046            out.print(value.toString());
047            out.println();
048        }
049    
050        public void println(String text) {
051            out.print(text);
052            out.println();
053        }
054    
055        public void print(String text) {
056            out.print(text);
057        }
058    
059        public void printIndent() {
060            for (int i = 0; i < indentLevel; i++) {
061                out.print(indent);
062            }
063        }
064    
065        public void println() {
066            out.println();
067        }
068    
069        public void incrementIndent() {
070            ++indentLevel;
071        }
072    
073        public void decrementIndent() {
074            --indentLevel;
075        }
076    
077        public int getIndentLevel() {
078            return indentLevel;
079        }
080    
081        public void setIndentLevel(int indentLevel) {
082            this.indentLevel = indentLevel;
083        }
084    
085        public void flush() {
086            out.flush();
087        }
088    }