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

/**  class NonTerminalDiagram
 *   draws a nonterminal symbol using the size of the string
 *   to determine the size of the diagram
 */
public class NonTerminalDiagram extends Diagram{

	public String symbol;
	private Font font = new Font ("TimesRoman", Font.BOLD, fontSize);
	private int sw;
	private int fontHeight;
	private int width;
	private int height;
	private Color color;
	private Color brighterColor = new Color(250,0,0);
	private Color normalColor = new Color(0,0,180);
        private	Color terminalColor = new Color(255,0,255);
        private Color brighterRegular;

	// uses stringWidth from the FontMetrics class to determine
	// the size of the name of the nonterminal when drawn
	// sets the fontHeight for later use
	// determines the size of the completed diagram
	// sets the connector location at the middle
	// sets the color to the default nonterminal color
	public NonTerminalDiagram(String s){
		FontMetrics fm = this.getFontMetrics(font);
		symbol = s;
                  
	

                terminalColor = ((terminalColor.brighter()).darker()).darker();
                terminalColor = (terminalColor.brighter()).darker();
                brighterRegular = (terminalColor.brighter()).brighter();
		sw = fm.stringWidth(symbol);
		fontHeight = fm.getHeight();
		width = terminalSize + sw + 1;
		height = terminalSize + 1;
		connectorLocation = height / 2;

                if (( symbol.equals("Identifier")) || (symbol.equals("Nil")) || 
                   (symbol.equals("StringLiteral")) || (symbol.equals("Anonymous"))
                   || (symbol.equals("Octal") ) || (symbol.equals("Hexadecimal"))
                   || (symbol.equals("Decimal")) || (symbol.equals("CharLiteral"))
                   || (symbol.equals("Symbol"))  || (symbol.equals("Space")) 
                   || (symbol.equals("Exponent")) || (symbol.equals("Unit")) 
		   || (symbol.equals("ModuleIdentifier")) )
                  { color = terminalColor;
                  }
               else
		color = normalColor;
 	}

	// changes the color of the diagram to a brighter
	// shade of the current color

	public void brighten (){
		color = brighterColor;
	}

	// returns the color of the drawing to the default
 	public void normal(){
		color = normalColor;
	}

	public void normalRegular(){
		color = terminalColor;
	}

	public void brightenRegular (){
		color = brighterRegular;
	}


	// overrides the paint method
	// after setting the color and font, the name of the diagram
	// is drawn and a rectangle around it
	public void paint (Graphics g){
		int thisTerminal = terminalSize + sw;
		int rightEdge = thisTerminal + connectorSize;
		int startString = (thisTerminal - sw) / 2;


                if (( symbol.equals("Identifier")) || (symbol.equals("Nil")) || 
                   (symbol.equals("StringLiteral")) || (symbol.equals("Anonymous"))
                   || (symbol.equals("Octal") ) || (symbol.equals("Hexadecimal"))
                   || (symbol.equals("Decimal")) || (symbol.equals("CharLiteral"))
                   || (symbol.equals("Exponent") ) || (symbol.equals("Symbol")) ||
                     (symbol.equals("Unit")) || (symbol.equals("Space"))
		   || (symbol.equals("ModuleIdentifier")))
                  {
                         setBackground(Color.white);
                  }
                if (symbol.equals("Identifier"))
                  {
                      setBackground(Color.white);
                  }
		g.setFont(font);
		g.setColor(color);
		g.drawString(symbol, startString,
					terminalSize
					- (terminalSize - fontHeight)
					);
		g.drawRect(0,0,
					thisTerminal,
					terminalSize);
		g.setColor (color);
	}

	// overrides preferredSize()
	// returns the size determined by the constructor
	public Dimension preferredSize () {
		return new Dimension (width, height);
    }
}



















