| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FigAssociationClass |
|
| 3.2142857142857144;3.214 |
| 1 | /* $Id: FigAssociationClass.java 18712 2010-08-31 15:44:03Z 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 | * Michiel van der Wulp | |
| 12 | ******************************************************************************* | |
| 13 | * | |
| 14 | * Some portions of this file were previously release using the BSD License: | |
| 15 | */ | |
| 16 | // $Id: FigAssociationClass.java 18712 2010-08-31 15:44:03Z bobtarling $ | |
| 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.ui; | |
| 41 | ||
| 42 | import java.awt.Color; | |
| 43 | import java.awt.Rectangle; | |
| 44 | import java.util.Iterator; | |
| 45 | import java.util.List; | |
| 46 | ||
| 47 | import org.argouml.uml.diagram.DiagramEdgeSettings; | |
| 48 | import org.argouml.uml.diagram.DiagramSettings; | |
| 49 | import org.argouml.uml.diagram.PathContainer; | |
| 50 | import org.tigris.gef.presentation.Fig; | |
| 51 | import org.tigris.gef.presentation.FigNode; | |
| 52 | import org.tigris.gef.presentation.FigPoly; | |
| 53 | import org.tigris.gef.presentation.FigText; | |
| 54 | ||
| 55 | /** | |
| 56 | * An Association Class is represented by 3 separate Figs: | |
| 57 | * <nl> | |
| 58 | * <li>FigAssociationClass is the association edge drawn between two | |
| 59 | * classifiers this displays that association properties of the association | |
| 60 | * class.</li> | |
| 61 | * <li>FigClassAssociationClass is the classifier box that displays the class | |
| 62 | * properties of the association class.</li> | |
| 63 | * </li> | |
| 64 | * FigEdgeAssociationClass is the dashed line that joins these two.</li> | |
| 65 | * </nl> | |
| 66 | * | |
| 67 | * Whenever the user attempts to remove or delete one of these parts then all | |
| 68 | * parts must go. Delete would be handled because the model element is deleted | |
| 69 | * and all parts are listening for such an event and will remove themselves. | |
| 70 | * However if the user attempts to just remove from diagram one of these parts | |
| 71 | * then there is no such event. Hence the removeFromDiagram method is overridden | |
| 72 | * to delegate removal from a single removeFromDiagram method on | |
| 73 | * FigAssociationClass. | |
| 74 | * | |
| 75 | * @author bob.tarling@gmail.com | |
| 76 | */ | |
| 77 | public class FigAssociationClass | |
| 78 | extends FigAssociation implements PathContainer { | |
| 79 | ||
| 80 | private static final long serialVersionUID = 3643715304027095083L; | |
| 81 | ||
| 82 | /** | |
| 83 | * Construct an association class figure for the given AssociationClass | |
| 84 | * model element using the rendering settings. | |
| 85 | * | |
| 86 | * @param diagramElementSettings the settings for this new diagram element | |
| 87 | * @param settings rendering settings | |
| 88 | */ | |
| 89 | public FigAssociationClass( | |
| 90 | final DiagramEdgeSettings diagramElementSettings, | |
| 91 | final DiagramSettings settings) { | |
| 92 | 0 | super(diagramElementSettings, settings); |
| 93 | 0 | setBetweenNearestPoints(true); |
| 94 | 0 | ((FigPoly) getFig()).setRectilinear(false); |
| 95 | 0 | setDashed(false); |
| 96 | 0 | } |
| 97 | ||
| 98 | /** | |
| 99 | * This overrides the parent class to do nothing here. An association class | |
| 100 | * has no name label but instead has the name and stereotype editable in | |
| 101 | * the association-classes class box. | |
| 102 | * | |
| 103 | * @param owner owning uml element | |
| 104 | * @param settings rendering settings | |
| 105 | */ | |
| 106 | protected void createNameLabel(Object owner, DiagramSettings settings) { | |
| 107 | 0 | } |
| 108 | ||
| 109 | /** | |
| 110 | * Remove entire composite Fig from Diagram. Discover the attached | |
| 111 | * FigEdgeAssociationClass and the FigClassAssociationClass attached to | |
| 112 | * that. Remove them from the diagram before removing this. | |
| 113 | */ | |
| 114 | @Override | |
| 115 | protected void removeFromDiagramImpl() { | |
| 116 | 0 | FigEdgeAssociationClass figEdgeLink = null; |
| 117 | 0 | List edges = null; |
| 118 | ||
| 119 | 0 | FigEdgePort figEdgePort = getEdgePort(); |
| 120 | 0 | if (figEdgePort != null) { |
| 121 | 0 | edges = figEdgePort.getFigEdges(); |
| 122 | } | |
| 123 | ||
| 124 | 0 | if (edges != null) { |
| 125 | 0 | for (Iterator it = edges.iterator(); it.hasNext() |
| 126 | 0 | && figEdgeLink == null;) { |
| 127 | 0 | Object o = it.next(); |
| 128 | 0 | if (o instanceof FigEdgeAssociationClass) { |
| 129 | 0 | figEdgeLink = (FigEdgeAssociationClass) o; |
| 130 | } | |
| 131 | 0 | } |
| 132 | } | |
| 133 | ||
| 134 | 0 | if (figEdgeLink != null) { |
| 135 | 0 | FigNode figClassBox = figEdgeLink.getDestFigNode(); |
| 136 | 0 | if (!(figClassBox instanceof FigClassAssociationClass)) { |
| 137 | 0 | figClassBox = figEdgeLink.getSourceFigNode(); |
| 138 | } | |
| 139 | 0 | figEdgeLink.removeFromDiagramImpl(); |
| 140 | 0 | ((FigClassAssociationClass) figClassBox).removeFromDiagramImpl(); |
| 141 | } | |
| 142 | ||
| 143 | 0 | super.removeFromDiagramImpl(); |
| 144 | 0 | } |
| 145 | ||
| 146 | /* | |
| 147 | * TODO: Is this required? Why would the fig already be dashed? | |
| 148 | * | |
| 149 | * @see org.tigris.gef.presentation.FigEdge#setFig( | |
| 150 | * org.tigris.gef.presentation.Fig) | |
| 151 | */ | |
| 152 | @Override | |
| 153 | public void setFig(Fig f) { | |
| 154 | 0 | super.setFig(f); |
| 155 | 0 | getFig().setDashed(false); |
| 156 | 0 | } |
| 157 | ||
| 158 | /* | |
| 159 | * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getNameFig() | |
| 160 | */ | |
| 161 | @Override | |
| 162 | protected FigText getNameFig() { | |
| 163 | 0 | return null; |
| 164 | } | |
| 165 | ||
| 166 | /* | |
| 167 | * Overridden in order to implement PathCompartmentContainer. | |
| 168 | */ | |
| 169 | public boolean isPathVisible() { | |
| 170 | 0 | if (getAssociationClass() != null) { |
| 171 | 0 | return getAssociationClass().isPathVisible(); |
| 172 | } else { | |
| 173 | 0 | return false; |
| 174 | } | |
| 175 | } | |
| 176 | ||
| 177 | /* | |
| 178 | * Overridden in order to implement PathCompartmentContainer. | |
| 179 | */ | |
| 180 | public void setPathVisible(boolean visible) { | |
| 181 | 0 | if (getAssociationClass() != null) { |
| 182 | 0 | getAssociationClass().setPathVisible(visible); |
| 183 | } | |
| 184 | 0 | } |
| 185 | ||
| 186 | public Rectangle getOperationsBounds() { | |
| 187 | 0 | if (getAssociationClass() != null) { |
| 188 | 0 | return getAssociationClass().getOperationsBounds(); |
| 189 | } else { | |
| 190 | 0 | return new Rectangle(0, 0, 0, 0); |
| 191 | } | |
| 192 | } | |
| 193 | ||
| 194 | public boolean isOperationsVisible() { | |
| 195 | 0 | if (getAssociationClass() != null) { |
| 196 | 0 | return getAssociationClass().isOperationsVisible(); |
| 197 | } else { | |
| 198 | 0 | return true; |
| 199 | } | |
| 200 | } | |
| 201 | ||
| 202 | /** | |
| 203 | * Set fill color of contained FigClassAssociationClass. | |
| 204 | * | |
| 205 | * @param color new fill color | |
| 206 | */ | |
| 207 | @Override | |
| 208 | public void setFillColor(Color color) { | |
| 209 | 0 | if (getAssociationClass() != null) { |
| 210 | 0 | getAssociationClass().setFillColor(color); |
| 211 | } | |
| 212 | 0 | } |
| 213 | ||
| 214 | /** | |
| 215 | * @return fill color of contained FigClassAssociationClass. | |
| 216 | */ | |
| 217 | @Override | |
| 218 | public Color getFillColor() { | |
| 219 | 0 | if (getAssociationClass() != null) { |
| 220 | 0 | return getAssociationClass().getFillColor(); |
| 221 | } else { | |
| 222 | 0 | return FILL_COLOR; |
| 223 | } | |
| 224 | } | |
| 225 | ||
| 226 | /** | |
| 227 | * Set line color of contained FigClassAssociationClass. | |
| 228 | * | |
| 229 | * @param arg0 new line color | |
| 230 | */ | |
| 231 | @Override | |
| 232 | public void setLineColor(Color arg0) { | |
| 233 | 0 | super.setLineColor(arg0); |
| 234 | 0 | if (getAssociationClass() != null) { |
| 235 | 0 | getAssociationClass().setLineColor(arg0); |
| 236 | } | |
| 237 | 0 | if (getFigEdgeAssociationClass() != null) { |
| 238 | 0 | getFigEdgeAssociationClass().setLineColor(arg0); |
| 239 | } | |
| 240 | 0 | } |
| 241 | ||
| 242 | /** | |
| 243 | * Gets FigClassAssociationClass that is contained in this | |
| 244 | * FigAssociationClass. | |
| 245 | * | |
| 246 | * @return FigClassAssociationClass that is contained in this | |
| 247 | * FigAssociationClass. | |
| 248 | */ | |
| 249 | public FigClassAssociationClass getAssociationClass() { | |
| 250 | 0 | FigEdgeAssociationClass figEdgeLink = null; |
| 251 | 0 | List edges = null; |
| 252 | ||
| 253 | 0 | FigEdgePort figEdgePort = this.getEdgePort(); |
| 254 | 0 | if (figEdgePort != null) { |
| 255 | 0 | edges = figEdgePort.getFigEdges(); |
| 256 | } | |
| 257 | ||
| 258 | 0 | if (edges != null) { |
| 259 | 0 | for (Iterator it = edges.iterator(); it.hasNext() |
| 260 | 0 | && figEdgeLink == null;) { |
| 261 | 0 | Object o = it.next(); |
| 262 | 0 | if (o instanceof FigEdgeAssociationClass) { |
| 263 | 0 | figEdgeLink = (FigEdgeAssociationClass) o; |
| 264 | } | |
| 265 | 0 | } |
| 266 | } | |
| 267 | ||
| 268 | 0 | FigNode figClassBox = null; |
| 269 | 0 | if (figEdgeLink != null) { |
| 270 | 0 | figClassBox = figEdgeLink.getDestFigNode(); |
| 271 | 0 | if (!(figClassBox instanceof FigClassAssociationClass)) { |
| 272 | 0 | figClassBox = figEdgeLink.getSourceFigNode(); |
| 273 | } | |
| 274 | } | |
| 275 | 0 | return (FigClassAssociationClass) figClassBox; |
| 276 | } | |
| 277 | ||
| 278 | /** | |
| 279 | * Gets FigEdgeAssociationClass that is contained in this | |
| 280 | * FigAssociationClass. | |
| 281 | * | |
| 282 | * @return FigEdgeAssociationClass that is contained in this | |
| 283 | * FigAssociationClass | |
| 284 | */ | |
| 285 | public FigEdgeAssociationClass getFigEdgeAssociationClass() { | |
| 286 | 0 | FigEdgeAssociationClass figEdgeLink = null; |
| 287 | 0 | List edges = null; |
| 288 | ||
| 289 | 0 | FigEdgePort figEdgePort = this.getEdgePort(); |
| 290 | 0 | if (figEdgePort != null) { |
| 291 | 0 | edges = figEdgePort.getFigEdges(); |
| 292 | } | |
| 293 | ||
| 294 | 0 | if (edges != null) { |
| 295 | 0 | for (Iterator it = edges.iterator(); it.hasNext() |
| 296 | 0 | && figEdgeLink == null;) { |
| 297 | 0 | Object o = it.next(); |
| 298 | 0 | if (o instanceof FigEdgeAssociationClass) { |
| 299 | 0 | figEdgeLink = (FigEdgeAssociationClass) o; |
| 300 | } | |
| 301 | 0 | } |
| 302 | } | |
| 303 | ||
| 304 | 0 | return figEdgeLink; |
| 305 | } | |
| 306 | } |