Source code: com/port80/graph/dot/impl/DotRoute.java
1 //
2 // Copyright(c) 2002, Chris Leung
3 //
4
5 package com.port80.graph.dot.impl;
6
7 import java.awt.geom.*;
8 import com.port80.graph.*;
9
10 /** A wrapper around a GeneralPath with end points.
11 *
12 */
13 public class DotRoute {
14
15 // Static fields ///////////////////////////////////////////////////////
16 //
17
18 private static final String NAME = "DotRoute";
19 private static final boolean VERBOSE = true;
20 private static final boolean DEBUG = false;
21
22 // Instance fields /////////////////////////////////////////////////////
23 //
24
25 GeneralPath path;
26 DotPoint tail0; /** Tail arrow origin (on the spline).*/
27 DotPoint tail1; /** Tail arrow head (on vertex).*/
28 DotPoint head0; /** Head arrow origin (on spline).*/
29 DotPoint head1; /** Head arrow head (on vertex).*/
30 boolean isReversed;
31
32 /** @param p The route.
33 * @param t0 Tail arrow origin.
34 * @param t1 Tail arrow head.
35 * @param h0 Head arrow origin.
36 * @param h1 Head arrow head.
37 */
38 public DotRoute(GeneralPath p, DotPoint s0, DotPoint s1, DotPoint e0, DotPoint e1, boolean isReversed) {
39 this.path = p;
40 this.isReversed = isReversed;
41 if (isReversed) {
42 this.tail0 = e0;
43 this.tail1 = e1;
44 this.head0 = s0;
45 this.head1 = s1;
46 } else {
47 this.tail0 = s0;
48 this.tail1 = s1;
49 this.head0 = e0;
50 this.head1 = e1;
51 }
52 }
53
54 public GeneralPath getPath() {
55 return path;
56 }
57 public DotPoint getStartPt() {
58 return isReversed ? head1 : tail1;
59 }
60 public DotPoint getEndPt() {
61 return isReversed ? tail1 : head1;
62 }
63 public boolean isReversed() {
64 return isReversed;
65 }
66 public AffineTransform getHeadTransform() {
67 AffineTransform tx = AffineTransform.getTranslateInstance(head0.x, head0.y);
68 tx.rotate(Math.atan2(head1.y - head0.y, head1.x - head0.x));
69 return tx;
70 }
71 public AffineTransform getTailTransform() {
72 AffineTransform tx = AffineTransform.getTranslateInstance(tail0.x, tail0.y);
73 tx.rotate(Math.atan2(tail1.y - tail0.y, tail1.x - tail0.x));
74 return tx;
75 }
76
77 ////////////////////////////////////////////////////////////////////////
78 }