package fplot;

import java.awt.*;
import java.util.Vector;
/**
 * 
 * 
 * @author Christian Semrau
 * <a href="mailto:Christian.Semrau@student.uni-magdeburg.de">
 * Christian.Semrau@student.uni-magdeburg.de</a>
 * <br><a href="http://chsemrau.de">Homepage</a>
 */
class Graph {
	protected Vector graph = null;
	protected int desiredLength;
	protected int height, width;
	protected Line last;
	protected Dimension size;

	final static int
		OUTLOW = Line.OUTLOW,
		OUTHIGH = Line.OUTHIGH,
		OUTLEFT = Line.OUTLEFT,
		OUTRIGHT = Line.OUTRIGHT,
		UNDEFINED = Line.UNDEFINED;
/**
 * Graph constructor comment.
 */
public Graph(int len, int h, int w) {
	graph = new Vector(desiredLength = len);
	height = h; width = w;
	size = new Dimension(width, height);
}
/**
 * 
 * @param g Graphics
 */
public void paint(Graphics g) {
	g.setColor(Color.black);
	// Stellt den Graphen dar
	Line l;
	for (int i = 0; i<graph.size(); i++){
		l = (Line)graph.elementAt(i);
		l.paint(g);
	} // for(px
}
/**
 * 
 */
public void reset() {
	graph = new Vector(desiredLength);
	last = null;
}
/**
 * 
 * @param x int
 * @param y int
 */
public void set(int x, int y) {
	Line l;
	if (last==null)
		l = new Line(x, y, size);
	else{
		if (last.destY==OUTLOW && y==OUTHIGH
		|| last.destY==OUTHIGH && y==OUTLOW
		|| last.destX==OUTLEFT && x==OUTRIGHT
		|| last.destX==OUTRIGHT && x==OUTLEFT)
			l = new Line(UNDEFINED, UNDEFINED, x, y, size);
		else
			l = new Line(last, x, y, size);
	}
	graph.addElement(l);
	last = l;
}
/**
 * 
 * @param x int
 */
public void setTooHigh(int x) {
	set(x, OUTHIGH);
}
/**
 * 
 * @param y int
 */
public void setTooLeft(int y) {
	set(OUTLEFT, y);
}
/**
 * 
 * @param x int
 */
public void setTooLow(int x) {
	set(x, OUTLOW);
}
/**
 * 
 * @param y int
 */
public void setTooRight(int y) {
	set(OUTRIGHT, y);
}
/**
 * 
 * @param x int
 */
public void setUndefined() {
	set(UNDEFINED, UNDEFINED);
}
}