Coverage Report - org.argouml.uml.diagram.deployment.ui.AbstractFigComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFigComponent
0%
0/77
0%
0/10
1.545
 
 1  
 /* $Id: AbstractFigComponent.java 17857 2010-01-12 19:59:07Z linus $
 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) 2007-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.deployment.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.Collection;
 46  
 import java.util.Iterator;
 47  
 
 48  
 import org.argouml.model.AssociationChangeEvent;
 49  
 import org.argouml.model.AttributeChangeEvent;
 50  
 import org.argouml.model.Model;
 51  
 import org.argouml.uml.diagram.DiagramSettings;
 52  
 import org.argouml.uml.diagram.ui.FigNodeModelElement;
 53  
 import org.tigris.gef.presentation.FigRect;
 54  
 import org.tigris.gef.presentation.FigText;
 55  
 
 56  
 /**
 57  
  * Common abstract superclass for FigComponent and FigComponentInstance
 58  
  * to encapsulate common behavior.
 59  
  * 
 60  
  * @author 5eichler
 61  
  * @author Tom Morris <tfmorris@gmail.com>
 62  
  */
 63  
 public abstract class AbstractFigComponent extends FigNodeModelElement {
 64  
 
 65  
     /**
 66  
      * Size of the prong or finger that extends from the left side of the
 67  
      * figure. It is also the distance between the left edge of the fig and the
 68  
      * left edge of the main rectangle. Originally named BIGPORT_X (which
 69  
      * explains what BX stands for).
 70  
      */
 71  
     private static final int BX = 10;
 72  
     private static final int FINGER_HEIGHT = BX;
 73  
     private static final int FINGER_WIDTH = BX * 2;
 74  
     private static final int OVERLAP = 0;
 75  
     private static final int DEFAULT_WIDTH = 120;
 76  
     private static final int DEFAULT_HEIGHT = 80;
 77  
     private FigRect cover;
 78  
     private FigRect upperRect;
 79  
     private FigRect lowerRect;
 80  
 
 81  
     private void initFigs() {
 82  0
         cover = new FigRect(BX, 10, DEFAULT_WIDTH, DEFAULT_HEIGHT, LINE_COLOR,
 83  
                 FILL_COLOR);
 84  0
         upperRect = new FigRect(0, 2 * FINGER_HEIGHT, 
 85  
                 FINGER_WIDTH, FINGER_HEIGHT,
 86  
                 LINE_COLOR, FILL_COLOR);
 87  0
         lowerRect = new FigRect(0, 5 * FINGER_HEIGHT, 
 88  
                 FINGER_WIDTH, FINGER_HEIGHT,
 89  
                 LINE_COLOR, FILL_COLOR);
 90  
 
 91  0
         getNameFig().setLineWidth(0);
 92  0
         getNameFig().setFilled(false);
 93  0
         getNameFig().setText(placeString());
 94  
 
 95  0
         addFig(getBigPort());
 96  0
         addFig(cover);
 97  0
         addFig(getStereotypeFig());
 98  0
         addFig(getNameFig());
 99  0
         addFig(upperRect);
 100  0
         addFig(lowerRect);
 101  0
     }
 102  
     
 103  
     /**
 104  
      * Construct a new AbstractFigComponent.
 105  
      * 
 106  
      * @param owner owning UML element
 107  
      * @param bounds position and size
 108  
      * @param settings render settings
 109  
      */
 110  
     public AbstractFigComponent(Object owner, Rectangle bounds,
 111  
             DiagramSettings settings) {
 112  0
         super(owner, bounds, settings);
 113  0
         initFigs();
 114  0
     }
 115  
 
 116  
     @Override
 117  
     public Object clone() {
 118  0
         AbstractFigComponent figClone = (AbstractFigComponent) super.clone();
 119  0
         Iterator it = figClone.getFigs().iterator();
 120  0
         figClone.setBigPort((FigRect) it.next());
 121  0
         figClone.cover = (FigRect) it.next();
 122  0
         it.next();
 123  0
         figClone.setNameFig((FigText) it.next());
 124  0
         figClone.upperRect = (FigRect) it.next();
 125  0
         figClone.lowerRect = (FigRect) it.next();
 126  
     
 127  0
         return figClone;
 128  
     }
 129  
 
 130  
     @Override
 131  
     protected void modelChanged(PropertyChangeEvent mee) {
 132  0
         super.modelChanged(mee);
 133  0
         if (mee instanceof AssociationChangeEvent 
 134  
                 || mee instanceof AttributeChangeEvent) {
 135  0
             renderingChanged();
 136  0
             updateListeners(getOwner(), getOwner());
 137  0
             damage();
 138  
         }
 139  0
     }
 140  
 
 141  
     @Override
 142  
     protected void updateListeners(Object oldOwner, Object newOwner) {
 143  0
         super.updateListeners(oldOwner, newOwner);
 144  0
         if (newOwner != null) {
 145  0
             Collection c = Model.getFacade().getStereotypes(newOwner);
 146  0
             Iterator i = c.iterator();
 147  0
             while (i.hasNext()) {
 148  0
                 Object st = i.next();
 149  0
                 addElementListener(st, "name");
 150  0
             }
 151  
         }
 152  0
     }
 153  
 
 154  
     @Override
 155  
     public void setLineColor(Color c) {
 156  0
         cover.setLineColor(c);
 157  0
         getStereotypeFig().setFilled(false);
 158  0
         getStereotypeFig().setLineWidth(0);
 159  0
         getNameFig().setFilled(false);
 160  0
         getNameFig().setLineWidth(0);
 161  0
         upperRect.setLineColor(c);
 162  0
         lowerRect.setLineColor(c);
 163  0
     }
 164  
 
 165  
     @Override
 166  
     public Dimension getMinimumSize() {
 167  0
         Dimension stereoDim = getStereotypeFig().getMinimumSize();
 168  0
         Dimension nameDim = getNameFig().getMinimumSize();
 169  
 
 170  0
         int h = Math.max(stereoDim.height + nameDim.height - OVERLAP,
 171  
                 4 * FINGER_HEIGHT);
 172  0
         int w = Math.max(stereoDim.width, nameDim.width) + FINGER_WIDTH;
 173  
 
 174  0
         return new Dimension(w, h);
 175  
     }
 176  
 
 177  
     @Override
 178  
     protected void setStandardBounds(int x, int y, int w,
 179  
             int h) {
 180  0
         if (getNameFig() == null) {
 181  0
             return;
 182  
         }
 183  
 
 184  0
         Rectangle oldBounds = getBounds();
 185  0
         getBigPort().setBounds(x + BX, y, w - BX, h);
 186  0
         cover.setBounds(x + BX, y, w - BX, h);
 187  
 
 188  0
         Dimension stereoDim = getStereotypeFig().getMinimumSize();
 189  0
         Dimension nameDim = getNameFig().getMinimumSize();
 190  
 
 191  0
         int halfHeight = FINGER_HEIGHT / 2;
 192  0
         upperRect.setBounds(x, y + h / 3 - halfHeight, FINGER_WIDTH,
 193  
                 FINGER_HEIGHT);
 194  0
         lowerRect.setBounds(x, y + 2 * h / 3 - halfHeight, FINGER_WIDTH,
 195  
                 FINGER_HEIGHT);
 196  
 
 197  0
         getStereotypeFig().setBounds(x + FINGER_WIDTH + 1,
 198  
                 y + 1,
 199  
                 w - FINGER_WIDTH - 2,
 200  
                 stereoDim.height);
 201  0
         getNameFig().setBounds(x + FINGER_WIDTH + 1,
 202  
                 y + stereoDim.height - OVERLAP + 1,
 203  
                 w - FINGER_WIDTH - 2,
 204  
                 nameDim.height);
 205  0
         _x = x;
 206  0
         _y = y;
 207  0
         _w = w;
 208  0
         _h = h;
 209  0
         firePropChange("bounds", oldBounds, getBounds());
 210  0
         updateEdges();
 211  0
     }
 212  
 
 213  
 
 214  
     @Override
 215  
     public boolean getUseTrapRect() {
 216  0
         return true;
 217  
     }
 218  
 
 219  
     @Override
 220  
     public Rectangle getHandleBox() {
 221  0
         Rectangle r = getBounds();
 222  0
         return new Rectangle(r.x + BX, r.y, r.width - BX, r.height);
 223  
     }
 224  
 
 225  
     @Override
 226  
     public void setHandleBox(int x, int y, int w, int h) {
 227  0
         setBounds(x - BX, y, w + BX, h);
 228  0
     }
 229  
 
 230  
 }