import java.awt.*;
import java.applet.*;

/**  class TerminalDiagram
 *   very simply draws an circular rectangle for the terminal diagram
 *   uses the size of the string to determine the size of the diagram
 */
 public class TerminalDiagram extends Diagram{

	private String symbol;
	private Font font = new Font ("TimesRoman", Font.BOLD, 12);
	private int sw;
	private int fontHeight;
	private int width = 0;
	private int height = 0;

	// public TerminalDiagram (constructor)
	// uses information from the FontMetrics class to
	// determine the width of the string in the diagram
	// and the height of the string.
	// the width and height of the completed diagram are
	// calculated using the terminalSize set in Diagram class
	// and the width of the string
	// the connector location is set in the middle of the
	// diagram
	public TerminalDiagram(String s){

		FontMetrics fm = this.getFontMetrics(font);
		symbol = s;
		sw = fm.stringWidth(symbol);
		fontHeight = fm.getHeight();
		width = terminalSize + sw + 1;
		height = terminalSize + 1;
		connectorLocation = height / 2;
	}

	// paint method (overridden)
	// sets color, draws the string and a series of
	// arcs and lines to created a round ended rectangle

	public void paint (Graphics g){
		int startString = terminalSize / 2;

		g.setFont(font);
		Color terminalColor = new Color(0,130,0);
		g.setColor (terminalColor);
		g.drawString(symbol, startString,
					terminalSize
					- (terminalSize - fontHeight)
					);
		g.drawArc(0,0,terminalSize,terminalSize,
					90,180);
		g.drawLine(terminalSize / 2, 0, sw + terminalSize / 2, 0);
		g.drawLine(terminalSize / 2, terminalSize,
					sw + terminalSize / 2, terminalSize);
		g.drawArc(sw, 0, terminalSize,
					terminalSize, 90, -180);

	}

	// preferredSize (overridden)
	// width and height are set to the values calculated
	// in the constructor
	public Dimension preferredSize () {
		return new Dimension (width, height);
  }
}

