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

/**************************************************************

File				: ASTMain.java
Auther				: M. Spiller
Registration #		: Y0259667
Date				: Thursday 13th november 2003
Unit				: CMP-2A25 Programming - Software Development Techniques
Description			: Main class that controls flow of program

**************************************************************/

import java.io.*;

public class ASTMain extends SimpleNode 
{
	public ASTMain(int id) 
	{
		super(id);
	}

	public ASTMain(DrawPhase3 p, int id) 
	{
		super(p, id);
	}

	public void generate(FileWriter SVGFile,String SVG, String HTML, int Xsc, 
							int Ysc,int X, int Y, String colour, int brush)
	{
		try
		{
			FileHeader(SVGFile);//creates header for SVG file

			//cycles throught all children
			for(int count = 2; count < jjtGetNumChildren(); count++)
			{
				//generates each child, parsing file objects and variables
				jjtGetChild(count).generate(SVGFile, Xsc, Ysc, X, Y, colour, brush);
			}
			FileComplete(SVGFile);//completes the svg file
			SVGFile.close();//closes the svgfile

			Generate_HTML_File(SVG, HTML);//generates the HTML file
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.err.println ("Error writing to file");
		}
	}

	//Method to generate HTML file
	public void Generate_HTML_File(String SVGFileName, String HTMLFileName)
	{
		try
		{
			//Creates new HTML file
			FileWriter HTMLFile = new FileWriter(HTMLFileName);

			//Inserts HTML code linking SVG file
			HTMLFile.write("<html>\n<embed src = \"" 
			+ SVGFileName 
			+ "\" width = \"" + ((ASTInt)jjtGetChild(0)).val 
			+ "\" height = \"" + ((ASTInt)jjtGetChild(1)).val 
			+ "\" />\n</html>");
			HTMLFile.close();//completes file
		}
		catch(Exception e)
		{
			System.out.println("ERROR creating HTML file \"" + HTMLFileName + "\"");
		}
	}
}
