| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| FigJunctionState |
|
| 1.125;1.125 |
| 1 | /* $Id: FigJunctionState.java 18728 2010-09-10 09:29:47Z 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 | * Michiel van der Wulp | |
| 11 | ***************************************************************************** | |
| 12 | * | |
| 13 | * Some portions of this file was previously release using the BSD License: | |
| 14 | */ | |
| 15 | ||
| 16 | // Copyright (c) 2004-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.Point; | |
| 43 | import java.awt.Rectangle; | |
| 44 | import java.awt.event.MouseEvent; | |
| 45 | import java.util.Iterator; | |
| 46 | ||
| 47 | import org.argouml.uml.diagram.DiagramSettings; | |
| 48 | import org.tigris.gef.base.Geometry; | |
| 49 | import org.tigris.gef.presentation.Fig; | |
| 50 | import org.tigris.gef.presentation.FigDiamond; | |
| 51 | ||
| 52 | /** | |
| 53 | * Class to display graphics for a UML Junction State | |
| 54 | * in e.g. a statechart diagram - the diamond. | |
| 55 | * | |
| 56 | * @author pepargouml | |
| 57 | */ | |
| 58 | public class FigJunctionState extends FigStateVertex { | |
| 59 | ||
| 60 | private static final int X = 0; | |
| 61 | private static final int Y = 0; | |
| 62 | private static final int WIDTH = 32; | |
| 63 | private static final int HEIGHT = 32; | |
| 64 | ||
| 65 | private FigDiamond head; | |
| 66 | ||
| 67 | ||
| 68 | /** | |
| 69 | * Construct a new FigJunctionState. | |
| 70 | * | |
| 71 | * @param owner owning UML element | |
| 72 | * @param bounds position and size | |
| 73 | * @param settings rendering settings | |
| 74 | */ | |
| 75 | public FigJunctionState(Object owner, Rectangle bounds, | |
| 76 | DiagramSettings settings) { | |
| 77 | 0 | super(owner, bounds, settings); |
| 78 | 0 | initFigs(); |
| 79 | 0 | } |
| 80 | ||
| 81 | @Override | |
| 82 | protected Fig createBigPortFig() { | |
| 83 | 0 | return new FigDiamond(X, Y, WIDTH, HEIGHT, false, |
| 84 | DEBUG_COLOR, DEBUG_COLOR); | |
| 85 | } | |
| 86 | ||
| 87 | private void initFigs() { | |
| 88 | 0 | setEditable(false); |
| 89 | 0 | head = new FigDiamond(X, Y, WIDTH, HEIGHT, false, |
| 90 | LINE_COLOR, FILL_COLOR); | |
| 91 | ||
| 92 | 0 | addFig(getBigPort()); |
| 93 | 0 | addFig(head); |
| 94 | ||
| 95 | 0 | setBlinkPorts(false); //make port invisible unless mouse enters |
| 96 | 0 | } |
| 97 | ||
| 98 | /* | |
| 99 | * @see java.lang.Object#clone() | |
| 100 | */ | |
| 101 | @Override | |
| 102 | public Object clone() { | |
| 103 | 0 | FigJunctionState figClone = (FigJunctionState) super.clone(); |
| 104 | 0 | Iterator it = figClone.getFigs().iterator(); |
| 105 | 0 | figClone.setBigPort((FigDiamond) it.next()); |
| 106 | 0 | figClone.head = (FigDiamond) it.next(); |
| 107 | 0 | return figClone; |
| 108 | } | |
| 109 | ||
| 110 | ||
| 111 | /** | |
| 112 | * Initial states are fixed size. | |
| 113 | * @return false | |
| 114 | */ | |
| 115 | @Override | |
| 116 | public boolean isResizable() { | |
| 117 | 0 | return false; |
| 118 | } | |
| 119 | ||
| 120 | /* | |
| 121 | * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color) | |
| 122 | */ | |
| 123 | @Override | |
| 124 | public void setLineColor(Color col) { | |
| 125 | 0 | head.setLineColor(col); |
| 126 | 0 | } |
| 127 | ||
| 128 | /* | |
| 129 | * @see org.tigris.gef.presentation.Fig#getLineColor() | |
| 130 | */ | |
| 131 | @Override | |
| 132 | public Color getLineColor() { | |
| 133 | 0 | return head.getLineColor(); |
| 134 | } | |
| 135 | ||
| 136 | /* | |
| 137 | * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color) | |
| 138 | */ | |
| 139 | @Override | |
| 140 | public void setFillColor(Color col) { | |
| 141 | 0 | head.setFillColor(col); |
| 142 | 0 | } |
| 143 | ||
| 144 | /* | |
| 145 | * @see org.tigris.gef.presentation.Fig#getFillColor() | |
| 146 | */ | |
| 147 | @Override | |
| 148 | public Color getFillColor() { | |
| 149 | 0 | return head.getFillColor(); |
| 150 | } | |
| 151 | ||
| 152 | /* | |
| 153 | * @see org.tigris.gef.presentation.Fig#setFilled(boolean) | |
| 154 | */ | |
| 155 | @Override | |
| 156 | public void setFilled(boolean f) { | |
| 157 | 0 | } |
| 158 | ||
| 159 | @Override | |
| 160 | public boolean isFilled() { | |
| 161 | 0 | return true; |
| 162 | } | |
| 163 | ||
| 164 | /* | |
| 165 | * @see org.tigris.gef.presentation.Fig#setLineWidth(int) | |
| 166 | */ | |
| 167 | @Override | |
| 168 | public void setLineWidth(int w) { | |
| 169 | 0 | head.setLineWidth(w); |
| 170 | 0 | } |
| 171 | ||
| 172 | /* | |
| 173 | * @see org.tigris.gef.presentation.Fig#getLineWidth() | |
| 174 | */ | |
| 175 | @Override | |
| 176 | public int getLineWidth() { | |
| 177 | 0 | return head.getLineWidth(); |
| 178 | } | |
| 179 | ||
| 180 | /* | |
| 181 | * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) | |
| 182 | */ | |
| 183 | @Override | |
| 184 | 0 | public void mouseClicked(MouseEvent me) { } |
| 185 | ||
| 186 | /* | |
| 187 | * @see org.tigris.gef.presentation.Fig#getClosestPoint(java.awt.Point) | |
| 188 | */ | |
| 189 | @Override | |
| 190 | public Point getClosestPoint(Point anotherPt) { | |
| 191 | 0 | Rectangle r = getBounds(); |
| 192 | 0 | int[] xs = {r.x + r.width / 2, |
| 193 | r.x + r.width, | |
| 194 | r.x + r.width / 2, | |
| 195 | r.x, | |
| 196 | r.x + r.width / 2, | |
| 197 | }; | |
| 198 | 0 | int[] ys = {r.y, |
| 199 | r.y + r.height / 2, | |
| 200 | r.y + r.height, | |
| 201 | r.y + r.height / 2, | |
| 202 | r.y, | |
| 203 | }; | |
| 204 | 0 | Point p = |
| 205 | Geometry.ptClosestTo( | |
| 206 | xs, | |
| 207 | ys, | |
| 208 | 5, | |
| 209 | anotherPt); | |
| 210 | 0 | return p; |
| 211 | } | |
| 212 | ||
| 213 | /** | |
| 214 | * Override setStandardBounds to keep shapes looking right. | |
| 215 | * {@inheritDoc} | |
| 216 | */ | |
| 217 | @Override | |
| 218 | protected void setStandardBounds(int x, int y, int w, int h) { | |
| 219 | 0 | if (getNameFig() == null) { |
| 220 | 0 | return; |
| 221 | } | |
| 222 | 0 | Rectangle oldBounds = getBounds(); |
| 223 | ||
| 224 | 0 | getBigPort().setBounds(x, y, w, h); |
| 225 | 0 | head.setBounds(x, y, w, h); |
| 226 | ||
| 227 | 0 | calcBounds(); //_x = x; _y = y; _w = w; _h = h; |
| 228 | 0 | updateEdges(); |
| 229 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
| 230 | 0 | } |
| 231 | ||
| 232 | /** | |
| 233 | * The UID. | |
| 234 | */ | |
| 235 | private static final long serialVersionUID = -5845934640541945686L; | |
| 236 | } |