/*
 * Created on Nov 5, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package WheelOfFortune.game.userOutput;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;



/**
 * @author warren
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class ConsolePanel extends JPanel{

	JTextArea ta;
	JScrollPane scrollPane;
	ConsolePanel cp;
	/**
	 * 
	 */
	public ConsolePanel() {
		cp = this;
		ta = new JTextArea(8,33);
		ta.setEditable(false);
		ta.setLineWrap(true);
		ta.setWrapStyleWord(true);
		ta.setBorder(BorderFactory.createLineBorder(Color.BLACK));
		this.setLayout(new BorderLayout());
		scrollPane = new JScrollPane(ta);
		Border lowered = BorderFactory.createLoweredBevelBorder();
		Border titled = 
			BorderFactory.createTitledBorder(lowered, 
			"Summary");
		scrollPane.setBorder(titled);
		
		add(scrollPane, BorderLayout.SOUTH);
	}
	/**
	 * @return Returns the ta.
	 */
	public JTextArea getTa() {
		return ta;
	}
	public void println(String msg)
	{	
		ta.setText(ta.getText() + msg + "\n");
		SwingUtilities.invokeLater(new ScrollTask());
		
		//Timer tim = new Timer();		
		//tim.schedule(new ScrollTask(), 100);
	}
	public class ScrollTask extends Thread
	{
		public synchronized void run()
		{
			int m = scrollPane.getVerticalScrollBar().getMaximum();
			scrollPane.getVerticalScrollBar().setValue(m);
			cp.repaint();
		}
	}
	public void print(String msg)
	{
		ta.setText(ta.getText() + msg);
	}
}
