1
16package org.tp23.gui.widget;
17
18import java.io.ByteArrayOutputStream;
19import java.io.PrintStream;
20
21import javax.swing.JTextArea;
22
23
32public class JTextAreaPrintStream extends PrintStream{
33
34 private JTextArea textArea;
35 private StringBuffer line;
36
37 public JTextAreaPrintStream(JTextArea textArea) {
38 super(new ByteArrayOutputStream(0)); this.textArea = textArea;
40 line = new StringBuffer();
41 }
42
43
46 public void close(){
47 }
48
49 public synchronized void flush(){
50 if(line.length()>0){
51 textArea.append(line.toString());
52 line = new StringBuffer();
53 }
54 }
55
56 public synchronized void write(byte[] b){
57 line.append(new String(b));
58 }
59
60 public synchronized void write(byte[] b, int off, int len){
61 line.append(new String(b,off,len));
62 }
63
64
65 public synchronized void write(int c){
66 line.append(c);
67 }
68
69 public synchronized boolean checkError() {
70 return false;
71 }
72
73 public synchronized void print(Object obj) {
74 line.append(obj);
75 }
76
77
78 public synchronized void print(String s) {
79 line.append(s);
80 }
81
82
83 public synchronized void print(boolean b) {
84 line.append(b);
85 }
86
87
88 public synchronized void print(char c) {
89 line.append(c);
90 }
91
92
93 public synchronized void print(char[] s) {
94 line.append(s);
95 }
96
97
98 public synchronized void print(double d) {
99 line.append(d);
00 }
01
02
03 public synchronized void print(float f) {
04 line.append(f);
05 }
06
07
08 public synchronized void print(int i) {
09 line.append(i);
10 }
11
12
13 public synchronized void print(long l) {
14 line.append(l);
15 }
16
17
18 public synchronized void println() {
19 line.append('\n');
20 flush();
21 }
22
23
24 public synchronized void println(Object x) {
25 if(line.length()>0){
26 textArea.append(line.append(String.valueOf(x)).toString());
27 textArea.append("\n");
28 line = new StringBuffer();
29 }
30 else {
31 textArea.append(String.valueOf(x));
32 textArea.append("\n");
33 }
34 }
35
36
37 public synchronized void println(String x) {
38 if(line.length()>0){
39 textArea.append(line.append(x).toString());
40 textArea.append("\n");
41 line = new StringBuffer();
42 }
43 else {
44 textArea.append(x);
45 textArea.append("\n");
46 }
47 }
48
49 public synchronized void println(boolean x) {
50 if(line.length()>0){
51 textArea.append(line.append(String.valueOf(x)).toString());
52 textArea.append("\n");
53 line = new StringBuffer();
54 }
55 else {
56 textArea.append(String.valueOf(x));
57 textArea.append("\n");
58 }
59 }
60
61
62 public synchronized void println(char x) {
63 if(line.length()>0){
64 textArea.append(line.append(String.valueOf(x)).toString());
65 textArea.append("\n");
66 line = new StringBuffer();
67 }
68 else {
69 textArea.append(String.valueOf(x));
70 textArea.append("\n");
71 }
72 }
73
74
75 public synchronized void println(char[] x) {
76 if(line.length()>0){
77 textArea.append(line.append(String.valueOf(x)).toString());
78 textArea.append("\n");
79 line = new StringBuffer();
80 }
81 else {
82 textArea.append(String.valueOf(x));
83 textArea.append("\n");
84 }
85 }
86
87
88 public synchronized void println(double x) {
89 if(line.length()>0){
90 textArea.append(line.append(String.valueOf(x)).toString());
91 textArea.append("\n");
92 line = new StringBuffer();
93 }
94 else {
95 textArea.append(String.valueOf(x));
96 textArea.append("\n");
97 }
98 }
99
00
01 public synchronized void println(float x) {
02 if(line.length()>0){
03 textArea.append(line.append(String.valueOf(x)).toString());
04 textArea.append("\n");
05 line = new StringBuffer();
06 }
07 else {
08 textArea.append(String.valueOf(x));
09 textArea.append("\n");
10 }
11 }
12
13
14 public synchronized void println(int x) {
15 if(line.length()>0){
16 textArea.append(line.append(String.valueOf(x)).toString());
17 textArea.append("\n");
18 line = new StringBuffer();
19 }
20 else {
21 textArea.append(String.valueOf(x));
22 textArea.append("\n");
23 }
24 }
25
26
27 public synchronized void println(long x) {
28 if(line.length()>0){
29 textArea.append(line.append(String.valueOf(x)).toString());
30 textArea.append("\n");
31 line = new StringBuffer();
32 }
33 else {
34 textArea.append(String.valueOf(x));
35 textArea.append("\n");
36 }
37 }
38
39
40 protected void setError() {
41 }
42
43
44}
45