| 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 | |
|
| 40 | |
package org.argouml.uml.diagram.ui; |
| 41 | |
|
| 42 | |
import java.awt.Color; |
| 43 | |
import java.awt.Dimension; |
| 44 | |
import java.awt.Polygon; |
| 45 | |
import java.awt.Rectangle; |
| 46 | |
import java.beans.PropertyChangeEvent; |
| 47 | |
import java.util.Iterator; |
| 48 | |
import java.util.Vector; |
| 49 | |
|
| 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.collaboration.ui.FigAssociationRole; |
| 54 | |
import org.tigris.gef.base.Layer; |
| 55 | |
import org.tigris.gef.presentation.Fig; |
| 56 | |
import org.tigris.gef.presentation.FigPoly; |
| 57 | |
import org.tigris.gef.presentation.FigText; |
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public class FigMessage extends FigNodeModelElement { |
| 66 | |
|
| 67 | |
private static Vector<String> arrowDirections; |
| 68 | |
|
| 69 | |
private static final int SOUTH = 0; |
| 70 | |
private static final int EAST = 1; |
| 71 | |
private static final int WEST = 2; |
| 72 | |
private static final int NORTH = 3; |
| 73 | |
|
| 74 | |
static { |
| 75 | 0 | arrowDirections = new Vector<String>(4); |
| 76 | |
|
| 77 | 0 | arrowDirections.add(SOUTH, "South"); |
| 78 | 0 | arrowDirections.add(EAST, "East"); |
| 79 | 0 | arrowDirections.add(WEST, "West"); |
| 80 | 0 | arrowDirections.add(NORTH, "North"); |
| 81 | 0 | } |
| 82 | |
|
| 83 | |
private FigPoly figPoly; |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | 0 | private int arrowDirection = -1; |
| 89 | |
|
| 90 | |
private void initFigs() { |
| 91 | 0 | setShadowSize(0); |
| 92 | 0 | getNameFig().setLineWidth(0); |
| 93 | 0 | getNameFig().setReturnAction(FigText.END_EDITING); |
| 94 | 0 | getNameFig().setFilled(false); |
| 95 | 0 | Dimension nameMin = getNameFig().getMinimumSize(); |
| 96 | 0 | getNameFig().setBounds(X0, Y0, 90, nameMin.height); |
| 97 | 0 | getBigPort().setBounds(X0, Y0, 90, nameMin.height); |
| 98 | |
|
| 99 | 0 | figPoly = new FigPoly(LINE_COLOR, SOLID_FILL_COLOR); |
| 100 | 0 | int[] xpoints = {75, 75, 77, 75, 73, 75}; |
| 101 | 0 | int[] ypoints = {33, 24, 24, 15, 24, 24}; |
| 102 | 0 | Polygon polygon = new Polygon(xpoints, ypoints, 6); |
| 103 | 0 | figPoly.setPolygon(polygon); |
| 104 | 0 | figPoly.setBounds(100, 10, 5, 18); |
| 105 | |
|
| 106 | 0 | getBigPort().setFilled(false); |
| 107 | 0 | getBigPort().setLineWidth(0); |
| 108 | |
|
| 109 | 0 | addFig(getBigPort()); |
| 110 | 0 | addFig(getNameFig()); |
| 111 | 0 | addFig(figPoly); |
| 112 | 0 | } |
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
public FigMessage(Object owner, Rectangle bounds, |
| 122 | |
DiagramSettings settings) { |
| 123 | 0 | super(owner, bounds, settings); |
| 124 | 0 | initFigs(); |
| 125 | 0 | updateNameText(); |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
@Override |
| 132 | |
protected int getNotationProviderType() { |
| 133 | 0 | return NotationProviderFactory2.TYPE_MESSAGE; |
| 134 | |
} |
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
@Override |
| 141 | |
protected void updateListeners(Object oldOwner, Object newOwner) { |
| 142 | 0 | if (oldOwner != null) { |
| 143 | 0 | removeElementListener(oldOwner); |
| 144 | |
} |
| 145 | 0 | if (newOwner != null) { |
| 146 | 0 | addElementListener(newOwner, "remove"); |
| 147 | |
} |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
|
| 151 | |
@Override |
| 152 | |
public Object clone() { |
| 153 | 0 | FigMessage figClone = (FigMessage) super.clone(); |
| 154 | 0 | Iterator it = figClone.getFigs().iterator(); |
| 155 | 0 | figClone.setNameFig((FigText) it.next()); |
| 156 | 0 | figClone.figPoly = (FigPoly) it.next(); |
| 157 | |
|
| 158 | 0 | return figClone; |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
@Override |
| 165 | |
public void setLineColor(Color col) { |
| 166 | 0 | figPoly.setLineColor(col); |
| 167 | 0 | getNameFig().setLineColor(col); |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
@Override |
| 174 | |
public Color getLineColor() { |
| 175 | 0 | return figPoly.getLineColor(); |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
@Override |
| 182 | |
public void setFillColor(Color col) { |
| 183 | |
|
| 184 | 0 | getNameFig().setFillColor(col); |
| 185 | 0 | } |
| 186 | |
|
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
@Override |
| 191 | |
public Color getFillColor() { |
| 192 | 0 | return getNameFig().getFillColor(); |
| 193 | |
} |
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
@Override |
| 199 | |
public void setFilled(boolean f) { |
| 200 | 0 | } |
| 201 | |
|
| 202 | |
|
| 203 | |
@Override |
| 204 | |
public boolean isFilled() { |
| 205 | 0 | return true; |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
@Override |
| 212 | |
public void setLineWidth(int w) { |
| 213 | 0 | figPoly.setLineWidth(w); |
| 214 | 0 | } |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
@Override |
| 220 | |
public int getLineWidth() { |
| 221 | 0 | return figPoly.getLineWidth(); |
| 222 | |
} |
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
|
| 228 | |
|
| 229 | |
|
| 230 | |
|
| 231 | |
public void setArrow(int direction) { |
| 232 | 0 | Rectangle bbox = getBounds(); |
| 233 | |
|
| 234 | 0 | if (arrowDirection == direction) { |
| 235 | 0 | return; |
| 236 | |
} |
| 237 | |
|
| 238 | 0 | arrowDirection = direction; |
| 239 | 0 | switch (direction) { |
| 240 | |
case SOUTH: { |
| 241 | 0 | int[] xpoints = {75, 75, 77, 75, 73, 75}; |
| 242 | 0 | int[] ypoints = {15, 24, 24, 33, 24, 24}; |
| 243 | 0 | Polygon polygon = new Polygon(xpoints, ypoints, 6); |
| 244 | 0 | figPoly.setPolygon(polygon); |
| 245 | 0 | break; |
| 246 | |
} |
| 247 | |
case EAST: { |
| 248 | 0 | int[] xpoints = {66, 75, 75, 84, 75, 75}; |
| 249 | 0 | int[] ypoints = {24, 24, 26, 24, 22, 24}; |
| 250 | 0 | Polygon polygon = new Polygon(xpoints, ypoints, 6); |
| 251 | 0 | figPoly.setPolygon(polygon); |
| 252 | 0 | break; |
| 253 | |
} |
| 254 | |
case WEST: { |
| 255 | 0 | int[] xpoints = {84, 75, 75, 66, 75, 75}; |
| 256 | 0 | int[] ypoints = {24, 24, 26, 24, 22, 24}; |
| 257 | 0 | Polygon polygon = new Polygon(xpoints, ypoints, 6); |
| 258 | 0 | figPoly.setPolygon(polygon); |
| 259 | 0 | break; |
| 260 | |
} |
| 261 | |
default: { |
| 262 | 0 | int[] xpoints = {75, 75, 77, 75, 73, 75}; |
| 263 | 0 | int[] ypoints = {33, 24, 24, 15, 24, 24}; |
| 264 | 0 | Polygon polygon = new Polygon(xpoints, ypoints, 6); |
| 265 | 0 | figPoly.setPolygon(polygon); |
| 266 | 0 | break; |
| 267 | |
} |
| 268 | |
} |
| 269 | 0 | setBounds(bbox); |
| 270 | 0 | } |
| 271 | |
|
| 272 | |
|
| 273 | |
|
| 274 | |
|
| 275 | 0 | public int getArrow() { return arrowDirection; } |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
@Override |
| 281 | |
public Dimension getMinimumSize() { |
| 282 | 0 | Dimension nameMin = getNameFig().getMinimumSize(); |
| 283 | 0 | Dimension figPolyMin = figPoly.getSize(); |
| 284 | |
|
| 285 | 0 | int h = Math.max(figPolyMin.height, nameMin.height); |
| 286 | 0 | int w = figPolyMin.width + nameMin.width; |
| 287 | 0 | return new Dimension(w, h); |
| 288 | |
} |
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
@Override |
| 295 | |
protected void setStandardBounds(int x, int y, int w, int h) { |
| 296 | 0 | if (getNameFig() == null) { |
| 297 | 0 | return; |
| 298 | |
} |
| 299 | |
|
| 300 | 0 | Rectangle oldBounds = getBounds(); |
| 301 | |
|
| 302 | 0 | Dimension nameMin = getNameFig().getMinimumSize(); |
| 303 | |
|
| 304 | 0 | int ht = 0; |
| 305 | |
|
| 306 | 0 | if (nameMin.height > figPoly.getHeight()) { |
| 307 | 0 | ht = (nameMin.height - figPoly.getHeight()) / 2; |
| 308 | |
} |
| 309 | |
|
| 310 | 0 | getNameFig().setBounds(x, y, w - figPoly.getWidth(), nameMin.height); |
| 311 | 0 | getBigPort().setBounds(x, y, w - figPoly.getWidth(), nameMin.height); |
| 312 | 0 | figPoly.setBounds(x + getNameFig().getWidth(), y + ht, |
| 313 | |
figPoly.getWidth(), figPoly.getHeight()); |
| 314 | |
|
| 315 | 0 | firePropChange("bounds", oldBounds, getBounds()); |
| 316 | 0 | calcBounds(); |
| 317 | 0 | updateEdges(); |
| 318 | 0 | } |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
|
| 324 | |
|
| 325 | |
|
| 326 | |
|
| 327 | |
|
| 328 | |
|
| 329 | |
@Override |
| 330 | |
protected void modelChanged(PropertyChangeEvent mee) { |
| 331 | 0 | super.modelChanged(mee); |
| 332 | |
|
| 333 | |
|
| 334 | |
if (true) { |
| 335 | 0 | return; |
| 336 | |
} |
| 337 | |
|
| 338 | |
if (Model.getFacade().isAMessage(getOwner())) { |
| 339 | |
if (Model.getFacade().isAParameter(mee.getSource())) { |
| 340 | |
Object par = mee.getSource(); |
| 341 | |
updateArgumentsFromParameter(getOwner(), par); |
| 342 | |
|
| 343 | |
} |
| 344 | |
|
| 345 | |
if (mee == null || mee.getSource() == getOwner() |
| 346 | |
|| Model.getFacade().isAAction(mee.getSource()) |
| 347 | |
|| Model.getFacade().isAOperation(mee.getSource()) |
| 348 | |
|| Model.getFacade().isAArgument(mee.getSource()) |
| 349 | |
|| Model.getFacade().isASignal(mee.getSource())) { |
| 350 | |
updateListeners(getOwner()); |
| 351 | |
} |
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
updateArrow(); |
| 357 | |
damage(); |
| 358 | |
} |
| 359 | |
} |
| 360 | |
|
| 361 | |
|
| 362 | |
|
| 363 | |
|
| 364 | |
|
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
|
| 372 | |
protected void updateArgumentsFromParameter(Object newOwner, |
| 373 | |
Object parameter) { |
| 374 | |
|
| 375 | |
|
| 376 | |
if (true) { |
| 377 | 0 | return; |
| 378 | |
} |
| 379 | |
|
| 380 | |
if (newOwner != null) { |
| 381 | |
Object act = Model.getFacade().getAction(newOwner); |
| 382 | |
if (Model.getFacade().isACallAction(act)) { |
| 383 | |
if (Model.getFacade().getOperation(act) != null) { |
| 384 | |
Object operation = Model.getFacade().getOperation(act); |
| 385 | |
if (Model.getDirectionKind().getInParameter().equals( |
| 386 | |
Model.getFacade().getKind(parameter))) { |
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
|
| 392 | |
|
| 393 | |
|
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
Object newArgument = Model.getCommonBehaviorFactory() |
| 404 | |
.createArgument(); |
| 405 | |
Model.getCommonBehaviorHelper().setValue( |
| 406 | |
newArgument, |
| 407 | |
Model.getDataTypesFactory().createExpression( |
| 408 | |
"", |
| 409 | |
Model.getFacade().getName(parameter))); |
| 410 | |
Model.getCoreHelper().setName(newArgument, |
| 411 | |
Model.getFacade().getName(parameter)); |
| 412 | |
Model.getCommonBehaviorHelper().addActualArgument(act, |
| 413 | |
newArgument); |
| 414 | |
|
| 415 | |
Model.getPump().removeModelEventListener(this, |
| 416 | |
parameter); |
| 417 | |
Model.getPump().addModelEventListener(this, parameter); |
| 418 | |
} |
| 419 | |
} |
| 420 | |
} |
| 421 | |
} |
| 422 | |
} |
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
|
| 428 | |
|
| 429 | |
|
| 430 | |
|
| 431 | |
|
| 432 | |
|
| 433 | |
|
| 434 | |
protected void updateListeners(Object newOwner) { |
| 435 | |
|
| 436 | |
|
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
if (true) { |
| 441 | 0 | return; |
| 442 | |
} |
| 443 | |
|
| 444 | |
if (newOwner != null) { |
| 445 | |
Object act = Model.getFacade().getAction(newOwner); |
| 446 | |
if (act != null) { |
| 447 | |
Model.getPump().removeModelEventListener(this, act); |
| 448 | |
Model.getPump().addModelEventListener(this, act); |
| 449 | |
Iterator iter = Model.getFacade().getActualArguments(act) |
| 450 | |
.iterator(); |
| 451 | |
while (iter.hasNext()) { |
| 452 | |
Object arg = iter.next(); |
| 453 | |
Model.getPump().removeModelEventListener(this, arg); |
| 454 | |
Model.getPump().addModelEventListener(this, arg); |
| 455 | |
} |
| 456 | |
if (Model.getFacade().isACallAction(act)) { |
| 457 | |
Object oper = Model.getFacade().getOperation(act); |
| 458 | |
if (oper != null) { |
| 459 | |
Model.getPump().removeModelEventListener(this, oper); |
| 460 | |
Model.getPump().addModelEventListener(this, oper); |
| 461 | |
Iterator it2 = Model.getFacade().getParameters(oper) |
| 462 | |
.iterator(); |
| 463 | |
while (it2.hasNext()) { |
| 464 | |
Object param = it2.next(); |
| 465 | |
Model.getPump().removeModelEventListener(this, |
| 466 | |
param); |
| 467 | |
Model.getPump().addModelEventListener(this, param); |
| 468 | |
} |
| 469 | |
} |
| 470 | |
} |
| 471 | |
if (Model.getFacade().isASendAction(act)) { |
| 472 | |
Object sig = Model.getFacade().getSignal(act); |
| 473 | |
if (sig != null) { |
| 474 | |
Model.getPump().removeModelEventListener(this, sig); |
| 475 | |
} |
| 476 | |
Model.getPump().addModelEventListener(this, sig); |
| 477 | |
} |
| 478 | |
} |
| 479 | |
} |
| 480 | |
} |
| 481 | |
|
| 482 | |
|
| 483 | |
|
| 484 | |
|
| 485 | |
|
| 486 | |
|
| 487 | |
public void updateArrow() { |
| 488 | 0 | Object mes = getOwner(); |
| 489 | 0 | if (mes == null || getLayer() == null) { |
| 490 | 0 | return; |
| 491 | |
} |
| 492 | 0 | Object sender = Model.getFacade().getSender(mes); |
| 493 | 0 | Object receiver = Model.getFacade().getReceiver(mes); |
| 494 | 0 | Fig senderPort = getLayer().presentationFor(sender); |
| 495 | 0 | Fig receiverPort = getLayer().presentationFor(receiver); |
| 496 | 0 | if (senderPort == null || receiverPort == null) { |
| 497 | 0 | return; |
| 498 | |
} |
| 499 | 0 | int sx = senderPort.getX(); |
| 500 | 0 | int sy = senderPort.getY(); |
| 501 | 0 | int rx = receiverPort.getX(); |
| 502 | 0 | int ry = receiverPort.getY(); |
| 503 | 0 | if (sx < rx && Math.abs(sy - ry) <= Math.abs(sx - rx)) { |
| 504 | 0 | setArrow(EAST); |
| 505 | 0 | } else if (sx > rx && Math.abs(sy - ry) <= Math.abs(sx - rx)) { |
| 506 | 0 | setArrow(WEST); |
| 507 | 0 | } else if (sy < ry) { |
| 508 | 0 | setArrow(SOUTH); |
| 509 | |
} else { |
| 510 | 0 | setArrow(NORTH); |
| 511 | |
} |
| 512 | 0 | } |
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
public void addPathItemToFigAssociationRole(Layer lay) { |
| 520 | 0 | Object associationRole = |
| 521 | |
Model.getFacade().getCommunicationConnection(getOwner()); |
| 522 | 0 | if (associationRole != null && lay != null) { |
| 523 | 0 | FigAssociationRole figAssocRole = |
| 524 | |
(FigAssociationRole) lay.presentationFor(associationRole); |
| 525 | 0 | if (figAssocRole != null) { |
| 526 | 0 | figAssocRole.addMessage(this); |
| 527 | 0 | lay.bringToFront(this); |
| 528 | |
} |
| 529 | |
} |
| 530 | 0 | } |
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
@Override |
| 536 | |
public void renderingChanged() { |
| 537 | 0 | super.renderingChanged(); |
| 538 | 0 | updateArrow(); |
| 539 | 0 | } |
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
public static Vector<String> getArrowDirections() { |
| 545 | 0 | return arrowDirections; |
| 546 | |
} |
| 547 | |
} |