package automatvgi.components;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JComponent;
import javax.swing.JLabel;

import automatvgi.LatexColor;
import automatvgi.Projection;
import automatvgi.tools.Point;
import automatvgi.edit.Edit;
import automatvgi.edit.FillColorChooser;
import automatvgi.edit.LabelColorChooser;
import automatvgi.edit.LineColorChooser;

public class AutomatonFrame extends AutomatonComponent{
	private int minX=-10;
	private int maxX=10;
	private int minY=-8;
	private int maxY=8;
	
	private AutomatonStyle defaultStyle=new AutomatonStyle();

	public AutomatonStyle.StateSetter getStateDefaultStyle(){
		return defaultStyle.getStateSetter();
	}
	public AutomatonStyle.EdgeSetter getEdgeDefaultStyle(){
		return defaultStyle.getEdgeSetter();
	}
	
	
	@Override
	public void draw(Graphics g, Projection j) {
		g.setColor(new Color(255,0,0,50));
		for(int i=minX; i<=maxX; i++){
			Point r=new Point(i,minY);
			Point s=new Point(i,maxY);
			j.drawLine(r,s,g);
		}
		for(int i=minY; i<=maxY; i++){
			Point r=new Point(minX,i);
			Point s=new Point(maxX,i);
			j.drawLine(r,s,g);
		}
		g.setColor(new Color(255,0,0,150));
		Point r=new Point(0,minY);
		Point s=new Point(0,maxY);
		j.drawLine(r,s,g);
		Point r2=new Point(minX,0);
		Point s2=new Point(maxX,0);
		j.drawLine(r2,s2,g);
	}

	@Override
	public void edit() {
		JComponent[] tab={new JLabel("Edges"),
				new LineColorChooser(getEdgeDefaultStyle()),
				new LabelColorChooser(getEdgeDefaultStyle()),
				new JLabel("States"),
				new LineColorChooser(getStateDefaultStyle()),
				new LabelColorChooser(getStateDefaultStyle()),
				new FillColorChooser(getStateDefaultStyle())};
		new Edit("Param¸tres par dˇfaut",tab);
	}
/*
@Override
	public void edit() {
		new FrameEdit(defaultStyle);
	}
*/
	@Override
	public Point handle() {
		return new Point(minX,minY);
	}

	@Override
	public String toString(){
		StringBuilder sb=new StringBuilder();
		sb.append("\\begin{VCPicture}{("+minX+","+minY+")("+maxX+","+maxY+")}\n");
		if(defaultStyle.edgeLabelColor!=LatexColor.getColorByName("Black"))
			sb.append("\\SetEdgeLabelColor{"+defaultStyle.edgeLabelColor+"}");
		if(defaultStyle.edgeLineColor!=LatexColor.getColorByName("Black"))
			sb.append("\\SetEdgeLineColor{"+defaultStyle.edgeLineColor+"}");
		if(defaultStyle.stateLineColor!=LatexColor.getColorByName("Black"))
			sb.append("\\SetStateLineColor{"+defaultStyle.stateLineColor+"}");
		if(defaultStyle.stateLabelColor!=LatexColor.getColorByName("Black"))
			sb.append("\\SetStateLabelColor{"+defaultStyle.stateLabelColor+"}");
		if(defaultStyle.stateFillColor!=LatexColor.getColorByName("White"))
			sb.append("\\SetStateFillColor{"+defaultStyle.stateFillColor+"}");
	  return sb.toString();
	}
	
	public int getMinX() {
		return minX;
	}

	public void setMinX(int minX) {
		this.minX = minX;
	}

	public int getMaxX() {
		return maxX;
	}

	public void setMaxX(int maxX) {
		this.maxX = maxX;
	}

	public int getMinY() {
		return minY;
	}

	public void setMinY(int minY) {
		this.minY = minY;
	}

	public int getMaxY() {
		return maxY;
	}

	public void setMaxY(int maxY) {
		this.maxY = maxY;
	}
	public LatexColor getLabelColor() {
		throw new UnsupportedOperationException();
	}

}
