1 package org.kite9.diagram.primitives;
2
3 import org.kite9.diagram.position.Direction;
4 import org.kite9.diagram.position.RenderingInformation;
5 import org.kite9.diagram.position.RouteRenderingInformation;
6
7 /***
8 * This is the base class for connections within the diagram. i.e. Links.
9 *
10 * @author robmoffat
11 *
12 */
13 public abstract class AbstractConnection extends AbstractBiDirectional<Connected> implements Connection {
14
15 private static final long serialVersionUID = -1941426216200603569L;
16
17 /***
18 * For serialization
19 */
20 public AbstractConnection() {
21 }
22
23 /***
24 * Call this with modify verteConnected false to avoid adding the edge connection to the vertex
25 */
26 public AbstractConnection(Connected from, Connected to, Direction drawDirection, Object fromDecoration, Label fromLabel, Object toDecoration, Label tolabel) {
27 super(from, to, drawDirection);
28 this.fromDecoration = fromDecoration;
29 this.toDecoration = toDecoration;
30 if (fromLabel!=null) {
31 this.fromLabel = fromLabel;
32 fromLabel.setParent(this);
33 }
34 if (tolabel!=null) {
35 this.toLabel = tolabel;
36 tolabel.setParent(this);
37 }
38 from.addLink(this);
39 to.addLink(this);
40 }
41
42 protected Object fromDecoration = null;
43 public Object getFromDecoration() {
44 return fromDecoration;
45 }
46
47 public Object getToDecoration() {
48 return toDecoration;
49 }
50
51 public Label getFromLabel() {
52 return fromLabel;
53 }
54
55 public Label getToLabel() {
56 return toLabel;
57 }
58
59 protected Object toDecoration = null;
60 protected Label fromLabel;
61 protected Label toLabel;
62
63 /***
64 * This is used by layout engines to set the position of the elements in the
65 * diagram
66 */
67 protected RenderingInformation renderingInformation = null;
68
69 public int compareTo(DiagramElement o) {
70 if (o!=null) {
71 return this.toString().compareTo(o.toString());
72 } else {
73 return -1;
74 }
75 }
76
77 public RouteRenderingInformation getRenderingInformation() {
78 if (renderingInformation==null) {
79 renderingInformation = new RouteRenderingInformation();
80 }
81
82 return (RouteRenderingInformation) renderingInformation;
83 }
84
85 public void setFromDecoration(Object fromDecoration) {
86 this.fromDecoration = fromDecoration;
87 }
88
89 public void setToDecoration(Object toDecoration) {
90 this.toDecoration = toDecoration;
91 }
92
93 public void setFromLabel(Label fromLabel) {
94 this.fromLabel = fromLabel;
95 }
96
97 public void setToLabel(Label toLabel) {
98 this.toLabel = toLabel;
99 }
100 }