Coverage Report - org.argouml.uml.diagram.state.ui.FigState
 
Classes in this File Line Coverage Branch Coverage Complexity
FigState
0%
0/74
0%
0/30
1.842
 
 1  
 /* $Id: FigState.java 18859 2010-11-29 21:37:03Z 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  
  *    Bob Tarling
 12  
  *    Tom Morris
 13  
  *****************************************************************************
 14  
  *
 15  
  * Some portions of this file was previously release using the BSD License:
 16  
  */
 17  
 
 18  
 // Copyright (c) 1996-2009 The Regents of the University of California. All
 19  
 // Rights Reserved. Permission to use, copy, modify, and distribute this
 20  
 // software and its documentation without fee, and without a written
 21  
 // agreement is hereby granted, provided that the above copyright notice
 22  
 // and this paragraph appear in all copies. This software program and
 23  
 // documentation are copyrighted by The Regents of the University of
 24  
 // California. The software program and documentation are supplied "AS
 25  
 // IS", without any accompanying services from The Regents. The Regents
 26  
 // does not warrant that the operation of the program will be
 27  
 // uninterrupted or error-free. The end-user understands that the program
 28  
 // was developed for research purposes and is advised not to rely
 29  
 // exclusively on the program for any reason. IN NO EVENT SHALL THE
 30  
 // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
 31  
 // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS,
 32  
 // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 33  
 // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
 34  
 // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
 35  
 // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 36  
 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 37  
 // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 38  
 // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,
 39  
 // UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 40  
 
 41  
 package org.argouml.uml.diagram.state.ui;
 42  
 
 43  
 import java.awt.Font;
 44  
 import java.awt.Rectangle;
 45  
 import java.beans.PropertyChangeEvent;
 46  
 import java.beans.PropertyVetoException;
 47  
 
 48  
 import org.argouml.model.AssociationChangeEvent;
 49  
 import org.argouml.model.AttributeChangeEvent;
 50  
 import org.argouml.model.Model;
 51  
 import org.argouml.notation.Notation;
 52  
 import org.argouml.notation.NotationName;
 53  
 import org.argouml.notation.NotationProvider;
 54  
 import org.argouml.notation.NotationProviderFactory2;
 55  
 import org.argouml.notation.NotationSettings;
 56  
 import org.argouml.uml.diagram.DiagramSettings;
 57  
 import org.tigris.gef.presentation.Fig;
 58  
 import org.tigris.gef.presentation.FigRRect;
 59  
 import org.tigris.gef.presentation.FigText;
 60  
 
 61  
 /**
 62  
  * Abstract class with common functionality for all Figs representing a UML
 63  
  * State element.
 64  
  *
 65  
  * @author jaap.branderhorst@xs4all.nl
 66  
  * @since Dec 30, 2002
 67  
  */
 68  0
 public abstract class FigState extends FigStateVertex {
 69  
 
 70  
     protected static final int SPACE_TOP = 0;
 71  
     protected static final int SPACE_MIDDLE = 0;
 72  
     protected static final int DIVIDER_Y = 0;
 73  
     protected static final int SPACE_BOTTOM = 6;
 74  
 
 75  
     protected static final int MARGIN = 2;
 76  
 
 77  
     protected NotationProvider notationProviderBody;
 78  
 
 79  
     /**
 80  
      * The text inside the state.
 81  
      */
 82  
     private FigText internal;
 83  
 
 84  
     /**
 85  
      * Constructor used by PGML parser.
 86  
      * 
 87  
      * @param owner the owning UML element
 88  
      * @param bounds rectangle describing bounds
 89  
      * @param settings rendering settings
 90  
      */
 91  
     public FigState(Object owner, Rectangle bounds, DiagramSettings settings) {
 92  0
         super(owner, bounds, settings);
 93  
 
 94  0
         initializeState();
 95  
 
 96  0
         NotationName notation = Notation.findNotation(
 97  
                 getNotationSettings().getNotationLanguage());
 98  0
         notationProviderBody =
 99  
             NotationProviderFactory2.getInstance().getNotationProvider(
 100  
                     NotationProviderFactory2.TYPE_STATEBODY, getOwner(), this, 
 101  
                     notation);
 102  0
     }
 103  
 
 104  
     @Override
 105  
     protected Fig createBigPortFig() {
 106  0
         return new FigRRect(getInitialX() + 1, getInitialY() + 1,
 107  
                 getInitialWidth() - 2, getInitialHeight() - 2,
 108  
                 DEBUG_COLOR, DEBUG_COLOR);
 109  
     }
 110  
 
 111  
     private void initializeState() {
 112  
         // TODO: Get rid of magic numbers!  Figure out which represent line
 113  
         // widths vs padding vs offsets
 114  0
         getNameFig().setLineWidth(0);
 115  0
         getNameFig().setBounds(getInitialX() + 2, getInitialY() + 2,
 116  
                        getInitialWidth() - 4,
 117  
                        getNameFig().getBounds().height);
 118  0
         getNameFig().setFilled(false);
 119  
 
 120  0
         internal =
 121  
             new FigText(getInitialX() + 2,
 122  
                     getInitialY() + 2 + NAME_FIG_HEIGHT + 4,
 123  
                     getInitialWidth() - 4,
 124  
                     getInitialHeight() 
 125  
                     - (getInitialY() + 2 + NAME_FIG_HEIGHT + 4));
 126  0
         internal.setFont(getSettings().getFont(Font.PLAIN));
 127  0
         internal.setTextColor(TEXT_COLOR);
 128  0
         internal.setLineWidth(0);
 129  0
         internal.setFilled(false);
 130  0
         internal.setExpandOnly(true);
 131  0
         internal.setReturnAction(FigText.INSERT);
 132  0
         internal.setJustification(FigText.JUSTIFY_LEFT);
 133  0
     }
 134  
 
 135  
     /*
 136  
      * @see org.argouml.uml.diagram.state.ui.FigStateVertex#initNotationProviders(java.lang.Object)
 137  
      */
 138  
     @Override
 139  
     protected void initNotationProviders(Object own) {
 140  0
         if (notationProviderBody != null) {
 141  0
             notationProviderBody.cleanListener();
 142  
         }
 143  0
         super.initNotationProviders(own);
 144  0
         NotationName notation = Notation.findNotation(
 145  
                 getNotationSettings().getNotationLanguage());
 146  0
         if (Model.getFacade().isAState(own)) {
 147  0
             notationProviderBody =
 148  
                 NotationProviderFactory2.getInstance().getNotationProvider(
 149  
                         NotationProviderFactory2.TYPE_STATEBODY, own, this, 
 150  
                         notation);
 151  
         }
 152  0
     }
 153  
 
 154  
     @Override
 155  
     protected void modelChanged(PropertyChangeEvent mee) {
 156  0
         super.modelChanged(mee);
 157  
         // TODO: Do we really need to be listening for both of these events?
 158  0
         if (mee instanceof AssociationChangeEvent 
 159  
                 || mee instanceof AttributeChangeEvent) {
 160  
             
 161  
             // TODO: We definitely don't want to react to addition and
 162  
             // removal of transitions. Can't we be more specific when
 163  
             // we register ourselves as a listener.
 164  0
             if ((mee.getPropertyName().equals("incoming")
 165  
                         || mee.getPropertyName().equals("outgoing"))) {
 166  0
                 return;
 167  
             }
 168  
             
 169  0
             renderingChanged();
 170  0
             damage();
 171  
         }
 172  0
     }
 173  
 
 174  
     /*
 175  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#removeFromDiagramImpl()
 176  
      */
 177  
     @Override
 178  
     public void removeFromDiagramImpl() {
 179  0
         if (notationProviderBody != null) {
 180  0
             notationProviderBody.cleanListener();
 181  
         }
 182  0
         super.removeFromDiagramImpl();
 183  0
     }
 184  
 
 185  
     /*
 186  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#renderingChanged()
 187  
      */
 188  
     @Override
 189  
     public void renderingChanged() {
 190  0
         super.renderingChanged();
 191  0
         Object state = getOwner();
 192  
         // Entered in 0.29.3
 193  
         // Prove that the test below is not needed
 194  0
         assert state != null;
 195  0
         if (state == null) {
 196  0
             return;
 197  
         }
 198  0
         if (notationProviderBody != null) {
 199  0
             internal.setText(notationProviderBody.toString(getOwner(), 
 200  
                     getNotationSettings()));
 201  
         }
 202  0
         calcBounds();
 203  0
         setBounds(getBounds());
 204  0
     }
 205  
 
 206  
     /**
 207  
      * @return the initial X
 208  
      */
 209  
     protected abstract int getInitialX();
 210  
 
 211  
     /**
 212  
      * @return the initial Y
 213  
      */
 214  
     protected abstract int getInitialY();
 215  
 
 216  
     /**
 217  
      * @return the initial width
 218  
      */
 219  
     protected abstract int getInitialWidth();
 220  
 
 221  
     /**
 222  
      * @return the initial height
 223  
      */
 224  
     protected abstract int getInitialHeight();
 225  
 
 226  
     /**
 227  
      * @param theInternal The internal to set.
 228  
      */
 229  
     protected void setInternal(FigText theInternal) {
 230  0
         this.internal = theInternal;
 231  0
     }
 232  
 
 233  
     /**
 234  
      * @return Returns the internal.
 235  
      */
 236  
     protected FigText getInternal() {
 237  0
         return internal;
 238  
     }
 239  
 
 240  
     /*
 241  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#textEditStarted(org.tigris.gef.presentation.FigText)
 242  
      */
 243  
     @Override
 244  
     protected void textEditStarted(FigText ft) {
 245  0
         super.textEditStarted(ft);
 246  0
         if (ft == internal) {
 247  0
             showHelp(notationProviderBody.getParsingHelp());
 248  
         }
 249  0
     }
 250  
 
 251  
     /*
 252  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#textEdited(org.tigris.gef.presentation.FigText)
 253  
      */
 254  
     @Override
 255  
     public void textEdited(FigText ft) throws PropertyVetoException {
 256  0
         super.textEdited(ft);
 257  0
         if (ft == getInternal()) {
 258  0
             Object st = getOwner();
 259  0
             if (st == null) {
 260  0
                 return;
 261  
             }
 262  0
             notationProviderBody.parse(getOwner(), ft.getText());
 263  0
             ft.setText(notationProviderBody.toString(getOwner(), 
 264  
                     getNotationSettings()));
 265  
         }
 266  0
     }
 267  
 
 268  
     /**
 269  
      * 
 270  
      * @see org.argouml.uml.diagram.ui.FigNodeModelElement#updateFont()
 271  
      */
 272  
     @Override
 273  
     protected void updateFont() {
 274  0
         super.updateFont();
 275  0
         Font f = getSettings().getFont(Font.PLAIN);
 276  0
         internal.setFont(f);
 277  0
     }
 278  
 
 279  
     public void notationRenderingChanged(NotationProvider np, String rendering) {
 280  0
         super.notationRenderingChanged(np, rendering);
 281  0
         if (notationProviderBody == np) {
 282  0
             internal.setText(rendering);
 283  0
             updateBounds();
 284  0
             damage();
 285  
         }
 286  0
     }
 287  
 
 288  
     public NotationSettings getNotationSettings(NotationProvider np) {
 289  
         // both have the same settings
 290  0
         return getNotationSettings();
 291  
     }
 292  
 
 293  
     public Object getOwner(NotationProvider np) {
 294  
         // both have the same owner
 295  0
         return getOwner();
 296  
     }
 297  
 
 298  
 }