1 20 21 package JFlex; 22 23 24 import java.io.*; 25 import java.awt.TextArea ; 26 27 28 35 public final class StdOutWriter extends PrintWriter { 36 37 38 private TextArea text; 39 40 44 private int col; 45 46 47 private final static int wrap = 78; 48 49 50 public StdOutWriter() { 51 super(System.out,true); 52 } 53 54 55 public StdOutWriter(OutputStream out) { 56 super(out,true); 57 } 58 59 65 public void setGUIMode(TextArea text) { 66 this.text = text; 67 } 68 69 70 public void write(int c) { 71 if (text != null) { 72 text.append(String.valueOf((char) c)); 73 if (++col > wrap) println(); 74 } 75 else 76 super.write(c); 77 } 78 79 80 public void write(char buf[], int off, int len) { 81 if (text != null) { 82 text.append(new String (buf,off,len)); 83 if ((col+=len) > wrap) println(); 84 } 85 else 86 super.write(buf, off, len); 87 } 88 89 90 public void write(String s, int off, int len) { 91 if (text != null) { 92 text.append(s.substring(off,off+len)); 93 if ((col+=len) > wrap) println(); 94 } 95 else { 96 super.write(s,off,len); 97 flush(); 98 } 99 } 100 101 105 public void println() { 106 if (text != null) { 107 text.append(Out.NL); 108 col = 0; 109 } 110 else 111 super.println(); 112 } 113 } 114 | Popular Tags |