Coverage Report - th.co.edge.jseq.argouml.pgml.FigObject
 
Classes in this File Line Coverage Branch Coverage Complexity
FigObject
98%
45/46
75%
6/8
0
 
 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  55
 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  3
     private List<String> dynObjects = new LinkedList<String>();
 40  3
     private List<String> dynObjectsActivation = new LinkedList<String>();
 41  3
     private Stack<Integer> startPortNumbers = new Stack<Integer>();
 42  
 
 43  
     public FigObject(String name, String objectName, String uuid, int x, int y) {
 44  3
         super(name, FIG_SEQ_OBJECT_CLASS, uuid, Fill.ON, FillColor.WHITE,
 45  
                 Stroke.ON, StrokeColor.BLACK);
 46  3
         this.objectName = objectName;
 47  3
         this.x = x;
 48  3
         this.y = y;
 49  
 
 50  3
         addPrivateAttribute("enclosingFig", name);
 51  
 
 52  3
         addFig(new FigRectangle(getNextFigName(), x, y, getNameBoxWidth(),
 53  
                 getNameBoxHeight(), FillColor.CYAN));
 54  3
         addFig(new FigRectangle(getNextFigName(), x, y, getNameBoxWidth(),
 55  
                 getNameBoxHeight(), FillColor.WHITE));
 56  3
         addFig(new FigText(getNextFigName(), objectName, x, y, "dialog", 9,
 57  
                 Stroke.ON, StrokeColor.BLACK));
 58  3
         addFig(new FigRectangle(getNextFigName(), x + getNameBoxWidth() / 2 -
 59  
                 getLifeLineWidth() / 2, y + getNameBoxHeight(),
 60  
                 getLifeLineWidth(), getLifeLineHeight(), FillColor.WHITE));
 61  3
         addFig(new FigLine(getNextFigName(), 10, 49, 19, 49));
 62  3
         addFig(new FigLine(getNextFigName(), 19, 49, 10, 49));
 63  3
     }
 64  
 
 65  
     public Element getXML(Document doc) {
 66  3
         Element group = super.getXML(doc);
 67  3
         group.setAttribute("dynobjects", getDynObjects());
 68  3
         return group;
 69  
     }
 70  
 
 71  
     public String getObjectName() {
 72  0
         return objectName;
 73  
     }
 74  
 
 75  
     public String getDynObjects() {
 76  3
         return dynObjects.toString();
 77  
     }
 78  
 
 79  
     public boolean isActive() {
 80  47
         return !startPortNumbers.empty();
 81  
     }
 82  
 
 83  
     public void activate(int portNumber) {
 84  10
         startPortNumbers.push(portNumber);
 85  10
     }
 86  
 
 87  
     public void deactivate(int portNumber) {
 88  10
         if (isActive()) {
 89  10
             int startPortNumber = startPortNumbers.pop();
 90  10
             if (!isActive()) {
 91  10
                 String activationDynObject =
 92  
                         "a|" + startPortNumber + "|" + portNumber +
 93  
                                 "|false|false";
 94  10
                 dynObjectsActivation.add(0, activationDynObject);
 95  10
                 dynObjects.addAll(dynObjectsActivation);
 96  10
                 dynObjectsActivation.clear();
 97  
             }
 98  
         }
 99  10
     }
 100  
 
 101  
     public String addPort(int portNumber) {
 102  18
         dynObjectsActivation.add("b|" + portNumber);
 103  18
         if (!isActive()) {
 104  10
             Fig activation =
 105  
                     new FigRectangle(getNextFigName(), x + getNameBoxWidth() /
 106  
                             2 - getActivationWidth() / 2, y +
 107  
                             getNameBoxHeight(), getActivationWidth(),
 108  
                             getActivationHeight(), FillColor.WHITE);
 109  10
             addFig(activation);
 110  
         }
 111  18
         String portName = getNextFigName();
 112  18
         Fig figPort2 =
 113  
                 new FigRectangle(portName, x + getNameBoxWidth() / 2 -
 114  
                         getActivationWidth() / 2, y + getNameBoxHeight(),
 115  
                         getActivationWidth(), 0, FillColor.WHITE);
 116  18
         addFig(figPort2);
 117  18
         return portName;
 118  
     }
 119  
 
 120  
     private int getNameBoxWidth() {
 121  37
         return 75;
 122  
     }
 123  
 
 124  
     private int getNameBoxHeight() {
 125  37
         return 26;
 126  
     }
 127  
 
 128  
     private int getLifeLineWidth() {
 129  6
         return 10;
 130  
     }
 131  
 
 132  
     private int getLifeLineHeight() {
 133  3
         return 120;
 134  
     }
 135  
 
 136  
     private int getActivationWidth() {
 137  56
         return 20;
 138  
     }
 139  
 
 140  
     private int getActivationHeight() {
 141  10
         return 20;
 142  
     }
 143  
 }