Coverage Report - org.argouml.uml.diagram.use_case.ui.FigActor
 
Classes in this File Line Coverage Branch Coverage Complexity
FigActor
0%
0/113
0%
0/26
1.737
FigActor$ActorPortFigRect
0%
0/8
N/A
1.737
 
 1  
 /* $Id: FigActor.java 18242 2010-04-12 16:07:47Z 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  
  *    mvw
 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.use_case.ui;
 40  
 
 41  
 import java.awt.Color;
 42  
 import java.awt.Dimension;
 43  
 import java.awt.Font;
 44  
 import java.awt.Point;
 45  
 import java.awt.Rectangle;
 46  
 import java.awt.event.MouseEvent;
 47  
 import java.beans.PropertyChangeEvent;
 48  
 import java.util.ArrayList;
 49  
 import java.util.List;
 50  
 import java.util.Vector;
 51  
 
 52  
 import org.argouml.model.Model;
 53  
 import org.argouml.uml.diagram.DiagramSettings;
 54  
 import org.argouml.uml.diagram.ui.ArgoFigUtil;
 55  
 import org.argouml.uml.diagram.ui.FigNodeModelElement;
 56  
 import org.tigris.gef.base.Selection;
 57  
 import org.tigris.gef.presentation.Fig;
 58  
 import org.tigris.gef.presentation.FigCircle;
 59  
 import org.tigris.gef.presentation.FigLine;
 60  
 import org.tigris.gef.presentation.FigRect;
 61  
 
 62  
 /**
 63  
  * Class to display graphics for an Actor in a diagram. <p>
 64  
  * 
 65  
  * The dimensions of the stick-man figure are fixed at 40 wide by 55 high.
 66  
  * It does not support different line-widths.<p>
 67  
  * 
 68  
  * Stereotypes and the name are shown below the stick-man.<p>
 69  
  * 
 70  
  *  This seems to be the only ArgoUML element where the stereotypes 
 71  
  *  are shown below the name. The UML 1.4.2 standard does not forbid nor 
 72  
  *  prescribe this layout detail.
 73  
  */
 74  0
 public class FigActor extends FigNodeModelElement {
 75  
 
 76  
     /**
 77  
      * The padding between the actor body and name and the top of the
 78  
      * stereotype.
 79  
      */
 80  
     protected static final int MIN_VERT_PADDING = 4;
 81  
 
 82  
     //These are the positions of child figs inside this fig
 83  
     //They must be added in the constructor in this order.
 84  
     //For now the name must not be last as this would force
 85  
     //zero width lines (until GEF is fixed)
 86  
     private static final int HEAD_POSN = 2;
 87  
     private static final int BODY_POSN = 3;
 88  
     private static final int ARMS_POSN = 4;
 89  
     private static final int LEFT_LEG_POSN = 5;
 90  
     private static final int RIGHT_LEG_POSN = 6;
 91  
 
 92  
     private void constructFigs(Rectangle bounds) {
 93  
 
 94  0
         FigCircle head =
 95  
             new FigCircle(X0 + 2, Y0, 16, 15);
 96  0
         FigLine body = new FigLine(X0 + 10, Y0 + 15, 20, 40);
 97  0
         FigLine arms = new FigLine(X0, Y0 + 20, 30, 30);
 98  0
         FigLine leftLeg = new FigLine(X0 + 10, Y0 + 30, 15, 55);
 99  0
         FigLine rightLeg = new FigLine(X0 + 10, Y0 + 30, 25, 55);
 100  
         
 101  0
         getNameFig().setBounds(X0, Y0 + 45, 20, 20);
 102  
 
 103  0
         getNameFig().setTextFilled(false);
 104  0
         getNameFig().setFilled(false);
 105  0
         getNameFig().setLineWidth(0);
 106  
         // initialize any other Figs here
 107  0
         getStereotypeFig().setBounds(getBigPort().getCenter().x,
 108  
                                      getBigPort().getCenter().y,
 109  
                                      0, 0);
 110  0
         setSuppressCalcBounds(true);
 111  
         // add Figs to the FigNode in back-to-front order
 112  
         // Put this rectangle behind the rest, so it goes first
 113  0
         addFig(getBigPort());
 114  0
         addFig(getNameFig());
 115  0
         addFig(head);
 116  0
         addFig(body);
 117  0
         addFig(arms);
 118  0
         addFig(leftLeg);
 119  0
         addFig(rightLeg);
 120  0
         addFig(getStereotypeFig());
 121  
         
 122  0
         bindPort(getOwner(), getBigPort());
 123  0
         setResizable(false);
 124  
         
 125  0
         setFilled(true);
 126  0
         setFillColor(FILL_COLOR);
 127  0
         setLineColor(LINE_COLOR);
 128  0
         setLineWidth(LINE_WIDTH);
 129  0
         setTextColor(TEXT_COLOR);
 130  
         
 131  
         /* Set the drop location in the case of D&D: */
 132  0
         if (bounds != null) {
 133  0
             setLocation(bounds.x, bounds.y);
 134  
         }
 135  
 
 136  0
         setSuppressCalcBounds(false);
 137  0
         setBounds(getBounds());
 138  0
     }
 139  
     
 140  
     @Override
 141  
     protected Fig createBigPortFig() {
 142  0
         return new ActorPortFigRect(X0, Y0, 0, 0, this);
 143  
     }
 144  
 
 145  
     /**
 146  
      * Construct a new Actor with the given owner, bounds, and settings.  This
 147  
      * constructor is used by the PGML parser.
 148  
      * 
 149  
      * @param owner model element that owns this fig
 150  
      * @param bounds position and size
 151  
      * @param settings rendering settings
 152  
      */
 153  
     public FigActor(Object owner, Rectangle bounds, 
 154  
             DiagramSettings settings) {
 155  0
         super(owner, bounds, settings);
 156  0
         constructFigs(bounds);
 157  0
     }
 158  
 
 159  
     @Override
 160  
     public void setLineWidth(int width) {
 161  
         /* This sets the lineWidth of all in the group: */
 162  0
         super.setLineWidth(width);
 163  
         /* NameFig and StereotypeFig are handled by parent. */
 164  0
     }
 165  
     
 166  
     @Override
 167  
     public void setFillColor(Color col) {
 168  0
         super.setFillColor(col);
 169  0
         getStereotypeFig().setFillColor(null);
 170  0
         getNameFig().setFillColor(null);
 171  0
     }
 172  
 
 173  
     @Override
 174  
     public void setFilled(boolean filled) {
 175  0
         super.setFilled(filled);
 176  0
         getBigPort().setFilled(false);
 177  0
         getNameFig().setFilled(false);
 178  0
         getStereotypeFig().setFilled(false);
 179  
         // Only the head should be filled (not the text)
 180  0
     }
 181  
 
 182  
     @Override
 183  
     public Selection makeSelection() {
 184  0
         return new SelectionActor(this);
 185  
     }
 186  
 
 187  
     @Override
 188  
     public Vector getPopUpActions(MouseEvent me) {
 189  0
         Vector popUpActions = super.getPopUpActions(me);
 190  
         // Modifiers ...
 191  0
         popUpActions.add(
 192  
                 popUpActions.size() - getPopupAddOffset(),
 193  
                 buildModifierPopUp(ABSTRACT | LEAF | ROOT));
 194  0
         return popUpActions;
 195  
     }
 196  
 
 197  
     @Override
 198  
     public boolean isResizable() {
 199  0
         return false;
 200  
     }
 201  
 
 202  
     @Override
 203  
     public Dimension getMinimumSize() {
 204  0
         Dimension aSize = new Dimension(40, 55);
 205  0
         aSize = ArgoFigUtil.addChildDimensions(aSize, getNameFig());
 206  0
         aSize = ArgoFigUtil.addChildDimensions(aSize, getStereotypeFig());
 207  0
         return aSize;
 208  
     }
 209  
 
 210  
     @Override
 211  
     protected void setStandardBounds(final int x, final int y, 
 212  
             final int w, final int h) {
 213  
 
 214  0
         Rectangle oldBounds = getBounds();
 215  
         
 216  
         // Make sure we don't try to set things smaller than the minimum
 217  0
         Dimension minimumSize = getMinimumSize();
 218  0
         int newW = Math.max(w, minimumSize.width);
 219  0
         int newH = Math.max(h, minimumSize.height);
 220  
 
 221  0
         int middle = x + newW / 2;
 222  
 
 223  0
         getFigAt(HEAD_POSN).setLocation(
 224  
                 middle - getFigAt(HEAD_POSN).getWidth() / 2, y + 10);
 225  0
         getFigAt(BODY_POSN).setLocation(middle, y + 25);
 226  0
         getFigAt(ARMS_POSN).setLocation(
 227  
                 middle - getFigAt(ARMS_POSN).getWidth() / 2, y + 30);
 228  0
         getFigAt(LEFT_LEG_POSN).setLocation(
 229  
                 middle - getFigAt(LEFT_LEG_POSN).getWidth(), y + 40);
 230  0
         getFigAt(RIGHT_LEG_POSN).setLocation(middle, y +  40);
 231  
 
 232  0
         Dimension minTextSize = getNameFig().getMinimumSize();
 233  0
         getNameFig().setBounds(middle - minTextSize.width / 2,
 234  
                 y +  55,
 235  
                 minTextSize.width,
 236  
                 minTextSize.height);
 237  
 
 238  0
         if (getStereotypeFig().isVisible()) {
 239  0
             Dimension minStereoSize = getStereotypeFig().getMinimumSize();
 240  0
             assert minStereoSize.width <= newW;
 241  0
             getStereotypeFig().setBounds(middle - minStereoSize.width / 2,
 242  
                     y + 55 + getNameFig().getHeight(),
 243  
                     minStereoSize.width, 
 244  
                     minStereoSize.height);
 245  
         }
 246  
 
 247  0
         getBigPort().setBounds(x, y, newW, newH);
 248  
 
 249  0
         calcBounds(); //Accumulate a bounding box for all the Figs in the group.
 250  0
         firePropChange("bounds", oldBounds, getBounds());
 251  0
         updateEdges();
 252  0
     }
 253  
 
 254  
     @Override
 255  
     public Object deepHitPort(int x, int y) {
 256  0
         Object o = super.deepHitPort(x, y);
 257  0
         if (o != null) {
 258  0
             return o;
 259  
         }
 260  0
         if (hit(new Rectangle(new Dimension(x, y)))) {
 261  0
             return getOwner();
 262  
         }
 263  0
         return null;
 264  
     }
 265  
 
 266  
     /*
 267  
      * Makes sure that the edges stick to the outline of the fig.
 268  
      * @see org.tigris.gef.presentation.Fig#getGravityPoints()
 269  
      */
 270  
     @Override
 271  
     public List<Point> getGravityPoints() {
 272  0
         final int maxPoints = 20;
 273  0
         List<Point> ret = new ArrayList<Point>();
 274  0
         int cx = getFigAt(HEAD_POSN).getCenter().x;
 275  0
         int cy = getFigAt(HEAD_POSN).getCenter().y;
 276  0
         int radiusx = Math.round(getFigAt(HEAD_POSN).getWidth() / 2) + 1;
 277  0
         int radiusy = Math.round(getFigAt(HEAD_POSN).getHeight() / 2) + 1;
 278  0
         Point point = null;
 279  0
         for (int i = 0; i < maxPoints; i++) {
 280  0
             double angle = 2 * Math.PI / maxPoints * i;
 281  0
             point =
 282  
                 new Point((int) (cx + Math.cos(angle) * radiusx),
 283  
                           (int) (cy + Math.sin(angle) * radiusy));
 284  0
             ret.add(point);
 285  
         }
 286  0
         ret.add(new Point(((FigLine) getFigAt(LEFT_LEG_POSN)).getX2(),
 287  
                           ((FigLine) getFigAt(LEFT_LEG_POSN)).getY2()));
 288  0
         ret.add(new Point(((FigLine) getFigAt(RIGHT_LEG_POSN)).getX2(),
 289  
                           ((FigLine) getFigAt(RIGHT_LEG_POSN)).getY2()));
 290  0
         ret.add(new Point(((FigLine) getFigAt(RIGHT_LEG_POSN)).getX2(),
 291  
                           ((FigLine) getFigAt(RIGHT_LEG_POSN)).getY2() + getNameFig().getHeight()));
 292  0
         ret.add(new Point(((FigLine) getFigAt(ARMS_POSN)).getX1(),
 293  
                           ((FigLine) getFigAt(ARMS_POSN)).getY1()));
 294  0
         ret.add(new Point(((FigLine) getFigAt(ARMS_POSN)).getX2(),
 295  
                           ((FigLine) getFigAt(ARMS_POSN)).getY2()));
 296  0
         ret.add(new Point(((FigLine) getFigAt(LEFT_LEG_POSN)).getX2(),
 297  
                           ((FigLine) getFigAt(LEFT_LEG_POSN)).getY2() + getNameFig().getHeight()));
 298  0
         return ret;
 299  
     }
 300  
 
 301  
     @Override
 302  
     protected void modelChanged(PropertyChangeEvent mee) {
 303  
         //      name updating
 304  0
         super.modelChanged(mee);
 305  
 
 306  0
         boolean damage = false;
 307  0
         if (getOwner() == null) {
 308  0
             return;
 309  
         }
 310  
 
 311  0
         if (mee == null 
 312  
                 || mee.getPropertyName().equals("stereotype") 
 313  
                 || Model.getFacade().getStereotypes(getOwner())
 314  
                                 .contains(mee.getSource())) {
 315  0
             updateStereotypeText();
 316  0
             damage = true;
 317  
         }
 318  
 
 319  0
         if (damage) {
 320  0
             damage();
 321  
         }
 322  0
     }
 323  
 
 324  
     @Override
 325  
     protected int getNameFigFontStyle() {
 326  0
         Object cls = getOwner();
 327  0
         return Model.getFacade().isAbstract(cls) ? Font.ITALIC : Font.PLAIN;
 328  
     }
 329  
 
 330  
     /**
 331  
      * The bigPort needs to overrule the getGravityPoints,
 332  
      * because it is the port of this FigNode.
 333  
      *
 334  
      * @author mvw
 335  
      */
 336  
     static class ActorPortFigRect extends FigRect {
 337  
         /**
 338  
          * the parent fig, i.e. the Actor
 339  
          */
 340  
         private Fig parent;
 341  
 
 342  
         /**
 343  
          * The constructor.
 344  
          *
 345  
          * @param x the x
 346  
          * @param y the y
 347  
          * @param w the width
 348  
          * @param h the height
 349  
          * @param p the Actor fig
 350  
          */
 351  
         public ActorPortFigRect(int x, int y, int w, int h, Fig p) {
 352  0
             super(x, y, w, h, null, null);
 353  0
             parent = p;
 354  0
         }
 355  
 
 356  
         /**
 357  
          * Makes sure that the edges stick to the outline of the fig.
 358  
          * @see org.tigris.gef.presentation.Fig#getGravityPoints()
 359  
          */
 360  
         @Override
 361  
         public List getGravityPoints() {
 362  0
             return parent.getGravityPoints();
 363  
         }
 364  
 
 365  
         @Override
 366  
         public void setFilled(boolean f) {
 367  0
             super.setFilled(false);
 368  0
         }
 369  
 
 370  
         @Override
 371  
         public void setLineWidth(int w) {
 372  0
             super.setLineWidth(0);
 373  0
         }
 374  
 
 375  
     }
 376  
 
 377  
 }