blob: 76b75707b02220fab841480fb8e71d554a458f40 [file] [log] [blame]
/** Copyright (C) Conformiq Software Ltd.
* All rights reserved.
*
* Created Wed Aug 27 16:49:21 2008.
*
* @file PrettyPrinter.java
*
* @author Conformiq Software Ltd.
*
*
*/
package com.conformiq.adaptation.ttcn;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.List;
import java.util.Vector;
class PrettyPrinter extends PrintWriter
{
private List<String> stack;
private String header;
private boolean headerPrinted;
public PrettyPrinter(Writer writer)
{
super(writer);
this.stack = new Vector<String>();
this.header = "";
this.headerPrinted = true;
}
private void printHeader()
{
if (headerPrinted)
return;
for (int i = 0; i < this.stack.size(); i++)
{
super.print(this.stack.get(i));
}
this.headerPrinted = true;
}
public void print(String s)
{
printHeader();
this.header = this.header.concat(s);
super.print(s);
}
public void println(String s)
{
print(s);
endl();
}
// Start a new block
public void block()
{
this.stack.add(header);
this.header = "";
}
// Resume to previous state
public void resume()
{
// remove last
this.stack.remove(this.stack.size() - 1);
}
// Print EOL char
public void endl()
{
if (this.headerPrinted)
{ // suppress double empty lines
println();
this.header = "";
this.headerPrinted = false;
}
}
public void emptyline()
{
println();
this.header = "";
this.headerPrinted = false;
}
public void print(BigInteger bi)
{
print("" + bi.toString());
}
public void ws()
{
print(" ");
}
}