Coverage Report - org.argouml.uml.diagram.ui.StylePanelFigAssociationClass
 
Classes in this File Line Coverage Branch Coverage Complexity
StylePanelFigAssociationClass
0%
0/59
0%
0/24
3.333
 
 1  
 /* $Id: StylePanelFigAssociationClass.java 17924 2010-01-27 19:50:58Z 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) 2007 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.ui;
 40  
 
 41  
 import java.awt.Rectangle;
 42  
 import java.awt.event.FocusListener;
 43  
 import java.awt.event.ItemEvent;
 44  
 import java.awt.event.ItemListener;
 45  
 import java.awt.event.KeyListener;
 46  
 import java.beans.PropertyChangeEvent;
 47  
 
 48  
 import javax.swing.JCheckBox;
 49  
 
 50  
 import org.argouml.i18n.Translator;
 51  
 import org.argouml.model.Model;
 52  
 import org.argouml.ui.StylePanelFigNodeModelElement;
 53  
 import org.tigris.gef.presentation.Fig;
 54  
 
 55  
 /**
 56  
  * The style Panel for FigEdgeModelElement.
 57  
  *
 58  
  */
 59  
 public class StylePanelFigAssociationClass
 60  
     extends StylePanelFigNodeModelElement
 61  
     implements ItemListener, FocusListener, KeyListener {
 62  
 
 63  0
     private JCheckBox attrCheckBox =
 64  
         new JCheckBox(Translator.localize("checkbox.attributes"));
 65  
 
 66  0
     private JCheckBox operCheckBox =
 67  
         new JCheckBox(Translator.localize("checkbox.operations"));
 68  
 
 69  
     /**
 70  
      * Flag to indicate that a refresh is going on.
 71  
      */
 72  
     private boolean refreshTransaction;
 73  
 
 74  
     /**
 75  
      * Constructor.
 76  
      */
 77  
     public StylePanelFigAssociationClass() {
 78  0
         super();
 79  
 
 80  0
         addToDisplayPane(attrCheckBox);
 81  0
         addToDisplayPane(operCheckBox);
 82  
 
 83  0
         attrCheckBox.setSelected(false);
 84  0
         operCheckBox.setSelected(false);
 85  0
         attrCheckBox.addItemListener(this);
 86  0
         operCheckBox.addItemListener(this);
 87  0
     }
 88  
 
 89  
     /**
 90  
      * Bounding box is editable (although this is style panel for an
 91  
      * FigEdgeModelElement).
 92  
      * 
 93  
      * @param value Ignored argument.
 94  
      */
 95  
     @Override
 96  
     protected void hasEditableBoundingBox(boolean value) {
 97  0
         super.hasEditableBoundingBox(true);
 98  0
     }
 99  
 
 100  
     /*
 101  
      * @see org.argouml.ui.StylePanelFig#setTargetBBox()
 102  
      */
 103  
     @Override
 104  
     protected void setTargetBBox() {
 105  0
         Fig target = getPanelTarget();
 106  
         // Can't do anything if we don't have a fig.
 107  0
         if (target == null) {
 108  0
             return;
 109  
         }
 110  
         // Parse the boundary box text. Null is
 111  
         // returned if it is empty or
 112  
         // invalid, which causes no change. Otherwise we tell
 113  
         // GEF we are making
 114  
         // a change, make the change and tell GEF we've
 115  
         // finished.
 116  0
         Rectangle bounds = parseBBox();
 117  0
         if (bounds == null) {
 118  0
             return;
 119  
         }
 120  
 
 121  
         // Get class box, because we will set it's bounding box
 122  0
         Rectangle oldAssociationBounds = target.getBounds();
 123  0
         if (((FigAssociationClass) target).getAssociationClass() != null) {
 124  0
             target = ((FigAssociationClass) target).getAssociationClass();
 125  
         }
 126  
 
 127  0
         if (!target.getBounds().equals(bounds)
 128  
                 && !oldAssociationBounds.equals(bounds)) {
 129  0
             target.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
 130  0
             target.endTrans();
 131  
         }
 132  0
     }
 133  
 
 134  
     /*
 135  
      * Only refresh the tab if the bounds propertyChange event arrives.
 136  
      *
 137  
      * @see org.argouml.ui.StylePanel#refresh(java.beans.PropertyChangeEvent)
 138  
      */
 139  
     public void refresh(PropertyChangeEvent e) {
 140  0
         String propertyName = e.getPropertyName();
 141  0
         if (propertyName.equals("bounds")) {
 142  0
             refresh();
 143  
         }
 144  0
     }
 145  
     /*
 146  
      * @see org.argouml.ui.StylePanelFig#refresh()
 147  
      */
 148  
     @Override
 149  
     public void refresh() {
 150  
         // StylePanelFigClass relies on getPanelTarget() to return a 
 151  
         // FigCompartmentBox
 152  0
         refreshTransaction = true;
 153  0
         FigAssociationClass panelTarget =
 154  
             (FigAssociationClass) getPanelTarget();
 155  
         try {
 156  0
             super.refresh();
 157  0
             final FigCompartmentBox fcb = panelTarget.getAssociationClass();
 158  0
             if (fcb != null) {
 159  0
                 FigCompartment compartment =
 160  
                     fcb.getCompartment(Model.getMetaTypes().getAttribute());
 161  0
                 attrCheckBox.setSelected(compartment.isVisible());
 162  0
                 compartment =
 163  
                     fcb.getCompartment(Model.getMetaTypes().getOperation());
 164  0
                 operCheckBox.setSelected(compartment.isVisible());
 165  
             }
 166  
         } finally {
 167  0
             refreshTransaction = false;
 168  0
         }
 169  
 
 170  
         // The boundary box as held in the target fig, and as listed
 171  
         // in the boundary box style field (null if we don't have 
 172  
         // anything valid)
 173  0
         Fig target = panelTarget;
 174  
 
 175  
         // Get class box, because we will set it's bounding box in text field
 176  0
         if (((FigAssociationClass) target).getAssociationClass() != null) {
 177  0
             target = ((FigAssociationClass) target).getAssociationClass();
 178  
         }
 179  
 
 180  0
         Rectangle figBounds = target.getBounds();
 181  0
         Rectangle styleBounds = parseBBox();
 182  
 
 183  
         // Only reset the text if the two are not the same (i.e the fig
 184  
         // has
 185  
         // moved, rather than we've just edited the text, when
 186  
         // setTargetBBox()
 187  
         // will have made them the same). Note that styleBounds could
 188  
         // be null,
 189  
         // so we do the test this way round.
 190  
 
 191  0
         if (!(figBounds.equals(styleBounds))) {
 192  0
             getBBoxField().setText(
 193  
                     figBounds.x + "," + figBounds.y + "," + figBounds.width
 194  
                             + "," + figBounds.height);
 195  
         }
 196  0
     }
 197  
 
 198  
     ////////////////////////////////////////////////////////////////
 199  
     // event handling
 200  
 
 201  
     /*
 202  
      * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
 203  
      */
 204  
     public void itemStateChanged(ItemEvent e) {
 205  0
         if (!refreshTransaction) {
 206  0
             Object src = e.getSource();
 207  
 
 208  0
             if (src == attrCheckBox) {
 209  0
                 FigCompartmentBox fcb = (FigCompartmentBox) getPanelTarget();
 210  0
                 fcb.showCompartment(Model.getMetaTypes().getAttribute(), 
 211  
                         attrCheckBox.isSelected());
 212  0
             } else if (src == operCheckBox) {
 213  0
                 FigCompartmentBox fcb = (FigCompartmentBox) getPanelTarget();
 214  0
                 fcb.showCompartment(Model.getMetaTypes().getOperation(),
 215  
                         operCheckBox.isSelected());
 216  0
             } else {
 217  0
                 super.itemStateChanged(e);
 218  
             }
 219  
         }
 220  0
     }
 221  
 
 222  
 } /* end class StylePanelFigAssociationClass */