Coverage Report - org.argouml.uml.diagram.collaboration.ui.FigAssociationRole
 
Classes in this File Line Coverage Branch Coverage Complexity
FigAssociationRole
0%
0/12
N/A
2
FigMessageGroup
0%
0/44
0%
0/18
2
 
 1  
 /* $Id: FigAssociationRole.java 18712 2010-08-31 15:44:03Z bobtarling $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 Contributors - see below
 4  
  * All rights reserved. This program and the accompanying materials
 5  
  * are made available under the terms of the Eclipse Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/epl-v10.html
 8  
  *
 9  
  * Contributors:
 10  
  *    bobtarling
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2009 The Regents of the University of California. All
 17  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 18  
 // software and its documentation without fee, and without a written
 19  
 // agreement is hereby granted, provided that the above copyright notice
 20  
 // and this paragraph appear in all copies.  This software program and
 21  
 // documentation are copyrighted by The Regents of the University of
 22  
 // California. The software program and documentation are supplied "AS
 23  
 // IS", without any accompanying services from The Regents. The Regents
 24  
 // does not warrant that the operation of the program will be
 25  
 // uninterrupted or error-free. The end-user understands that the program
 26  
 // was developed for research purposes and is advised not to rely
 27  
 // exclusively on the program for any reason.  IN NO EVENT SHALL THE
 28  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 29  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 30  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 31  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 32  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 33  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 34  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 35  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 36  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 37  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 38  
 
 39  
 package org.argouml.uml.diagram.collaboration.ui;
 40  
 
 41  
 import java.util.Collection;
 42  
 import java.util.Iterator;
 43  
 import java.util.List;
 44  
 
 45  
 import org.argouml.notation.NotationProviderFactory2;
 46  
 import org.argouml.uml.diagram.DiagramEdgeSettings;
 47  
 import org.argouml.uml.diagram.DiagramSettings;
 48  
 import org.argouml.uml.diagram.ui.ArgoFigGroup;
 49  
 import org.argouml.uml.diagram.ui.FigAssociation;
 50  
 import org.argouml.uml.diagram.ui.FigMessage;
 51  
 import org.argouml.uml.diagram.ui.PathItemPlacement;
 52  
 import org.tigris.gef.presentation.Fig;
 53  
 
 54  
 
 55  
 /**
 56  
  * This class represents the Fig of an AssociationRole
 57  
  * for a collaboration diagram.
 58  
  *
 59  
  */
 60  
 public class FigAssociationRole extends FigAssociation {
 61  
     
 62  
     private FigMessageGroup messages;
 63  
 
 64  
     /**
 65  
      * Construct an AssociationRole fig with the given properties and diagram
 66  
      * settings.
 67  
      * 
 68  
      * @param diagramEdgeSettings the properties of the edge
 69  
      * @param settings render settings
 70  
      */
 71  
     public FigAssociationRole(
 72  
             final DiagramEdgeSettings diagramEdgeSettings, 
 73  
             final DiagramSettings settings) {
 74  0
         super(diagramEdgeSettings, settings);
 75  0
         messages = new FigMessageGroup(getOwner(), settings);
 76  0
         addPathItem(messages, new PathItemPlacement(this, messages, 50, 10));
 77  0
     }
 78  
     
 79  
     /*
 80  
      * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getNotationProviderType()
 81  
      */
 82  
     protected int getNotationProviderType() {
 83  0
         return NotationProviderFactory2.TYPE_ASSOCIATION_ROLE;
 84  
     }
 85  
 
 86  
     /**
 87  
      * @param message the message to be added
 88  
      */
 89  
     public void addMessage(FigMessage message) {
 90  0
             messages.addFig(message);
 91  0
             updatePathItemLocations();
 92  0
             messages.damage();
 93  0
     }
 94  
 
 95  
     @Override
 96  
     public void computeRouteImpl() {
 97  0
         super.computeRouteImpl();
 98  0
         messages.updateArrows();
 99  0
     }
 100  
     
 101  
 } /* end class FigAssociationRole */
 102  
 
 103  
 /**
 104  
  * A Fig for the group of Messages shown above the Association Role.
 105  
  */
 106  
 class FigMessageGroup extends ArgoFigGroup {
 107  
     
 108  
     /**
 109  
      * The constructor.
 110  
      * 
 111  
      * @param owner the UML Message object
 112  
      * @param settings rendering properties
 113  
      */
 114  
     public FigMessageGroup(Object owner, DiagramSettings settings) {
 115  0
         super(owner, settings);
 116  0
     }
 117  
 
 118  
     private void updateFigPositions() {
 119  0
             Collection figs = getFigs(); // the figs that make up this group
 120  0
         Iterator it = figs.iterator();
 121  0
             if (!figs.isEmpty()) {
 122  0
             FigMessage previousFig = null;
 123  0
             for (int i = 0; it.hasNext(); i++) {
 124  0
                 FigMessage figMessage = (FigMessage) it.next();
 125  
                 int y;
 126  0
                 if (i != 0) {
 127  0
                     y = previousFig.getY() + previousFig.getHeight() + 5;
 128  
                 } else {
 129  0
                     y = getY();
 130  
                 }
 131  0
                 figMessage.setLocation(getX(), y);
 132  0
                 figMessage.endTrans();
 133  0
                 previousFig = figMessage;
 134  
             }
 135  
             }
 136  0
     }
 137  
 
 138  
     /*
 139  
      * @see org.tigris.gef.presentation.Fig#calcBounds()
 140  
      */
 141  
     public void calcBounds() {
 142  0
         super.calcBounds();
 143  0
         Collection figs = getFigs();
 144  0
         if (!figs.isEmpty()) {
 145  0
             Fig last = null;
 146  0
             Fig first = null;
 147  
             // _x = first.getX();
 148  
             // _y = first.getY();
 149  0
             _w = 0;
 150  0
             Iterator it = figs.iterator();
 151  0
             int size = figs.size();
 152  0
             for (int i = 0; i < size; i++) {
 153  0
                 Fig fig = (Fig) it.next();
 154  
 
 155  0
                 if (i == 0) {
 156  0
                     first = fig;
 157  
                 }
 158  0
                 if (i == size - 1) {
 159  0
                     last = fig;
 160  
                 }
 161  
 
 162  0
                 if (fig.getWidth() > _w) {
 163  0
                     _w = fig.getWidth();
 164  
                 }
 165  
             }
 166  0
             _h = last.getY() + last.getHeight() - first.getY();
 167  0
         } else {
 168  0
             _w = 0;
 169  0
             _h = 0;
 170  
         }
 171  0
     }
 172  
 
 173  
     /*
 174  
      * @see org.tigris.gef.presentation.FigGroup#addFig(Fig)
 175  
      */
 176  
     @Override
 177  
     public void addFig(Fig f) {
 178  0
         super.addFig(f);
 179  0
         updateFigPositions();
 180  0
         updateArrows();
 181  0
         calcBounds();
 182  0
     }
 183  
     
 184  
     void updateArrows() {
 185  0
         for (FigMessage fm : (List<FigMessage>) getFigs()) {
 186  0
             fm.updateArrow();
 187  
         }
 188  0
     }
 189  
 
 190  
 }
 191