KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > visitorIDL3 > common > PrintStream


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2005 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library 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 GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Philippe Merle, Mathieu Vadet.
23 Contributor(s): .
24
25 ====================================================================
26 $Id: PrintStream.java,v 1.1 2005/06/17 15:58:27 merle Exp $
27 ====================================================================*/

28
29 package org.objectweb.ccm.visitorIDL3.common;
30
31 /**
32  * This class handles an output stream with:
33  * - indentation management.
34  *
35  * @author <a HREF="mailto:Philippe.Merle@lifl.fr">Philippe Merle</a>
36  * <a HREF="mailto:Mathieu.Vadet@lifl.fr">Mathieu Vadet</a>
37  *
38  * @version 0.3
39  */

40
41 public class PrintStream
42 {
43     // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48

49     /**
50      ** The managed stream.
51      **/

52     private java.io.PrintStream JavaDoc stream_;
53
54     /**
55      ** The tabular indentation.
56      **/

57     private String JavaDoc tabular_;
58
59     /**
60      ** The current indentation depth.
61      **/

62     private int depth_;
63
64     /**
65      ** The name of the underlying file.
66      **/

67     private String JavaDoc name_;
68
69     /**
70      ** The manager for this stream.
71      **/

72     private PrintStreamManager manager_;
73
74     // ==================================================================
75
//
76
// Constructor.
77
//
78
// ==================================================================
79

80     /**
81      ** Constructor.
82      **
83      ** @param stream A Java PrintStream on which data will be written.
84      ** @param tabular The atomic indentation that should contains only space and tabulation
85      ** characters.
86      ** @param name The name of the underlying file.
87      **/

88     public
89     PrintStream(java.io.PrintStream JavaDoc stream,
90                 String JavaDoc tabular,
91                 String JavaDoc name,
92                 PrintStreamManager manager)
93     {
94         // init internal state.
95
stream_ = stream;
96         tabular_ = tabular;
97         depth_ = 0;
98         name_ = name;
99         manager_ = manager;
100     }
101
102     // ==================================================================
103
//
104
// Public methods.
105
//
106
// ==================================================================
107

108     /**
109      **
110      **/

111     public void
112     close()
113     {
114         stream_.close();
115     }
116
117     /**
118      ** Obtain the name of the underlying file.
119      **
120      ** @return The file name.
121      **/

122     public String JavaDoc
123     getName()
124     {
125         return name_;
126     }
127
128     /**
129      ** Obtain the managed stream.
130      **
131      ** @return The Java PrintStream on which the data are written.
132      **/

133     public java.io.PrintStream JavaDoc
134     getStream()
135     {
136         return stream_;
137     }
138
139     /**
140      ** Obtain the manager of this stream.
141      **
142      ** @return The PrintStreamManager that manages this stream.
143      **/

144     public PrintStreamManager
145     getManager()
146     {
147         return manager_;
148     }
149
150     /**
151      ** Return the current indentation.
152      **
153      ** @return The current indentation ie depth times the atomic indentation.
154      **/

155     public String JavaDoc
156     getTab()
157     {
158         StringBuffer JavaDoc ret = new StringBuffer JavaDoc("");
159         for(int i=0;i<depth_;i++)
160             ret.append(tabular_);
161         return ret.toString();
162     }
163
164     /**
165      ** Increment the depth.
166      **/

167     public void
168     incDepth()
169     {
170         depth_++;
171     }
172
173     /**
174      ** Decrement the depth.
175      **/

176     public void
177     decDepth()
178     {
179         depth_--;
180     }
181
182     /**
183      ** Print indentation.
184      **/

185     public void
186     printTab()
187     {
188         for(int i=0; i<depth_; i++)
189             stream_.print(tabular_);
190     }
191
192     /**
193      ** Print a text line with indentation.
194      **
195      ** @param textLine The text to print.
196      **/

197     public void
198     print(String JavaDoc textLine)
199     {
200         printTab();
201         stream_.print(textLine);
202     }
203
204     /**
205      ** Print a text line with indentation and new line.
206      **
207      ** @param textLine The text to print.
208      **/

209     public void
210     println(String JavaDoc textLine)
211     {
212         printTab();
213         stream_.println(textLine);
214     }
215 }
216
Popular Tags