package com.knutejohnson.pi.chat;

import java.awt.*;
import java.text.*;
import java.util.*;
import javax.swing.*;
import javax.swing.text.*;

public class ReceiverArea extends JTextArea {
    private final SimpleDateFormat sdf;

    public ReceiverArea(Document doc, String text, int rows, int cols,
     String format) {
        super(doc,text,rows,cols);

        sdf = new SimpleDateFormat(format);
    }

    public ReceiverArea(Document doc, String text, int rows, int cols) {
        this(doc,text,rows,cols,"YYYY/MM/dd HH:mm:ss ");
    }

    @Override public void append(String text) {
        EventQueue.invokeLater(() -> {
            ReceiverArea.super.append(sdf.format(new Date()));
            ReceiverArea.super.append(text);
        });
    }
}