/*---------------------------------------------------------------------------
File:         			FSAtoRegExpCanvas.java
Package:                        JFLAP Version 3.1
Author:			        Ted Hung
                                
Description of Contents:	Contains class FSAtoRegExpCanvas.
				
--------------------------------------------------------------------------*/

/* 
 * Susan H. Rodger, Magda Procopiuc, Octavian Procopiuc, Eric Gramond, Ted Hung
 * Computer Science Department
 * Duke University
 * August 1999
 * Supported by National Science Foundation DUE-9596002, DUE-9555084,
 *  and DUE-9752583
 *
 * Copyright (c) 1999
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that the above copyright notice and this paragraph are
 * duplicated in all such forms and that any documentation,
 * advertising materials, and other materials related to such
 * distribution and use acknowledge that the software was developed
 * by the author.  The name of the author may not be used to
 * endorse or promote products derived from this software without
 * specific prior written permission.
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

package flap;

import java.awt.*;
import java.awt.event.*;
import java.util.*;

/**
 *  Draws the states into the FSAtoRegExpAskDialog
 */
public class FSAtoRegExpCanvas extends Canvas
{
   //the radius of the states that are being drawn to the
   //dialog
   public static int r = 11;
   private int stateid;

   public FSAtoRegExpCanvas(int id)
   {
      setBackground(Params._e_backcolor);
      setSize(2*r + 8, 2*r + 8);
      stateid = id;
   }

   public void paint(Graphics g)
   {
      FontMetrics fm;
      try
      {
	 fm = g.getFontMetrics();
      }
      catch (Exception e)
      {
	 g.setFont(new Font("System", Font.PLAIN, 12));
	 fm = g.getFontMetrics();
      }

      g.setColor(Params._s_normalcolor);
      g.fillOval(2, 2, 2*r, 2*r);
      g.setColor(Params._c_forecolor);
      g.drawOval(2, 2, 2*r, 2*r);
      g.drawOval(0, 0, 2*(r+2), 2*(r+2));

      String str = "q" + Integer.toString(stateid);
      int l = fm.stringWidth(str);
      int hh = fm.getAscent();
      g.drawString(str, r - ((int) l/2) + 1, r + ((int) hh/2));
   }

   public void update()
   {
      paint(getGraphics());
   }
}

