/*
 * State.java  
 *
 * Copyright 2001
 * College of Computer Science
 * Northeastern University
 * Boston, MA  02115
 *
 * This software may be used for educational purposes as long as
 * this copyright notice is retained intact at the top of all files.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either in whole
 * or in part without explicit permission.
 *
 * Contact information:
 *   Richard Rasala    rasala@ccs.neu.edu
 *   Viera Proulx      vkp@ccs.neu.edu
 *   Jeff Raab         jmr@ccs.neu.edu
 *   Jennifer McDonald jenimac@ccs.neu.edu
 * 
 * Telephone:          617-373-2462
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

import edu.neu.ccs.*;
import edu.neu.ccs.util.*;
import edu.neu.ccs.codec.*;
import java.text.ParseException;
import java.awt.*;

//Defines a State
public class State extends Animateable
				   implements Stringable {

	// State name
	private String name = null;
	
	// Is this a final state?
	private boolean isFinal = false;
	
	// Is this the start state?
	private boolean isStart = false;
	
	private StateImage image = null;
	
	public State() {}
	
	// constructors
	public State(String data) throws ParseException {
		fromStringData(data);
	}	
	
	public State(String s, boolean f, StateImage i) {
		name = s;
		isFinal = f;
		image = i;
	} 

	public void fromStringData(String data) 
						throws ParseException{
		
		String[] terms = CodecUtilities.decode(data);
		
		name = terms[0];
		isFinal = XBoolean.parseBoolean(terms[1]);
		image = new StateImage(terms[2]);
	}
	
	public String toStringData() {
	
	 	return CodecUtilities.encode(
            new String[] {name, isFinal + "", 
            			  image.toStringData()});
	}

	
	// Method to set this state to the start state
	public void setStart() {
		isStart = true;
	}	
	
	public String getName() {
		return name;
	}

	
	public boolean isFinal() {
		return isFinal;
	}
	
	public Point getCenter() {
		return image.getCenter();
	}
	
	public int getRadius() {
		return image.getRadius();
	}
	
	public boolean contains(Point p) {
		return image.buildEllipse().contains(p);
	}
	
	public void draw(Graphics2D g, Color c) {
		image.draw(g, c, name, isFinal, isStart);
	}
}

