|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectgroovy.util.IndentPrinter
public class IndentPrinter extends Object
A helper class for printing indented text. This can be used stand-alone or, more commonly, from Builders.
By default, System.out is used as the PrintWriter, but it is possible to change the PrintWriter by passing a new one as a constructor argument.
Indention by default is 2 characters but can be changed by passing a different value as a constructor argument.
The following is an example usage. Note that within a "with" block you need to specify a parameter name so that this.println is not called instead of IndentPrinter.println:
new IndentPrinter(new PrintWriter(out)).with { p ->
p.printIndent()
p.println('parent1')
p.incrementIndent()
p.printIndent()
p.println('child 1')
p.printIndent()
p.println('child 2')
p.decrementIndent()
p.printIndent()
p.println('parent2')
p.flush()
}
The above example prints this to standard output:
parent1 child 1 child 2 parent2
| Constructor and Description |
|---|
IndentPrinter()
Creates a PrintWriter pointing to System.out, with an indent of two spaces. |
IndentPrinter(PrintWriter out)
Create an IndentPrinter to the given PrintWriter, with an indent of two spaces. |
IndentPrinter(PrintWriter out,
String indent)
Create an IndentPrinter to the given PrintWriter |
IndentPrinter(PrintWriter out,
String indent,
boolean addNewlines)
|
| Modifier and Type | Method and Description |
|---|---|
void |
decrementIndent()
|
void |
flush()
|
int |
getIndentLevel()
|
void |
incrementIndent()
|
void |
print(char c)
|
void |
print(String text)
|
void |
printIndent()
Prints the current indent level. |
void |
println()
|
void |
println(String text)
|
void |
setIndentLevel(int indentLevel)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IndentPrinter()
IndentPrinter(PrintWriter, String)public IndentPrinter(PrintWriter out)
out - PrintWriter to output toIndentPrinter(PrintWriter, String)
public IndentPrinter(PrintWriter out,
String indent)
out - PrintWriter to output toindent - character(s) used to indent each line
public IndentPrinter(PrintWriter out,
String indent,
boolean addNewlines)
| Method Detail |
|---|
public void println(String text)
public void print(String text)
public void print(char c)
public void printIndent()
public void println()
public void incrementIndent()
public void decrementIndent()
public int getIndentLevel()
public void setIndentLevel(int indentLevel)
public void flush()
|
Copyright © 2003-2010 The Codehaus. All rights reserved. | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||