-
Notifications
You must be signed in to change notification settings - Fork 8
/
ACLineData.java
164 lines (148 loc) · 5.07 KB
/
ACLineData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Classname : ACLineData
*
* Version information : 1
*
* Date
*
* Description : Contains methods for drawing
* lines for the
* association classes
*/
/******************************
* Copyright (c) 2003,2019 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
/* Package: GUI */
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
import java.util.Vector;
public class ACLineData extends LineData
{ // coordinates of start and end points of the line
RectData myclass;
final static BasicStroke solid = stroke;
public ACLineData(int xs, int ys, int xe,
int ye, int linecount, int type, RectData rd)
{ super(xs,ys,xe,ye,linecount,type);
myclass = rd;
}
public Object clone()
{ String cnt = label.substring(1,label.length()-1);
int count = 0;
try { count = Integer.parseInt(cnt); }
catch (Exception e)
{ count = 0; }
ACLineData ld =
new ACLineData(xstart, ystart, xend,
yend, count, linetype, myclass);
ld.setTransition(transition);
ld.setFlow(flow);
ld.setModelElement(modelElement);
return ld;
}
private void drawClass(Graphics2D g)
{ // draw dashed line down from midpoint, to a class
int midx = (xstart + xend)/2;
int midy = (ystart + yend)/2;
g.setStroke(dashed);
g.drawLine(midx,midy,midx,midy+25);
g.setStroke(solid);
if (myclass != null)
{ myclass.changePosition(0,0,midx - 10, midy+25);
myclass.drawData(g);
}
}
private void drawClass(Graphics g)
{ // draw dashed line down from midpoint, to a class
int midx = (xstart + xend)/2;
int midy = (ystart + yend)/2;
// g.setStroke(dashed);
g.drawLine(midx,midy,midx,midy+25);
// g.setStroke(solid);
if (myclass != null)
{ myclass.changePosition(0,0,midx - 10, midy+25);
myclass.drawData(g);
}
}
void drawData(Graphics2D g)
{ if (LineLength() > 5)
{ g.setColor(Color.black);
if (linetype == 1)
{ g.setStroke(dashed); }
g.drawLine(xstart,ystart,xend,yend);
g.setStroke(stroke);
g.draw(new Line2D.Double(arrow1x,arrow1y,
(double) xend,(double) yend));
g.draw(new Line2D.Double(arrow2x,arrow2y,
(double) xend,(double) yend));
if (modelElement != null)
{ Association ast = (Association) modelElement;
String role1 = ast.getRole1();
String role2 = ast.getRole2();
boolean ord = ast.isOrdered();
if (ord) { role2 = role2 + " { ordered }"; }
if (ast.isFrozen())
{ role2 = role2 + " { frozen }"; }
else if (ast.isAddOnly())
{ role2 = role2 + " { addOnly }"; } // and derived
if (ast.isDerived())
{ role2 = "/" + role2; }
FontMetrics fm = g.getFontMetrics();
int xoffset = fm.stringWidth(role2);
String c1 =
ModelElement.convertCard(ast.getCard1());
String c2 =
ModelElement.convertCard(ast.getCard2());
if (role1 != null)
{ g.drawString(role1,xstart+5,ystart-5); }
if (role2 != null)
{ g.drawString(role2,(int) role2x - leftright*xoffset,(int) role2y); }
g.drawString(c1,(int) card1x,(int) card1y);
g.drawString(c2,(int) card2x,(int) card2y);
g.drawString(ast.getName(), (int) (xend + xstart)/2,
(int) (yend + ystart)/2);
if (myclass != null)
{ drawClass(g); }
}
}
}
void drawData(Graphics g)
{ if (LineLength() > 5)
{ g.setColor(Color.black);
// if (linetype == 1)
// { g.setStroke(dashed); }
g.drawLine(xstart,ystart,xend,yend);
// g.setStroke(stroke);
g.drawLine((int) arrow1x,(int) arrow1y,xend,yend);
g.drawLine((int) arrow2x,(int) arrow2y,xend,yend);
if (modelElement != null)
{ Association ast = (Association) modelElement;
String role1 = ast.getRole1();
String role2 = ast.getRole2();
if (ast.isOrdered())
{ role2 = role2 + " { ordered }"; }
if (ast.isFrozen())
{ role2 = role2 + " { frozen }"; }
else if (ast.isAddOnly())
{ role2 = role2 + " { addOnly }"; } // and derived
String c1 =
ModelElement.convertCard(ast.getCard1());
String c2 =
ModelElement.convertCard(ast.getCard2());
if (role1 != null)
{ g.drawString(role1,xstart+5,ystart-5); }
if (role2 != null)
{ g.drawString(role2,(int) role2x,(int) role2y); }
g.drawString(c1,xstart+5,ystart+8);
g.drawString(c2,(int) card2x,(int) card2y);
if (myclass != null)
{ drawClass(g); }
}
}
}
}