/*
 * @(#)DebugArea.java	1.00  16/05/00
 *
 * Jan Hnátek
 * 
 */
import java.awt.*;

/**
 * The <code>DebugArea</code> class is a tool for easy debuging. 
 * It is a <code>TextArea</code> extension with methods to output the debuging
 * text in it. 
 * <p>
 * It is possible to set priorities to the messages, the output is then filtered
 * according to the globally set priority .
 * <p>
 *
 * @version 	1.00, 16/05/00
 * @author	Jan Hnátek
 */
public class DebugArea extends TextArea
//***********************************//
{
// constants
	/**
	* The priority OFF. Means zero output. This value makes sense only as the global setting.
	*/
public static final int OFF = 0;
	/**
	* The priority NONE. Same as OFF. Means zero output. This value makes sense only as the global setting.
	*/
public static final int NONE = 0;
	/**
	* The priority HIGH. Usable both for global and message priority setting.
	*/
public static final int HIGH = 1;
	/**
	* The priority MEDIUM. Usable both for global and message priority setting.
	*/
public static final int MEDIUM = 2;
	/**
	* The priority LOW. Usable both for global and message priority setting.
	*/
public static final int LOW = 3;

// private variables
	/**
	* Boolean output trigger. When <code>true</code> the output is enabled.
	* When <code>false</code> the output is disabled.
	*/
private boolean output = true;
	/**
	* Global priority trigger. Set to one of priority constants, defaults to <code>MEDIUM</code>
	*/
private int priority = MEDIUM;


/*** public functions ***/

	/**
	 * Outputs given String with default priority (==<code>MEDIUM</code>), if the <code>output</code>
       * is enabled.
       * @param s String to output
	 */
public void write (String s)
	{
	if (priority >= MEDIUM)
		if (output)
			append (s+"\n");
	}
	/**
	 * Outputs given String with given priority, if the <code>output</code> is enabled.
	 * @param pr priority to give the outgoing message
       * @param s String to output
	 */
public void write (int pr, String s)
	{
	if (priority >= pr)
		if (output)
			append (s+"\n");
	}
	/**
	 * Clears output
	 */
public void clear ()
	{
	setText ("cleared ...\n");
	}

	/**
	 * Returns the global priority value.
	 * @return the global priority
	 */
public int getPriority ()			{ return priority; }
	/**
	 * Sets the global priority.
	 * @param pr new global priority value
	 */
public void setPriority (int pr)		{ priority = pr; }
	/**
	 * Returns the state of output (<code>true</code> == enabled, <code>false</code> == disabled
	 * @return the value of <code>output</code> trigger
	 */
public boolean getOutput ()			{ return output; }
	/**
	 * Enable/disable output
	 * @param in <code>true</code> to enable, <code>false</code> to disable output
	 */
public void setOutput (boolean in)
	{
	if (in)
		output = true;
	else	output = false;
	}
}