Coverage Report - org.argouml.uml.diagram.ui.ArgoFigUtil
 
Classes in this File Line Coverage Branch Coverage Complexity
ArgoFigUtil
0%
0/30
0%
0/20
4.75
 
 1  
 /* $Id: ArgoFigUtil.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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 2007-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.ui;
 40  
 
 41  
 import java.awt.Color;
 42  
 import java.awt.Dimension;
 43  
 
 44  
 import org.argouml.kernel.Project;
 45  
 import org.argouml.kernel.ProjectManager;
 46  
 import org.argouml.uml.diagram.UMLMutableGraphSupport;
 47  
 import org.tigris.gef.base.Editor;
 48  
 import org.tigris.gef.base.Globals;
 49  
 import org.tigris.gef.base.Layer;
 50  
 import org.tigris.gef.base.LayerPerspective;
 51  
 import org.tigris.gef.graph.GraphModel;
 52  
 import org.tigris.gef.presentation.Fig;
 53  
 import org.tigris.gef.presentation.FigCircle;
 54  
 import org.tigris.gef.presentation.FigEdge;
 55  
 import org.tigris.gef.presentation.FigRect;
 56  
 
 57  
 /**
 58  
  * Static utility methods for use with ArgoFigs.
 59  
  * 
 60  
  * @author Tom Morris <tfmorris@gmail.com>
 61  
  */
 62  0
 public class ArgoFigUtil {
 63  
     
 64  
     /**
 65  
      * Find the Project that contains a given figure.  Because we don't have
 66  
      * a single reliable way to do this, we try a bunch of different approaches.
 67  
      * 
 68  
      * @param fig the Fig to return the project of
 69  
      * @return the project containing the given fig
 70  
      */
 71  
     public static Project getProject(ArgoFig fig) {
 72  0
         if (fig instanceof Fig) {
 73  0
             Fig f = (Fig) fig;
 74  0
             LayerPerspective layer = (LayerPerspective) f.getLayer();
 75  0
             if (layer == null) {
 76  
                 /* TODO: Without this, we fail to draw e.g. a Class.
 77  
                  * But is this a good solution? 
 78  
                  * Why is the Layer not set in the constructor? */
 79  0
                 Editor editor = Globals.curEditor();
 80  0
                 if (editor == null) {
 81  
                     // TODO: The above doesn't work reliably in a constructor.
 82  
                     // We need a better way of getting default fig settings 
 83  
                     // for the owning project rather than using the 
 84  
                     // project manager singleton. - tfm
 85  0
                     return ProjectManager.getManager().getCurrentProject();
 86  
                 }
 87  0
                 Layer lay = editor.getLayerManager().getActiveLayer();
 88  0
                 if (lay instanceof LayerPerspective) {
 89  0
                     layer = (LayerPerspective) lay;
 90  
                 }
 91  
             }
 92  0
             if (layer == null) {
 93  0
                 return ProjectManager.getManager().getCurrentProject();
 94  
             }
 95  0
             GraphModel gm = layer.getGraphModel();
 96  0
             if (gm instanceof UMLMutableGraphSupport) {
 97  0
                 Project project = ((UMLMutableGraphSupport) gm).getProject();
 98  0
                 if (project != null) {
 99  0
                     return project;
 100  
                 }
 101  
             }
 102  0
             return ProjectManager.getManager().getCurrentProject();
 103  
         }
 104  0
         return null;
 105  
     }
 106  
 
 107  
 
 108  
     /**
 109  
      * Add pretty little markers for debugging purposes. We use three markers so
 110  
      * you can see the anchor, the computed target position, and how collision
 111  
      * detection affects a largish box.
 112  
      */
 113  
     static void markPosition(FigEdge fe, 
 114  
             int pct, int delta, int angle, int offset,
 115  
             Color color) {
 116  
         // set this to true on to enable debugging figs
 117  
         if (false) {
 118  
             Fig f;
 119  
             f = new FigCircle(0, 0, 5, 5, color, Color.red);
 120  
             // anchor position
 121  
             fe.addPathItem(f, new PathItemPlacement(fe, f, pct, delta, angle, 
 122  
                     0));
 123  
             f = new FigRect(0, 0, 100, 20, color, Color.red);
 124  
             f.setFilled(false);
 125  
             fe.addPathItem(f, new PathItemPlacement(fe, f, pct, delta, angle,
 126  
                     offset));
 127  
             f = new FigCircle(0, 0, 5, 5, color, Color.blue);
 128  
             fe.addPathItem(f, new PathItemPlacement(fe, f, pct, delta, angle,
 129  
                     offset));
 130  
         }
 131  0
     }
 132  
 
 133  
     /**
 134  
      * This utility adds the size of a child component to an overall size. The
 135  
      * width is maximized with child's width and the child's height is added to
 136  
      * the overall height. If the child figure is not visible or not yet
 137  
      * created, it's size is not added.
 138  
      * 
 139  
      * @param size current dimensions - modified with the result
 140  
      * @param child child figure
 141  
      * @return new Dimension with child size added
 142  
      */
 143  
     public static Dimension addChildDimensions(Dimension size, Fig child) {
 144  0
         if (child != null && child.isVisible()) {
 145  0
             Dimension childSize = child.getMinimumSize();
 146  0
             size.width = Math.max(size.width, childSize.width);
 147  0
             size.height += childSize.height;
 148  
         }
 149  0
         return size;
 150  
     }
 151  
 
 152  
 
 153  
     /**
 154  
      * This utility adds the width of a child component to an overall size. The
 155  
      * width is maximized with child's width and the child's height is ignored.
 156  
      * If the child figure is not visible, it's size is not added.
 157  
      * 
 158  
      * @param size current dimensions - modified with the result
 159  
      * @param child child figure
 160  
      * @return new Dimension with child width added
 161  
      */
 162  
     public static Dimension addChildWidth(Dimension size, Fig child) {
 163  0
         if (child.isVisible()) {
 164  0
             Dimension childSize = child.getMinimumSize();
 165  0
             size.width = Math.max(size.width, childSize.width);
 166  
         }
 167  0
         return size;
 168  
     }
 169  
 }