Coverage Report - org.argouml.uml.diagram.static_structure.layout.ClassdiagramInheritanceEdge
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassdiagramInheritanceEdge
0%
0/34
0%
0/8
1.5
 
 1  
 /* $Id: ClassdiagramInheritanceEdge.java 17863 2010-01-12 20:07:22Z 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  
  *    linus
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-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.static_structure.layout;
 40  
 
 41  
 import org.apache.log4j.Logger;
 42  
 import org.tigris.gef.presentation.Fig;
 43  
 import org.tigris.gef.presentation.FigEdge;
 44  
 
 45  
 /**
 46  
  *
 47  
  * @author mkl
 48  
  */
 49  
 public abstract class ClassdiagramInheritanceEdge extends ClassdiagramEdge {
 50  0
     private static final Logger LOG = Logger
 51  
             .getLogger(ClassdiagramInheritanceEdge.class);
 52  
     
 53  
     /**
 54  
      * The largest difference that we consider equivalent to zero
 55  
      */
 56  
     private static final int EPSILON = 5;
 57  
 
 58  
     /**
 59  
      * The figures which are connected by this edge
 60  
      */
 61  
     private Fig high, low;
 62  
 
 63  
     /**
 64  
      * Offset used to distribute the lines
 65  
      */
 66  
     private int offset;
 67  
 
 68  
     /**
 69  
      * Constructor.
 70  
      *
 71  
      * @param edge the fig edge
 72  
      */
 73  
     public ClassdiagramInheritanceEdge(FigEdge edge) {
 74  0
         super(edge);
 75  
 
 76  
         // calculate the higher and lower Figs
 77  0
         high = getDestFigNode();
 78  0
         low = getSourceFigNode();
 79  0
         offset = 0;
 80  0
     }
 81  
 
 82  
     /**
 83  
      * @return the vertical offset
 84  
      */
 85  
     public int getVerticalOffset() {
 86  0
         return (getVGap() / 2) - 10 + getOffset();
 87  
     }
 88  
 
 89  
     /**
 90  
      * @return the center of the high node
 91  
      */
 92  
     public int getCenterHigh() {
 93  0
         return (int) (high.getLocation().getX() + high.getSize().width / 2)
 94  
             + getOffset();
 95  
     }
 96  
 
 97  
     /**
 98  
      * @return the center of the low node
 99  
      */
 100  
     public int getCenterLow() {
 101  0
         return (int) (low.getLocation().getX() + low.getSize().width / 2)
 102  
                 + getOffset();
 103  
     }
 104  
 
 105  
     /**
 106  
      * @return the gap with the node one level down
 107  
      */
 108  
     public int getDownGap() {
 109  0
         return (int) (low.getLocation().getY() - getVerticalOffset());
 110  
     }
 111  
 
 112  
     /**
 113  
      * @see org.argouml.uml.diagram.layout.LayoutedEdge#layout()
 114  
      *
 115  
      * Layout the edges in a way that they form a nice inheritance tree. Try to
 116  
      * implement these nice zigzag lines between classes and works well when the
 117  
      * row difference is one.
 118  
      *
 119  
      * @author Markus Klink
 120  
      * @since 0.9.6
 121  
      */
 122  
     public void layout() {
 123  
         // now we construct the zig zag inheritance line
 124  
         //getUnderlyingFig()
 125  0
         Fig fig = getUnderlyingFig();
 126  0
         int centerHigh = getCenterHigh();
 127  0
         int centerLow = getCenterLow();
 128  
 
 129  
         // the amount of the "sidestep"
 130  0
         int difference = centerHigh - centerLow;
 131  
 
 132  
         /*
 133  
          * If center points are "close enough" we just adjust the endpoints
 134  
          * of the line a little bit.  Otherwise we add a jog in the middle to
 135  
          * deal with the offset.
 136  
          * 
 137  
          * TODO: Epsilon is currently fixed, but could probably be computed
 138  
          * dynamically as 10% of the width of the narrowest figure or some
 139  
          * other value which is visually not noticeable.
 140  
          */
 141  0
         if (Math.abs(difference) < EPSILON) {
 142  0
             fig.addPoint(centerLow + (difference / 2 + (difference % 2)), 
 143  
                     (int) (low.getLocation().getY()));
 144  0
             fig.addPoint(centerHigh - (difference / 2),
 145  
                     high.getLocation().y + high.getSize().height);
 146  
         } else {
 147  0
             fig.addPoint(centerLow, (int) (low.getLocation().getY()));
 148  0
             if (LOG.isDebugEnabled()) {
 149  0
                 LOG.debug("Point: x: " + centerLow + " y: " 
 150  
                         + low.getLocation().y);
 151  
             }
 152  
 
 153  0
             getUnderlyingFig().addPoint(centerHigh - difference, getDownGap());
 154  0
             getUnderlyingFig().addPoint(centerHigh, getDownGap());
 155  0
             if (LOG.isDebugEnabled()) {
 156  0
                 LOG.debug("Point: x: " + (centerHigh - difference) + " y: "
 157  
                         + getDownGap());
 158  0
                 LOG.debug("Point: x: " + centerHigh + " y: " + getDownGap());
 159  
             }
 160  
 
 161  0
             fig.addPoint(centerHigh, 
 162  
                     high.getLocation().y + high.getSize().height);
 163  0
             if (LOG.isDebugEnabled()) {
 164  0
                 LOG.debug("Point x: " + centerHigh + " y: "
 165  
                         + (high.getLocation().y + high.getSize().height));
 166  
             }
 167  
         }
 168  0
         fig.setFilled(false);
 169  0
         getCurrentEdge().setFig(getUnderlyingFig());
 170  
         // currentEdge.setBetweenNearestPoints(false);
 171  0
     }
 172  
 
 173  
     /**
 174  
      * Set the line-offset for this edge
 175  
      *
 176  
      * @param anOffset
 177  
      *            the offset to use for this edge
 178  
      */
 179  
     public void setOffset(int anOffset) {
 180  0
         offset = anOffset;
 181  0
     }
 182  
 
 183  
     /**
 184  
      * @return Line-offset for this edge
 185  
      */
 186  
     public int getOffset() {
 187  0
         return offset;
 188  
     }
 189  
 
 190  
 }
 191