KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > diff > Printer


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.diff;
34
35 public abstract class Printer extends VisitorBase {
36     private StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
37
38     private String JavaDoc indentText = " ";
39     private int indentLevel = 0;
40
41     public String JavaDoc getIndentText() {
42         return indentText;
43     }
44
45     public void setIndentText(String JavaDoc indentText) {
46         this.indentText = indentText;
47     }
48
49     protected Printer append(boolean b) {
50         buffer.append(b);
51         return this;
52     }
53
54     protected Printer append(char c) {
55         buffer.append(c);
56         return this;
57     }
58
59     protected Printer append(char[] str) {
60         buffer.append(str);
61         return this;
62     }
63
64     protected Printer append(char[] str, int offset, int len) {
65         buffer.append(str, offset, len);
66         return this;
67     }
68
69     protected Printer append(double d) {
70         buffer.append(d);
71         return this;
72     }
73
74     protected Printer append(float f) {
75         buffer.append(f);
76         return this;
77     }
78
79     protected Printer append(int i) {
80         buffer.append(i);
81         return this;
82     }
83
84     protected Printer append(long l) {
85         buffer.append(l);
86         return this;
87     }
88
89     protected Printer append(Object JavaDoc obj) {
90         buffer.append(obj);
91         return this;
92     }
93
94     protected Printer append(String JavaDoc str) {
95         buffer.append(str);
96         return this;
97     }
98
99     protected Printer indent() {
100         for (int i=0; i<indentLevel; i++) {
101             append(getIndentText());
102         }
103
104         return this;
105     }
106
107     protected Printer eol() {
108         return append(System.getProperty("line.separator", "\n"));
109     }
110
111     protected void raiseIndent() {
112         indentLevel++;
113     }
114
115     protected void lowerIndent() {
116         indentLevel--;
117     }
118
119     public String JavaDoc toString() {
120         return buffer.toString();
121     }
122 }
123
Popular Tags