| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FigActionState |
|
| 1.3125;1.312 |
| 1 | /* $Id: FigActionState.java 18732 2010-09-11 18:34:38Z 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) 1996-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.activity.ui; | |
| 41 | ||
| 42 | import java.awt.Color; | |
| 43 | import java.awt.Dimension; | |
| 44 | import java.awt.Rectangle; | |
| 45 | import java.beans.PropertyChangeEvent; | |
| 46 | import java.util.Iterator; | |
| 47 | ||
| 48 | import org.argouml.model.AddAssociationEvent; | |
| 49 | import org.argouml.model.AttributeChangeEvent; | |
| 50 | import org.argouml.model.Model; | |
| 51 | import org.argouml.notation.NotationProviderFactory2; | |
| 52 | import org.argouml.uml.diagram.DiagramSettings; | |
| 53 | import org.argouml.uml.diagram.state.ui.FigStateVertex; | |
| 54 | import org.argouml.uml.diagram.ui.FigMultiLineTextWithBold; | |
| 55 | import org.tigris.gef.presentation.Fig; | |
| 56 | import org.tigris.gef.presentation.FigRRect; | |
| 57 | import org.tigris.gef.presentation.FigText; | |
| 58 | ||
| 59 | /** | |
| 60 | * Class to display graphics for a UML ActionState in a diagram. | |
| 61 | * It contains a multiline textfield for the Entry Action Expression. | |
| 62 | * | |
| 63 | * @author ics 125b silverbullet team | |
| 64 | */ | |
| 65 | public class FigActionState extends FigStateVertex { | |
| 66 | ||
| 67 | private static final int HEIGHT = 25; | |
| 68 | ||
| 69 | private static final int STATE_WIDTH = 90; | |
| 70 | ||
| 71 | private static final int PADDING = 8; | |
| 72 | ||
| 73 | private FigRRect cover; | |
| 74 | ||
| 75 | /** | |
| 76 | * Constructor used by PGML parser. | |
| 77 | * | |
| 78 | * @param owner the owning UML element | |
| 79 | * @param bounds rectangle describing bounds | |
| 80 | * @param settings rendering settings | |
| 81 | */ | |
| 82 | public FigActionState(Object owner, Rectangle bounds, | |
| 83 | DiagramSettings settings) { | |
| 84 | 0 | super(owner, bounds, settings); |
| 85 | 0 | initializeActionState(); |
| 86 | 0 | } |
| 87 | ||
| 88 | @Override | |
| 89 | protected Fig createBigPortFig() { | |
| 90 | 0 | FigRRect frr = new FigRRect(X0 + 1, Y0 + 1, STATE_WIDTH - 2, HEIGHT - 2, |
| 91 | DEBUG_COLOR, DEBUG_COLOR); | |
| 92 | 0 | frr.setCornerRadius(frr.getHeight() / 2); |
| 93 | 0 | return frr; |
| 94 | } | |
| 95 | ||
| 96 | private void initializeActionState() { | |
| 97 | 0 | cover = new FigRRect(X0, Y0, STATE_WIDTH, HEIGHT, |
| 98 | LINE_COLOR, FILL_COLOR); | |
| 99 | 0 | cover.setCornerRadius(getHeight() / 2); |
| 100 | ||
| 101 | // overrule the single-line name-fig created by the parent | |
| 102 | 0 | Rectangle bounds = new Rectangle(X0 + PADDING, Y0, |
| 103 | STATE_WIDTH - PADDING * 2, HEIGHT); | |
| 104 | 0 | setNameFig(new FigMultiLineTextWithBold( |
| 105 | getOwner(), | |
| 106 | bounds, | |
| 107 | getSettings(), | |
| 108 | true)); | |
| 109 | 0 | getNameFig().setText(placeString()); |
| 110 | 0 | getNameFig().setBotMargin(7); // make space for the clarifier |
| 111 | 0 | getNameFig().setTopMargin(7); // for vertical symmetry |
| 112 | 0 | getNameFig().setRightMargin(4); // margin between text and border |
| 113 | 0 | getNameFig().setLeftMargin(4); |
| 114 | 0 | getNameFig().setJustification(FigText.JUSTIFY_CENTER); |
| 115 | ||
| 116 | 0 | getBigPort().setLineWidth(0); |
| 117 | ||
| 118 | // add Figs to the FigNode in back-to-front order | |
| 119 | 0 | addFig(getBigPort()); |
| 120 | 0 | addFig(cover); |
| 121 | 0 | addFig(getStereotypeFig()); |
| 122 | 0 | addFig(getNameFig()); |
| 123 | ||
| 124 | //setBlinkPorts(false); //make port invisible unless mouse enters | |
| 125 | 0 | Rectangle r = getBounds(); |
| 126 | 0 | setBounds(r.x, r.y, r.width, r.height); |
| 127 | 0 | } |
| 128 | ||
| 129 | /** | |
| 130 | * The FigActionState needs a different | |
| 131 | * NotationProvider for its "name" field. | |
| 132 | * | |
| 133 | * @return the type of the notation provider | |
| 134 | */ | |
| 135 | @Override | |
| 136 | protected int getNotationProviderType() { | |
| 137 | 0 | return NotationProviderFactory2.TYPE_ACTIONSTATE; |
| 138 | } | |
| 139 | ||
| 140 | /* | |
| 141 | * @see java.lang.Object#clone() | |
| 142 | */ | |
| 143 | @Override | |
| 144 | public Object clone() { | |
| 145 | 0 | FigActionState figClone = (FigActionState) super.clone(); |
| 146 | 0 | Iterator it = figClone.getFigs().iterator(); |
| 147 | 0 | figClone.setBigPort((FigRRect) it.next()); |
| 148 | 0 | figClone.cover = (FigRRect) it.next(); |
| 149 | 0 | figClone.setNameFig((FigText) it.next()); |
| 150 | /* TODO: Do we need to clone the stereotype(s)? */ | |
| 151 | 0 | return figClone; |
| 152 | } | |
| 153 | ||
| 154 | /* | |
| 155 | * @see org.tigris.gef.presentation.Fig#getMinimumSize() | |
| 156 | */ | |
| 157 | @Override | |
| 158 | public Dimension getMinimumSize() { | |
| 159 | 0 | Dimension stereoDim = getStereotypeFig().getMinimumSize(); |
| 160 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
| 161 | ||
| 162 | 0 | int w = Math.max(stereoDim.width, nameDim.width) + PADDING * 2; |
| 163 | /* The stereoDim has height=2, even if it is empty, | |
| 164 | * hence the -2 below: */ | |
| 165 | 0 | int h = stereoDim.height - 2 + nameDim.height + PADDING; |
| 166 | 0 | w = Math.max(w, h + 44); // the width needs to be > the height |
| 167 | 0 | return new Dimension(w, h); |
| 168 | } | |
| 169 | ||
| 170 | /* | |
| 171 | * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int) | |
| 172 | * | |
| 173 | * Override setBounds to keep shapes looking right. | |
| 174 | */ | |
| 175 | @Override | |
| 176 | protected void setStandardBounds(int x, int y, int w, int h) { | |
| 177 | 0 | if (getNameFig() == null) { |
| 178 | 0 | return; |
| 179 | } | |
| 180 | 0 | Rectangle oldBounds = getBounds(); |
| 181 | ||
| 182 | 0 | Dimension stereoDim = getStereotypeFig().getMinimumSize(); |
| 183 | 0 | Dimension nameDim = getNameFig().getMinimumSize(); |
| 184 | 0 | getNameFig().setBounds(x + PADDING, y + stereoDim.height, |
| 185 | w - PADDING * 2, nameDim.height); | |
| 186 | 0 | getStereotypeFig().setBounds(x + PADDING, y, |
| 187 | w - PADDING * 2, stereoDim.height); | |
| 188 | 0 | getBigPort().setBounds(x + 1, y + 1, w - 2, h - 2); |
| 189 | 0 | cover.setBounds(x, y, w, h); |
| 190 | 0 | ((FigRRect) getBigPort()).setCornerRadius(h); |
| 191 | 0 | cover.setCornerRadius(h); |
| 192 | ||
| 193 | 0 | calcBounds(); |
| 194 | 0 | updateEdges(); |
| 195 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
| 196 | 0 | } |
| 197 | ||
| 198 | /* | |
| 199 | * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color) | |
| 200 | */ | |
| 201 | @Override | |
| 202 | public void setLineColor(Color col) { | |
| 203 | 0 | cover.setLineColor(col); |
| 204 | 0 | } |
| 205 | ||
| 206 | /* | |
| 207 | * @see org.tigris.gef.presentation.Fig#getLineColor() | |
| 208 | */ | |
| 209 | @Override | |
| 210 | public Color getLineColor() { | |
| 211 | 0 | return cover.getLineColor(); |
| 212 | } | |
| 213 | ||
| 214 | /* | |
| 215 | * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color) | |
| 216 | */ | |
| 217 | @Override | |
| 218 | public void setFillColor(Color col) { | |
| 219 | 0 | cover.setFillColor(col); |
| 220 | 0 | } |
| 221 | ||
| 222 | /* | |
| 223 | * @see org.tigris.gef.presentation.Fig#getFillColor() | |
| 224 | */ | |
| 225 | @Override | |
| 226 | public Color getFillColor() { | |
| 227 | 0 | return cover.getFillColor(); |
| 228 | } | |
| 229 | ||
| 230 | /* | |
| 231 | * @see org.tigris.gef.presentation.Fig#setFilled(boolean) | |
| 232 | */ | |
| 233 | @Override | |
| 234 | public void setFilled(boolean f) { | |
| 235 | 0 | cover.setFilled(f); |
| 236 | 0 | } |
| 237 | ||
| 238 | @Override | |
| 239 | public boolean isFilled() { | |
| 240 | 0 | return cover.isFilled(); |
| 241 | } | |
| 242 | ||
| 243 | /* | |
| 244 | * @see org.tigris.gef.presentation.Fig#setLineWidth(int) | |
| 245 | */ | |
| 246 | @Override | |
| 247 | public void setLineWidth(int w) { | |
| 248 | 0 | cover.setLineWidth(w); |
| 249 | 0 | } |
| 250 | ||
| 251 | /* | |
| 252 | * @see org.tigris.gef.presentation.Fig#getLineWidth() | |
| 253 | */ | |
| 254 | @Override | |
| 255 | public int getLineWidth() { | |
| 256 | 0 | return cover.getLineWidth(); |
| 257 | } | |
| 258 | ||
| 259 | /* | |
| 260 | * @see org.argouml.uml.diagram.ui.FigNodeModelElement#modelChanged(java.beans.PropertyChangeEvent) | |
| 261 | */ | |
| 262 | @Override | |
| 263 | protected void modelChanged(PropertyChangeEvent mee) { | |
| 264 | 0 | super.modelChanged(mee); |
| 265 | 0 | if (mee instanceof AddAssociationEvent |
| 266 | || mee instanceof AttributeChangeEvent) { | |
| 267 | // TODO: Rather than specifically ignore some item maybe it would be better | |
| 268 | // to specifically state what items are of interest. Otherwise we may still | |
| 269 | // be acting on other events we don't need | |
| 270 | 0 | if (!Model.getFacade().isATransition(mee.getNewValue())) { |
| 271 | 0 | renderingChanged(); |
| 272 | 0 | damage(); |
| 273 | } | |
| 274 | } | |
| 275 | 0 | } |
| 276 | } |