import java.awt.*;
import java.awt.geom.*;

/**
   A class that draws a UML symbol that symbolizes a dependance relationship
   @author Sugiharto Widjaja
   @version 05/01/02
*/

public class DashedArrowEdge extends AbstractEdge
{
   /**
      Draw the dashed line with the arrow edge
      @param g2 the Graphics
   */

   public void doDraw(Graphics2D g2)
   {
      AbstractObjectNode node1 = (AbstractObjectNode) getStart();
      AbstractObjectNode node2 = (AbstractObjectNode) getEnd();
      Rectangle2D vrect = node1.getTitleRectangle();
      Rectangle2D trect = node2.getTitleRectangle();

      Point2D p = new Point2D.Double( vrect.getMinX() + vrect.getWidth() / 2,
                                      vrect.getMinY() + vrect.getHeight());
      Point2D q2 = new Point2D.Double(trect.getCenterX(),
                                      trect.getCenterY() - trect.getHeight() / 2);
      line = new Line2D.Double(p, q2);
      float[] dashPattern = {5};
      g2.setStroke(new BasicStroke(2.0F, BasicStroke.CAP_BUTT,
                   BasicStroke.JOIN_MITER, 2.0F, dashPattern, 0));
      g2.draw(line);
      g2.setStroke(new BasicStroke());
      final double ARROW_ANGLE = Math.PI / 6;
      final double ARROW_LENGTH = 10;

      Point2D x1Point = new Point2D.Double(q2.getX() - ARROW_LENGTH * Math.cos(ARROW_ANGLE),
                                           q2.getY() - ARROW_LENGTH * Math.sin(ARROW_ANGLE));
      line1 = new Line2D.Double(q2, x1Point);
      Point2D x2Point = new Point2D.Double(q2.getX() + ARROW_LENGTH * Math.cos(ARROW_ANGLE),
                                           q2.getY() - ARROW_LENGTH * Math.sin(ARROW_ANGLE));
      line2 = new Line2D.Double(q2, x2Point);
      g2.draw(line1);
      g2.draw(line2);
   }

   /**
      Checks whether a point is contained in the line with the triangle edge
      @param aPoint a point to be checked
      @return true if it is contained, false otherwise
   */
   public boolean contains(Point2D aPoint)
   {
      final double MAX_DIST = 2;
      return line.ptSegDist(aPoint) < MAX_DIST || line.contains(aPoint.getX(), aPoint.getY());
   }

   // The line that connects two classes
   private Line2D line;
   // The first line of the arrow
   private Line2D line1;
   // The second line of the arrow
   private Line2D line2;
}
