From 9e090ec2a5dca83883e7a61d8822cd09b02f3881 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Tue, 20 Oct 2020 18:32:40 -0400 Subject: Move TextAreaOutputStream It seemed like it was more sensible to put this class in with the other IO related things, instead of in with the GUI stuff --- .../bjc/utils/ioutils/TextAreaOutputStream.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 base/src/main/java/bjc/utils/ioutils/TextAreaOutputStream.java (limited to 'base/src/main/java/bjc/utils/ioutils/TextAreaOutputStream.java') diff --git a/base/src/main/java/bjc/utils/ioutils/TextAreaOutputStream.java b/base/src/main/java/bjc/utils/ioutils/TextAreaOutputStream.java new file mode 100644 index 0000000..10f5104 --- /dev/null +++ b/base/src/main/java/bjc/utils/ioutils/TextAreaOutputStream.java @@ -0,0 +1,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(); + } + } +} -- cgit v1.2.3