package tools;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.io.Serializable;
import java.awt.Point;

import main.ChronoPanel;

public class Text //implements Serializable
{
	
	private static final long serialVersionUID = 1L;

	private String text;
	private int x, y;
	private int xmin, xmax, ymin, ymax;	
	
	private int textwidth;
	private int textheight;
	
	private Boolean selected;
		
	public Text(ChronoPanel chrono)
	{

	}
	
	public Text(String text) 
	{
		this.text = text;
		this.x = 0;
		this.y = 0;
		this.textwidth = 0;
	    this.textheight = 0;
	    this.selected = false;
	}

	public void draw(Graphics g)
	{
		if(selected == true)
		{
			g.setColor(Color.RED);
		}
		else
		{	
			g.setColor(Color.BLUE);
		}
		
		g.drawString(text, x, y);
		System.out.println("----- " + x + " " + y + " " + text);
	    
		g.drawRect(xmin, ymin, textwidth ,textheight);
		
		
		//g.drawRect(xmin, ymin, xmax - xmin, ymax - ymin);
		
		//this.textwidth = g.getFontMetrics().stringWidth(text);
	    //this.textheight = g.getFontMetrics().getHeight();
	    //this.xmin = x;
	    //this.ymin = y - textheight;
	    //this.xmax = x + textwidth;
	    //this.ymax = y ;
	    
	    
	}
	
	public boolean textAt(double xmouse, double ymouse) 
	{
	    /*	
	    		int xmin = (int) x;
	    		int xmax = xmin + width_string;7
	    		
	    		int ymin = (int) y - height_string;
	    		int ymax = (int) y;
	        	
	    		System.out.println("555 ::: " + xmouse + " " +  xmin + " " +  xmouse + " " + xmax + " " + ymouse + " " + ymin + " " + ymouse + " " + ymax );
	    		
	        	if( xmouse >= xmin && xmouse <= xmax && ymouse >= ymin && ymouse <= ymax  )
	            {
	        		return(true);
	            }
	        
				return (false);
				*/
		
		 	//this.xmin = x;
		    //this.ymin = y - height_string;
		    
		    //this.xmax = x + width_string;
		    //this.ymax = y ;
		
		    Rectangle r = new Rectangle (xmin, ymin  , textwidth ,textheight);    
		  
		    boolean detection = r.contains(new Point((int)xmouse, (int)ymouse));
		  
		    return (detection);
		   /* if(detection == true)
		    {
	    		System.out.println("Match");
	    		this.selected = true;
		    }
		    else
		    {
			  this.selected = false;
		    }*/
		  		 
	}
	
	 public void toggleSelected() 
	 { 
		 selected = !selected; 
	 }
	
	
	 public void setSelected(boolean select)
	 {
		 selected = select;
	 }
	 
	 public void setX(int x)
	 {
		 this.x = x;
	 }
	
	 public int getX()
	 {
		 return x;
	 } 

	 public void setY(int y)
	 {
		 this.y = y;
	 }
	 
	 public int getY()
	 {
		 return y;
	 }
	 
	 public String getText()
	 {
		 return text;
	 }

	 public void setHalo(int xmin, int ymin, int xmax, int ymax, int textwidth, int textheight)
	 {
		 this.xmin = xmin;
		 this.ymin = ymin;
		 this.xmax = xmax;
		 this.ymax = ymax;
		 this.textwidth = textwidth;
		 this.textheight = textheight; 
	 }
}
