View Javadoc
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 bar head (indicating a mandatory relationship) 9 * at the end of a FigEdge */ 10 public final class ArrowHeadBar extends ArrowHead 11 { 12 ////////////////////////////////////////////////////////// 13 // Singleton instance 14 private final static ArrowHeadBar _instance = new ArrowHeadBar(); 15 16 private ArrowHeadBar() {} 17 18 public static ArrowHead getInstance() 19 { 20 return _instance; 21 } 22 23 public void paint(Graphics g, Point start, Point end) 24 { 25 int xFrom, xTo, yFrom, yTo; 26 double denom, x, y, dx, dy, cos, sin; 27 28 xFrom = start.x; 29 xTo = end.x; 30 yFrom = start.y; 31 yTo = end.y; 32 33 dx = (double)(xTo - xFrom); 34 dy = (double)(yTo - yFrom); 35 denom = dist(dx, dy); //hypotenuse length 36 if (denom == 0) return; 37 38 cos = arrow_height/denom; 39 sin = arrow_width /denom; 40 x = xTo - cos*dx; //projection of the arrow relative to the line (i.e. point on line) 41 y = yTo - cos*dy; 42 int x1 = (int)(x - sin*dy); 43 int y1 = (int)(y + sin*dx); 44 int x2 = (int)(x + sin*dy); 45 int y2 = (int)(y - sin*dx); 46 47 g.setColor(arrowLineColor); 48 g.drawLine(x1, y1, (int)x, (int)y); 49 g.drawLine(x2, y2, (int)x, (int)y); 50 } 51 } /*** end class ArrowHeadBar */

This page was automatically generated by Maven