Coverage Report - org.argouml.uml.diagram.activity.ui.FigSubactivityState
 
Classes in this File Line Coverage Branch Coverage Complexity
FigSubactivityState
0%
0/93
0%
0/18
1.556
 
 1  
 /* $Id: FigSubactivityState.java 18726 2010-09-10 08:37:15Z mvw $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009-2010 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.activity.ui;
 40  
 
 41  
 import java.awt.Color;
 42  
 import java.awt.Dimension;
 43  
 import java.awt.Rectangle;
 44  
 import java.beans.PropertyChangeEvent;
 45  
 import java.util.HashSet;
 46  
 import java.util.Iterator;
 47  
 import java.util.Set;
 48  
 
 49  
 import org.argouml.model.AssociationChangeEvent;
 50  
 import org.argouml.model.AttributeChangeEvent;
 51  
 import org.argouml.model.Model;
 52  
 import org.argouml.uml.diagram.DiagramSettings;
 53  
 import org.argouml.uml.diagram.state.ui.FigStateVertex;
 54  
 import org.tigris.gef.presentation.Fig;
 55  
 import org.tigris.gef.presentation.FigLine;
 56  
 import org.tigris.gef.presentation.FigRRect;
 57  
 import org.tigris.gef.presentation.FigText;
 58  
 
 59  
 
 60  
 /**
 61  
  * Class to display graphics for a UML SubactivityState in a diagram.
 62  
  *
 63  
  * @author MVW
 64  
  */
 65  
 public class FigSubactivityState extends FigStateVertex {
 66  
 
 67  
     private static final int PADDING = 8;
 68  
 
 69  
     private static final int X = X0;
 70  
     private static final int Y = Y0;
 71  
     private static final int W = 90;
 72  
     private static final int H = 25;
 73  
 
 74  
     private static final int SX = 3;
 75  
     private static final int SY = 3;
 76  
     private static final int SW = 9;
 77  
     private static final int SH = 5;
 78  
 
 79  
 
 80  
     private FigRRect cover;
 81  
 
 82  
     private FigRRect s1;
 83  
     private FigRRect s2;
 84  
     private FigLine s3;
 85  
 
 86  
     
 87  
     /**
 88  
      * Construct a new FigSubactivityState.
 89  
      * 
 90  
      * @param owner owning UML element
 91  
      * @param bounds position and size
 92  
      * @param settings rendering settings
 93  
      */
 94  
     public FigSubactivityState(Object owner, Rectangle bounds, 
 95  
             DiagramSettings settings) {
 96  0
         super(owner, bounds, settings);
 97  0
         initFigs();
 98  0
     }
 99  
 
 100  
     @Override
 101  
     protected Fig createBigPortFig() {
 102  0
         FigRRect frr = new FigRRect(X, Y, W, H, DEBUG_COLOR, DEBUG_COLOR);
 103  0
         frr.setCornerRadius(frr.getHeight() / 2);
 104  0
         frr.setLineWidth(0);
 105  0
         return frr;
 106  
     }
 107  
 
 108  
     private void initFigs() {
 109  0
         cover = new FigRRect(X, Y, W, H, LINE_COLOR, FILL_COLOR);
 110  0
         cover.setCornerRadius(getHeight() / 2);
 111  
 
 112  0
         getNameFig().setLineWidth(0);
 113  0
         getNameFig().setBounds(10 + PADDING, 10, 90 - PADDING * 2, 25);
 114  0
         getNameFig().setFilled(false);
 115  0
         getNameFig().setReturnAction(FigText.INSERT);
 116  0
         getNameFig().setEditable(false);
 117  
 
 118  
         // add Figs to the FigNode in back-to-front order
 119  0
         addFig(getBigPort());
 120  0
         addFig(cover);
 121  0
         addFig(getNameFig());
 122  
 
 123  0
         makeSubStatesIcon(X + W, Y);
 124  
 
 125  0
         setBounds(getBounds());
 126  0
     }
 127  
 
 128  
     /**
 129  
      * @param x the x-coordinate of the right corner
 130  
      * @param y the y coordinate of the bottom corner
 131  
      */
 132  
     private void makeSubStatesIcon(int x, int y) {
 133  0
         s1 = new FigRRect(x - 22, y + 3, 8, 6, LINE_COLOR, FILL_COLOR);
 134  0
         s2 = new FigRRect(x - 11, y + 9, 8, 6, LINE_COLOR, FILL_COLOR);
 135  0
         s1.setFilled(true);
 136  0
         s2.setFilled(true);
 137  0
         s1.setLineWidth(LINE_WIDTH);
 138  0
         s2.setLineWidth(LINE_WIDTH);
 139  0
         s1.setCornerRadius(SH);
 140  0
         s2.setCornerRadius(SH);
 141  0
         s3 = new FigLine(x - 18, y + 6, x - 7, y + 12, LINE_COLOR);
 142  
 
 143  0
         addFig(s3); // add them back to front
 144  0
         addFig(s1);
 145  0
         addFig(s2);
 146  0
     }
 147  
 
 148  
     /*
 149  
      * @see java.lang.Object#clone()
 150  
      */
 151  
     @Override
 152  
     public Object clone() {
 153  0
         FigSubactivityState figClone = (FigSubactivityState) super.clone();
 154  0
         Iterator it = figClone.getFigs().iterator();
 155  0
         figClone.setBigPort((FigRRect) it.next());
 156  0
         figClone.cover = (FigRRect) it.next();
 157  0
         figClone.setNameFig((FigText) it.next());
 158  0
         return figClone;
 159  
     }
 160  
 
 161  
 
 162  
     /*
 163  
      * @see org.tigris.gef.presentation.Fig#getMinimumSize()
 164  
      */
 165  
     @Override
 166  
     public Dimension getMinimumSize() {
 167  0
         Dimension nameDim = getNameFig().getMinimumSize();
 168  0
         int w = nameDim.width + PADDING * 2;
 169  0
         int h = nameDim.height + PADDING;
 170  0
         return new Dimension(Math.max(w, W / 2), Math.max(h, H / 2));
 171  
     }
 172  
 
 173  
     /*
 174  
      * Override setBounds to keep shapes looking right.
 175  
      *
 176  
      * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
 177  
      */
 178  
     @Override
 179  
     protected void setStandardBounds(int x, int y, int w, int h) {
 180  0
         if (getNameFig() == null) {
 181  0
             return;
 182  
         }
 183  0
         Rectangle oldBounds = getBounds();
 184  
 
 185  0
         getNameFig().setBounds(x + PADDING, y, w - PADDING * 2, h - PADDING);
 186  0
         getBigPort().setBounds(x, y, w, h);
 187  0
         cover.setBounds(x, y, w, h);
 188  0
         ((FigRRect) getBigPort()).setCornerRadius(h);
 189  0
         cover.setCornerRadius(h);
 190  
 
 191  0
         s1.setBounds(x + w - 2 * (SX + SW), y + h - 1 * (SY + SH), SW, SH);
 192  0
         s2.setBounds(x + w - 1 * (SX + SW), y + h - 2 * (SY + SH), SW, SH);
 193  0
         s3.setShape(x + w - (SX * 2 + SW + SW / 2), y + h - (SY + SH / 2),
 194  
                 x + w - (SX + SW / 2), y + h - (SY * 2 + SH + SH / 2));
 195  
 
 196  0
         calcBounds();
 197  0
         updateEdges();
 198  0
         firePropChange("bounds", oldBounds, getBounds());
 199  0
     }
 200  
 
 201  
     /*
 202  
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
 203  
      */
 204  
     @Override
 205  
     public void setLineColor(Color col) {
 206  0
         cover.setLineColor(col);
 207  0
     }
 208  
 
 209  
     /*
 210  
      * @see org.tigris.gef.presentation.Fig#getLineColor()
 211  
      */
 212  
     public Color getLineColor() {
 213  0
         return cover.getLineColor();
 214  
     }
 215  
 
 216  
     /*
 217  
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
 218  
      */
 219  
     public void setFillColor(Color col) {
 220  0
         cover.setFillColor(col);
 221  0
     }
 222  
 
 223  
     /*
 224  
      * @see org.tigris.gef.presentation.Fig#getFillColor()
 225  
      */
 226  
     public Color getFillColor() {
 227  0
         return cover.getFillColor();
 228  
     }
 229  
 
 230  
     /*
 231  
      * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
 232  
      */
 233  
     @Override
 234  
     public void setFilled(boolean f) {
 235  0
         cover.setFilled(f);
 236  0
     }
 237  
 
 238  
     @Override
 239  
     public boolean isFilled() {
 240  0
         return cover.isFilled();
 241  
     }
 242  
 
 243  
     /*
 244  
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
 245  
      */
 246  
     @Override
 247  
     public void setLineWidth(int w) {
 248  0
         cover.setLineWidth(w);
 249  0
     }
 250  
 
 251  
     /*
 252  
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
 253  
      */
 254  
     @Override
 255  
     public int getLineWidth() {
 256  0
         return cover.getLineWidth();
 257  
     }
 258  
 
 259  
     /*
 260  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent)
 261  
      */
 262  
     @Override
 263  
     protected void modelChanged(PropertyChangeEvent mee) {
 264  
         // Let our superclass sort itself out first
 265  0
         super.modelChanged(mee);
 266  0
         if (mee instanceof AssociationChangeEvent 
 267  
                 || mee instanceof AttributeChangeEvent) {
 268  
             // TODO: Rather than specifically ignore some item maybe it would be better
 269  
             // to specifically state what items are of interest. Otherwise we may still
 270  
             // be acting on other events we don't need
 271  0
             if (!Model.getFacade().isATransition(mee.getNewValue())) {
 272  0
                 renderingChanged();
 273  0
                 updateListeners(getOwner(), getOwner());
 274  
             }
 275  
         }
 276  0
     }
 277  
 
 278  
     /*
 279  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object)
 280  
      */
 281  
     @Override
 282  
     protected void updateListeners(Object oldOwner, Object newOwner) {
 283  0
         Set<Object[]> l = new HashSet<Object[]>();
 284  0
         if (newOwner != null) {
 285  
             // add the listeners to the newOwner
 286  0
             l.add(new Object[] {newOwner, null});
 287  
             // and listen to name changes of the submachine
 288  0
             Object machine = Model.getFacade().getSubmachine(newOwner);
 289  0
             if (machine != null) {
 290  0
                 l.add(new Object[] {machine, null});
 291  
             }
 292  
         }
 293  0
         updateElementListeners(l);
 294  0
     }
 295  
 
 296  
     /*
 297  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateNameText()
 298  
      */
 299  
     @Override
 300  
     protected void updateNameText() {
 301  0
         String s = "";
 302  0
         if (getOwner() != null) {
 303  0
             Object machine = Model.getFacade().getSubmachine(getOwner());
 304  0
             if (machine != null) {
 305  0
                 s = Model.getFacade().getName(machine);
 306  
             }
 307  
         }
 308  0
         if (s == null) {
 309  0
             s = "";
 310  
         }
 311  0
         getNameFig().setText(s);
 312  0
     }
 313  
 
 314  
 }