import java.awt.*;
/*
   Programmer:   Konstantin Lukin
   Created   :   8/4/96
   Purpose   :   creates a handle of specified size, position, and
                 orientation. Useful to show directions (in dragging).
*/
public class Handle extends Rectangle {

public static int HORIZONTAL = 0;
public static int VERTICAL   = 1;
public static int BOTH       = 2;
private boolean dragable;
   
public Handle(int orient, int width, int height) {
   super(0, 0, width, height);
   orientation = orient;
   dragable = false;
   setPolygon();
}

public Handle(int orient, int x, int y, int width, int height) {
   super(x,y,width,height);
   this.orientation = orient;
   setPolygon();
}   

public void setDragable(boolean mode) {
   dragable = mode;
}

public boolean isDragable() {
   return dragable;
}

public void move(int x, int y) {
   this.x = x;
   this.y = y;
   setPolygon();
}

public void resize(int width, int height) {
   this.width = width;
   this.height = height;
   setPolygon();
}

public void draw(Graphics g) {
   g.drawPolygon(poly);
}   

public void fill(Graphics g) {
   g.fillPolygon(poly);
}

public void draw(Graphics g, boolean showRectangle) {
   if(showRectangle) g.drawRect(x, y, width, height);
   draw(g);
}

public void fill(Graphics g, boolean showRectangle) {
   if(showRectangle) g.drawRect(x, y, width, height);
   fill(g);
}

public void setX(int x) {
   this.x = x;
   setPolygon();
}

public int getX() {
   return this.x;
}

public void setY(int y) {
   this.y = y;
   setPolygon();
}

public int getY() {
   return this.y;
}

public int getWidth() {
   return this.width;
}

public int getHeight() {
   return this.height;
}

public Point getCenter() {
   return new Point(x+width/2, y+height/2);
}

private void setPolygon() {
   poly = new Polygon();
   switch (orientation) {
      case 0: // HORIZONTAL 
         setHorizontal();
         break;
      case 1: // VERTICAL
         setVertical();
         break;
      case 2: // BOTH
         setBoth();
         break;
      default:
         setHorizontal();
   }
}
   
private void setHorizontal() {   
   poly.addPoint(x, y+height/2);               // 1
   poly.addPoint(x+width/4, y);                // 2
   poly.addPoint(x+width/4, y+2*height/5);      // 3
   poly.addPoint(x+3*width/4, y+2*height/5);    // 4
   poly.addPoint(x+3*width/4, y);              // 5
   poly.addPoint(x+width, y+height/2);         // 6
   poly.addPoint(x+3*width/4, y+height);       // 7
   poly.addPoint(x+3*width/4, y+3*height/5);   // 8
   poly.addPoint(x+width/4, y+3*height/5);         // 9
   poly.addPoint(x+width/4, y+height);         // 10
   poly.addPoint(x, y+height/2);               // 11
}

private void setVertical() {
   poly.addPoint(x+width/2, y);               // 1
   poly.addPoint(x+width, y+height/4);                // 2
   poly.addPoint(x+3*width/5, y+height/4);      // 3
   poly.addPoint(x+3*width/5, y+3*height/4);    // 4
   poly.addPoint(x+width, y+3*height/4);              // 5
   poly.addPoint(x+width/2, y+height);         // 6
   poly.addPoint(x, y+3*height/4);       // 7
   poly.addPoint(x+2*width/5, y+3*height/4);   // 8
   poly.addPoint(x+2*width/5, y+height/4);         // 9
   poly.addPoint(x, y+height/4);         // 10
   poly.addPoint(x+width/2, y);               // 11   
}

private void setBoth() {
   int xmid = x+width/2;
   int ymid = y+height/2;
   
   int xhead = width/5;
   int yhead = height/5;
   
   int xstem = width/20;
   int ystem = height/20;
   
   poly.addPoint(xmid, y);
   poly.addPoint(xmid+xhead, y+yhead);   
   poly.addPoint(xmid+xstem, y+yhead);
   poly.addPoint(xmid+xstem, ymid-ystem);
   poly.addPoint(x+width-xhead, ymid-ystem);
   poly.addPoint(x+width-xhead, ymid-yhead);
   poly.addPoint(x+width, ymid);
   poly.addPoint(x+width-xhead, ymid+yhead);
   poly.addPoint(x+width-xhead, ymid+ystem);
   poly.addPoint(xmid+xstem, ymid+ystem);
   poly.addPoint(xmid+xstem, y+height-yhead);
   poly.addPoint(xmid+xhead, y+height-yhead);
   poly.addPoint(xmid, y+height);
   poly.addPoint(xmid-xhead, y+height-yhead);
   poly.addPoint(xmid-xstem, y+height-yhead);
   poly.addPoint(xmid-xstem, ymid+ystem);
   poly.addPoint(x+xhead, ymid+ystem);
   poly.addPoint(x+xhead, ymid+yhead);
   poly.addPoint(x, ymid);
   poly.addPoint(x+xhead, ymid-yhead);
   poly.addPoint(x+xhead, ymid-ystem);
   poly.addPoint(xmid-xstem, ymid-ystem);
   poly.addPoint(xmid-xstem, y+yhead);
   poly.addPoint(xmid-xhead, y+yhead);
   poly.addPoint(xmid, y);
}


private Polygon poly;
private int orientation;
}
   
   
    
      

