import java.awt.*;

public class SFRect extends FRect{
  private Color color;
  private int w=6;
  private int width,height,tempx,tempy;
  private boolean itsMe=true;
  private boolean object=false;
  private boolean handle=false;
  private int pickedHandle;
  // Constructor for when the rectangle is being drawn.
  public SFRect(int x1, int y1, int x2, int y2, Color color){
    super(x1,y1,x2,y2,color);
    tempx=x1;
    width=x2;
    tempy=y1;
    height=y2;
    this.color=color;
  }
  // Method for when writing to a file, returns a string will all attributes
  // of the object to be written to the file
  public String returnString(){
    return (new String("frect" + " " + tempx + " " + tempy + " " + width 
                       + " " + height + " " + color.getRed() + "," +
                       color.getGreen() + "," + color.getBlue()));
  }
  public void setFirstPoint(int x,int y){
    tempx=x;
    tempy=y;
  }
  public Point firstSelPoint(){
    return(new Point(tempx,tempy));
  }
  public Point secondSelPoint(){
    return(new Point(width,height));
  }
  public Color selColor(){
    return color;
  }
  public void setSelColor(Color c){
    color=c;
  }
  public int getPickedHandle(){
    return pickedHandle;
  }
  public void paint (Graphics g){
    g.setColor(color);
    g.fillRect(tempx,tempy,width,height);
    g.setColor(Color.black);
    g.fillRect(tempx-(w/2),tempy-(w/2),w,w);
    g.fillRect(tempx+width-(w/2),tempy-(w/2),w,w);
    g.fillRect(tempx-(w/2),tempy+height-(w/2),w,w);
    g.fillRect(tempx+width-(w/2),tempy+height-(w/2),w,w);
  }
  public boolean areYouSelected(){
    return itsMe;
  }
  public void youAreSelected(boolean b){
    itsMe=b;
  }
  public boolean getIfObjectClicked(){
    return object;
  }
  public boolean getIfHandleClicked(){
    return handle;
  }
  public void setSecondPoint(int x,int y){
    width=x;
    height=y;
  }
  public boolean intersects(int x, int y){
    object=((tempx <= x && x<=(tempx+width)) && (tempy <= y && y <= (tempy+height)));
    if ((x>=(tempx-(w/2)))&&(x<=(tempx-(w/2)+w)) && (y>=(tempy-(w/2))) && 
        (y<=(tempy-(w/2)+w))){
      handle=true;
      pickedHandle=1;
    }
    else if ((x>=(tempx+(width)-(w/2)))&&(x<=(tempx+(width)-(w/2)+w))
             && (y>=(tempy-(w/2))) && (y<=(tempy-(w/2)+w))){
      handle=true;
      pickedHandle=3;
    }
    else if ((x>=(tempx-(w/2)))&&(x<=(tempx-(w/2)+w)) && 
             (y>=(tempy+(height)-(w/2))) && (y<=(tempy+(height)-(w/2)+w))){
      handle=true;
      pickedHandle=6;
    }
    else if ((x>=(tempx+(width)-(w/2)))&&(x<=(tempx+(width)-(w/2)+w))
             && (y>=(tempy+(height)-(w/2))) && (y<=(tempy+(height)-(w/2)+w))){
      handle=true;
      pickedHandle=8;
    }
    if(handle) object = false;
    if(handle||object) return true;
    else return false;
  }
}