1 package com.bonevich.erj.diagram;
2
3 import org.tigris.gef.presentation.ArrowHead;
4
5 import java.awt.Graphics;
6 import java.awt.Point;
7
8 /*** Draws a reverse-triangluar arrow head (aka crow's
9 * feet) at the end of a FigEdge */
10 public final class ArrowHeadLesser extends ArrowHead
11 {
12 //////////////////////////////////////////////////////////
13 // Attributes
14 protected int arrow_width = 8, arrow_height = 15;
15
16 //////////////////////////////////////////////////////////
17 // Singleton instance
18 public final static ArrowHeadLesser _instance = new ArrowHeadLesser();
19
20 private ArrowHeadLesser() {}
21
22 public static ArrowHead getInstance()
23 {
24 return _instance;
25 }
26
27 public void paint(Graphics g, Point start, Point end)
28 {
29 int xFrom, xTo, yFrom, yTo;
30 double denom, x, y, dx, dy, cos, sin;
31
32 xFrom = start.x;
33 xTo = end.x;
34 yFrom = start.y;
35 yTo = end.y;
36
37 dx = (double)(xTo - xFrom);
38 dy = (double)(yTo - yFrom);
39 denom = dist(dx, dy); //hypotenuse length
40 if (denom == 0) return;
41
42 cos = arrow_height/denom;
43 sin = arrow_width /denom;
44 x = xTo - cos*dx; //projection of the arrow relative to the line (i.e. point on line)
45 y = yTo - cos*dy;
46 int x1 = (int)(xTo - sin*dy);
47 int y1 = (int)(yTo + sin*dx);
48 int x2 = (int)(xTo + sin*dy);
49 int y2 = (int)(yTo - sin*dx);
50
51 g.setColor(arrowLineColor);
52 g.drawLine(x1, y1, (int)x, (int)y);
53 g.drawLine(x2, y2, (int)x, (int)y);
54 }
55 } /*** end class ArrowHeadLesser */
This page was automatically generated by Maven