Coverage Report - org.argouml.uml.diagram.deployment.ui.AbstractFigNode
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractFigNode
0%
0/91
0%
0/24
1.765
 
 1  
 /* $Id: AbstractFigNode.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  
  *    tfmorris
 11  
  *    Michiel van der Wulp
 12  
  *****************************************************************************
 13  
  *
 14  
  * Some portions of this file was previously release using the BSD License:
 15  
  */
 16  
 
 17  
 // Copyright (c) 2007-2009 The Regents of the University of California. All
 18  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 19  
 // software and its documentation without fee, and without a written
 20  
 // agreement is hereby granted, provided that the above copyright notice
 21  
 // and this paragraph appear in all copies. This software program and
 22  
 // documentation are copyrighted by The Regents of the University of
 23  
 // California. The software program and documentation are supplied "AS
 24  
 // IS", without any accompanying services from The Regents. The Regents
 25  
 // does not warrant that the operation of the program will be
 26  
 // uninterrupted or error-free. The end-user understands that the program
 27  
 // was developed for research purposes and is advised not to rely
 28  
 // exclusively on the program for any reason. IN NO EVENT SHALL THE
 29  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 30  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 31  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 32  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 33  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 34  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 35  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 36  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 37  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 38  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 39  
 
 40  
 package org.argouml.uml.diagram.deployment.ui;
 41  
 
 42  
 import java.awt.Color;
 43  
 import java.awt.Dimension;
 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.Collection;
 50  
 import java.util.HashSet;
 51  
 import java.util.Iterator;
 52  
 import java.util.Set;
 53  
 
 54  
 import org.argouml.model.AssociationChangeEvent;
 55  
 import org.argouml.model.AttributeChangeEvent;
 56  
 import org.argouml.model.Model;
 57  
 import org.argouml.uml.diagram.DiagramSettings;
 58  
 import org.argouml.uml.diagram.ui.FigEdgeModelElement;
 59  
 import org.argouml.uml.diagram.ui.FigNodeModelElement;
 60  
 import org.tigris.gef.base.Geometry;
 61  
 import org.tigris.gef.base.Selection;
 62  
 import org.tigris.gef.presentation.Fig;
 63  
 import org.tigris.gef.presentation.FigCube;
 64  
 import org.tigris.gef.presentation.FigRect;
 65  
 import org.tigris.gef.presentation.FigText;
 66  
 
 67  
 /**
 68  
  * Introduce abstract superclass for FigMNode & FigNodeInstance 
 69  
  * so that we can do proper inheritance.
 70  
  *
 71  
  * @author Tom Morris
 72  
  */
 73  
 public abstract class AbstractFigNode extends FigNodeModelElement {
 74  
 
 75  
     /**
 76  
      * Offset in x & y for depth perspective lines of cube.
 77  
      * TODO: This is the same value as the member 'D'in 
 78  
      * {@link org.tigris.gef.presentation.FigCube}, but there is
 79  
      * nothing enforcing that correspondence.  Things will probably
 80  
      * break if they don't match.
 81  
      */
 82  
     protected static final int DEPTH = 20;
 83  
     private FigCube cover;
 84  
     private static final int DEFAULT_X = 10;
 85  
     private static final int DEFAULT_Y = 10;
 86  
     private static final int DEFAULT_WIDTH = 200;
 87  
     private static final int DEFAULT_HEIGHT = 180;
 88  
 
 89  
     @Override
 90  
     protected Fig createBigPortFig() {
 91  0
        Fig cpfr = new CubePortFigRect(DEFAULT_X, DEFAULT_Y - DEPTH, 
 92  
                DEFAULT_WIDTH + DEPTH, 
 93  
                DEFAULT_HEIGHT + DEPTH, DEPTH);
 94  0
        cpfr.setFilled(false);
 95  0
        cpfr.setLineWidth(0);
 96  0
         return cpfr;
 97  
     }
 98  
 
 99  
     private void initFigs() {
 100  0
         cover = new FigCube(DEFAULT_X, DEFAULT_Y, DEFAULT_WIDTH,
 101  
                 DEFAULT_HEIGHT, LINE_COLOR, FILL_COLOR);
 102  
 
 103  0
         getNameFig().setLineWidth(0);
 104  0
         getNameFig().setFilled(false);
 105  0
         getNameFig().setJustification(0);
 106  
 
 107  0
         addFig(getBigPort());
 108  0
         addFig(cover);
 109  0
         addFig(getStereotypeFig());
 110  0
         addFig(getNameFig());
 111  0
     }
 112  
 
 113  
     /**
 114  
      * Construct a new AbstractFigNode.
 115  
      * 
 116  
      * @param owner owning UML element
 117  
      * @param bounds position and size
 118  
      * @param settings render settings
 119  
      */
 120  
     public AbstractFigNode(Object owner, Rectangle bounds,
 121  
             DiagramSettings settings) {
 122  0
         super(owner, bounds, settings);
 123  0
         initFigs();
 124  0
     }
 125  
     
 126  
     @Override
 127  
     public Object clone() {
 128  0
         AbstractFigNode figClone = (AbstractFigNode) super.clone();
 129  0
         Iterator it = figClone.getFigs().iterator();
 130  0
         figClone.setBigPort((FigRect) it.next());
 131  0
         figClone.cover = (FigCube) it.next();
 132  0
         it.next();
 133  0
         figClone.setNameFig((FigText) it.next());
 134  0
         return figClone;
 135  
     }
 136  
 
 137  
     @Override
 138  
     public void setLineColor(Color c) {
 139  0
         cover.setLineColor(c);
 140  0
     }
 141  
 
 142  
     @Override
 143  
     public void setLineWidth(int w) {
 144  0
         cover.setLineWidth(w);
 145  0
     }
 146  
 
 147  
 
 148  
     @Override
 149  
     public boolean isFilled() {
 150  0
         return cover.isFilled();
 151  
     }
 152  
 
 153  
     @Override
 154  
     public void setFilled(boolean f) {
 155  0
         cover.setFilled(f);
 156  0
     }
 157  
 
 158  
     @Override
 159  
     public Selection makeSelection() {
 160  0
         return new SelectionNode(this);
 161  
     }
 162  
 
 163  
     @Override
 164  
     public Dimension getMinimumSize() {
 165  0
         Dimension stereoDim = getStereotypeFig().getMinimumSize();
 166  0
         Dimension nameDim = getNameFig().getMinimumSize();
 167  
     
 168  0
         int w = Math.max(stereoDim.width, nameDim.width + 1) + DEPTH;
 169  0
         int h = stereoDim.height + nameDim.height + DEPTH;
 170  
         
 171  0
         w = Math.max(3 * DEPTH, w); // so it still looks like a cube
 172  0
         h = Math.max(3 * DEPTH, h);
 173  0
         return new Dimension(w, h);
 174  
     }
 175  
 
 176  
     @Override
 177  
     protected void setStandardBounds(int x, int y, int w, int h) {
 178  0
         if (getNameFig() == null) {
 179  0
             return;
 180  
         }
 181  0
         Rectangle oldBounds = getBounds();
 182  0
         getBigPort().setBounds(x, y, w, h);
 183  0
         cover.setBounds(x, y + DEPTH, w - DEPTH, h - DEPTH);
 184  
 
 185  0
         Dimension stereoDim = getStereotypeFig().getMinimumSize();
 186  0
         Dimension nameDim = getNameFig().getMinimumSize();
 187  0
         getNameFig().setBounds(
 188  
                 x + 4, y + DEPTH + stereoDim.height + 1,
 189  
                 w - DEPTH - 8, nameDim.height);
 190  0
         getStereotypeFig().setBounds(x + 1, y + DEPTH + 1,
 191  
                 w - DEPTH - 2, stereoDim.height);
 192  0
         _x = x;
 193  0
         _y = y;
 194  0
         _w = w;
 195  0
         _h = h;
 196  0
         firePropChange("bounds", oldBounds, getBounds());
 197  0
         updateEdges();
 198  0
     }
 199  
 
 200  
     @Override
 201  
     public void mouseClicked(MouseEvent me) {
 202  0
         super.mouseClicked(me);
 203  0
         setLineColor(LINE_COLOR);
 204  0
     }
 205  
 
 206  
     @Override
 207  
     public void setEnclosingFig(Fig encloser) {
 208  0
         if (encloser == null
 209  
                 || (encloser != null
 210  
                 && Model.getFacade().isANode(encloser.getOwner()))) {
 211  0
             super.setEnclosingFig(encloser);
 212  
         }
 213  
     
 214  0
         if (getLayer() != null) {
 215  
             // elementOrdering(figures);
 216  0
             Collection contents = getLayer().getContents();
 217  0
             Collection<FigEdgeModelElement> bringToFrontList = 
 218  
                 new ArrayList<FigEdgeModelElement>();
 219  0
             for (Object o : contents) {
 220  0
                 if (o instanceof FigEdgeModelElement) {
 221  0
                     bringToFrontList.add((FigEdgeModelElement) o);
 222  
                 }
 223  
             }
 224  0
             for (FigEdgeModelElement figEdge : bringToFrontList) {
 225  0
                 figEdge.getLayer().bringToFront(figEdge);
 226  
             }
 227  
         }
 228  0
     }
 229  
 
 230  
     @Override
 231  
     public boolean getUseTrapRect() {
 232  0
         return true;
 233  
     }
 234  
 
 235  
     @Override
 236  
     protected void modelChanged(PropertyChangeEvent mee) {
 237  0
         super.modelChanged(mee);
 238  0
         if (mee instanceof AssociationChangeEvent 
 239  
                 || mee instanceof AttributeChangeEvent) {
 240  0
             renderingChanged();
 241  0
             updateListeners(getOwner(), getOwner());
 242  0
             damage();
 243  
         }
 244  0
     }
 245  
 
 246  
     @Override
 247  
     protected void updateListeners(Object oldOwner, Object newOwner) {
 248  0
         Set<Object[]> l = new HashSet<Object[]>();
 249  0
         if (newOwner != null) {
 250  
             // add the listeners to the newOwner
 251  0
             l.add(new Object[] {newOwner, null});
 252  
             
 253  0
             Collection c = Model.getFacade().getStereotypes(newOwner);
 254  0
             Iterator i = c.iterator();
 255  0
             while (i.hasNext()) {
 256  0
                 Object st = i.next();
 257  0
                 l.add(new Object[] {st, "name"});
 258  0
             }
 259  
         }
 260  0
         updateElementListeners(l);
 261  0
     }
 262  
 
 263  
     @Override
 264  
     public Point getClosestPoint(Point anotherPt) {
 265  0
         Rectangle r = getBounds();
 266  0
         int[] xs = {
 267  
             r.x,
 268  
             r.x + DEPTH,
 269  
             r.x + r.width,
 270  
             r.x + r.width,
 271  
             r.x + r.width - DEPTH,
 272  
             r.x,
 273  
             r.x,
 274  
         };
 275  0
         int[] ys = {
 276  
             r.y + DEPTH,
 277  
             r.y,
 278  
             r.y,
 279  
             r.y + r.height - DEPTH,
 280  
             r.y + r.height,
 281  
             r.y + r.height,
 282  
             r.y + DEPTH,
 283  
         };
 284  0
         Point p = Geometry.ptClosestTo(xs, ys, 7, anotherPt);
 285  0
         return p;
 286  
     }
 287  
 
 288  
 }