package de.memtext.widgets;

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

import javax.swing.JPanel;

/**
 A Scrollable Textarea which has a title at the top.

 */
public class TitledTextScrollArea extends JPanel {

	private TitledContainerDec titleCont;
	private ScrollableTextArea scrollableTextArea;

	public TitledTextScrollArea(String title) {
		this(title, 70);
	}
	public TitledTextScrollArea(String title, int maxHeight) {
		super(new BorderLayout());
		scrollableTextArea = new ScrollableTextArea(maxHeight);
		titleCont = new TitledContainerDec(scrollableTextArea, title);
		this.add(titleCont, BorderLayout.CENTER);
		scrollableTextArea.setEditable(true);
		scrollableTextArea.setLineWrap(true);
		scrollableTextArea.setWrapStyleWord(true);
	}

	/**
	 * @param f
	 */
	public void setTitleFont(Font f) {
		titleCont.setTitleFont(f);
	}

	/**
	 * @param title
	 */
	public void setTitleText(String title) {
		titleCont.setTitleText(title);
	}

	/**
	 * @param txt
	 */
	public void setText(String txt) {
		scrollableTextArea.setText(txt);
	}
	public String getText() {
		return scrollableTextArea.getText();
	}
	public void setTitleBackground(Color c) {
		if (titleCont != null)
			titleCont.setTitleBackground(c);
	}
	public void setBackground(Color c) {
		super.setBackground(c);
		if (scrollableTextArea != null)
			scrollableTextArea.setBackground(c);
		if (titleCont != null)
			titleCont.setBackground(c);
	}
	public void setEditable(boolean b) {
		scrollableTextArea.setEditable(b);

	}
	public void setColumns(int cols) {
		scrollableTextArea.setColumns(cols);
	}
}