View Javadoc
1   /*
2    * Created on Oct 19, 2004
3    *
4    * Copyright (c) 2004, The JUNG Authors 
5    *
6    * All rights reserved.
7    *
8    * This software is open-source under the BSD license; see either
9    * "license.txt" or
10   * https://github.com/jrtom/jung/blob/master/LICENSE for a description.
11   */
12  package edu.uci.ics.jung.visualization.util;
13  
14  import java.awt.geom.GeneralPath;
15  
16  /**
17   * A utility class for creating arrowhead shapes.
18   * 
19   * @author Joshua O'Madadhain
20   */
21  public class ArrowFactory
22  {
23      /**
24       * Returns an arrowhead in the shape of a simple isosceles triangle
25       * with the specified base and height measurements.  It is placed
26       * with the vertical axis along the negative x-axis, with its base
27       * centered on (0,0).
28       * 
29       * @param base the width of the arrow's base
30       * @param height the arrow's height
31       * @return a path in the form of an isosceles triangle with dimensions {@code (base, height)}
32       */
33      public static GeneralPath getWedgeArrow(float base, float height)
34      {
35          GeneralPath arrow = new GeneralPath();
36          arrow.moveTo(0,0);
37          arrow.lineTo( - height, base/2.0f);
38          arrow.lineTo( - height, -base/2.0f);
39          arrow.lineTo( 0, 0 );
40          return arrow;
41      }
42  
43      /**
44       * Returns an arrowhead in the shape of an isosceles triangle
45       * with an isoceles-triangle notch taken out of the base,
46       * with the specified base and height measurements.  It is placed
47       * with the vertical axis along the negative x-axis, with its base
48       * centered on (0,0).
49       * 
50       * @param base the width of the arrow's base
51       * @param height the arrow's height
52       * @param notch_height the height of the arrow's notch
53       * @return a path in the form of a notched isosceles triangle
54       */
55      public static GeneralPath getNotchedArrow(float base, float height, float notch_height)
56      {
57          GeneralPath arrow = new GeneralPath();
58          arrow.moveTo(0,0);
59          arrow.lineTo(-height, base/2.0f);
60          arrow.lineTo(-(height - notch_height), 0);
61          arrow.lineTo(-height, -base/2.0f);
62          arrow.lineTo(0,0);
63          return arrow;
64      }
65  }