1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package th.co.edge.jseq.argouml.pgml;
24
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Stack;
28
29 import org.w3c.dom.Document;
30 import org.w3c.dom.Element;
31
32 public class FigObject extends FigGroup {
33 private static final String FIG_SEQ_OBJECT_CLASS =
34 "org.argouml.uml.diagram.sequence.ui.FigSeqObject";
35
36 private String objectName;
37 private int x;
38 private int y;
39 private List<String> dynObjects = new LinkedList<String>();
40 private List<String> dynObjectsActivation = new LinkedList<String>();
41 private Stack<Integer> startPortNumbers = new Stack<Integer>();
42
43 public FigObject(String name, String objectName, String uuid, int x, int y) {
44 super(name, FIG_SEQ_OBJECT_CLASS, uuid, Fill.ON, FillColor.WHITE,
45 Stroke.ON, StrokeColor.BLACK);
46 this.objectName = objectName;
47 this.x = x;
48 this.y = y;
49
50 addPrivateAttribute("enclosingFig", name);
51
52 addFig(new FigRectangle(getNextFigName(), x, y, getNameBoxWidth(),
53 getNameBoxHeight(), FillColor.CYAN));
54 addFig(new FigRectangle(getNextFigName(), x, y, getNameBoxWidth(),
55 getNameBoxHeight(), FillColor.WHITE));
56 addFig(new FigText(getNextFigName(), objectName, x, y, "dialog", 9,
57 Stroke.ON, StrokeColor.BLACK));
58 addFig(new FigRectangle(getNextFigName(), x + getNameBoxWidth() / 2 -
59 getLifeLineWidth() / 2, y + getNameBoxHeight(),
60 getLifeLineWidth(), getLifeLineHeight(), FillColor.WHITE));
61 addFig(new FigLine(getNextFigName(), 10, 49, 19, 49));
62 addFig(new FigLine(getNextFigName(), 19, 49, 10, 49));
63 }
64
65 public Element getXML(Document doc) {
66 Element group = super.getXML(doc);
67 group.setAttribute("dynobjects", getDynObjects());
68 return group;
69 }
70
71 public String getObjectName() {
72 return objectName;
73 }
74
75 public String getDynObjects() {
76 return dynObjects.toString();
77 }
78
79 public boolean isActive() {
80 return !startPortNumbers.empty();
81 }
82
83 public void activate(int portNumber) {
84 startPortNumbers.push(portNumber);
85 }
86
87 public void deactivate(int portNumber) {
88 if (isActive()) {
89 int startPortNumber = startPortNumbers.pop();
90 if (!isActive()) {
91 String activationDynObject =
92 "a|" + startPortNumber + "|" + portNumber +
93 "|false|false";
94 dynObjectsActivation.add(0, activationDynObject);
95 dynObjects.addAll(dynObjectsActivation);
96 dynObjectsActivation.clear();
97 }
98 }
99 }
100
101 public String addPort(int portNumber) {
102 dynObjectsActivation.add("b|" + portNumber);
103 if (!isActive()) {
104 Fig activation =
105 new FigRectangle(getNextFigName(), x + getNameBoxWidth() /
106 2 - getActivationWidth() / 2, y +
107 getNameBoxHeight(), getActivationWidth(),
108 getActivationHeight(), FillColor.WHITE);
109 addFig(activation);
110 }
111 String portName = getNextFigName();
112 Fig figPort2 =
113 new FigRectangle(portName, x + getNameBoxWidth() / 2 -
114 getActivationWidth() / 2, y + getNameBoxHeight(),
115 getActivationWidth(), 0, FillColor.WHITE);
116 addFig(figPort2);
117 return portName;
118 }
119
120 private int getNameBoxWidth() {
121 return 75;
122 }
123
124 private int getNameBoxHeight() {
125 return 26;
126 }
127
128 private int getLifeLineWidth() {
129 return 10;
130 }
131
132 private int getLifeLineHeight() {
133 return 120;
134 }
135
136 private int getActivationWidth() {
137 return 20;
138 }
139
140 private int getActivationHeight() {
141 return 20;
142 }
143 }