1 46 package groovy.util; 47 48 import java.io.PrintWriter ; 49 50 56 public class IndentPrinter { 57 58 private int indentLevel; 59 private String indent; 60 private PrintWriter out; 61 62 public IndentPrinter() { 63 this(new PrintWriter (System.out), " "); 64 } 65 66 public IndentPrinter(PrintWriter out) { 67 this(out, " "); 68 } 69 70 public IndentPrinter(PrintWriter out, String indent) { 71 if (out == null) { 72 73 out = new PrintWriter (System.out); 74 } 76 this.out = out; 77 this.indent = indent; 78 } 79 80 public void println(String text) { 81 out.print(text); 82 out.println(); 83 } 84 85 public void print(String text) { 86 out.print(text); 87 } 88 89 public void printIndent() { 90 for (int i = 0; i < indentLevel; i++) { 91 out.print(indent); 92 } 93 } 94 95 public void println() { 96 out.println(); 97 } 98 99 public void incrementIndent() { 100 ++indentLevel; 101 } 102 103 public void decrementIndent() { 104 --indentLevel; 105 } 106 107 public int getIndentLevel() { 108 return indentLevel; 109 } 110 111 public void setIndentLevel(int indentLevel) { 112 this.indentLevel = indentLevel; 113 } 114 115 public void flush() { 116 out.flush(); 117 } 118 } 119 | Popular Tags |