Coverage Report - org.argouml.uml.diagram.ui.FigMessage
 
Classes in this File Line Coverage Branch Coverage Complexity
FigMessage
0%
0/136
0%
0/38
3.083
 
 1  
 /* $Id: FigMessage.java 18558 2010-07-24 15:53:42Z linus $
 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  
  *    mvw
 11  
  *    Linus Tolke
 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.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  
  * Class to display graphics for a UML Message 
 61  
  * above an AssociationRole in a collaborations diagram.
 62  
  *
 63  
  * @author agauthie
 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  
         // TODO: i18n
 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  
      * The current arrow direction set to constants above.
 87  
      */
 88  0
     private int arrowDirection = -1;
 89  
 
 90  
     private void initFigs() {
 91  0
         setShadowSize(0); // Issue 2714.
 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  
         // add Figs to the FigNode in back-to-front order
 109  0
         addFig(getBigPort());
 110  0
         addFig(getNameFig());
 111  0
         addFig(figPoly);
 112  0
     }
 113  
 
 114  
     /**
 115  
      * Construct a FigMessage.
 116  
      * 
 117  
      * @param owner owning UML element
 118  
      * @param bounds position and size
 119  
      * @param settings render settings
 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  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#getNotationProviderType()
 130  
      */
 131  
     @Override
 132  
     protected int getNotationProviderType() {
 133  0
         return NotationProviderFactory2.TYPE_MESSAGE;
 134  
     }
 135  
 
 136  
     /*
 137  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateListeners(
 138  
      * java.lang.Object, java.lang.Object)
 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  
         //figClone._polygon = (Polygon) _polygon.clone();
 158  0
         return figClone;
 159  
     }
 160  
 
 161  
     /*
 162  
      * @see org.tigris.gef.presentation.Fig#setLineColor(java.awt.Color)
 163  
      */
 164  
     @Override
 165  
     public void setLineColor(Color col) {
 166  0
         figPoly.setLineColor(col);
 167  0
         getNameFig().setLineColor(col);
 168  0
     }
 169  
 
 170  
     /*
 171  
      * @see org.tigris.gef.presentation.Fig#getLineColor()
 172  
      */
 173  
     @Override
 174  
     public Color getLineColor() {
 175  0
         return figPoly.getLineColor();
 176  
     }
 177  
 
 178  
     /*
 179  
      * @see org.tigris.gef.presentation.Fig#setFillColor(java.awt.Color)
 180  
      */
 181  
     @Override
 182  
     public void setFillColor(Color col) {
 183  
         //figPoly.setFillColor(col);
 184  0
         getNameFig().setFillColor(col);
 185  0
     }
 186  
     
 187  
     /*
 188  
      * @see org.tigris.gef.presentation.Fig#getFillColor()
 189  
      */
 190  
     @Override
 191  
     public Color getFillColor() {
 192  0
         return getNameFig().getFillColor();
 193  
     }
 194  
 
 195  
     /*
 196  
      * @see org.tigris.gef.presentation.Fig#setFilled(boolean)
 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  
      * @see org.tigris.gef.presentation.Fig#setLineWidth(int)
 210  
      */
 211  
     @Override
 212  
     public void setLineWidth(int w) {
 213  0
         figPoly.setLineWidth(w);
 214  0
     }
 215  
 
 216  
     /*
 217  
      * @see org.tigris.gef.presentation.Fig#getLineWidth()
 218  
      */
 219  
     @Override
 220  
     public int getLineWidth() {
 221  0
         return figPoly.getLineWidth();
 222  
     }
 223  
 
 224  
     /**
 225  
      * @param direction for the arrow
 226  
      * FigMessage.SOUTH
 227  
      * FigMessage.EAST
 228  
      * FigMessage.WEST
 229  
      * FigMessage.NORTH
 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: { // north
 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  
      * @return the arrow direction
 274  
      */
 275  0
     public int getArrow() { return arrowDirection; }
 276  
 
 277  
     /*
 278  
      * @see org.tigris.gef.presentation.Fig#getMinimumSize()
 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  
      * Override setBounds to keep shapes looking right.
 292  
      * @see org.tigris.gef.presentation.Fig#setBounds(int, int, int, int)
 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(); //_x = x; _y = y; _w = w; _h = h;
 317  0
         updateEdges();
 318  0
     }
 319  
     
 320  
     
 321  
     /*
 322  
      * TODO: The code implementing this method is from 2003 (see issue 2171) -
 323  
      * mechanically integrated by tfmorris in May 2007. Needs to be
 324  
      * reviewed/updated.
 325  
      * 
 326  
      * @author Decki,Endi,Yayan, Politechnic of Bandung. Computer Departement
 327  
      * method for changing text of Message
 328  
      */
 329  
     @Override
 330  
     protected void modelChanged(PropertyChangeEvent mee) {
 331  0
         super.modelChanged(mee);
 332  
         
 333  
         // Do nothing until code is reviewed
 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  
             // needs to be updated for changes in Notation subsystem - tfm
 354  
 //            String nameStr = Notation.generate(this, getOwner()).trim();
 355  
 //            getNameFig().setText(nameStr);
 356  
             updateArrow();
 357  
             damage();
 358  
         }
 359  
     }
 360  
 
 361  
 
 362  
     /**
 363  
      * TODO: The code implementing this method is from 2003 (see issue 2171) -
 364  
      * mechanically integrated by tfmorris in May 2007. Needs to be
 365  
      * reviewed/updated.
 366  
      * 
 367  
      * @author Decki,Endi,Yayan, Politechnic of Bandung. Computer Departement
 368  
      * method for changing text of Message
 369  
      * @param newOwner
 370  
      * @param parameter
 371  
      */
 372  
     protected void updateArgumentsFromParameter(Object newOwner,
 373  
             Object parameter) {
 374  
 
 375  
         // Do nothing until code is reviewed
 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  
                         // Update for changes in Model subsystem - tfm
 389  
 //                        Collection colpar = Model.getFacade().getInParameters(
 390  
 //                                operation);
 391  
 //                        Collection colarg = Model.getFacade()
 392  
 //                                .getActualArguments(act);
 393  
 //                        if (colpar.size() == colarg.size()) {
 394  
 //                            Iterator iter = colarg.iterator();
 395  
 //                            while (iter.hasNext()) {
 396  
 //                                Object arg = iter.next();
 397  
 //                                if (!iter.hasNext()) {
 398  
 //                                    Model.getCommonBehaviorHelper()
 399  
 //                                            .removeActualArgument(act, arg);
 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  
      * TODO: The code implementing this method is from 2003 (see issue 2171) -
 427  
      * mechanically integrated by tfmorris in May 2007. Needs to be
 428  
      * reviewed/updated.
 429  
      * 
 430  
      * @author Decki,Endi,Yayan, Politechnic of Bandung. Computer Departement
 431  
      * method for changing text of Message
 432  
      * @param newOwner model element which should now be listened to
 433  
      */
 434  
     protected void updateListeners(Object newOwner) {
 435  
         // Our superclass no longer has this method, so perhaps this whole
 436  
         // thing should be removed? - tfm 
 437  
 //        super.updateListeners(newOwner);
 438  
         
 439  
         // TODO: Do nothing until code is reviewed
 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  
      * Determines the direction of the message arrow. Determination of the type
 485  
      * of arrow happens in modelChanged.
 486  
      */
 487  
     public void updateArrow() {
 488  0
           Object mes = getOwner(); // Message
 489  0
         if (mes == null || getLayer() == null) {
 490  0
             return;
 491  
         }
 492  0
         Object sender = Model.getFacade().getSender(mes); // ClassifierRole
 493  0
         Object receiver = Model.getFacade().getReceiver(mes); // ClassifierRole
 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)) { // east
 504  0
             setArrow(EAST);
 505  0
         } else if (sx > rx && Math.abs(sy - ry) <= Math.abs(sx - rx)) { // west
 506  0
             setArrow(WEST);
 507  0
         } else if (sy < ry) { // south
 508  0
             setArrow(SOUTH);
 509  
         } else {
 510  0
             setArrow(NORTH);
 511  
         }
 512  0
     }
 513  
 
 514  
     /**
 515  
      * Add the FigMessage to the Path Items of its FigAssociationRole.
 516  
      * 
 517  
      * @param lay the Layer
 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  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#renderingChanged()
 534  
      */
 535  
     @Override
 536  
     public void renderingChanged() {
 537  0
         super.renderingChanged();
 538  0
         updateArrow();
 539  0
     }
 540  
 
 541  
     /**
 542  
      * @return Returns the arrowDirections.
 543  
      */
 544  
     public static Vector<String> getArrowDirections() {
 545  0
         return arrowDirections;
 546  
     }
 547  
 }