// JDraw - SLine class
// Written by Jim Calciano, Melanie Lear, and PJ Waskiewicz
// November 18, 1998
// Class which creates a Selected Line object from a Line

import java.awt.*;

public class SLine extends Line{
  private int w=6;
  private int x1, y1, x2, y2;
  private Color color;
  private boolean itsMe=true;
  private boolean object=false;
  private boolean handle=false;
  private int displacementX, displacementY, pickedHandle;
  // Method to return a string of all attributes of the line to be written
  // to a file
  public String returnString(){
    return (new String("line" + " " + x1 + " " + y1 + " " + 
                   x2 + " " + y2 + " " + color.getRed() + "," +
                       color.getGreen() + "," + color.getBlue()));
  }
  // Constructor for when the line is drawn and opened from a file
  public SLine(int x1, int y1, int x2, int y2, Color color){
    super(x1,y1,x2,y2,color);
    this.x1 = x1;
    this.x2 = x2;
    this.y1 = y1;
    this.y2 = y2;
    this.color = color;
  }
  public void paint(Graphics g){
    g.setColor(color);
    g.drawLine(x1,y1,x2,y2);
    g.setColor(Color.black);
    g.fillRect(x1-w/2,y1-w/2,w,w);
    g.fillRect(x2-w/2,y2-w/2,w,w);
  }
  public Point firstSelPoint(){
    return(new Point(x1,y1));
  }
  public Point secondSelPoint(){
    return(new Point(x2,y2));
  }
  public void setFirstPoint(int x, int y){
    x1=x;
    y1=y;
  }
  public void setSecondPoint(int x, int y){
    x2=x;
    y2=y;
  }
  public Color selColor(){
    return color;
  }
  public void setSelColor(Color c){
    color=c;
  }
  public boolean areYouSelected(){
    return itsMe;
  }
  public void youAreSelected(boolean b){
    itsMe=b;
  }
  public boolean getIfObjectClicked(){
    return object;
  }
  public boolean getIfHandleClicked(){
    return handle;
  }
  public int getPickedHandle() {
    return pickedHandle;
  }
  public boolean intersects(int x, int y){
    object=super.intersects(x,y);
    // Now check if this click landed on a handle or not
    handle=((((x>=(x1-w/2))&&(x<=(x1-w/2)+w))&&
            ((y>=(y1-w/2))&&(y<=(y1-w/2)+w))))||
      (((x>=(x2-w/2))&&(x<=(x2-w/2)+w))&&((y>=(y2-w/2))&&(y<=(y2-w/2)+w)));
    if (handle) {
      if ((x<=(x1-w/2)+w)&&(y<=(y1-w/2)+w))
        pickedHandle = 1;
      else
        pickedHandle = 2;
    }
    // If the handle is clicked, then the object shouldn't be clicked
    if(handle) object=false;
    if(handle || object) return true;
    else return false;
  }
}