View Javadoc

1   /*
2    * Copyright (c) 2003-2008, by Henrik Arro and Contributors
3    *
4    * This file is part of JSeq, a tool to automatically create
5    * sequence diagrams by tracing program execution.
6    *
7    * See <http://jseq.sourceforge.net> for more information.
8    *
9    * JSeq is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of
12   * the License, or (at your option) any later version.
13   *
14   * JSeq is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   * GNU Lesser General Public License for more details.
18   *
19   * You should have received a copy of the GNU Lesser General Public License
20   * along with JSeq. If not, see <http://www.gnu.org/licenses/>.
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 }