1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.devaki.nextobjects.workspace.models.graphics;
21 import java.io.Serializable;
22 import java.awt.Graphics;
23 import java.awt.Point;
24 import java.awt.Polygon;
25 import org.devaki.nextobjects.util.NOGraphicsUtil;
26 import org.devaki.nextobjects.workspace.models.ConceptualModel;
27 import org.devaki.nextobjects.workspace.models.objects.AssociationLink;
28 /***
29 * This class is responsible for drawing an Association Link
30 * in the Merise formalism
31 * @author <a href="mailto:eflorent@devaki.org">Emmanuel Florent</a>
32 */
33 public class AssociationLinkView extends LineView implements Serializable
34 {
35
36 private int associationPointType = SelectionPoint.NORTH;
37
38 private int entityPointType = SelectionPoint.NORTH;
39 /***
40 * Create a new 'AssociationLinkView' object
41 * @param pAssociationLink the contextual link
42 */
43 public AssociationLinkView(AssociationLink pAssociationLink)
44 {
45 super(pAssociationLink);
46 selectionPoints[0] =
47 ((AssociationLink) this.getBaseObject())
48 .getParentClass()
49 .getObjectView()
50 .getSelectionPoint(0);
51 selectionPoints[1] =
52 ((AssociationLink) this.getBaseObject())
53 .getChildClass()
54 .getObjectView()
55 .getSelectionPoint(0);
56 }
57 /***
58 * Return the surface on which the user can click to select the object
59 * @return the surface as polygon/shape
60 */
61 public Polygon getSurface()
62 {
63 Point p3 =
64 NOGraphicsUtil.getMiddle(
65 selectionPoints[0].getPoint(),
66 selectionPoints[1].getPoint());
67 int delta = 20;
68 int tmpX1 = (int) p3.getX();
69 int tmpY1 = (int) p3.getY();
70 int xi[] =
71 {
72 (int) selectionPoints[0].getPoint().x,
73 tmpX1 - delta,
74 (int) selectionPoints[1].getPoint().x,
75 tmpX1 + delta,
76 selectionPoints[0].getPoint().x };
77 int yi[] =
78 {
79 selectionPoints[0].getPoint().y,
80 tmpY1 - delta,
81 selectionPoints[1].getPoint().y,
82 tmpY1 + delta,
83 selectionPoints[1].getPoint().y };
84 return new Polygon(xi, yi, 4);
85 }
86 /***
87 * Set the entity point location
88 * @param pEntityPointType the entity point location
89 */
90 public void setEntityPointType(int pEntityPointType)
91 {
92 entityPointType = pEntityPointType;
93 }
94 /***
95 * Set the associatioon point location
96 * @param pAssociationPointType the location
97 */
98 public void setAssociationPointType(int pAssociationPointType)
99 {
100 associationPointType = pAssociationPointType;
101 }
102 /***
103 * Paint the association link
104 * @param g graphics context
105 * @task Implement getVisibleRectangle in ConceptualView and PhysicalView.
106 */
107 public void paint(Graphics g)
108 {
109 Point p0 =
110 ((ConceptualView) myObject.getMyModel().getPanel())
111 .getRectangle()
112 .getLocation();
113 Point p1 = selectionPoints[0].getPoint();
114 p1.translate(-p0.x, -p0.y);
115 Point p2 = selectionPoints[1].getPoint();
116 p2.translate(-p0.x, -p0.y);
117
118 g.setColor(this.myStyle.getLineColor());
119 Point p3 = NOGraphicsUtil.getMiddle(p1, p2);
120 String strCard =
121 this.getCardString(((AssociationLink) this.myObject).getCard());
122 g.drawLine(
123 (int) p1.getX(),
124 (int) p1.getY(),
125 (int) p2.getX(),
126 (int) p2.getY());
127 g.drawString(strCard, (int) p3.getX(), (int) p3.getY());
128 }
129 /***
130 * Return the String association to the cardinality static definition
131 * @param Card the cardinality
132 * @return the cardinality as a string
133 */
134 private String getCardString(int Card)
135 {
136 String str = "";
137 switch (Card)
138 {
139 case ConceptualModel.ASSO_01 :
140 str = "0,1";
141 break;
142 case ConceptualModel.ASSO_11 :
143 str = "1,1";
144 break;
145 case ConceptualModel.ASSO_0N :
146 str = "0,n";
147 break;
148 case ConceptualModel.ASSO_1N :
149 str = "1,n";
150 break;
151 }
152 return str;
153 }
154 /***
155 * reset selection point
156 * Do nothing here.
157 */
158 public void resetSelectionPoint()
159 {
160 }
161 }