|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| TextOutput.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 | /* $Id: TextOutput.java,v 1.1 2006/10/20 20:23:05 m31 Exp $ | |
| 2 | * | |
| 3 | * This file is part of the project "Hilbert II" - http://www.qedeq.org | |
| 4 | * | |
| 5 | * Copyright 2000-2006, Michael Meyling <mime@qedeq.org>. | |
| 6 | * | |
| 7 | * "Hilbert II" is free software; you can redistribute | |
| 8 | * it and/or modify it under the terms of the GNU General Public | |
| 9 | * License as published by the Free Software Foundation; either | |
| 10 | * version 2 of the License, or (at your option) any later version. | |
| 11 | * | |
| 12 | * This program is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | * GNU General Public License for more details. | |
| 16 | */ | |
| 17 | ||
| 18 | package org.qedeq.kernel.utility; | |
| 19 | ||
| 20 | import java.io.PrintStream; | |
| 21 | ||
| 22 | /** | |
| 23 | * Wraps a text output stream. | |
| 24 | * | |
| 25 | * @version $Revision: 1.1 $ | |
| 26 | * @author Michael Meyling | |
| 27 | */ | |
| 28 | public final class TextOutput { | |
| 29 | ||
| 30 | /** Wrapped stream. */ | |
| 31 | private PrintStream output; | |
| 32 | ||
| 33 | /** Tab level. */ | |
| 34 | private StringBuffer spaces = new StringBuffer(); | |
| 35 | ||
| 36 | /** | |
| 37 | * Constructor. | |
| 38 | * | |
| 39 | * @param output Write to this output. | |
| 40 | */ | |
| 41 | 0 | public TextOutput(final PrintStream output) { |
| 42 | 0 | this.output = output; |
| 43 | } | |
| 44 | ||
| 45 | /** | |
| 46 | * Print text to output. | |
| 47 | * | |
| 48 | * @param text Append this. | |
| 49 | */ | |
| 50 | 0 | public void print(final String text) { |
| 51 | 0 | output.print(text); |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * Print spaces and text to output. | |
| 56 | * | |
| 57 | * @param text Append this. | |
| 58 | */ | |
| 59 | 0 | public void levelPrint(final String text) { |
| 60 | 0 | output.print(spaces); |
| 61 | 0 | output.print(text); |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Print object to output. | |
| 66 | * | |
| 67 | * @param object Append text representation of this. | |
| 68 | */ | |
| 69 | 0 | public void print(final Object object) { |
| 70 | 0 | output.print(object); |
| 71 | } | |
| 72 | ||
| 73 | /** | |
| 74 | * Print spaces text and new line to output. | |
| 75 | * | |
| 76 | * @param line Append this. | |
| 77 | */ | |
| 78 | 0 | public final void println(final String line) { |
| 79 | 0 | output.println(line); |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * Print spaces, text and new line to output. | |
| 84 | * | |
| 85 | * @param line Append this. | |
| 86 | */ | |
| 87 | 0 | public final void levelPrintln(final String line) { |
| 88 | 0 | output.print(spaces); |
| 89 | 0 | output.println(line); |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Print object and new line to output. | |
| 94 | * | |
| 95 | * @param object Append text representation of this. | |
| 96 | */ | |
| 97 | 0 | public final void println(final Object object) { |
| 98 | 0 | output.println(object); |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Print new line to output. | |
| 103 | */ | |
| 104 | 0 | public final void println() { |
| 105 | 0 | output.println(); |
| 106 | } | |
| 107 | ||
| 108 | /** | |
| 109 | * Close output. | |
| 110 | */ | |
| 111 | 0 | public final void close() { |
| 112 | 0 | output.close(); |
| 113 | } | |
| 114 | ||
| 115 | /** | |
| 116 | * Reset tab level to zero. | |
| 117 | */ | |
| 118 | 0 | public final void clearLevel() { |
| 119 | 0 | spaces.setLength(0); |
| 120 | } | |
| 121 | ||
| 122 | /** | |
| 123 | * Decrement tab level. | |
| 124 | */ | |
| 125 | 0 | public final void popLevel() { |
| 126 | 0 | if (spaces.length() > 0) { |
| 127 | 0 | spaces.setLength(spaces.length() - 2); |
| 128 | } | |
| 129 | } | |
| 130 | ||
| 131 | /** | |
| 132 | * Increment tab level. | |
| 133 | */ | |
| 134 | 0 | public final void pushLevel() { |
| 135 | 0 | spaces.append(" "); |
| 136 | } | |
| 137 | ||
| 138 | /** | |
| 139 | * Did any error occur during output? | |
| 140 | * | |
| 141 | * @return Did an error occur? | |
| 142 | */ | |
| 143 | 0 | public boolean checkError() { |
| 144 | 0 | return output.checkError(); |
| 145 | } | |
| 146 | ||
| 147 | } |
|
||||||||||