Coverage Report - org.argouml.uml.diagram.state.ui.FigTransition
 
Classes in this File Line Coverage Branch Coverage Complexity
FigTransition
0%
0/96
0%
0/22
1.923
 
 1  
 /* $Id: FigTransition.java 17862 2010-01-12 20:06:14Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 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  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-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.Graphics;
 42  
 import java.awt.event.MouseEvent;
 43  
 import java.util.Vector;
 44  
 
 45  
 import javax.swing.Action;
 46  
 
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.notation.NotationProviderFactory2;
 49  
 import org.argouml.ui.ArgoJMenu;
 50  
 import org.argouml.ui.targetmanager.TargetManager;
 51  
 import org.argouml.uml.diagram.DiagramSettings;
 52  
 import org.argouml.uml.diagram.ui.FigEdgeModelElement;
 53  
 import org.argouml.uml.diagram.ui.PathItemPlacement;
 54  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewActionSequence;
 55  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewCallAction;
 56  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewCreateAction;
 57  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewDestroyAction;
 58  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewReturnAction;
 59  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewSendAction;
 60  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewTerminateAction;
 61  
 import org.argouml.uml.ui.behavior.common_behavior.ActionNewUninterpretedAction;
 62  
 import org.argouml.uml.ui.behavior.state_machines.ButtonActionNewGuard;
 63  
 import org.tigris.gef.base.Layer;
 64  
 import org.tigris.gef.presentation.ArrowHeadGreater;
 65  
 import org.tigris.gef.presentation.Fig;
 66  
 import org.tigris.gef.presentation.FigNode;
 67  
 
 68  
 /**
 69  
  * This class represents the graphical representation of a transition
 70  
  * on a Statechart diagram and an Activity diagram.
 71  
  */
 72  
 public class FigTransition extends FigEdgeModelElement {
 73  
 
 74  0
     private ArrowHeadGreater endArrow = new ArrowHeadGreater();
 75  
 
 76  
     /**
 77  
      * If <code>dashed</code> is true, then the transition represents
 78  
      * "object flow".
 79  
      * If the line is solid, then it represents "control flow".
 80  
      */
 81  
     private boolean dashed;
 82  
     
 83  
     /**
 84  
      * Constructor used by PGML parser.
 85  
      * 
 86  
      * @param owner owning uml element
 87  
      * @param settings rendering settings
 88  
      */
 89  
     public FigTransition(Object owner, DiagramSettings settings) {
 90  0
         super(owner, settings);
 91  
         
 92  0
         initializeTransition();
 93  0
     }
 94  
 
 95  
     private void initializeTransition() {
 96  0
         addPathItem(getNameFig(),
 97  
                 new PathItemPlacement(this, getNameFig(), 50, 10));
 98  0
         getFig().setLineColor(LINE_COLOR);
 99  0
         setDestArrowHead(endArrow);
 100  0
         allowRemoveFromDiagram(false);
 101  
         
 102  0
         updateDashed();
 103  0
     }
 104  
 
 105  
     @Override
 106  
     public void setLayer(Layer lay) {
 107  0
         super.setLayer(lay);
 108  
 
 109  
         /* This presumes that the layer is set after the owner: */
 110  0
         if (getLayer() != null && getOwner() != null) {
 111  0
             initPorts(lay, getOwner());
 112  
         }
 113  0
     }
 114  
 
 115  
     /**
 116  
      * Set the owners of the associated FigNodes to be the StateVertexes which
 117  
      * are at either end of the Transition.
 118  
      * <p>
 119  
      * TODO: This needs documentation! Is this really needed? Why?
 120  
      * 
 121  
      * @param lay diagram layer containing this fig
 122  
      * @param owner owning UML element
 123  
      * @deprecated in 0.28 by Bob Tarling - The above TODO is from Michiel.
 124  
      * I also don't understand the purpose of this method. The GEF framework
 125  
      * should be setting source/dest or persistence should manage.
 126  
      */
 127  
     @Deprecated
 128  
     private void initPorts(Layer lay, Object owner) {
 129  0
         final Object sourceSV = Model.getFacade().getSource(owner);
 130  0
         final FigNode sourceFN = (FigNode) lay.presentationFor(sourceSV);
 131  0
         if (sourceFN != null) {
 132  
             // The purpose of this method is not explained and it give give
 133  
             // NPE depending on z order of figs as they are read. For now
 134  
             // ignore if null but for future lets delete this.
 135  0
             setSourcePortFig(sourceFN);
 136  0
             setSourceFigNode(sourceFN);
 137  
         }
 138  
         
 139  0
         final Object destSV = Model.getFacade().getTarget(owner);
 140  0
         final FigNode destFN = (FigNode) lay.presentationFor(destSV);
 141  0
         if (destFN != null) {
 142  
             // The purpose of this method is not explained and it give give
 143  
             // NPE depending on z order of figs as they are read. For now
 144  
             // ignore if null but for future lets delete this.
 145  0
             setDestPortFig(destFN);
 146  0
             setDestFigNode(destFN);
 147  
         }
 148  0
     }
 149  
 
 150  
     /*
 151  
      * The Transition has a name text box. It contains:
 152  
      * <ul>
 153  
      * <li>The event-signature
 154  
      * <li>The guard condition between []
 155  
      * <li>The action expression
 156  
      * </ul><p>
 157  
      *
 158  
      * The content of the text box is generated by its own notationProvider.
 159  
      * 
 160  
      * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getNotationProviderType()
 161  
      */
 162  
     @Override
 163  
     protected int getNotationProviderType() {
 164  0
         return NotationProviderFactory2.TYPE_TRANSITION;
 165  
     }
 166  
 
 167  
     @Override
 168  
     public void renderingChanged() {
 169  0
         super.renderingChanged();
 170  0
         updateDashed();
 171  0
     }
 172  
     
 173  
     /**
 174  
      * The transition is dashed if connected to an 
 175  
      * ObjectFlowState (only for an Activity diagram).
 176  
      * This method updates the rendering of the transition on the diagram.
 177  
      */
 178  
     private void updateDashed() {
 179  0
         if (Model.getFacade().isATransition(getOwner())) {
 180  0
             dashed =
 181  
                 Model.getFacade().isAObjectFlowState(
 182  
                         Model.getFacade().getSource(getOwner()))
 183  
                     || Model.getFacade().isAObjectFlowState(
 184  
                             Model.getFacade().getTarget(getOwner()));
 185  0
             getFig().setDashed(dashed);
 186  
         }
 187  0
     }
 188  
 
 189  
     @Override
 190  
     public Vector getPopUpActions(MouseEvent me) {
 191  0
         Vector popUpActions = super.getPopUpActions(me);
 192  
         /* Check if multiple items are selected: */
 193  0
         boolean ms = TargetManager.getInstance().getTargets().size() > 1;
 194  
         /* None of the menu-items below apply
 195  
          * when multiple modelelements are selected:*/
 196  0
         if (ms) {
 197  0
             return popUpActions;
 198  
         }
 199  
 
 200  
         Action a;
 201  
 
 202  0
         ArgoJMenu triggerMenu =
 203  
             new ArgoJMenu("menu.popup.trigger");
 204  0
         a = new ButtonActionNewCallEvent();
 205  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 206  0
         triggerMenu.add(a);
 207  0
         a = new ButtonActionNewChangeEvent();
 208  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 209  0
         triggerMenu.add(a);
 210  0
         a = new ButtonActionNewSignalEvent();
 211  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 212  0
         triggerMenu.add(a);
 213  0
         a = new ButtonActionNewTimeEvent();
 214  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 215  0
         triggerMenu.add(a);
 216  0
         popUpActions.add(
 217  
                 popUpActions.size() - getPopupAddOffset(),
 218  
                 triggerMenu);
 219  
 
 220  0
         a = new ButtonActionNewGuard();
 221  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 222  0
         popUpActions.add(popUpActions.size() - getPopupAddOffset(), a);
 223  
 
 224  0
         ArgoJMenu effectMenu =
 225  
             new ArgoJMenu("menu.popup.effect");
 226  0
         a = ActionNewCallAction.getButtonInstance();
 227  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 228  0
         effectMenu.add(a);
 229  0
         a = ActionNewCreateAction.getButtonInstance();
 230  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 231  0
         effectMenu.add(a);
 232  0
         a = ActionNewDestroyAction.getButtonInstance();
 233  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 234  0
         effectMenu.add(a);
 235  0
         a = ActionNewReturnAction.getButtonInstance();
 236  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 237  0
         effectMenu.add(a);
 238  0
         a = ActionNewSendAction.getButtonInstance();
 239  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 240  0
         effectMenu.add(a);
 241  0
         a = ActionNewTerminateAction.getButtonInstance();
 242  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 243  0
         effectMenu.add(a);
 244  0
         a = ActionNewUninterpretedAction.getButtonInstance();
 245  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 246  0
         effectMenu.add(a);
 247  0
         a = ActionNewActionSequence.getButtonInstance();
 248  0
         a.putValue(Action.NAME, a.getValue(Action.SHORT_DESCRIPTION));
 249  0
         effectMenu.add(a);
 250  0
         popUpActions.add(popUpActions.size() - getPopupAddOffset(), 
 251  
                 effectMenu);
 252  
 
 253  0
         return popUpActions;
 254  
     }
 255  
 
 256  
     /*
 257  
      * @see org.tigris.gef.presentation.FigEdge#setFig(org.tigris.gef.presentation.Fig)
 258  
      */
 259  
     @Override
 260  
     public void setFig(Fig f) {
 261  0
         super.setFig(f);
 262  0
         getFig().setDashed(dashed);
 263  0
     }
 264  
 
 265  
     /*
 266  
      * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getDestination()
 267  
      */
 268  
     @Override
 269  
     protected Object getDestination() {
 270  0
         if (getOwner() != null) {
 271  0
             return Model.getStateMachinesHelper().getDestination(getOwner());
 272  
         }
 273  0
         return null;
 274  
     }
 275  
 
 276  
     /*
 277  
      * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#getSource()
 278  
      */
 279  
     @Override
 280  
     protected Object getSource() {
 281  0
         if (getOwner() != null) {
 282  0
             return Model.getStateMachinesHelper().getSource(getOwner());
 283  
         }
 284  0
         return null;
 285  
     }
 286  
 
 287  
     /*
 288  
      * @see org.tigris.gef.presentation.Fig#paint(java.awt.Graphics)
 289  
      */
 290  
     @Override
 291  
     public void paint(Graphics g) {
 292  0
         endArrow.setLineColor(getLineColor());
 293  0
         super.paint(g);
 294  0
     }
 295  
 
 296  
     /*
 297  
      * @see org.argouml.uml.diagram.ui.FigEdgeModelElement#paintClarifiers(java.awt.Graphics)
 298  
      */
 299  
     @Override
 300  
     public void paintClarifiers(Graphics g) {
 301  0
         indicateBounds(getNameFig(), g);
 302  0
         super.paintClarifiers(g);
 303  0
     }
 304  
 
 305  
 }