Skip to content

Commit 2daafa1

Browse files
authored
Add files via upload
1 parent e065221 commit 2daafa1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+57031
-0
lines changed

RectData.java

Lines changed: 345 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
/*
2+
* Classname : RectData
3+
*
4+
* Version information : 1
5+
*
6+
* Date
7+
*
8+
* Description : Contains methods for
9+
* drawing the rectangle required for
10+
* the classes in the class diagram
11+
12+
package: GUI
13+
*/
14+
/******************************
15+
* Copyright (c) 2003,2019 Kevin Lano
16+
* This program and the accompanying materials are made available under the
17+
* terms of the Eclipse Public License 2.0 which is available at
18+
* http://www.eclipse.org/legal/epl-2.0
19+
*
20+
* SPDX-License-Identifier: EPL-2.0
21+
* *****************************/
22+
23+
import java.awt.*;
24+
import javax.swing.*;
25+
import java.util.Vector;
26+
27+
class RectData extends RectForm
28+
{ private boolean features = false;
29+
Statemachine component;
30+
31+
RectData(int xx, int yy, Color cc, int cType, int rectcount)
32+
{ super(" ",cc,xx,yy);
33+
if (cType == UCDArea.SENSOR)
34+
{ label = new String("s" + rectcount); }
35+
else
36+
{ label = new String("a" + rectcount); }
37+
38+
namex = xx + 5;
39+
namey = yy + 15;
40+
width = 50;
41+
height = 50;
42+
features = true;
43+
}
44+
45+
public Object clone()
46+
{ int cType = UCDArea.SENSOR; // default.
47+
RectData rd =
48+
new RectData(sourcex,sourcey,color,cType,0);
49+
rd.setName(label,namex,namey);
50+
rd.setSize(width,height);
51+
rd.setModelElement(modelElement);
52+
return rd;
53+
}
54+
55+
public VisualData getCDVisual()
56+
{ RectData rd = (RectData) clone();
57+
rd.showFeatures();
58+
return rd;
59+
}
60+
61+
void setName(String ss, int xpos, int ypos)
62+
{ label = ss;
63+
namex = xpos;
64+
namey = ypos;
65+
}
66+
67+
public void setSize(int wid, int high)
68+
{ width = wid;
69+
height = high;
70+
}
71+
72+
private void adjustWidth(Graphics g)
73+
{ // compare size of name and width of rectangle
74+
FontMetrics fm = g.getFontMetrics();
75+
if (fm.stringWidth(label) + (namex - sourcex) >= width)
76+
{ width = fm.stringWidth(label) + (namex - sourcex) + 5; }
77+
if (20 + (namey - sourcey) >= height)
78+
{ height = 20 + (namey - sourcey) + 5; }
79+
}
80+
81+
void drawData(Graphics2D g)
82+
{ g.setFont(new Font("Serif", Font.BOLD, 18));
83+
adjustWidth(g);
84+
g.setColor(Color.black);
85+
if (features)
86+
{ drawFeatures(g); }
87+
g.drawRect(sourcex, sourcey,width - 1, height - 1);
88+
// if (modelElement != null && modelElement instanceof Type)
89+
// { g.drawString(label + " <<enumeration>>",namex,namey); }
90+
91+
if (modelElement != null && modelElement instanceof Entity)
92+
{ Entity e = (Entity) modelElement;
93+
if (e.isAbstract() || e.isInterface())
94+
{ Font ff = g.getFont();
95+
Font newff = new Font(ff.getName(),Font.ITALIC,ff.getSize());
96+
g.setFont(newff);
97+
g.drawString(label,namex,namey);
98+
g.setFont(ff);
99+
if (e.isInterface())
100+
{ g.drawString("<<interface>>",namex,namey-5);
101+
FontMetrics fm = g.getFontMetrics();
102+
if (fm.stringWidth("<<interface>>") + (namex - sourcex) >= width)
103+
{ width = fm.stringWidth("<<interface>>") + (namex - sourcex) + 5; }
104+
}
105+
}
106+
else if (e.isActive())
107+
{ g.drawString(label,namex,namey);
108+
g.drawString("<<active>>",namex,namey-5);
109+
FontMetrics fm = g.getFontMetrics();
110+
if (fm.stringWidth("<<active>>") + (namex - sourcex) >= width)
111+
{ width = fm.stringWidth("<<active>>") + (namex - sourcex) + 5; }
112+
}
113+
else
114+
{ g.drawString(label,namex,namey); }
115+
116+
117+
// String ecard = e.getCardinality();
118+
// if (ecard != null)
119+
// { g.drawString(ecard, sourcex + width - 10, sourcey + 10); }
120+
}
121+
else if (modelElement != null && modelElement instanceof Requirement)
122+
{ Requirement req = (Requirement) modelElement;
123+
Font ff = g.getFont();
124+
// Font newff = new Font(ff.getName(),Font.ITALIC,ff.getSize());
125+
// g.setFont(newff);
126+
g.drawString(label,namex,namey+5);
127+
g.setFont(ff);
128+
g.drawString("<<requirement>>",namex,namey-5);
129+
FontMetrics fm = g.getFontMetrics();
130+
if (fm.stringWidth("<<requirement>>") + (namex - sourcex) >= width)
131+
{ width = fm.stringWidth("<<requirement>>") + (namex - sourcex) + 5; }
132+
}
133+
else if (modelElement != null && modelElement instanceof Type)
134+
{ Type typ = (Type) modelElement;
135+
Font ff = g.getFont();
136+
g.drawString(label,namex,namey+5);
137+
g.setFont(ff);
138+
g.drawString("<<enumeration>>",namex,namey-5);
139+
FontMetrics fm = g.getFontMetrics();
140+
if (fm.stringWidth("<<enumeration>>") + (namex - sourcex) >= width)
141+
{ width = fm.stringWidth("<<enumeration>>") + (namex - sourcex) + 5; }
142+
}
143+
else
144+
{ g.drawString(label,namex,namey); }
145+
146+
// for entity draw card
147+
}
148+
149+
/* private void drawMultiplicity(Graphics g)
150+
{ if (component != null)
151+
{ int multip = component.getMultiplicity();
152+
if (multip > 1)
153+
{ g.drawString(""+multip, sourcex + width - 10, sourcey + 10); }
154+
}
155+
} */
156+
157+
void drawData(Graphics g) // and <<active>>, <<interface>>
158+
{ adjustWidth(g);
159+
g.setColor(Color.black);
160+
if (features)
161+
{ drawFeatures(g); }
162+
g.drawRect(sourcex, sourcey,width - 1, height - 1);
163+
if (modelElement != null && modelElement instanceof Type)
164+
{ g.drawString(label + " <<enumeration>>",namex,namey); }
165+
else
166+
{ g.drawString(label,namex,namey); } // for entity draw card
167+
}
168+
169+
/* Returns true if (xx,yy), which is coordinate
170+
of the start of a line,
171+
* are found within rectangle */
172+
boolean isUnder(int xx, int yy)
173+
{ // get the end points of the rectangle
174+
int endx = sourcex + width;
175+
int endy = sourcey + height;
176+
177+
// Check that xx,yy is within start & end rectangle
178+
if (xx <= endx && sourcex <= xx &&
179+
yy <= endy && sourcey <= yy)
180+
{ return true; }
181+
else
182+
{ return false; }
183+
}
184+
185+
public boolean isUnderStart(int x, int y)
186+
{ return false; }
187+
188+
public boolean isUnderEnd(int x, int y)
189+
{ return false; }
190+
191+
public void changePosition(int oldx, int oldy,
192+
int x, int y)
193+
{ sourcex = x;
194+
sourcey = y;
195+
namex = sourcex + 5;
196+
namey = sourcey + 15;
197+
}
198+
199+
private void showFeatures()
200+
{ features = true; }
201+
202+
// Show all the attributes:
203+
private void drawFeatures(Graphics g)
204+
{ FontMetrics fm = g.getFontMetrics();
205+
int widest = width;
206+
// int ypos = namey;
207+
if (modelElement == null) { return; }
208+
if (modelElement instanceof Entity)
209+
{ drawEntityFeatures(g,fm,widest); }
210+
else if (modelElement instanceof Type)
211+
{ drawTypeFeatures(g,fm,widest); }
212+
else if (modelElement instanceof Requirement)
213+
{ drawRequirementFeatures(g,fm,widest); }
214+
}
215+
216+
private void drawEntityFeatures(Graphics g,FontMetrics fm,int widest)
217+
{ Vector atts =
218+
((Entity) modelElement).getAttributes();
219+
int xpos = namex;
220+
int y = namey + 15;
221+
for (int i = 0; i < atts.size(); i++)
222+
{ Attribute att = (Attribute) atts.get(i);
223+
String nme = att.getName();
224+
String init = att.getInitialValue();
225+
boolean uniq = att.isUnique();
226+
boolean froz = att.isFrozen();
227+
boolean classScope = att.isClassScope();
228+
int kind = att.getKind();
229+
String decor = " ";
230+
if (kind == ModelElement.SEN) { decor = "? "; }
231+
else if (kind == ModelElement.ACT) { decor = "! "; }
232+
else if (kind == ModelElement.DERIVED) { decor = "/ "; }
233+
234+
String line1 = decor + nme + ": " + att.getType();
235+
if (init != null && !init.equals(""))
236+
{ line1 = line1 + " = " + init; }
237+
if (uniq)
238+
{ if (froz)
239+
{ line1 = line1 + " { identity, frozen }"; }
240+
else
241+
{ line1 = line1 + " { identity }"; }
242+
}
243+
else if (froz)
244+
{ line1 = line1 + " { frozen }"; }
245+
g.drawString(line1,xpos,y);
246+
if (classScope)
247+
{ g.drawLine(xpos,y+1,xpos + fm.stringWidth(line1),y+1); }
248+
int wid1 = fm.stringWidth(line1) + 10;
249+
if (wid1 > widest)
250+
{ widest = wid1; }
251+
y += 15;
252+
}
253+
width = widest;
254+
height = y - namey + 10;
255+
int attendy = y - 10;
256+
Vector ops = ((Entity) modelElement).getOperations();
257+
int nops = ops.size();
258+
// if (nops > 0)
259+
// { g.drawLine(sourcex,height,sourcex + width - 1,height); }
260+
for (int j = 0; j < nops; j++)
261+
{ BehaviouralFeature op = (BehaviouralFeature) ops.get(j);
262+
boolean cls = op.isClassScope();
263+
// draw opname(): type
264+
String brackets = "()";
265+
Vector pps = op.getParameters();
266+
if (pps.size() > 0) { brackets = "(...)"; }
267+
String opname = op.getName() + brackets;
268+
Type resT = op.getResultType();
269+
if (resT != null)
270+
{ opname = opname + ": " + resT; }
271+
if (op.isAbstract())
272+
{ Font ff = g.getFont();
273+
Font newff = new Font(ff.getName(),Font.ITALIC,ff.getSize());
274+
g.setFont(newff);
275+
g.drawString(opname,xpos,y);
276+
g.setFont(ff);
277+
}
278+
else
279+
{ g.drawString(opname,xpos,y); }
280+
281+
if (cls)
282+
{ g.drawLine(xpos,y+1,xpos + fm.stringWidth(opname),y+1); }
283+
284+
int wid1 = fm.stringWidth(opname) + 10;
285+
if (wid1 > widest)
286+
{ widest = wid1; }
287+
y += 15;
288+
}
289+
width = widest;
290+
if (nops > 0)
291+
{ g.drawLine(sourcex,attendy,sourcex + width - 1,attendy); }
292+
height = y - namey + 10;
293+
g.drawLine(sourcex,namey + 2,
294+
sourcex + width-1,namey + 2);
295+
}
296+
297+
private void drawTypeFeatures(Graphics g,FontMetrics fm,int widest)
298+
{ Vector vals =
299+
((Type) modelElement).getValues();
300+
int xpos = namex;
301+
int y = namey+15;
302+
if (vals != null)
303+
{ for (int i = 0; i < vals.size(); i++)
304+
{ String val = (String) vals.get(i);
305+
g.drawString(val,xpos,y);
306+
int wid1 = fm.stringWidth(val) + 10;
307+
if (wid1 > widest)
308+
{ widest = wid1; }
309+
y += 15;
310+
}
311+
}
312+
width = widest;
313+
height = y - namey + 10;
314+
g.drawLine(sourcex,namey + 2,
315+
sourcex + width-1,namey + 2);
316+
}
317+
318+
private void drawRequirementFeatures(Graphics g,FontMetrics fm,int widest)
319+
{ Vector vals = new Vector();
320+
Requirement req = (Requirement) modelElement;
321+
vals.add("id = " + req.id);
322+
vals.add("text = " + req.text);
323+
vals.add("kind = " + req.requirementKind);
324+
vals.add("scope = " + req.getScope());
325+
int xpos = namex;
326+
int y = namey+20;
327+
if (vals != null)
328+
{ for (int i = 0; i < vals.size(); i++)
329+
{ String val = (String) vals.get(i);
330+
g.drawString(val,xpos,y);
331+
int wid1 = fm.stringWidth(val) + 10;
332+
if (wid1 > widest)
333+
{ widest = wid1; }
334+
y += 15;
335+
}
336+
}
337+
width = widest;
338+
height = y - namey + 5;
339+
g.drawLine(sourcex,namey + 8,
340+
sourcex + width-1,namey + 8);
341+
}
342+
343+
}
344+
345+

0 commit comments

Comments
 (0)