Coverage Report - org.argouml.uml.diagram.state.ui.FigSubmachineState
 
Classes in this File Line Coverage Branch Coverage Complexity
FigSubmachineState
0%
0/121
0%
0/30
1.739
 
 1  
 /* $Id: FigSubmachineState.java 18612 2010-07-31 11:47:45Z bobtarling $
 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) 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.state.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.Iterator;
 46  
 
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.uml.diagram.DiagramSettings;
 49  
 import org.argouml.uml.diagram.ui.FigSingleLineText;
 50  
 import org.tigris.gef.presentation.FigLine;
 51  
 import org.tigris.gef.presentation.FigRRect;
 52  
 import org.tigris.gef.presentation.FigRect;
 53  
 import org.tigris.gef.presentation.FigText;
 54  
 
 55  
 /**
 56  
  * Class to display graphics for a UML SubmachineState in a diagram.
 57  
  *
 58  
  * @author pepargouml@yahoo.es
 59  
  */
 60  
 
 61  
 public class FigSubmachineState extends FigState {
 62  
 
 63  
     private static final int INCLUDE_HEIGHT = NAME_FIG_HEIGHT;
 64  
     private static final int WIDTH = 90;
 65  
     
 66  
     private FigRect cover;
 67  
     private FigLine divider;
 68  
     private FigLine divider2;
 69  
     private FigRect circle1;
 70  
     private FigRect circle2;
 71  
     private FigLine circle1tocircle2;
 72  
     private FigText include;
 73  
 
 74  
     
 75  
     /**
 76  
      * Construct a new FigSubmachineState.
 77  
      * 
 78  
      * @param owner owning UML element
 79  
      * @param bounds position and size
 80  
      * @param settings rendering settings
 81  
      */
 82  
     public FigSubmachineState(Object owner, Rectangle bounds,
 83  
             DiagramSettings settings) {
 84  0
         super(owner, bounds, settings);
 85  0
         include = new FigSingleLineText(owner, 
 86  
                 new Rectangle(X0, Y0, WIDTH, INCLUDE_HEIGHT), settings, true);
 87  0
         initFigs();
 88  0
     }
 89  
 
 90  
     private void initFigs() {
 91  0
         cover =
 92  
             new FigRRect(getInitialX(), getInitialY(),
 93  
                 getInitialWidth(), getInitialHeight(),
 94  
                 LINE_COLOR, FILL_COLOR);
 95  
 
 96  0
         getBigPort().setLineWidth(0);
 97  
 
 98  0
         divider =
 99  
                 new FigLine(getInitialX(),
 100  
                         getInitialY() + 2 + getNameFig().getBounds().height + 1,
 101  
                         getInitialWidth() - 1,
 102  
                         getInitialY() + 2 + getNameFig().getBounds().height + 1,
 103  
                         LINE_COLOR);
 104  
 
 105  0
         include.setText(placeString());
 106  0
         include.setBounds(getInitialX() + 2, getInitialY() + 2,
 107  
                 getInitialWidth() - 4, include.getBounds().height);
 108  0
         include.setEditable(false);
 109  0
         include.setBotMargin(4); // leave some space below the "include"
 110  
 
 111  0
         divider2 =
 112  
                 new FigLine(getInitialX(),
 113  
                         getInitialY() + 2 + getNameFig().getBounds().height + 1,
 114  
                         getInitialWidth() - 1,
 115  
                         getInitialY() + 2 + getNameFig().getBounds().height + 1,
 116  
                         LINE_COLOR);
 117  
 
 118  0
         circle1 =
 119  
             new FigRRect(getInitialX() + getInitialWidth() - 55,
 120  
                 getInitialY() + getInitialHeight() - 15,
 121  
                 20, 10,
 122  
                 LINE_COLOR, FILL_COLOR);
 123  0
         circle2 =
 124  
             new FigRRect(getInitialX() + getInitialWidth() - 25,
 125  
                 getInitialY() + getInitialHeight() - 15,
 126  
                 20, 10,
 127  
                 LINE_COLOR, FILL_COLOR);
 128  
 
 129  0
         circle1tocircle2 =
 130  
                 new FigLine(getInitialX() + getInitialWidth() - 35,
 131  
                         getInitialY() + getInitialHeight() - 10,
 132  
                         getInitialX() + getInitialWidth() - 25,
 133  
                         getInitialY() + getInitialHeight() - 10,
 134  
                         LINE_COLOR);
 135  
 
 136  0
         addFig(getBigPort());
 137  0
         addFig(cover);
 138  0
         addFig(getNameFig());
 139  0
         addFig(divider);
 140  0
         addFig(include);
 141  0
         addFig(divider2);
 142  0
         addFig(getInternal());
 143  0
         addFig(circle1);
 144  0
         addFig(circle2);
 145  0
         addFig(circle1tocircle2);
 146  
 
 147  0
         setBounds(getBounds());
 148  0
     }
 149  
 
 150  
     /*
 151  
      * @see java.lang.Object#clone()
 152  
      */
 153  
     @Override
 154  
     public Object clone() {
 155  0
         FigSubmachineState figClone = (FigSubmachineState) super.clone();
 156  0
         Iterator it = figClone.getFigs().iterator();
 157  0
         figClone.setBigPort((FigRect) it.next());
 158  0
         figClone.cover = (FigRect) it.next();
 159  0
         figClone.setNameFig((FigText) it.next());
 160  0
         figClone.divider = (FigLine) it.next();
 161  0
         figClone.include = (FigText) it.next();
 162  0
         figClone.divider2 = (FigLine) it.next();
 163  0
         figClone.setInternal((FigText) it.next());
 164  0
         return figClone;
 165  
     }
 166  
 
 167  
     /*
 168  
      * @see org.tigris.gef.presentation.Fig#getMinimumSize()
 169  
      */
 170  
     @Override
 171  
     public Dimension getMinimumSize() {
 172  0
         Dimension nameDim = getNameFig().getMinimumSize();
 173  0
         Dimension internalDim = getInternal().getMinimumSize();
 174  0
         Dimension includeDim = include.getMinimumSize();
 175  
 
 176  0
         int h =
 177  
             SPACE_TOP + nameDim.height
 178  
             + SPACE_MIDDLE + includeDim.height
 179  
             + SPACE_MIDDLE + internalDim.height
 180  
             + SPACE_BOTTOM;
 181  0
         int waux =
 182  
             Math.max(nameDim.width,
 183  
                 internalDim.width) + 2 * MARGIN;
 184  0
         int w = Math.max(waux, includeDim.width + 50);
 185  0
         return new Dimension(w, h);
 186  
     }
 187  
 
 188  
     /*
 189  
      * @see org.tigris.gef.presentation.Fig#getUseTrapRect()
 190  
      */
 191  
     @Override
 192  
     public boolean getUseTrapRect() {
 193  0
         return true;
 194  
     }
 195  
 
 196  
     /*
 197  
      * Override setBounds to keep shapes looking right.
 198  
      *
 199  
      * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
 200  
      */
 201  
     @Override
 202  
     protected void setStandardBounds(int x, int y, int w, int h) {
 203  0
         if (getNameFig() == null) {
 204  0
             return;
 205  
         }
 206  
 
 207  0
         Rectangle oldBounds = getBounds();
 208  0
         Dimension nameDim = getNameFig().getMinimumSize();
 209  0
         Dimension includeDim = include.getMinimumSize();
 210  
 
 211  0
         getNameFig().setBounds(x + MARGIN,
 212  
                 y + SPACE_TOP,
 213  
                 w - 2 * MARGIN,
 214  
                 nameDim.height);
 215  0
         divider.setShape(x,
 216  
                 y + DIVIDER_Y + nameDim.height,
 217  
                 x + w - 1,
 218  
                 y + DIVIDER_Y + nameDim.height);
 219  
 
 220  0
         include.setBounds(x + MARGIN,
 221  
                 y + SPACE_TOP + nameDim.height + SPACE_TOP,
 222  
                 w - 2 * MARGIN,
 223  
                 includeDim.height);
 224  0
         divider2.setShape(x,
 225  
                 y + nameDim.height + DIVIDER_Y + includeDim.height + DIVIDER_Y,
 226  
                 x + w - 1,
 227  
                 y + nameDim.height + DIVIDER_Y + includeDim.height + DIVIDER_Y);
 228  
 
 229  0
         getInternal().setBounds(
 230  
                 x + MARGIN,
 231  
                 y + SPACE_TOP + nameDim.height
 232  
                     + SPACE_TOP + includeDim.height + SPACE_MIDDLE,
 233  
                 w - 2 * MARGIN,
 234  
                 h - SPACE_TOP - nameDim.height
 235  
                     - SPACE_TOP - includeDim.height
 236  
                     - SPACE_MIDDLE - SPACE_BOTTOM);
 237  
 
 238  0
         circle1.setBounds(x + w - 55,
 239  
                 y + h - 15,
 240  
                 20, 10);
 241  0
         circle2.setBounds(x + w - 25,
 242  
                 y + h - 15,
 243  
                 20, 10);
 244  0
         circle1tocircle2.setShape(x + w - 35,
 245  
                 y + h - 10,
 246  
                 x + w - 25,
 247  
                 y + h - 10);
 248  
 
 249  0
         getBigPort().setBounds(x, y, w, h);
 250  0
         cover.setBounds(x, y, w, h);
 251  
 
 252  0
         calcBounds(); //_x = x; _y = y; _w = w; _h = h;
 253  0
         updateEdges();
 254  0
         firePropChange("bounds", oldBounds, getBounds());
 255  0
     }
 256  
 
 257  
     /*
 258  
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
 259  
      */
 260  
     @Override
 261  
     public void setLineColor(Color col) {
 262  0
         cover.setLineColor(col);
 263  0
         divider.setLineColor(col);
 264  0
         divider2.setLineColor(col);
 265  0
         circle1.setLineColor(col);
 266  0
         circle2.setLineColor(col);
 267  0
         circle1tocircle2.setLineColor(col);
 268  0
     }
 269  
 
 270  
     /*
 271  
      * @see org.tigris.gef.presentation.Fig#getLineColor()
 272  
      */
 273  
     @Override
 274  
     public Color getLineColor() {
 275  0
         return cover.getLineColor();
 276  
     }
 277  
 
 278  
     /*
 279  
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
 280  
      */
 281  
     @Override
 282  
     public void setFillColor(Color col) {
 283  0
         cover.setFillColor(col);
 284  0
     }
 285  
 
 286  
     /*
 287  
      * @see org.tigris.gef.presentation.Fig#getFillColor()
 288  
      */
 289  
     @Override
 290  
     public Color getFillColor() {
 291  0
         return cover.getFillColor();
 292  
     }
 293  
 
 294  
     /*
 295  
      * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
 296  
      */
 297  
     @Override
 298  
     public void setFilled(boolean f) {
 299  0
         cover.setFilled(f);
 300  0
         getBigPort().setFilled(f);
 301  0
     }
 302  
 
 303  
 
 304  
     @Override
 305  
     public boolean isFilled() {
 306  0
         return cover.isFilled();
 307  
     }
 308  
 
 309  
     /*
 310  
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
 311  
      */
 312  
     @Override
 313  
     public void setLineWidth(int w) {
 314  0
         cover.setLineWidth(w);
 315  0
         divider.setLineWidth(w);
 316  0
         divider2.setLineWidth(w);
 317  0
     }
 318  
 
 319  
     /*
 320  
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
 321  
      */
 322  
     @Override
 323  
     public int getLineWidth() {
 324  0
         return cover.getLineWidth();
 325  
     }
 326  
 
 327  
     ////////////////////////////////////////////////////////////////
 328  
     // event processing
 329  
 
 330  
     /*
 331  
      * Update the text labels and listeners.
 332  
      *
 333  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent)
 334  
      */
 335  
     protected void modelChanged(PropertyChangeEvent mee) {
 336  0
         super.modelChanged(mee);
 337  
         
 338  
         // TODO: Rather than specifically ignore some item maybe it would be better
 339  
         // to specifically state what items are of interest. Otherwise we may still
 340  
         // be acting on other events we don't need
 341  0
         if (!Model.getFacade().isATransition(mee.getNewValue())
 342  
                 && getOwner() != null) {
 343  0
             if ((mee.getSource().equals(getOwner()))) {
 344  0
                 if ((mee.getPropertyName()).equals("submachine")) {
 345  0
                     updateInclude();
 346  0
                     if (mee.getOldValue() != null) {
 347  0
                         updateListenersX(getOwner(), mee.getOldValue());
 348  
                     }
 349  
                 }
 350  
             } else {
 351  0
                 if (mee.getSource()
 352  
                         == Model.getFacade().getSubmachine(getOwner())) {
 353  
                     // The Machine State has got a new name
 354  0
                     if (mee.getPropertyName().equals("name")) {
 355  0
                         updateInclude();
 356  
                     }
 357  
                     // The Machine State has been deleted from model
 358  0
                     if (mee.getPropertyName().equals("top")) {
 359  0
                         updateListeners(getOwner(), null);
 360  
                     }
 361  
                 }
 362  
             }
 363  
         }
 364  0
     }
 365  
 
 366  
     /*
 367  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(java.lang.Object)
 368  
      */
 369  
     @Override
 370  
     protected void updateListeners(Object oldOwner, Object newOwner) {
 371  0
         super.updateListeners(oldOwner, newOwner);
 372  0
         if (newOwner != null) {
 373  0
             Object newSm = Model.getFacade().getSubmachine(newOwner);
 374  0
             if (newSm != null) {
 375  0
                 addElementListener(newSm);
 376  
             }
 377  
         }
 378  0
     }
 379  
 
 380  
     private void updateListenersX(Object newOwner, Object oldV) {
 381  0
         this.updateListeners(getOwner(), newOwner);
 382  0
         if (oldV != null) {
 383  0
             removeElementListener(oldV);
 384  
         }
 385  0
     }
 386  
 
 387  
     private void updateInclude() {
 388  0
         include.setText(generateSubmachine(getOwner()));
 389  0
         calcBounds();
 390  0
         setBounds(getBounds());
 391  0
         damage();
 392  0
     }
 393  
 
 394  
     private String generateSubmachine(Object m) {
 395  0
         Object c = Model.getFacade().getSubmachine(m);
 396  0
         String s = "include / ";
 397  0
         if ((c == null)
 398  
                 || (Model.getFacade().getName(c) == null)
 399  
                 || (Model.getFacade().getName(c).length() == 0)) {
 400  0
             return s;
 401  
         }
 402  0
         return (s + Model.getFacade().getName(c));
 403  
     }
 404  
 
 405  
     /*
 406  
      * @see org.argouml.uml.diagram.state.ui.FigState#getInitialHeight()
 407  
      */
 408  
     protected int getInitialHeight() {
 409  0
         return 150;
 410  
     }
 411  
 
 412  
     /*
 413  
      * @see org.argouml.uml.diagram.state.ui.FigState#getInitialWidth()
 414  
      */
 415  
     protected int getInitialWidth() {
 416  0
         return 180;
 417  
     }
 418  
 
 419  
     /*
 420  
      * @see org.argouml.uml.diagram.state.ui.FigState#getInitialX()
 421  
      */
 422  
     protected int getInitialX() {
 423  0
         return 0;
 424  
     }
 425  
 
 426  
     /*
 427  
      * @see org.argouml.uml.diagram.state.ui.FigState#getInitialY()
 428  
      */
 429  
     protected int getInitialY() {
 430  0
         return 0;
 431  
     }
 432  
 
 433  
 }