Coverage Report - org.argouml.uml.diagram.deployment.ui.FigObject
 
Classes in this File Line Coverage Branch Coverage Complexity
FigObject
0%
0/78
0%
0/24
1.667
 
 1  
 /* $Id: FigObject.java 18728 2010-09-10 09:29:47Z 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  
  *    Michiel van der Wulp
 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.deployment.ui;
 40  
 
 41  
 import java.awt.Color;
 42  
 import java.awt.Dimension;
 43  
 import java.awt.Rectangle;
 44  
 import java.util.Iterator;
 45  
 
 46  
 import org.argouml.model.Model;
 47  
 import org.argouml.notation.NotationProviderFactory2;
 48  
 import org.argouml.uml.diagram.DiagramSettings;
 49  
 import org.argouml.uml.diagram.ui.FigNodeModelElement;
 50  
 import org.tigris.gef.base.Selection;
 51  
 import org.tigris.gef.presentation.Fig;
 52  
 import org.tigris.gef.presentation.FigRect;
 53  
 import org.tigris.gef.presentation.FigText;
 54  
 
 55  
 /**
 56  
  * Class to display graphics for a UML Object in a diagram.
 57  
  *
 58  
  * @author 5eichler
 59  
  */
 60  0
 public class FigObject extends FigNodeModelElement {
 61  
 
 62  
     private FigRect cover;
 63  
 
 64  
     @Override
 65  
     protected Fig createBigPortFig() {
 66  0
         return new FigRect(X0, Y0, 90, 50, DEBUG_COLOR, DEBUG_COLOR);
 67  
     }
 68  
 
 69  
     private void initFigs() {
 70  0
         cover = new FigRect(X0, Y0, 90, 50, LINE_COLOR, FILL_COLOR);
 71  0
         getNameFig().setLineWidth(0);
 72  0
         getNameFig().setFilled(false);
 73  0
         getNameFig().setUnderline(true);
 74  0
         Dimension nameMin = getNameFig().getMinimumSize();
 75  0
         getNameFig().setBounds(X0, Y0, nameMin.width + 20, nameMin.height);
 76  
 
 77  
         // add Figs to the FigNode in back-to-front order
 78  0
         addFig(getBigPort());
 79  0
         addFig(cover);
 80  0
         addFig(getNameFig());
 81  
 
 82  0
         Rectangle r = getBounds();
 83  0
         setBounds(r.x, r.y, nameMin.width, nameMin.height);
 84  0
     }
 85  
 
 86  
     /**
 87  
      * Construct a new FigObject.
 88  
      * 
 89  
      * @param owner owning UML element
 90  
      * @param bounds position and size
 91  
      * @param settings render settings
 92  
      */
 93  
     public FigObject(Object owner, Rectangle bounds, DiagramSettings settings) {
 94  0
         super(owner, bounds, settings);
 95  0
         initFigs();
 96  0
     }
 97  
     
 98  
     /*
 99  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#getNotationProviderType()
 100  
      */
 101  
     @Override
 102  
     protected int getNotationProviderType() {
 103  0
         return NotationProviderFactory2.TYPE_OBJECT;
 104  
     }
 105  
 
 106  
     /*
 107  
      * @see java.lang.Object#clone()
 108  
      */
 109  
     @Override
 110  
     public Object clone() {
 111  0
         FigObject figClone = (FigObject) super.clone();
 112  0
         Iterator it = figClone.getFigs().iterator();
 113  0
         figClone.setBigPort((FigRect) it.next());
 114  0
         figClone.cover = (FigRect) it.next();
 115  0
         figClone.setNameFig((FigText) it.next());
 116  0
         return figClone;
 117  
     }
 118  
 
 119  
     /*
 120  
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
 121  
      */
 122  
     @Override
 123  
     public void setLineColor(Color col) {
 124  0
         cover.setLineColor(col);
 125  0
     }
 126  
 
 127  
     /*
 128  
      * @see org.tigris.gef.presentation.Fig#getLineColor()
 129  
      */
 130  
     @Override
 131  
     public Color getLineColor() {
 132  0
         return cover.getLineColor();
 133  
     }
 134  
 
 135  
     /*
 136  
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
 137  
      */
 138  
     @Override
 139  
     public void setFillColor(Color col) {
 140  0
         cover.setFillColor(col);
 141  0
     }
 142  
 
 143  
     /*
 144  
      * @see org.tigris.gef.presentation.Fig#getFillColor()
 145  
      */
 146  
     @Override
 147  
     public Color getFillColor() {
 148  0
         return cover.getFillColor();
 149  
     }
 150  
 
 151  
     /*
 152  
      * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
 153  
      */
 154  
     @Override
 155  
     public void setFilled(boolean f) {
 156  0
         cover.setFilled(f);
 157  0
     }
 158  
 
 159  
 
 160  
     @Override
 161  
     public boolean isFilled() {
 162  0
         return cover.isFilled();
 163  
     }
 164  
 
 165  
     /*
 166  
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
 167  
      */
 168  
     @Override
 169  
     public void setLineWidth(int w) {
 170  0
         cover.setLineWidth(w);
 171  0
     }
 172  
 
 173  
     /*
 174  
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
 175  
      */
 176  
     @Override
 177  
     public int getLineWidth() {
 178  0
         return cover.getLineWidth();
 179  
     }
 180  
 
 181  
     /*
 182  
      * @see org.tigris.gef.presentation.Fig#makeSelection()
 183  
      */
 184  
     @Override
 185  
     public Selection makeSelection() {
 186  0
         return new SelectionObject(this);
 187  
     }
 188  
 
 189  
     /*
 190  
      * @see org.tigris.gef.presentation.Fig#getMinimumSize()
 191  
      */
 192  
     @Override
 193  
     public Dimension getMinimumSize() {
 194  0
         Dimension nameMin = getNameFig().getMinimumSize();
 195  
 
 196  0
         int w = nameMin.width + 10;
 197  0
         int h = nameMin.height + 5;
 198  
         
 199  0
         w = Math.max(60, w);
 200  0
         return new Dimension(w, h);
 201  
     }
 202  
 
 203  
     /**
 204  
      * Override ancestor behaviour by always calling setBounds even if the
 205  
      * size hasn't changed. Without this override the Package bounds draw
 206  
      * incorrectly. This is not the best fix but is a workaround until the
 207  
      * true cause is known. See issue 6135.
 208  
      * 
 209  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateBounds()
 210  
      */
 211  
     protected void updateBounds() {
 212  0
         if (!isCheckSize()) {
 213  0
             return;
 214  
         }
 215  0
         Rectangle bbox = getBounds();
 216  0
         Dimension minSize = getMinimumSize();
 217  0
         bbox.width = Math.max(bbox.width, minSize.width);
 218  0
         bbox.height = Math.max(bbox.height, minSize.height);
 219  0
         setBounds(bbox.x, bbox.y, bbox.width, bbox.height);
 220  0
     }
 221  
 
 222  
     /*
 223  
      * Override setBounds to keep shapes looking right.
 224  
      *
 225  
      * @see org.tigris.gef.presentation.Fig#setBounds(int, int, int, int)
 226  
      */
 227  
     @Override
 228  
     protected void setStandardBounds(int x, int y, int w, int h) {
 229  0
         if (getNameFig() == null) {
 230  0
             return;
 231  
         }
 232  
 
 233  0
         Rectangle oldBounds = getBounds();
 234  
 
 235  0
         Dimension nameMin = getNameFig().getMinimumSize();
 236  
 
 237  0
         getBigPort().setBounds(x, y, w, h);
 238  0
         cover.setBounds(x, y, w, h);
 239  0
         getNameFig().setBounds(x, y, nameMin.width + 10, nameMin.height + 4);
 240  
 
 241  
         //_bigPort.setBounds(x+1, y+1, w-2, h-2);
 242  0
         _x = x; _y = y; _w = w; _h = h;
 243  
 
 244  0
         firePropChange("bounds", oldBounds, getBounds());
 245  0
         calcBounds(); //_x = x; _y = y; _w = w; _h = h;
 246  0
         updateEdges();
 247  0
     }
 248  
 
 249  
     /*
 250  
      * @see org.tigris.gef.presentation.Fig#setEnclosingFig(org.tigris.gef.presentation.Fig)
 251  
      */
 252  
     @Override
 253  
     public void setEnclosingFig(Fig encloser) {
 254  0
         assert Model.getFacade().isAObject(getOwner());
 255  
 
 256  0
         Object owner = getOwner();
 257  
 
 258  0
         if (encloser != null
 259  
                 && (Model.getFacade()
 260  
                         .isAComponentInstance(encloser.getOwner()))) {
 261  0
             Model.getCommonBehaviorHelper()
 262  
                     .setComponentInstance(owner, encloser.getOwner());
 263  0
             super.setEnclosingFig(encloser);
 264  
 
 265  0
         } else if (Model.getFacade().getComponentInstance(owner) != null) {
 266  0
             Model.getCommonBehaviorHelper().setComponentInstance(owner, null);
 267  0
             super.setEnclosingFig(null);
 268  
         }
 269  
         
 270  
         
 271  0
         if (encloser != null
 272  
                 && (Model.getFacade()
 273  
                         .isAComponent(encloser.getOwner()))) {
 274  
 
 275  0
             moveIntoComponent(encloser);
 276  0
             super.setEnclosingFig(encloser);
 277  0
         } else if (encloser != null
 278  
                 && Model.getFacade().isANode(encloser.getOwner())) {
 279  0
             super.setEnclosingFig(encloser);
 280  0
         } else if (encloser == null) {
 281  0
             super.setEnclosingFig(null);
 282  
         }
 283  0
     }
 284  
 
 285  
 }