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

import java.io.*;

public class ASTProgram extends SimpleNode {
  String name = "program";
  public ASTProgram(int id) {
    super(id);
  }

  public ASTProgram(drawphase2 p, int id) {
    super(p, id);
  }

  public void generateFile()
  {
    String file = "tester.svg";
    try
    {
    	FileWriter fw = new FileWriter(file);
    	BufferedWriter bw = new BufferedWriter(fw);
    	PrintWriter outFile = new PrintWriter(bw);
    	
    	outFile.println("<svg>\n");    	
   	    System.out.println("<svg>");      	    
   	    
   	    String colour = "black";
   	    int brushSize = 1, offsetX = 0, offsetY = 0;
   	    //Generates each child in the program and outputs to a file.
        for(int i = 2; i < jjtGetNumChildren(); i++)
    	{    		
    		String childName = jjtGetChild(i).getName();
    		
    		//This block works out the type of each child before generation.      		
    		if (childName.equals("colour") == true)
    		{
    			colour = jjtGetChild(i).generate(colour, brushSize, offsetX, offsetY);
    		}
    		else if (childName.equals("brush") == true)
    		{
    			brushSize = Integer.parseInt(jjtGetChild(i).generate(colour, brushSize, offsetX, offsetY));
    		}
    		else if (childName.equals("offset") == true)
    		{
    			offsetX += jjtGetChild(i).generateX();
    			offsetY += jjtGetChild(i).generateY();
    		}
    		else
    		{
    			outFile.println(jjtGetChild(i).generate(colour, brushSize, offsetX, offsetY)); 
    			
    			//Resets the variables after a command has been processed that is not in a block.
    			colour = "black";
    			brushSize = 1;
    			offsetX = 0;
    			offsetY = 0;
    		}   
    				
    	}
    	outFile.println("</svg>\n");
    	System.out.println("</svg>");
    	outFile.close();
    }
    catch(IOException e)
    {
    	System.exit(1);
    }
    
   
    	
  }
  
  public String getName()
  {
     return name;
  }
}
