package paramsim.paramicssimulator.gui;

import java.awt.Insets;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/** 
 * A JPanel which records of a log of errors and messages written or recieved
 * by the Paramics Simulator.
 * 
 * @author Greg Eddington
 **/
@SuppressWarnings("serial")
public class ParamicsLogPanel extends JPanel
{
	/** The timestamp format **/
	private static SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
	
	/** The log text area **/
	private JTextArea log;

	/** Constructor **/
	public ParamicsLogPanel()
	{
		log = new JTextArea();
		log.setColumns(35);
		log.setLineWrap(true);
		log.setRows(24);
		log.setWrapStyleWord(true);
		log.setEditable(false);
		log.setText("");
		log.setMargin(new Insets(0, 10, 0, 10));
		JScrollPane logPane = new JScrollPane(log);
		add(logPane);
	}
	
	/**
	 * Write a string appended to the end of the log.
	 * 
	 * @param message
	 */
	public void write(String message)
	{
		log.setText(log.getText() + sdf.format(Calendar.getInstance().getTime()) + ":\n" + 
				message + "\n\n");
	}
}
