01: /*
02: * ProGuard -- shrinking, optimization, obfuscation, and preverification
03: * of Java bytecode.
04: *
05: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the Free
09: * Software Foundation; either version 2 of the License, or (at your option)
10: * any later version.
11: *
12: * This program is distributed in the hope that it will be useful, but WITHOUT
13: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15: * more details.
16: *
17: * You should have received a copy of the GNU General Public License along
18: * with this program; if not, write to the Free Software Foundation, Inc.,
19: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: package proguard.gui;
22:
23: import javax.swing.*;
24: import java.io.*;
25:
26: /**
27: * This <code>PrintStream</code> appends its output to a given text area.
28: *
29: * @author Eric Lafortune
30: */
31: final class TextAreaOutputStream extends FilterOutputStream implements
32: Runnable {
33: private final JTextArea textArea;
34:
35: public TextAreaOutputStream(JTextArea textArea) {
36: super (new ByteArrayOutputStream());
37:
38: this .textArea = textArea;
39: }
40:
41: // Implementation for FilterOutputStream.
42:
43: public void flush() throws IOException {
44: super .flush();
45:
46: // Append the accumulated buffer contents to the text area.
47: SwingUtil.invokeAndWait(this );
48: }
49:
50: // Implementation for Runnable.
51:
52: public void run() {
53: ByteArrayOutputStream out = (ByteArrayOutputStream) super .out;
54:
55: // Has any new text been written?
56: String text = out.toString();
57: if (text.length() > 0) {
58: // Append the accumulated text to the text area.
59: textArea.append(text);
60:
61: // Clear the buffer.
62: out.reset();
63: }
64: }
65: }
|