-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathActorRectData.java
154 lines (125 loc) · 3.92 KB
/
ActorRectData.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
/*
* Classname : ActorRectData
*
* Version information : 1
*
* Date
*
* Description : Contains methods for
* drawing actors in use case diagrams
package: GUI
*/
/******************************
* Copyright (c) 2003-2025 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
* *****************************/
import java.awt.*;
import javax.swing.*;
import java.util.Vector;
class ActorRectData extends RectForm
{ private boolean features = false;
ActorRectData(int xx, int yy, Color cc, int rectcount)
{ super(" ",cc,xx,yy);
label = new String("Actor" + rectcount);
namex = xx + 5;
namey = yy + 15;
width = 50;
height = 50;
features = false;
}
public Object clone()
{ int cType = UCDArea.SENSOR; // default.
ActorRectData rd =
new ActorRectData(sourcex,sourcey,color,0);
rd.setName(label,namex,namey);
rd.setSize(width,height);
rd.setModelElement(modelElement);
return rd;
}
public VisualData getCDVisual()
{ ActorRectData rd = (ActorRectData) clone();
rd.showFeatures();
return rd;
}
void setName(String ss, int xpos, int ypos)
{ label = ss;
namex = xpos;
namey = ypos;
}
public void setSize(int wid, int high)
{ width = wid;
height = high;
}
private void adjustWidth(Graphics g)
{ // compare size of name and width of rectangle
FontMetrics fm = g.getFontMetrics();
int w1 = fm.stringWidth(label);
int w2 = fm.stringWidth(" <<actor>>");
int w = w2;
if (w1 > w2)
{ w = w1; }
if (w + (namex - sourcex) >= width)
{ width = w + (namex - sourcex) + 5; }
if (20 + (namey - sourcey) >= height)
{ height = 20 + (namey - sourcey) + 5; }
}
void drawData(Graphics2D g)
{ g.setFont(new Font("Serif", Font.BOLD, 18));
adjustWidth(g);
g.setColor(Color.black);
g.drawOval(sourcex, sourcey,width - 1, height - 1);
g.drawRect(sourcex, sourcey,width - 1, height - 1);
g.drawString(" <<actor>>",namex,namey);
g.drawString(label,namex,namey+20);
}
void drawData(Graphics g) // and <<active>>, <<interface>>
{ adjustWidth(g);
g.setColor(Color.black);
g.drawOval(sourcex, sourcey,width - 1, height - 1);
g.drawRect(sourcex, sourcey,width - 1, height - 1);
g.drawString(" <<actor>>",namex,namey);
g.drawString(label,namex,namey+20);
}
/* Returns true if (xx,yy), which is coordinate
of the start of a line,
* are found within rectangle */
boolean isUnder(int xx, int yy)
{ // get the end points of the rectangle
int endx = sourcex + width;
int endy = sourcey + height;
// Check that xx,yy is within start & end rectangle
if (xx <= endx && sourcex <= xx &&
yy <= endy && sourcey <= yy)
{ return true; }
else
{ return false; }
}
public boolean isUnderStart(int x, int y)
{ return false; }
public boolean isUnderEnd(int x, int y)
{ return false; }
public boolean isNearEnd(int x, int y)
{ return false; }
public void changePosition(int oldx, int oldy,
int x, int y)
{ sourcex = x;
sourcey = y;
namex = sourcex + 5;
namey = sourcey + 15;
}
private void showFeatures()
{ features = true; }
// Show all the attributes:
private void drawFeatures(Graphics g)
{ return; }
private void drawEntityFeatures(Graphics g,FontMetrics fm,int widest)
{ return; }
private void drawTypeFeatures(Graphics g,FontMetrics fm,int widest)
{ return; }
private void drawRequirementFeatures(Graphics g,FontMetrics fm,int widest)
{ return; }
}