import java.awt.TextArea;

public class LazyTextArea {
  boolean lazy = true;
  StringBuffer sb = new StringBuffer();
  TextArea textArea;

  public LazyTextArea(TextArea textArea) {
    this.textArea = textArea;
  }

  public synchronized void setLazy(boolean lazy) {
    if (lazy == this.lazy) return;
    this.lazy = lazy;
    if (! this.lazy && sb.length() != 0) {
      this.textArea.append(this.sb.toString());
      this.sb.setLength(0);
    }
  }

  public synchronized void appendText(String str) {
    if (str == null) return;
    if (this.lazy) { this.sb.append(str); }
    else { this.textArea.append(str); }
  }

  public synchronized void reset() {
    this.textArea.setText("");
    this.sb.setLength(0);
    this.lazy = true;
  }
}

