home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 July / Chip_1998-07_cd.bin / zkuste / JBuilder / BDK / Win / bdk_sep97.exe / _SETUP.1 / IndentedStream.java < prev    next >
Encoding:
Java Source  |  1997-09-10  |  1.3 KB  |  84 lines

  1. package sun.beanbox;
  2.  
  3. import java.io.*;
  4.  
  5. /**
  6.  * This is a utility class for the generation of Source Files.
  7.  */
  8.  
  9. public class IndentedStream {
  10.     
  11.     public IndentedStream(PrintWriter s, String space) {
  12.     currentStream = s;
  13.     indentSpace = space;
  14.     }
  15.  
  16.     public IndentedStream(PrintWriter s) {
  17.     this(s, "    ");
  18.     }
  19.  
  20.     public void close() {
  21.         currentStream.close();
  22.     }
  23.  
  24.     public void o() {
  25.     indentLevel--;
  26.     }
  27.  
  28.     public void i() {
  29.         indentLevel++;
  30.     }
  31.  
  32.     public void ip(String s) {
  33.         i();
  34.     pp(s);
  35.     }
  36.  
  37.     public void ip() {
  38.         i();
  39.     pp();
  40.     }
  41.  
  42.     public void op(String s) {
  43.         o();
  44.     pp(s);
  45.     }
  46.  
  47.     public void op() {
  48.         o();
  49.     pp();
  50.     }
  51.  
  52.     public void pp() {
  53.     currentStream.println(); 
  54.     }
  55.  
  56.     public void pp(String s) {
  57.     for (int i=0; i<indentLevel; i++) {
  58.         currentStream.print(indentSpace);
  59.     }
  60.     currentStream.println(s);
  61.     }
  62.  
  63.     public void pp0(String s) {
  64.     for (int i=0; i<indentLevel; i++) {
  65.         currentStream.print(indentSpace);
  66.     }
  67.     currentStream.print(s);
  68.     }
  69.  
  70.     public void pn(String s) {
  71.         currentStream.println(s);
  72.     }
  73.  
  74.     public void pn0(String s) {
  75.         currentStream.print(s);
  76.     }
  77.  
  78.     // Private fields for indented streams...
  79.  
  80.     private int indentLevel;    // indentation level
  81.     private String indentSpace; // space
  82.     private PrintWriter currentStream; // for generating code
  83. }
  84.