| /** Copyright (C) Conformiq Software Oy, Ltd. | |
| * All rights reserved. | |
| * | |
| * Created Wed Aug 27 17:13:05 2008. | |
| * | |
| * @file | |
| * | |
| * @author Tommi Vainikainen | |
| * | |
| * | |
| */ | |
| package com.conformiq.adaptation.ttcn; | |
| import java.io.PrintWriter; | |
| import java.io.Writer; | |
| 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 out) { | |
| super(out); | |
| 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); | |
| } | |
| // 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 ws() { | |
| print(" "); | |
| } | |
| } |