01: package interact;
02:
03: import java.io.IOException;
04: import java.io.Writer;
05:
06: /**
07: A Writer that writes into the output area of an IOTextArea.
08: **/
09:
10: public class IOTextAreaWriter extends Writer {
11:
12: private IOTextArea area;
13:
14: public IOTextAreaWriter(IOTextArea area) {
15: this .area = area;
16: }
17:
18: private void ensureOpen() throws IOException {
19: if (area == null)
20: throw new IOException("Writer " + this + " closed");
21: }
22:
23: public void write(String s) throws IOException {
24: ensureOpen();
25: this .area.write(s);
26: }
27:
28: public void write(String s, int off, int len) throws IOException {
29: ensureOpen();
30: if (off == 0 && len == s.length())
31: this .area.write(s);
32: else
33: super .write(s, off, len);
34: }
35:
36: public synchronized void write(final char[] buf, final int off,
37: final int len) throws IOException {
38: ensureOpen();
39: this .area.write(buf, off, len);
40: }
41:
42: public synchronized void flush() throws IOException {
43: ensureOpen();
44: }
45:
46: public synchronized void close() throws IOException {
47: ensureOpen();
48: area = null;
49: }
50: }
|