/*////////////////////////////////////////////////////////
Name: 	SimpleNode

Author: 	Sarah Han-de-Beaux

Description: This is where I describe the methods generate
				 and the paint methods.

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

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

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

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

  public SimpleNode(drawphase3 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 drawphase3TreeConstants.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 + " ");
	}
      }
    }
  }

  /* Added methods - had to incorperate colour and brush in this section*/
   public void generate(String Colour, int brush, int x, int y)
  {
   	throw new Error("Method override");//Should have been overidden
  }	 

  //These are the paint methods. PaintLine is the main one really as shapes are broken down into lines.
  public void paintLine(int x1, int y1, int x2, int y2, String colour, int brush, int x, int y)
  {
  	  System.out.println("<line x1=\"" + (x1+x) +
      "\" y1=\"" + (y1+y)+
       "\" x2=\"" + (x2+x)+
       "\" y2=\"" + (y2+y) +
       "\" stroke=\"" + colour + "\" stroke-width=\"" + brush + "\"/>");
  }
  /*Here I have tried to repeat the rectangle, where each repeatition the coordinates move slightly
    so that they are not drawn over the top of each other.  However it doesnt work.*/
  public void paintRectangle(int xleft, int ytop, int xright, int ybottom, String colour, int brush, int x, int y)
  {
	
  	    	paintLine(xleft,ytop,xright,ytop, colour, brush, x, y);
  			paintLine(xright,ytop,xright,ybottom, colour, brush, x, y);
  			paintLine(xright,ybottom,xleft,ybottom, colour, brush, x, y);
  			paintLine(xleft,ybottom,xleft,ytop, colour, brush, x, y);
  }
  
  public void paintSquare(int xleft, int ytop, int xright, String colour, int brush, int x, int y)
  {
  	int ybottom = (xright-xleft) + ytop;
  	paintRectangle(xleft,ytop,xright,ybottom, colour, brush, x, y);
  }
  
  public void paintEllipse(int xleft, int ytop, int xright, int ybottom, String colour, int brush, int x, int y)
  {
  	int xpos, ypos, xrad, yrad;
  	xrad = (xright-xleft)/2;
  	yrad = (ybottom-ytop)/2;
  	xpos = (xright-xrad);
  	ypos = (ybottom-yrad);
  	System.out.println("<ellipse cx=\"" + (xpos+x) + "\" cy=\"" + (ypos+y) + "\" rx=\"" +
  						xrad + "\" ry=\"" + yrad + "\" stroke=\"" + colour + "\" " +
  						" stroke-width=\"" + brush + "\" fill=\"none\"/>");
  }	
  
  public void paintCircle(int xleft, int ytop, int xright, String colour, int brush, int x, int y)
  {
  	int ybottom = (xright-xleft) + ytop;
  	paintEllipse(xleft,ytop,xright,ybottom, colour, brush, x, y);
  }
  
  public void paintTriangle(int x1, int y1, int x2, int y2, int x3, int y3, String colour, int brush, int x, int y)
  {
 	paintLine(x1, y1, x2, y2, colour, brush, x, y);
  	paintLine(x2, y2, x3, y3, colour, brush, x, y);
  	paintLine(x3, y3, x1, y1, colour, brush, x, y);
  }

  public void paintPolygon(int[] xpos, int[] ypos, String colour, int brush, int x, int y)
  {
  	for(int i = 0; i<xpos.length-1 ; i++)
  	paintLine(xpos[i], ypos[i], xpos[i+1], ypos[i+1], colour, brush, x, y);
  	paintLine(xpos[xpos.length-1], ypos[ypos.length-1], xpos[0], ypos[0], colour, brush, x, y);
  }

  public void paintText(int xleft, int ytop, int fontsize, String Message, String colour, int brush, int x, int y)
  {
  	System.out.println("<text x=\"" + (xleft+x) + "\" y=\"" + (ytop+y) + "\" font-size= \"" + 
  					    fontsize + "\" stroke=\"none\" fill=\"" + colour + "\" stroke-width=\"" + brush + "\">");
  	String strippedMessage="";
  	for(int i =1;i<Message.length()-1;i++)
  		strippedMessage+=Message.substring(i,i+1);
  	System.out.println(strippedMessage);
  	System.out.println("</text>");
  }
  
  
}







