| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
package org.argouml.uml.diagram.activity.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.beans.PropertyVetoException; |
| 46 | |
import java.util.Collection; |
| 47 | |
import java.util.HashSet; |
| 48 | |
import java.util.Iterator; |
| 49 | |
import java.util.Set; |
| 50 | |
|
| 51 | |
import org.argouml.model.Model; |
| 52 | |
import org.argouml.notation.Notation; |
| 53 | |
import org.argouml.notation.NotationName; |
| 54 | |
import org.argouml.notation.NotationProvider; |
| 55 | |
import org.argouml.notation.NotationProviderFactory2; |
| 56 | |
import org.argouml.notation.NotationSettings; |
| 57 | |
import org.argouml.uml.diagram.DiagramSettings; |
| 58 | |
import org.argouml.uml.diagram.ui.FigNodeModelElement; |
| 59 | |
import org.argouml.uml.diagram.ui.FigSingleLineText; |
| 60 | |
import org.tigris.gef.base.LayerPerspective; |
| 61 | |
import org.tigris.gef.base.Selection; |
| 62 | |
import org.tigris.gef.presentation.Fig; |
| 63 | |
import org.tigris.gef.presentation.FigRect; |
| 64 | |
import org.tigris.gef.presentation.FigText; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
public class FigObjectFlowState extends FigNodeModelElement { |
| 95 | |
|
| 96 | |
private static final int PADDING = 8; |
| 97 | |
private static final int OFS_WIDTH = 70; |
| 98 | |
private static final int HEIGHT = 50; |
| 99 | |
private static final int STATE_HEIGHT = NAME_FIG_HEIGHT; |
| 100 | |
|
| 101 | |
private NotationProvider notationProviderState; |
| 102 | |
|
| 103 | |
private FigRect cover; |
| 104 | |
private FigText state; |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
public FigObjectFlowState(Object owner, Rectangle bounds, |
| 115 | |
DiagramSettings settings) { |
| 116 | 0 | super(owner, bounds, settings); |
| 117 | 0 | state = new FigSingleLineText(owner, new Rectangle(X0, Y0, OFS_WIDTH, |
| 118 | |
STATE_HEIGHT), settings, true); |
| 119 | 0 | initFigs(bounds); |
| 120 | 0 | } |
| 121 | |
|
| 122 | |
private void initFigs(Rectangle bounds) { |
| 123 | 0 | cover = |
| 124 | |
new FigRect(X0, Y0, OFS_WIDTH, HEIGHT, |
| 125 | |
LINE_COLOR, FILL_COLOR); |
| 126 | |
|
| 127 | 0 | getNameFig().setUnderline(true); |
| 128 | 0 | getNameFig().setLineWidth(0); |
| 129 | |
|
| 130 | |
|
| 131 | 0 | addFig(getBigPort()); |
| 132 | 0 | addFig(cover); |
| 133 | 0 | addFig(getNameFig()); |
| 134 | 0 | addFig(state); |
| 135 | |
|
| 136 | 0 | enableSizeChecking(false); |
| 137 | |
|
| 138 | |
|
| 139 | 0 | if (bounds != null) { |
| 140 | 0 | setLocation(bounds.x, bounds.y); |
| 141 | |
} |
| 142 | |
|
| 143 | 0 | renderingChanged(); |
| 144 | 0 | setSuppressCalcBounds(false); |
| 145 | 0 | setBounds(getBounds()); |
| 146 | 0 | enableSizeChecking(true); |
| 147 | 0 | } |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
@Override |
| 153 | |
protected void initNotationProviders(Object own) { |
| 154 | 0 | super.initNotationProviders(own); |
| 155 | 0 | if (Model.getFacade().isAModelElement(own)) { |
| 156 | 0 | NotationName notationName = Notation |
| 157 | |
.findNotation(getNotationSettings().getNotationLanguage()); |
| 158 | 0 | notationProviderState = |
| 159 | |
NotationProviderFactory2.getInstance().getNotationProvider( |
| 160 | |
NotationProviderFactory2.TYPE_OBJECTFLOWSTATE_STATE, |
| 161 | |
own, this, notationName); |
| 162 | |
} |
| 163 | 0 | } |
| 164 | |
|
| 165 | |
protected int getNotationProviderType() { |
| 166 | 0 | return NotationProviderFactory2.TYPE_OBJECTFLOWSTATE_TYPE; |
| 167 | |
} |
| 168 | |
|
| 169 | |
@Override |
| 170 | |
protected void modelChanged(PropertyChangeEvent mee) { |
| 171 | 0 | super.modelChanged(mee); |
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | 0 | if (!Model.getFacade().isATransition(mee.getNewValue())) { |
| 176 | 0 | renderingChanged(); |
| 177 | 0 | updateListeners(getOwner(), getOwner()); |
| 178 | |
} |
| 179 | 0 | } |
| 180 | |
|
| 181 | |
@Override |
| 182 | |
protected void updateListeners(Object oldOwner, Object newOwner) { |
| 183 | 0 | Set<Object[]> l = new HashSet<Object[]>(); |
| 184 | |
|
| 185 | 0 | if (newOwner != null) { |
| 186 | |
|
| 187 | |
|
| 188 | 0 | l.add(new Object[] {newOwner, new String[] {"type", "remove"}}); |
| 189 | |
|
| 190 | 0 | Object type = Model.getFacade().getType(newOwner); |
| 191 | 0 | if (Model.getFacade().isAClassifier(type)) { |
| 192 | 0 | if (Model.getFacade().isAClassifierInState(type)) { |
| 193 | 0 | Object classifier = Model.getFacade().getType(type); |
| 194 | 0 | l.add(new Object[] {classifier, "name"}); |
| 195 | 0 | l.add(new Object[] {type, "inState"}); |
| 196 | 0 | Collection states = Model.getFacade().getInStates(type); |
| 197 | 0 | Iterator i = states.iterator(); |
| 198 | 0 | while (i.hasNext()) { |
| 199 | 0 | l.add(new Object[] {i.next(), "name"}); |
| 200 | |
} |
| 201 | 0 | } else { |
| 202 | 0 | l.add(new Object[] {type, "name"}); |
| 203 | |
} |
| 204 | |
} |
| 205 | |
} |
| 206 | |
|
| 207 | 0 | updateElementListeners(l); |
| 208 | 0 | } |
| 209 | |
|
| 210 | |
@Override |
| 211 | |
public Object clone() { |
| 212 | 0 | FigObjectFlowState figClone = (FigObjectFlowState) super.clone(); |
| 213 | 0 | Iterator it = figClone.getFigs().iterator(); |
| 214 | 0 | figClone.setBigPort((FigRect) it.next()); |
| 215 | 0 | figClone.cover = (FigRect) it.next(); |
| 216 | 0 | figClone.setNameFig((FigText) it.next()); |
| 217 | 0 | figClone.state = (FigText) it.next(); |
| 218 | 0 | return figClone; |
| 219 | |
} |
| 220 | |
|
| 221 | |
@Override |
| 222 | |
public void setEnclosingFig(Fig encloser) { |
| 223 | 0 | LayerPerspective layer = (LayerPerspective) getLayer(); |
| 224 | |
|
| 225 | 0 | if (layer == null) { |
| 226 | 0 | return; |
| 227 | |
} |
| 228 | |
|
| 229 | 0 | super.setEnclosingFig(encloser); |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
@Override |
| 237 | |
public Dimension getMinimumSize() { |
| 238 | 0 | Dimension tempDim = getNameFig().getMinimumSize(); |
| 239 | 0 | int w = tempDim.width + PADDING * 2; |
| 240 | 0 | int h = tempDim.height + PADDING; |
| 241 | 0 | tempDim = state.getMinimumSize(); |
| 242 | 0 | w = Math.max(w, tempDim.width + PADDING * 2); |
| 243 | 0 | h = h + PADDING + tempDim.height + PADDING; |
| 244 | |
|
| 245 | 0 | return new Dimension(Math.max(w, OFS_WIDTH / 2), Math.max(h, HEIGHT / 2)); |
| 246 | |
} |
| 247 | |
|
| 248 | |
|
| 249 | |
|
| 250 | |
|
| 251 | |
|
| 252 | |
|
| 253 | |
|
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
@Override |
| 259 | |
protected void setStandardBounds(int x, int y, int w, int h) { |
| 260 | 0 | Rectangle oldBounds = getBounds(); |
| 261 | |
|
| 262 | 0 | Dimension classDim = getNameFig().getMinimumSize(); |
| 263 | 0 | Dimension stateDim = state.getMinimumSize(); |
| 264 | |
|
| 265 | 0 | int blank = (h - PADDING - classDim.height - stateDim.height) / 2; |
| 266 | 0 | getNameFig().setBounds(x + PADDING, |
| 267 | |
y + blank, |
| 268 | |
w - PADDING * 2, |
| 269 | |
classDim.height); |
| 270 | 0 | state.setBounds(x + PADDING, |
| 271 | |
y + blank + classDim.height + PADDING, |
| 272 | |
w - PADDING * 2, |
| 273 | |
stateDim.height); |
| 274 | |
|
| 275 | 0 | getBigPort().setBounds(x, y, w, h); |
| 276 | 0 | cover.setBounds(x, y, w, h); |
| 277 | |
|
| 278 | 0 | calcBounds(); |
| 279 | 0 | updateEdges(); |
| 280 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
| 281 | 0 | } |
| 282 | |
|
| 283 | |
|
| 284 | |
|
| 285 | |
|
| 286 | |
@Override |
| 287 | |
public void renderingChanged() { |
| 288 | 0 | super.renderingChanged(); |
| 289 | 0 | updateStateText(); |
| 290 | 0 | updateBounds(); |
| 291 | 0 | damage(); |
| 292 | 0 | } |
| 293 | |
|
| 294 | |
|
| 295 | |
|
| 296 | |
|
| 297 | |
private void updateStateText() { |
| 298 | 0 | if (isReadyToEdit()) { |
| 299 | 0 | state.setText(notationProviderState.toString(getOwner(), |
| 300 | |
getNotationSettings())); |
| 301 | |
} |
| 302 | 0 | } |
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
@Override |
| 308 | |
public void setLineColor(Color col) { |
| 309 | 0 | cover.setLineColor(col); |
| 310 | 0 | } |
| 311 | |
|
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
@Override |
| 316 | |
public Color getLineColor() { |
| 317 | 0 | return cover.getLineColor(); |
| 318 | |
} |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
@Override |
| 324 | |
public void setFillColor(Color col) { |
| 325 | 0 | cover.setFillColor(col); |
| 326 | 0 | } |
| 327 | |
|
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
@Override |
| 332 | |
public Color getFillColor() { |
| 333 | 0 | return cover.getFillColor(); |
| 334 | |
} |
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
@Override |
| 340 | |
public void setFilled(boolean f) { |
| 341 | 0 | cover.setFilled(f); |
| 342 | 0 | } |
| 343 | |
|
| 344 | |
@Override |
| 345 | |
public boolean isFilled() { |
| 346 | 0 | return cover.isFilled(); |
| 347 | |
} |
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
@Override |
| 353 | |
public void setLineWidth(int w) { |
| 354 | 0 | cover.setLineWidth(w); |
| 355 | 0 | } |
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
@Override |
| 361 | |
public int getLineWidth() { |
| 362 | 0 | return cover.getLineWidth(); |
| 363 | |
} |
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
@Override |
| 369 | |
protected void textEdited(FigText ft) throws PropertyVetoException { |
| 370 | 0 | super.textEdited(ft); |
| 371 | 0 | if (ft == state) { |
| 372 | 0 | notationProviderState.parse(getOwner(), ft.getText()); |
| 373 | 0 | ft.setText(notationProviderState.toString(getOwner(), |
| 374 | |
getNotationSettings())); |
| 375 | |
} |
| 376 | 0 | } |
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
@Override |
| 382 | |
protected void textEditStarted(FigText ft) { |
| 383 | 0 | super.textEditStarted(ft); |
| 384 | 0 | if (ft == state) { |
| 385 | 0 | showHelp(notationProviderState.getParsingHelp()); |
| 386 | |
} |
| 387 | 0 | } |
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
@Override |
| 393 | |
public Selection makeSelection() { |
| 394 | 0 | return new SelectionActionState(this); |
| 395 | |
} |
| 396 | |
|
| 397 | |
public void notationRenderingChanged(NotationProvider np, String rendering) { |
| 398 | 0 | super.notationRenderingChanged(np, rendering); |
| 399 | 0 | if (notationProviderState == np) { |
| 400 | 0 | state.setText(rendering); |
| 401 | 0 | updateBounds(); |
| 402 | 0 | damage(); |
| 403 | |
} |
| 404 | 0 | } |
| 405 | |
|
| 406 | |
public NotationSettings getNotationSettings(NotationProvider np) { |
| 407 | |
|
| 408 | 0 | return getNotationSettings(); |
| 409 | |
} |
| 410 | |
|
| 411 | |
public Object getOwner(NotationProvider np) { |
| 412 | |
|
| 413 | 0 | return getOwner(); |
| 414 | |
} |
| 415 | |
|
| 416 | |
} |