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  
28  import org.w3c.dom.Document;
29  import org.w3c.dom.Element;
30  import org.w3c.dom.Text;
31  
32  class FigGroup extends Fig {
33      private String description;
34      private String href;
35  
36      private List<Fig> figs = new LinkedList<Fig>();
37      private List<String> privateAttributes = new LinkedList<String>();
38      private int nextFigNumber = 0;
39  
40      public FigGroup(String name, String description, String href, Fill fill,
41              FillColor fillColor, Stroke stroke, StrokeColor strokeColor) {
42          super(name, fill, fillColor, stroke, strokeColor);
43          this.description = description;
44          this.href = href;
45      }
46  
47      public Element getXML(Document doc) {
48          Element group = createElement(doc, "group");
49          group.setAttribute("description", getDescription());
50          group.setAttribute("href", getHREF());
51  
52          group.appendChild(getPrivateAttributesElement(doc));
53  
54          for (Fig fig : figs) {
55              group.appendChild(fig.getXML(doc));
56          }
57          return group;
58      }
59  
60      private Element getPrivateAttributesElement(Document doc) {
61          Element priv = doc.createElement("private");
62          for (String privateAttribute : privateAttributes) {
63              Text textNode = doc.createTextNode(privateAttribute);
64              priv.appendChild(textNode);
65          }
66          return priv;
67      }
68  
69      public void addPrivateAttribute(String attribute, String value) {
70          privateAttributes.add(attribute + "=\"" + value + "\"");
71      }
72  
73      public void addFig(Fig fig) {
74          figs.add(fig);
75      }
76  
77      //
78      // Getters
79      //
80  
81      public String getDescription() {
82          return description;
83      }
84  
85      public String getHREF() {
86          return href;
87      }
88  
89      protected String getNextFigName() {
90          return getName() + "." + nextFigNumber++;
91      }
92  
93  }