Coverage Report - org.argouml.uml.diagram.ui.ModeCreateAssociationClass
 
Classes in this File Line Coverage Branch Coverage Complexity
ModeCreateAssociationClass
0%
0/36
0%
0/6
1.75
 
 1  
 /* $Id: ModeCreateAssociationClass.java 17865 2010-01-12 20:45:26Z 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  
  *    bobtarling
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2006 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  
 
 43  
 import org.apache.log4j.Logger;
 44  
 import org.argouml.model.Model;
 45  
 import org.argouml.ui.ProjectBrowser;
 46  
 import org.argouml.uml.diagram.ArgoDiagram;
 47  
 import org.argouml.uml.diagram.DiagramSettings;
 48  
 import org.tigris.gef.base.Editor;
 49  
 import org.tigris.gef.base.Layer;
 50  
 import org.tigris.gef.base.LayerPerspective;
 51  
 import org.tigris.gef.graph.MutableGraphModel;
 52  
 import org.tigris.gef.presentation.FigEdge;
 53  
 
 54  
 /**
 55  
  * Mode to manage interaction while user is drawing the pseudo-edge that will
 56  
  * become an Association Class. The only difference from a basic edge is that
 57  
  * the completion action is extended to draw the extra associated node and edge
 58  
  * that are part of this composite figure.
 59  
  * 
 60  
  * @author Bob Tarling
 61  
  */
 62  0
 public class ModeCreateAssociationClass extends ModeCreateAssociation {
 63  
 
 64  
     private static final long serialVersionUID = -8656139458297932182L;
 65  
     
 66  0
     private static final Logger LOG =
 67  
         Logger.getLogger(ModeCreateAssociationClass.class);
 68  
 
 69  
     private static final int DISTANCE = 80;
 70  
     
 71  
     public Object getMetaType() {
 72  0
         return Model.getMetaTypes().getAssociationClass();
 73  
     }
 74  
     
 75  
     @Override
 76  
     protected void endAttached(FigEdge fe) {
 77  0
         Layer lay = editor.getLayerManager().getActiveLayer();
 78  0
         FigAssociationClass thisFig =
 79  
             (FigAssociationClass) lay.presentationFor(getNewEdge());
 80  0
         buildParts(editor, thisFig, lay);
 81  0
     }
 82  
 
 83  
     /**
 84  
      * Build the complex representation of an AssociationClass in the active
 85  
      * layer of the current editor. This is a convenience function which is used
 86  
      * when the pseudo-edge is added to a diagram via drag-and-drop or by using
 87  
      * the "Add to Diagram" menu item.
 88  
      * 
 89  
      * @param editor
 90  
      *            the GEF editor
 91  
      * @param element
 92  
      *            the model element
 93  
      */
 94  
     public static void buildInActiveLayer(Editor editor, Object element) {
 95  0
         Layer layer = editor.getLayerManager().getActiveLayer();
 96  0
         FigAssociationClass thisFig =
 97  
             (FigAssociationClass) layer.presentationFor(element);
 98  0
         if (thisFig != null) {
 99  0
             buildParts(editor, thisFig, layer);
 100  
         }
 101  0
     }
 102  
     
 103  
     private static void buildParts(Editor editor, FigAssociationClass thisFig,
 104  
             Layer lay) {
 105  
         
 106  0
         thisFig.removePathItem(thisFig.getMiddleGroup());
 107  
 
 108  0
         MutableGraphModel mutableGraphModel =
 109  
             (MutableGraphModel) editor.getGraphModel();
 110  0
         mutableGraphModel.addNode(thisFig.getOwner());
 111  
 
 112  
         // TODO: This can't depend on ProjectBrowser.  It needs to get
 113  
         // the current drawing area from the Diagram subsystem or GEF
 114  0
         Rectangle drawingArea =
 115  
             ProjectBrowser.getInstance()
 116  
                 .getEditorPane().getBounds();
 117  
         // Perhaps something like the following would workd.  If not, then 
 118  
         // traverse up the component hierarchy to a MultEditorPane
 119  
 //        Rectangle drawingArea = 
 120  
 //            Globals.curEditor().getJComponent().getVisibleRect();
 121  
         
 122  0
         thisFig.makeEdgePort();
 123  0
         FigEdgePort tee = thisFig.getEdgePort();
 124  0
         thisFig.calcBounds();
 125  
 
 126  0
         int x = tee.getX();
 127  0
         int y = tee.getY();
 128  
 
 129  0
         DiagramSettings settings = ((ArgoDiagram) ((LayerPerspective) lay)
 130  
                 .getDiagram()).getDiagramSettings();
 131  
         
 132  0
         LOG.info("Creating Class box for association class");
 133  0
         FigClassAssociationClass figNode =
 134  
             new FigClassAssociationClass(thisFig.getOwner(), 
 135  
                             new Rectangle(x, y, 0, 0),
 136  
                             settings);
 137  0
         y = y - DISTANCE;
 138  0
         if (y < 0) {
 139  0
             y = tee.getY() + figNode.getHeight() + DISTANCE;
 140  
         }
 141  0
         if (x + figNode.getWidth() > drawingArea.getWidth()) {
 142  0
             x = tee.getX() - DISTANCE;
 143  
         }
 144  0
         figNode.setLocation(x, y);
 145  0
         lay.add(figNode);
 146  
 
 147  0
         FigEdgeAssociationClass dashedEdge =
 148  
             new FigEdgeAssociationClass(figNode, thisFig, settings);
 149  0
         lay.add(dashedEdge);
 150  
 
 151  0
         dashedEdge.damage();
 152  0
         figNode.damage();
 153  0
     }
 154  
 }