/*
 * PathNode.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.gui.*;
import edu.neu.ccs.util.*;
import java.awt.*;

public class PathNode {

	protected State source = null;
	protected State target = null;
	protected Transition transition = null;
	protected int index = 0;
	protected boolean terminatingNode = false;
	
	public PathNode(State s) {
		this(null, s, null, 0);
	}
	
	// constructor
	public PathNode(State s, State t, 
					Transition tr, int i) {	
		source = s;
		target = t;
		transition = tr;
		index = i;
	}
	
	public State getSource() {
		return source;
	}
	
	public State getTarget() {
		return target;
	}
	
	public Transition getTransition() {
		return transition;
	}
	
	public StackClass.Action getStackAction() {
	
		if (transition == null)
			return null;
	
		return transition.getStackAction();
	}
	
	public String getStateString() {
	
		if(transition == null) 
			return "Start State: " + target.getName();
		else 
			return "State: " + target.getName();;	
	}
	
	public String getTapeCharRead() {
	
		if(transition != null)
			return "Read " + transition.getTokenSymbol().value();
		else
			return "";
	}
	
	
	public String getActionString() {
	
		if(transition != null)
			return transition.getActionString();
		else
			return "";
	}
	
	public boolean movesOnEpsilon() {
		
		if (transition == null)
			return true;
		
		return (transition.getTokenSymbol().is(Symbol.epsilon()));
	}
	
	public boolean tapeRead() {
		return !(movesOnEpsilon());
	}
	
	public boolean isFinal() {
		return target.isFinal();
	}
	
	public void setTerminating() {
		terminatingNode = true;
	}
	
	public boolean isTerminatingNode() {
		return isFinal() && terminatingNode;
	}
	
	public void animate(BufferedPanel p, int pauseTime) {
		
		if ((source != null) && (transition != null)) {
			
			Arrow a = new Arrow();
			a.set(source, target, null);
			a.animate(p, index, transition, pauseTime);
		}
			
		target.animate(p, pauseTime);	
			
	}
}
