/* Generated By:JJTree: Do not edit this line. SimpleNode.java */

import java.io.*;

public class SimpleNode implements Node 
{
	protected Node parent;
	protected Node[] children;
	protected int id;
	protected DrawPhase1 parser;

	public SimpleNode(int i) 
	{
		id = i;
	}

	public SimpleNode(DrawPhase1 p, int i) 
	{
		this(i);
		parser = p;
	}

	public void jjtOpen(){}
	public void jjtClose(){}
	public void jjtSetParent(Node n) 
	{ 
		parent = n; 
	}
	public Node jjtGetParent() 
	{ 
		return parent; 
	}

	public void jjtAddChild(Node n, int i) 
	{
		if (children == null) 
		{
			children = new Node[i + 1];
		} 
		else if (i >= children.length) 
		{
			Node c[] = new Node[i + 1];
			System.arraycopy(children, 0, c, 0, children.length);
			children = c;
		}
		children[i] = n;
	}

	public Node jjtGetChild(int i) 
	{
		return children[i];
	}

	public int jjtGetNumChildren() 
	{
		return (children == null) ? 0 : children.length;
	}

  /* You can override these two methods in subclasses of SimpleNode to
     customize the way the node appears when the tree is dumped.  If
     your output uses more than one line you should override
     toString(String), otherwise overriding toString() is probably all
     you need to do. */

	public String toString() 
	{ 
		return DrawPhase1TreeConstants.jjtNodeName[id]; 
	}
	public String toString(String prefix) 
	{ 
		return prefix + toString(); 
	}

  /* Override this method if you want to customize how the node dumps
     out its children. */

	public void dump(String prefix) 
	{
		System.out.println(toString(prefix));
		if (children != null) 
		{
			for (int i = 0; i < children.length; ++i)
			{
				SimpleNode n = (SimpleNode)children[i];
				if (n != null) 
				{
					n.dump(prefix + " ");
				}
			}
		}
	}

	public void generate(FileWriter SVGFile){}

	public void Error()
	{
		System.out.println("Error writing to file");
	}

	public void FileHeader(FileWriter SVGFile)
	{
		StartItem(SVGFile,"svg");
        NumberLabel(SVGFile,"width", ((ASTInt)jjtGetChild(0)).val);
		NumberLabel(SVGFile,"height", ((ASTInt)jjtGetChild(1)).val);
		EndItem(SVGFile);
	}

	public void FileComplete(FileWriter SVGFile)
	{
		Enclose(SVGFile,"svg");
	}

    public void StartItem(FileWriter SVGFile, String text)
    {
		try{
       		System.out.print("<" + text);
        	SVGFile.write("<" + text);
		}
		catch(Exception e){
			Error();
		}
    }

    public void NumberLabel(FileWriter SVGFile, String text, int value)
    {
		try{
    	    System.out.print(" " + text + "=\"" + value + "\"");
			SVGFile.write(" " + text + "=\"" + value + "\"");
		}
		catch(Exception e){
			Error();
		}
    }

    public void TextLabel(FileWriter SVGFile, String text, String text2)
    {
		try{
  	      System.out.print(" " + text + "=\"" + text2 + "\"");
			SVGFile.write(" " + text + "=\"" + text2 + "\"");
		}
		catch(Exception e){
			Error();
		}
    }

    public void EndItem(FileWriter SVGFile)
    {
		try{
			System.out.print(">\n");
			SVGFile.write(">\n");
		}
		catch(Exception e){
			Error();
		}
    }

    public void Stop(FileWriter SVGFile)
    {
		try{
			System.out.println("/>");
			SVGFile.write("/>\n");
		}
		catch(Exception e){
			Error();
		}
    }

    public void Enclose(FileWriter SVGFile, String text)
    {
		try{
			System.out.println("</" + text + ">");
			SVGFile.write("</" + text + ">");
		}
		catch(Exception e){
			Error();
		}
    }

    public void DrawLine(FileWriter SVGFile, int x1, int y1, int x2, int y2)
    {
        StartItem(SVGFile,"line");
        NumberLabel(SVGFile,"x1", x1);
        NumberLabel(SVGFile,"y1", y1);
        NumberLabel(SVGFile,"x2", x2);
        NumberLabel(SVGFile,"y2", y2);
		TextLabel(SVGFile, "stroke", "black");
		NumberLabel(SVGFile, "stroke-width", 1);
        Stop(SVGFile);

    }

    public void DrawRectangle(FileWriter SVGFile, int x1, int y1, int x2, int y2)
    {
        DrawLine(SVGFile, x1, y1, x2, y1);
        DrawLine(SVGFile, x2, y1, x2, y2);
        DrawLine(SVGFile, x2, y2, x1, y2);
        DrawLine(SVGFile, x1, y2, x1, y1);
    }

    public void DrawEllipse(FileWriter SVGFile, int x1, int y1, int x2, int y2)
    {
        StartItem(SVGFile, "ellipse");
        NumberLabel(SVGFile, "cx", (x1 + x2) / 2);
        NumberLabel(SVGFile, "cy", (y1 + y2) / 2);
        NumberLabel(SVGFile, "rx", (x2 - x1) / 2);
        NumberLabel(SVGFile, "ry", (y2 - y1) / 2);
        TextLabel(SVGFile, "fill", "none");
        TextLabel(SVGFile, "stroke", "black");
        NumberLabel(SVGFile, "stroke-width", 1);
        Stop(SVGFile);
    }

    public void DrawText(FileWriter SVGFile, int x1, int y1, int size, String text)
    {
		try{
        StartItem(SVGFile, "text");
        NumberLabel(SVGFile, "x", x1);
        NumberLabel(SVGFile, "y", y1);
        NumberLabel(SVGFile, "font-size", size);
        TextLabel(SVGFile, "stroke", "none");
        NumberLabel(SVGFile, "stroke-width", 1);
        EndItem(SVGFile);
        System.out.print(text.substring(1, text.length() - 1));
        SVGFile.write(text.substring(1, text.length() - 1));
        Enclose(SVGFile, "text");
		}
		catch(Exception e){
			Error();
		}
    }
}

