/* Author: Jeff Dalton * Updated: Sun Dec 2 00:06:33 2001 by Jeff Dalton * Copyright: (c) 2001, AIAI, University of Edinburgh */ package ix.iface.util; import java.util.*; import javax.swing.*; import ix.util.Util; /** * A JTextArea for recording transcripts and similar information. */ public class TranscriptTextArea extends JTextArea { /** * Constructs and empty text area of the specified size. */ public TranscriptTextArea(int rows, int cols) { super(rows, cols); } /** * Appends the text, then moves the caret position to the end, * which should also cause scrolling to the end. */ public void append(String text) { super.append(text); // Setting caret position to end should scoll to the end setCaretPosition(getText().length()); } /** * Appends the text, followed by a line separator. * The line separator is the value of * System.getProperty("line.separator"). */ public void appendLine(String text) { String lineSeparator = System.getProperty("line.separator"); append(text + lineSeparator); } /** * Breaks the text into lines, then appends the lines, each * prefixed by the specified number of spaces. */ public void appendIndentedLines(int indent, String text) { List lines = Util.breakIntoLines(text); for (Iterator i = lines.iterator(); i.hasNext();) { String line = (String)i.next(); appendLine(Util.repeatString(" ", 3) + line); } } }