import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
import java.lang.Math;
import java.text.DecimalFormat;
//import java.awt.Canvas;

public class SRCanvas extends JComponent 
{
  private int cursorX = 0;
  private int cursorY = 0;
  private int lastValidX = 0;
  private int lastValidY = 0;
  private boolean firstDraw = true;
  private boolean drawData = true;
	private boolean noSurvey = true;
  
  private XMLobject stim;
  
  
  private int[] line1 = {380,100,518,339};
  private int[] line2 = {518,339,242,339};
  private int[] line3 = {242,339,380,100};
  
	
	//total area of the triangle decision space
  DecimalFormat oneDigit = new DecimalFormat("0");
	private double totalArea = 0;
  //Percentage of decision space covered by the triangle drawn from the edge
  //opposite the topmost point to the user decision point. 
  private double p1 = 0;
  //Percentage of decision space covered by the triangle drawn from the edge
  //opposite the rightmost point to the user decision point.
  private double p2 = 0;
  //Percentage of decision space covered by the triangle drawn from the edge
  //opposite the leftmost point to the user decision point.
  private double p3 = 0;
  int p1T = 0;
  int p2T = 0;
  int p3T = 0;
  Polygon full = getPolygon(line1,line2,line3);
  Color nextFill = Color.red;
  
  /**
   * Default Constructor
   */
  public SRCanvas()  
  {
    totalArea = areaOfTriangle(line1[0],line1[1],line2[0],line2[1],line3[0],line3[1]);
  } 
  
  public SRCanvas(int[] l1, int[] l2, int[] l3)
  {
    line1 = l1;
    line2 = l2;
    line3 = l3;
    totalArea = areaOfTriangle(line1[0],line1[1],line2[0],line2[1],line3[0],line3[1]);
  }
  
  public void paintComponent(Graphics g)
  {
    try
    {
      //refresh canvas
      g.setColor(Color.white);
      g.fillRect(0,0,this.getWidth(),this.getHeight());
      g.setColor(Color.black);
      g.drawLine(line1[0],line1[1],line1[2],line1[3]);
      g.drawLine(line2[0],line2[1],line2[2],line2[3]);
      g.drawLine(line3[0],line3[1],line3[2],line3[3]);
      
      
      //draw new cursor
      if(!firstDraw && !noSurvey)//if not first drawing update, else draw centered
      {
        if(boundCheck(cursorX,cursorY))//if in the bounds update, else don't update
        {
          lastValidX=cursorX;
          lastValidY=cursorY;
          if(drawData)
          {
            setNextFill();
            calculatePercentages(cursorX,cursorY);
            drawDetailedCursorBroken(g,cursorX,cursorY, stim);
          }
          drawCursor(g,cursorX,cursorY);
        }
        else
        {
          if(drawData)
          {
            drawDetailedCursorBroken(g,lastValidX,lastValidY, stim);
          }
          drawCursor(g,lastValidX,lastValidY);
        }
      }
      else if(firstDraw && !noSurvey)
      {
        firstDraw = false;
        lastValidX=line1[0];
        lastValidY=159+line1[1];
        
        //drawCursor(g,lastValidX,lastValidY);
        if(drawData)
        {
          setNextFill();
          calculatePercentages(lastValidX,lastValidY);
          drawDetailedCursorSolid(g,lastValidX,lastValidY,nextFill,stim);
          drawCursor(g,lastValidX,lastValidY);
        }
        
      }
			else
			{
				firstDraw = false;
        lastValidX=line1[0];
        lastValidY=159+line1[1];
        
        //drawCursor(g,lastValidX,lastValidY);
        if(drawData)
        {
          setNextFill();
          calculatePercentages(lastValidX,lastValidY);
          drawDetailedCursorSolid(g,lastValidX,lastValidY,nextFill);
          drawCursor(g,lastValidX,lastValidY);
        }
			}
			   
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
    
  }

  //Overloading the update function so the background is not redrawn
  public void update(Graphics g)
  {
    paint(g); 
  }

  public void cursorNow(int locX, int locY)
  {
    cursorX = locX;
    cursorY = locY;
    repaint();
  }

	public void decompress(int locX, int locY)
	{
		
		Graphics g = getGraphics();
		
		if(locX >= line1[0]-90 && locX <= line1[0]+90 && locY >= line1[1]-60 && locY <= line1[1])
		{
			breakString(g, stim.getPoleDescrip(0),560,20, 0);
		}
		else if(locX >= line2[0] && locX <= line2[0]+180 && locY >= line2[1]-30 && locY <= line2[1]+30)
		{
			breakString(g, stim.getPoleDescrip(1),560,20, 0);
		}
		else if(locX >= line3[0]-180 && locX <= line3[0] && locY >= line3[1]-30 && locY <= line3[1]+30)
		{
			breakString(g, stim.getPoleDescrip(2),560,20, 0);
		}
		else
		{
			breakString(g,"",560,20, 0);
			repaint();
		}
		
	}

  private void drawCursor(Graphics g, int locX, int locY)
  {
    int size = 10;
    g.drawLine(locX-size, locY, locX+size, locY);
    g.drawLine(locX, locY-size, locX, locY+size);
  }

  private void drawDetailedCursor(Graphics g, int locX, int locY, XMLobject stim)
  {
		g.drawString(oneDigit.format(p1)+"%",line1[0]+10,line1[1]+7);
    g.drawString(oneDigit.format(p2)+"%",line2[0]-20,line2[1]+12);
    g.drawString(oneDigit.format(p3)+"%",line3[0]+2,line3[1]+12);
		
		breakString(g, stim.getDisplayData(),15,25, -1);
		breakString(g, stim.getPoleCues(0),line1[0]-60,line1[1]-20, 1); //top
		//breakString(g, stim.getPoleDescrip(0),line1[0]-80,line1[1]-65, 0); //top
    breakString(g, stim.getPoleCues(1),line2[0]+15,line2[1], 1);  //right
    //breakString(g, stim.getPoleDescrip(1),line2[0]+15,line2[1]-30, 0);  //right
		breakString(g, stim.getPoleCues(2),line3[0]-190,line3[1], 1); //left
		//breakString(g, stim.getPoleDescrip(2),line3[0]-225,line3[1]-30, 0); //left
	
    g.drawLine(locX,locY,line1[0],line1[1]);
    g.drawLine(locX,locY,line2[0],line2[1]);
    g.drawLine(locX,locY,line3[0],line3[1]);
  }

  private void drawDetailedCursorSolid(Graphics g, int locX, int locY, Color x, XMLobject stim)
  {
    g.setColor(x);
    g.fillPolygon(full);
    g.setColor(Color.black);
	
		g.drawString(oneDigit.format(p1)+"%",line1[0]+10,line1[1]+7);
    g.drawString(oneDigit.format(p2)+"%",line2[0]-20,line2[1]+12);
    g.drawString(oneDigit.format(p3)+"%",line3[0]+2,line3[1]+12);
		
		breakString(g, stim.getDisplayData(),15,25, -1);
		breakString(g, stim.getPoleCues(0),line1[0]-60,line1[1]-20, 1); //top
		//breakString(g, stim.getPoleDescrip(0),line1[0]-80,line1[1]-65, 0); //top
    breakString(g, stim.getPoleCues(1),line2[0]+15,line2[1], 1);  //right
    //breakString(g, stim.getPoleDescrip(1),line2[0]+15,line2[1]-30, 0);  //right
		breakString(g, stim.getPoleCues(2),line3[0]-190,line3[1], 1); //left
		//breakString(g, stim.getPoleDescrip(2),line3[0]-225,line3[1]-30, 0); //left
    
		g.drawLine(locX,locY,line1[0],line1[1]);
    g.drawLine(locX,locY,line2[0],line2[1]);
    g.drawLine(locX,locY,line3[0],line3[1]);
  }

	private void drawDetailedCursorSolid(Graphics g, int locX, int locY, Color x)
  {
    g.setColor(x);
    g.fillPolygon(full);
    g.setColor(Color.black);
	
		g.drawString(oneDigit.format(p1)+"%",line1[0]+10,line1[1]+7);
    g.drawString(oneDigit.format(p2)+"%",line2[0]-20,line2[1]+12);
    g.drawString(oneDigit.format(p3)+"%",line3[0]+2,line3[1]+12);
		
		breakString(g, "",15,25, -1);
		breakString(g, "",line1[0]-60,line1[1]-20, 1); //top
		//breakString(g, stim.getPoleDescrip(0),line1[0]-80,line1[1]-65, 0); //top
    breakString(g, "",line2[0]+15,line2[1], 1);  //right
    //breakString(g, stim.getPoleDescrip(1),line2[0]+15,line2[1]-30, 0);  //right
		breakString(g, "",line3[0]-190,line3[1], 1); //left
		//breakString(g, stim.getPoleDescrip(2),line3[0]-225,line3[1]-30, 0); //left
    
		g.drawLine(locX,locY,line1[0],line1[1]);
    g.drawLine(locX,locY,line2[0],line2[1]);
    g.drawLine(locX,locY,line3[0],line3[1]);
  }
	
  private void drawDetailedCursorBroken(Graphics g, int locX, int locY, XMLobject stim)
  {
    int[] one1 ={locX,line1[0],line2[0]};
    int[] one2 ={locY,line1[1],line2[1]};
    int[] two1 ={locX,line2[0],line3[0]};
    int[] two2 ={locY,line2[1],line3[1]};
    int[] three1 ={locX,line3[0],line1[0]};
    int[] three2 = {locY,line3[1],line1[1]};
    
    Polygon one = new Polygon(one1,one2,3);
    Polygon two = new Polygon(two1,two2,3);
    Polygon three = new Polygon(three1,three2,3);
    
		g.setColor(Color.red);
    g.fillPolygon(one);
    g.setColor(Color.yellow);
    g.fillPolygon(two);
    g.setColor(Color.blue);
    g.fillPolygon(three);
    g.setColor(Color.black);
	
		g.drawString(oneDigit.format(p1)+"%",line1[0]+10,line1[1]+7);
    g.drawString(oneDigit.format(p2)+"%",line2[0]-20,line2[1]+12);
    g.drawString(oneDigit.format(p3)+"%",line3[0]+2,line3[1]+12);
	
		breakString(g, stim.getDisplayData(),15,25, -1);
		breakString(g, stim.getPoleCues(0),line1[0]-60,line1[1]-20, 1); //top
		//breakString(g, stim.getPoleDescrip(0),line1[0]-80,line1[1]-65, 0); //top
    breakString(g, stim.getPoleCues(1),line2[0]+15,line2[1], 1);  //right
    //breakString(g, stim.getPoleDescrip(1),line2[0]+15,line2[1]-30, 0);  //right
		breakString(g, stim.getPoleCues(2),line3[0]-190,line3[1], 1); //left
		//breakString(g, stim.getPoleDescrip(2),line3[0]-225,line3[1]-30, 0); //left
    
		g.drawLine(locX,locY,line1[0],line1[1]);
    g.drawLine(locX,locY,line2[0],line2[1]);
    g.drawLine(locX,locY,line3[0],line3[1]);
  }


  public void stimDisplay(XMLobject s)
  {
  	
	stim = s;
	firstDraw = true;
	noSurvey = false;
	repaint();
	
  }
  
  
  public void refresh()
  {
    firstDraw = true;
    repaint();
  }

  public void reset()
  {
    firstDraw = true;
    lastValidX=line1[0];
    lastValidY=159+line1[1];
		
		//reset cursorX and cursorY
		
		cursorX = lastValidX;
		cursorY = lastValidY;
    repaint();
  }

	public void noSurvey()
	{
		noSurvey = true;
		firstDraw = true;
    lastValidX=line1[0];
    lastValidY=159+line1[1];
		
		//reset cursorX and cursorY
		
		cursorX = lastValidX;
		cursorY = lastValidY;
    repaint();
	}
	
  public Polygon getPolygon(int[] l1, int[] l2, int[] l3)
  {
    int[] x = {l1[0],l2[0],l3[0]};
    int[] y = {l1[1],l2[1],l3[1]};
    int num = 3;
    
    return new Polygon(x,y,num);
  }

  private int xOnALine(int x1, int y1, int x2, int y2, int yLocation)
  {
    //Calculate the function of the line given 2 points in our coordinate space.
    //y = mx+b or x = (y-b)/m
    
    double m = ((double)y2-(double)y1)/((double)x2-(double)x1);
    double b = (double)y1-(m*(double)x1);
    
    double x = ((double)yLocation-b)/m;
    int xTrunc = (int)x;
    if(xTrunc < 0)
      xTrunc = xTrunc*-1;
    return xTrunc; 
  }

  private int yOnALine(int x1, int y1, int x2, int y2, int xLocation)
  {
    //Calculate the function of the line given 2 points in our coordinate space.
    //y = mx+b or x = (y-b)/m
    
    double m = ((double)y2-(double)y1)/((double)x2-(double)x1);
    double b = (double)y1-(m*(double)x1);
    
    double y = m*(double)xLocation+b;
    int yTrunc = (int)y;
    if(yTrunc < 0)
      yTrunc = yTrunc*-1;
    return yTrunc;
  }

  private boolean boundCheck(int x, int y)
  {
    int line1Xbound = xOnALine(line1[0],line1[1],line1[2],line1[3],y);
    int line1Ybound = yOnALine(line1[0],line1[1],line1[2],line1[3],x);
    int line2Ybound = yOnALine(line2[0],line2[1],line2[2],line2[3],x);
    int line3Xbound = xOnALine(line3[0],line3[1],line3[2],line3[3],y);
    int line3Ybound = yOnALine(line3[0],line3[1],line3[2],line3[3],x);
    
    //System.out.println("In order to draw, the following must be valid");
    //System.out.println(x + " >= " + line1Xbound + " and " + y + " >= " + line1Ybound );
    //System.out.println(y + " <= " + line2Ybound);
    //System.out.println(x + " <= " + line3Xbound + " and " + y + " >= " + line3Ybound );
    
    //Start checking line ranges from the topmost point clockwise around the polygon.
    if((x <= line1Xbound && y >= line1Ybound) &&
       (y <= line2Ybound) &&
       (x >= line3Xbound && y >= line3Ybound))
       {
        return true;
       }
     else
       {
        return false;
       }
  }

  private boolean boundCheck(int x, int y, int[] array1, int[] array2, int[] array3)
  {
    int line1Xbound = xOnALine(array1[0],array1[1],array1[2],array1[3],y);
    int line1Ybound = yOnALine(array1[0],array1[1],array1[2],array1[3],x);
    int line2Ybound = yOnALine(array2[0],array2[1],array2[2],array2[3],x);
    int line3Xbound = xOnALine(array3[0],array3[1],array3[2],array3[3],y);
    int line3Ybound = yOnALine(array3[0],array3[1],array3[2],array3[3],x);
    
    //System.out.println("In order to draw, the following must be valid");
    //System.out.println(x + " <= " + line1Xbound + " and " + y + " >= " + line1Ybound );
    //System.out.println(y + " <= " + line2Ybound);
    //System.out.println(x + " >= " + line3Xbound + " and " + y + " >= " + line3Ybound );
    
    //Start checking line ranges from the topmost point clockwise around the polygon.
    if((x <= line1Xbound && y >= line1Ybound) &&
       (y <= line2Ybound) &&
       (x >= line3Xbound && y >= line3Ybound))
       {
        return true;
       }
     else
       {
        return false;
       }
  }

  private boolean boundCheckDown(int x, int y, int[] array1, int[] array2, int[] array3)
  {
    int line1Xbound = xOnALine(array1[0],array1[1],array1[2],array1[3],y);
    int line1Ybound = yOnALine(array1[0],array1[1],array1[2],array1[3],x);
    int line2Ybound = yOnALine(array2[0],array2[1],array2[2],array2[3],x);
    int line3Xbound = xOnALine(array3[0],array3[1],array3[2],array3[3],y);
    int line3Ybound = yOnALine(array3[0],array3[1],array3[2],array3[3],x);
    
    //System.out.println("In order to draw, the following must be valid");
    //System.out.println(x + " <= " + line1Xbound + " and " + y + " <= " + line1Ybound );
    //System.out.println(y + " <= " + line2Ybound);
    //System.out.println(x + " >= " + line3Xbound + " and " + y + " <= " + line3Ybound );
    
    //Start checking line ranges from the topmost point clockwise around the polygon.
    if((x <= line1Xbound && y <= line1Ybound) &&
       (y >= line2Ybound) &&
       (x >= line3Xbound && y <= line3Ybound))
       {
        return true;
       }
     else
       {
        return false;
       }
  }

	private boolean circleCheck(int x, int y)
	{
		
		double SqrtX = 0;
		double SqrtY = 0;
		
		double xExp1 = 0;
		double xExp2 = 0;
		double yExp1 = 0;
		double yExp2 = 0;
		
		boolean inX = true;
		boolean inY = true;
				
		//calculate squres
		double a = 30.5;
		double a2 = a*a;
		
		double xMod = (double)(x-380);		
		double xMod2 = xMod*xMod;
		double yMod = (double)(y-260);
		double yMod2 = yMod*yMod;
		
		SqrtX = a2*(1-(yMod2/a2));
		SqrtY = a2*(1-(xMod2/a2));
		
		//find if x is in
		
		if( SqrtX < 0)
		{
			inX = false;
		}
		else
		{
			//find xExp1 and xExp2
			
			xExp1 = Math.sqrt(SqrtX) + 380;
			xExp2 = -1*Math.sqrt(SqrtX) + 380;
			
			//System.out.println("In order to draw, the following must be valid");
    	//System.out.println(x + " <= " + xExp1 + " and " + x + " >= " + xExp2 );
			
			if(x <= xExp1 && x >= xExp2)
			{
				inX = true;
			}
			else
			{
				inX = false;
			}
			
		}
		

		//find if y is in
		
		if( SqrtY < 0)
		{
			inY = false;
		}
		else
		{
			//find yExp1 and yExp2
			
			yExp1 = Math.sqrt(SqrtY) + 260;
			yExp2 = -1*Math.sqrt(SqrtY) + 260;
			
			//System.out.println("In order to draw, the following must be valid");
    	//System.out.println(y + " <= " + yExp1 + " and " + y + " >= " + yExp2 );
			
			if(y <= yExp1 && y >= yExp2)
			{
				inY = true;
			}
			else
			{
				inY = false;
			}
			
		}
		
		//if in both x and y then return true
		
		if(inX && inY)
		{
			return true;
		}
		else
		{
			return false;
		}
		
	}

  private int distanceBetweenPoints(int x1, int y1, int x2, int y2)
  {
    double dx = (double)x1-(double)x2;
    double dy = (double)y1-(double)y2;
    
    int distance = (int)(Math.sqrt(dx*dx + dy*dy));
    return distance;
  }

  private double areaOfTriangle(int x1, int y1, int x2, int y2, int x3, int y3)
  {
    double area = (Math.abs((((double)x2*(double)y1)-((double)x1*(double)y2))
                           +(((double)x3*(double)y2)-((double)x2*(double)y3))
                           +(((double)x1*(double)y3)-((double)x3*(double)y1))))/2.0;
    return area;
  }

  private void setNextFill()
  {
    if(p1T >= p2T && p1T >= p3T)
     nextFill = Color.yellow;
    if(p2T >= p3T && p2T >= p1T)
     nextFill = Color.blue;
    if(p3T >= p1T && p3T >= p2T)
     nextFill = Color.red;
  }

  private void calculatePercentages(int x, int y)
  {
    double l1 = areaOfTriangle(x,y,line1[0],line1[1],line1[2],line1[3]);
    double l2 = areaOfTriangle(x,y,line2[0],line2[1],line2[2],line2[3]);
    double l3 = areaOfTriangle(x,y,line3[0],line3[1],line3[2],line3[3]);
    
    //Percentage for each triagle mapped to next point
    p3 = l1/totalArea*100.0; //point 3, triangle 1
    p1 = l2/totalArea*100.0; //point 1, triangle 2
    p2 = l3/totalArea*100.0; //point 2, triangle 3
    
    p1T = (int)p1;
    p2T = (int)p2;
    p3T = (int)p3;
    
   }
   
	public String getPercent(int n)
	{
		if(n == 1)
		{
			return oneDigit.format(p1);
		}
		else if(n == 2)
		{
			return oneDigit.format(p2);
		}
		else if(n == 3)
		{
			return oneDigit.format(p3);
		}
		else
		{
			return "-1";
		}
	}
	 
	public int getSector()
	{
	 	
		int sect = -1;
		
		//Triangle 0 in top range
		int[] line0a = {380,100,427,180};
		int[] line0b = {427,180,333,180};
		int[] line0c = {333,180,380,100};
		
		//Triangles 4,3,8 in mid range
		int[] line4a = {333,180,380,260};
		int[] line4b = {380,260,287,260};
		int[] line4c = {287,260,333,180};
		
		int[] line3a = {380,260,427,180};
		int[] line3b = {427,180,333,180};
		int[] line3c = {333,180,380,260};
		
		int[] line8a = {427,180,473,260};
		int[] line8b = {473,260,380,260};
		int[] line8c = {380,260,427,180};		
		
		
		//Triangles 1,5,6,7,2
		int[] line1a = {287,260,334,339};
		int[] line1b = {334,339,241,339};
		int[] line1c = {241,339,287,260};		
		
		int[] line5a = {334,339,380,260};
		int[] line5b = {380,260,287,260};
		int[] line5c = {287,260,334,339};

		int[] line6a = {380,260,426,339};
		int[] line6b = {426,339,334,339};
		int[] line6c = {334,339,380,260};
		
		int[] line7a = {426,339,473,260};
		int[] line7b = {473,260,380,260};
		int[] line7c = {380,260,426,339};
		
		int[] line2a = {473,260,519,339};
		int[] line2b = {519,339,426,339};
		int[] line2c = {426,339,473,260};
		
		
		//Test if in circle
		if(circleCheck(lastValidX, lastValidY))
		{
			sect = -2;
		}
		else if(lastValidY <= 180) //top range, only sector 0
		{
			sect = 0;
		}
		else if(lastValidY > 180 && lastValidY < 259)
		{
			if( boundCheck(lastValidX, lastValidY, line4a, line4b, line4c) )  //sector 4
			{
				sect = 4;
			}
			else if( boundCheckDown(lastValidX, lastValidY, line3a, line3b, line3c) ) //sector 3
			{
				sect = 3;
			}
			else if( boundCheck(lastValidX, lastValidY, line8a, line8b, line8c) ) //sector 8
			{
				sect = 8;
			}
			
		}
		else if(lastValidY >= 259)
		{
			if( boundCheck(lastValidX, lastValidY, line1a, line1b, line1c) )  //sector 1
			{
				sect = 1;
			}
			else if( boundCheckDown(lastValidX, lastValidY, line5a, line5b, line5c) ) //sector 5
			{
				sect = 5;
			}
			else if( boundCheck(lastValidX, lastValidY, line6a, line6b, line6c) ) //sector 6
			{
				sect = 6;
			}
			else if( boundCheckDown(lastValidX, lastValidY, line7a, line7b, line7c) ) //sector 7
			{
				sect = 7;
			}
			else if( boundCheck(lastValidX, lastValidY, line2a, line2b, line2c) ) //sector 2
			{
				sect = 2;
			}
		}
		else
		{
			System.out.println("ERROR: Could not locate sector");
			System.exit(102);
		}
		
		return sect;
				
	}
	 
	private void breakString(Graphics g, String s, int x, int y, int type)
	{
		int WIDTH = 30;
		
		
		//Declare variables
		int length;
		int counter = 1;
		int last = 0;
		
		length = s.length();
		
		
		if(type == 1)
		{
			g.setFont(new Font("Serif",Font.BOLD,14));
		}
		else if(type == 0)
		{
			g.setFont(new Font("Serif",Font.PLAIN,10));
		}
		else if(type == -1)
		{
			g.setFont(new Font("Serif",Font.BOLD + Font.ITALIC,12));
		}
		else
		{
			g.setFont(new Font("Serif",Font.PLAIN,10));
		}
		
		
		if(length <= WIDTH)
		{
			counter = length;
		}
		else
		{
			counter = WIDTH;
		}
		
				
		while(counter < length)
		{
			
			if(s.charAt(counter) == ' ')
			{
				//insert string and newline
				
				g.drawString(s.substring(last, counter), x, y);
				y += 10;
				
				last = counter;
				
				if(counter + WIDTH > length)
				{
					counter = length;
				}
				else
				{
					counter += WIDTH;
				}
			}
			else
			{
				counter++;
			}
			
		}
		
		if(counter == length)
		{
			//insert string
				
			g.drawString(s.substring(last), x, y);
			y += 10;
				
			last = counter;
				
			if(counter + WIDTH > length)
			{
				counter = length;
			}
			else
			{
				counter += WIDTH;
			}
				
		}
		
	}
}
