summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/ioutils/TextAreaOutputStream.java
blob: 10f510416e7bee46bcccd091d8f06199b1216581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bjc.utils.ioutils;

import java.io.IOException;
import java.io.OutputStream;

import javax.swing.JTextArea;

/**
 * An output stream that prints to a JTextArea
 *
 * @author epr
 * @author Levente S\u00e1ntha (lsantha@users.sourceforge.net)
 */
public class TextAreaOutputStream extends OutputStream {
	private final JTextArea textArea;

	/**
	 * Create a new output stream attached to a textarea
	 *
	 * @param console
	 *                The textarea to write to
	 */
	public TextAreaOutputStream(final JTextArea console) {
		this.textArea = console;
	}

	@Override
	public void write(final int b) throws IOException {
		textArea.append("" + (char) b);

		if (b == '\n') {
			textArea.repaint();
		}
	}
}