Coverage Report - org.argouml.uml.diagram.static_structure.ui.FigClass
 
Classes in this File Line Coverage Branch Coverage Complexity
FigClass
0%
0/80
0%
0/50
4.444
 
 1  
 /* $Id: FigClass.java 17739 2010-01-09 08:39:10Z bobtarling $
 2  
  *******************************************************************************
 3  
  * Copyright (c) 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  
  *    Bob Tarling
 11  
  *******************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 // $Id: FigClass.java 17739 2010-01-09 08:39:10Z bobtarling $
 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.static_structure.ui;
 40  
 
 41  
 import java.awt.Rectangle;
 42  
 import java.util.ArrayList;
 43  
 import java.util.Iterator;
 44  
 import java.util.List;
 45  
 
 46  
 import org.argouml.model.Model;
 47  
 import org.argouml.uml.diagram.DiagramSettings;
 48  
 import org.argouml.uml.diagram.ui.FigAttributesCompartment;
 49  
 import org.tigris.gef.base.Selection;
 50  
 import org.tigris.gef.presentation.Fig;
 51  
 import org.tigris.gef.presentation.FigGroup;
 52  
 import org.tigris.gef.presentation.FigText;
 53  
 
 54  
 /**
 55  
  * Class to display graphics for a UML Class in a diagram.<p>
 56  
  * 
 57  
  * A Class may show stereotypes, a name and compartments for
 58  
  * attributes and operations.
 59  
  */
 60  
 public class FigClass extends FigClassifierBox {
 61  
 
 62  
     /**
 63  
      * Constructor for a {@link FigClass} during file load.<p>
 64  
      *
 65  
      * Parent {@link org.argouml.uml.diagram.ui.FigNodeModelElement}
 66  
      * will have created the main box {@link #getBigPort()} and its
 67  
      * name {@link #getNameFig()} and stereotype
 68  
      * (@link #getStereotypeFig()}. This constructor
 69  
      * creates a box for the attributes and operations.<p>
 70  
      *
 71  
      * The properties of all these graphic elements are adjusted
 72  
      * appropriately. The main boxes are all filled and have
 73  
      * outlines. 
 74  
      * TODO: which is wrong, since the bigPort is filled, too.
 75  
      * 
 76  
      * @param element model element to be represented by this fig.
 77  
      * @param bounds rectangle describing bounds
 78  
      * @param settings rendering settings
 79  
      */
 80  
     public FigClass(Object element, Rectangle bounds, 
 81  
             DiagramSettings settings) {
 82  0
         super(element, bounds, settings);
 83  0
         constructFigs(bounds);
 84  0
     }
 85  
 
 86  
     private void constructFigs(Rectangle bounds) {
 87  0
         enableSizeChecking(false);
 88  0
         setSuppressCalcBounds(true);
 89  
         
 90  0
         addFig(getBigPort());
 91  0
         addFig(getNameFig());
 92  
         /* Stereotype covers NameFig: */
 93  0
         addFig(getStereotypeFig());
 94  
         /* Compartments from top to bottom: */
 95  0
         addFig(new FigAttributesCompartment(
 96  
                 getOwner(),
 97  
                 DEFAULT_COMPARTMENT_BOUNDS, 
 98  
                 getSettings()));
 99  0
         addFig(getOperationsFig());
 100  
         
 101  
         // Make all the parts match the main fig
 102  0
         setFilled(true);
 103  0
         setFillColor(FILL_COLOR);
 104  0
         setLineColor(LINE_COLOR);
 105  0
         setLineWidth(LINE_WIDTH);
 106  
         
 107  
         /* Set the drop location in the case of D&D: */
 108  0
         if (bounds != null) {
 109  0
             setLocation(bounds.x, bounds.y);
 110  
         }
 111  
         
 112  0
         setSuppressCalcBounds(false);
 113  0
         setBounds(getBounds());
 114  0
         enableSizeChecking(true);
 115  0
     }
 116  
 
 117  
     @Override
 118  
     public Object clone() {
 119  0
         FigClass figClone = (FigClass) super.clone();
 120  0
         Iterator thisIter = this.getFigs().iterator();
 121  0
         Iterator cloneIter = figClone.getFigs().iterator();
 122  0
         while (thisIter.hasNext()) {
 123  0
             Fig thisFig = (Fig) thisIter.next();
 124  0
             Fig cloneFig = (Fig) cloneIter.next();
 125  0
         }
 126  0
         return figClone;
 127  
     }
 128  
 
 129  
     public Selection makeSelection() {
 130  0
         return new SelectionClass(this);
 131  
     }
 132  
 
 133  
     protected Object buildModifierPopUp() {
 134  0
         return buildModifierPopUp(ABSTRACT | LEAF | ROOT | ACTIVE);
 135  
     }
 136  
 
 137  
     /**
 138  
      * @param fgVec the FigGroup
 139  
      * @param ft    the Figtext
 140  
      * @param i     get the fig before fig i
 141  
      * @return the FigText
 142  
      */
 143  
     protected FigText getPreviousVisibleFeature(FigGroup fgVec,
 144  
                                                 FigText ft, int i) {
 145  0
         if (fgVec == null || i < 1) {
 146  0
             return null;
 147  
         }
 148  0
         FigText ft2 = null;
 149  0
         List figs = fgVec.getFigs();
 150  0
         if (i >= figs.size() || !((FigText) figs.get(i)).isVisible()) {
 151  0
             return null;
 152  
         }
 153  
         do {
 154  0
             i--;
 155  0
             while (i < 1) {
 156  0
                 if (fgVec == getAttributesFig()) {
 157  0
                     fgVec = getOperationsFig();
 158  
                 } else {
 159  0
                     fgVec = getAttributesFig();
 160  
                 }
 161  0
                 figs = fgVec.getFigs();
 162  0
                 i = figs.size() - 1;
 163  
             }
 164  0
             ft2 = (FigText) figs.get(i);
 165  0
             if (!ft2.isVisible()) {
 166  0
                 ft2 = null;
 167  
             }
 168  0
         } while (ft2 == null);
 169  0
         return ft2;
 170  
     }
 171  
 
 172  
     /**
 173  
      * @param fgVec the FigGroup
 174  
      * @param ft    the FigText
 175  
      * @param i     get the fig after fig i
 176  
      * @return the FigText
 177  
      */
 178  
     protected FigText getNextVisibleFeature(FigGroup fgVec, FigText ft, int i) {
 179  0
         if (fgVec == null || i < 1) {
 180  0
             return null;
 181  
         }
 182  0
         FigText ft2 = null;
 183  0
         List v = fgVec.getFigs();
 184  0
         if (i >= v.size() || !((FigText) v.get(i)).isVisible()) {
 185  0
             return null;
 186  
         }
 187  
         do {
 188  0
             i++;
 189  0
             while (i >= v.size()) {
 190  0
                 if (fgVec == getAttributesFig()) {
 191  0
                     fgVec = getOperationsFig();
 192  
                 } else {
 193  0
                     fgVec = getAttributesFig();
 194  
                 }
 195  0
                 v = new ArrayList(fgVec.getFigs());
 196  0
                 i = 1;
 197  
             }
 198  0
             ft2 = (FigText) v.get(i);
 199  0
             if (!ft2.isVisible()) {
 200  0
                 ft2 = null;
 201  
             }
 202  0
         } while (ft2 == null);
 203  0
         return ft2;
 204  
     }
 205  
 
 206  
     public void setEnclosingFig(Fig encloser) {
 207  0
         if (encloser == getEncloser()) {
 208  0
             return;
 209  
         }
 210  0
         if (encloser == null
 211  
                 || (encloser != null
 212  
                 && !Model.getFacade().isAInstance(encloser.getOwner()))) {
 213  0
             super.setEnclosingFig(encloser);
 214  
         }
 215  0
         if (!(Model.getFacade().isAUMLElement(getOwner()))) {
 216  0
             return;
 217  
         }
 218  0
         if (encloser != null
 219  
                 && (Model.getFacade().isAComponent(encloser.getOwner()))) {
 220  0
             moveIntoComponent(encloser);
 221  0
             super.setEnclosingFig(encloser);
 222  
         }
 223  
 
 224  0
     }
 225  
 
 226  
     @Override
 227  
     protected void updateNameText() {
 228  0
         super.updateNameText();
 229  0
         calcBounds();
 230  0
         setBounds(getBounds());
 231  0
     }
 232  
     
 233  
 }