Coverage Report - org.argouml.uml.diagram.state.ui.FigFinalState
 
Classes in this File Line Coverage Branch Coverage Complexity
FigFinalState
0%
0/68
0%
0/14
1.353
 
 1  
 /* $Id: FigFinalState.java 17862 2010-01-12 20:06:14Z 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) 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.Rectangle;
 43  
 import java.awt.event.MouseEvent;
 44  
 import java.util.Iterator;
 45  
 import java.util.List;
 46  
 
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.uml.diagram.DiagramSettings;
 49  
 import org.argouml.uml.diagram.activity.ui.SelectionActionState;
 50  
 import org.argouml.uml.diagram.use_case.ui.FigUseCase.FigMyCircle;
 51  
 import org.tigris.gef.base.Globals;
 52  
 import org.tigris.gef.base.Selection;
 53  
 import org.tigris.gef.presentation.Fig;
 54  
 import org.tigris.gef.presentation.FigCircle;
 55  
 
 56  
 /**
 57  
  * Class to display graphics for a UML FinalState in a diagram.
 58  
  * <p>
 59  
  * This class supports any line width.
 60  
  *
 61  
  * @author ics125b spring 98
 62  
  */
 63  0
 public class FigFinalState extends FigStateVertex {
 64  
 
 65  
     /**
 66  
      * The diameter of the disc when the line width would be 0
 67  
      */
 68  
     private static final int DISC = 22;
 69  
     
 70  
     /**
 71  
      * The fixed outside diameter.
 72  
      */
 73  
     private static final int DIA = DISC + 2 * LINE_WIDTH;
 74  
 
 75  
     private FigCircle inCircle;
 76  
     private FigCircle outCircle;
 77  
 
 78  
     
 79  
     /**
 80  
      * Construct a new FigFinalState.
 81  
      * 
 82  
      * @param owner owning UML element
 83  
      * @param bounds position and size
 84  
      * @param settings rendering settings
 85  
      */
 86  
     public FigFinalState(Object owner, Rectangle bounds, 
 87  
             DiagramSettings settings) {
 88  0
         super(owner, bounds, settings);
 89  0
         initFigs(bounds);
 90  0
     }
 91  
 
 92  
     private void initFigs(Rectangle bounds) {
 93  0
         setEditable(false);
 94  0
         Color handleColor = Globals.getPrefs().getHandleColor();
 95  0
         outCircle =
 96  
             new FigCircle(X0, Y0, DIA, DIA, LINE_COLOR, FILL_COLOR);
 97  0
         inCircle =
 98  
             new FigCircle(
 99  
                           X0 + 5,
 100  
                           Y0 + 5,
 101  
                           DIA - 10,
 102  
                           DIA - 10,
 103  
                           handleColor,
 104  
                           LINE_COLOR);
 105  
 
 106  0
         outCircle.setLineWidth(LINE_WIDTH);
 107  0
         outCircle.setLineColor(LINE_COLOR);
 108  0
         inCircle.setLineWidth(0);
 109  
 
 110  0
         addFig(getBigPort());
 111  0
         addFig(outCircle);
 112  0
         addFig(inCircle);
 113  
 
 114  0
         setBlinkPorts(false); //make port invisible unless mouse enters
 115  
 
 116  
         /* Set the drop location in the case of D&D: */
 117  0
         if (bounds != null) {
 118  0
             setLocation(bounds.x, bounds.y);
 119  
         }
 120  
 
 121  0
         setSuppressCalcBounds(false);
 122  0
         setBounds(getBounds());
 123  0
         enableSizeChecking(true);
 124  0
     }
 125  
     
 126  
     @Override
 127  
     protected Fig createBigPortFig() {
 128  0
         return new FigMyCircle(X0, Y0, DIA, DIA, 
 129  
                 LINE_COLOR, FILL_COLOR);
 130  
     }
 131  
 
 132  
     @Override
 133  
     public Object clone() {
 134  0
         FigFinalState figClone = (FigFinalState) super.clone();
 135  0
         Iterator it = figClone.getFigs().iterator();
 136  0
         figClone.setBigPort((FigCircle) it.next());
 137  0
         figClone.outCircle = (FigCircle) it.next();
 138  0
         figClone.inCircle = (FigCircle) it.next();
 139  
 
 140  0
         return figClone;
 141  
     }
 142  
 
 143  
     /*
 144  
      * @see org.tigris.gef.presentation.Fig#makeSelection()
 145  
      */
 146  
     @Override
 147  
     public Selection makeSelection() {
 148  0
         Object pstate = getOwner();
 149  0
         Selection sel = null;
 150  0
         if ( pstate != null) {
 151  0
             if (Model.getFacade().isAActivityGraph(
 152  
                             Model.getFacade().getStateMachine(
 153  
                             Model.getFacade().getContainer(pstate)))) {
 154  0
                 sel = new SelectionActionState(this);
 155  0
                 ((SelectionActionState) sel).setOutgoingButtonEnabled(false);
 156  
             } else {
 157  0
                 sel = new SelectionState(this);
 158  0
                 ((SelectionState) sel).setOutgoingButtonEnabled(false);
 159  
             }
 160  
         }
 161  0
         return sel;
 162  
     }
 163  
 
 164  
     /**
 165  
      * Final states are fixed size.
 166  
      * @return false
 167  
      * @see org.tigris.gef.presentation.Fig#isResizable()
 168  
      */
 169  
     @Override
 170  
     public boolean isResizable() {
 171  0
         return false;
 172  
     }
 173  
 
 174  
     /*
 175  
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
 176  
      */
 177  
     @Override
 178  
     public void setLineColor(Color col) {
 179  0
         outCircle.setLineColor(col);
 180  0
         inCircle.setFillColor(col);
 181  0
     }
 182  
 
 183  
     /*
 184  
      * @see org.tigris.gef.presentation.Fig#getLineColor()
 185  
      */
 186  
     @Override
 187  
     public Color getLineColor() {
 188  0
         return outCircle.getLineColor();
 189  
     }
 190  
 
 191  
     /*
 192  
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
 193  
      */
 194  
     @Override
 195  
     public void setFillColor(Color col) {
 196  0
         if (Color.black.equals(col)) {
 197  
             /* See issue 5721. 
 198  
              * Projects before 0.28 have their fill color set to black.
 199  
              * We refuse that color and replace by white.
 200  
              * All other fill colors are accepted: */
 201  0
             col = Color.white;
 202  
         }
 203  0
         outCircle.setFillColor(col);
 204  0
     }
 205  
 
 206  
     /*
 207  
      * @see org.tigris.gef.presentation.Fig#getFillColor()
 208  
      */
 209  
     @Override
 210  
     public Color getFillColor() {
 211  0
         return outCircle.getFillColor();
 212  
     }
 213  
 
 214  
     /*
 215  
      * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
 216  
      */
 217  
     @Override
 218  
     public void setFilled(boolean f) {
 219  
         // ignored - rendering is fixed
 220  0
     }
 221  
 
 222  
     
 223  
     @Override
 224  
     public boolean isFilled() {
 225  0
         return true;
 226  
     }
 227  
 
 228  
     /*
 229  
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
 230  
      */
 231  
     @Override
 232  
     public void setLineWidth(int w) {
 233  0
         outCircle.setLineWidth(w);
 234  0
     }
 235  
 
 236  
     /*
 237  
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
 238  
      */
 239  
     @Override
 240  
     public int getLineWidth() {
 241  0
         return outCircle.getLineWidth();
 242  
     }
 243  
 
 244  
     /*
 245  
      * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
 246  
      */
 247  
     @Override
 248  
     public void mouseClicked(MouseEvent me) {
 249  
         // ignore mouse clicks
 250  0
     }
 251  
 
 252  
     /**
 253  
      * Return a list of gravity points around the outer circle. Used in place of
 254  
      * the default bounding box.
 255  
      *
 256  
      * {@inheritDoc}
 257  
      */
 258  
     @Override
 259  
     public List getGravityPoints() {
 260  0
         return getCircleGravityPoints();
 261  
     }
 262  
 
 263  
     /**
 264  
      * Override setBounds to keep shapes looking right.
 265  
      * Special care is taken to have the inner circle nicely centered 
 266  
      * within the outer circle.
 267  
      * {@inheritDoc}
 268  
      */
 269  
     @Override
 270  
     protected void setStandardBounds(int x, int y, int w, int h) {
 271  0
         if (getNameFig() == null) {
 272  0
             return;
 273  
         }
 274  0
         Rectangle oldBounds = getBounds();
 275  
 
 276  
         /* This assert fails for the TestPropertyPanels, 
 277  
          * file GUITestPropertyPanels.zargo: */
 278  
         //assert  w == h;
 279  
 
 280  
         /* Ignore w and h from here on. */
 281  
 
 282  0
         int out_d = DISC + 2 * getLineWidth();
 283  
         
 284  0
         getBigPort().setBounds(x, y, out_d, out_d);
 285  0
         outCircle.setBounds(x, y, out_d, out_d);
 286  
 
 287  0
         int inner_d = (out_d - 2 * getLineWidth()) - 6;
 288  0
         assert (inner_d % 2) == (out_d % 2);
 289  
         // keep d even or odd, just like the line width:
 290  0
         inner_d = inner_d - (getLineWidth() % 2);
 291  0
         inCircle.setBounds(
 292  
                 x + (out_d - inner_d) / 2, 
 293  
                 y + (out_d - inner_d) / 2, 
 294  
                 inner_d, 
 295  
                 inner_d);
 296  
 
 297  0
         calcBounds(); //_x = x; _y = y; _w = w; _h = h;
 298  0
         updateEdges();
 299  0
         firePropChange("bounds", oldBounds, getBounds());
 300  0
     }
 301  
 
 302  
 }