Coverage Report - org.argouml.uml.diagram.layout.LayoutHelper
 
Classes in this File Line Coverage Branch Coverage Complexity
LayoutHelper
0%
0/32
0%
0/38
5.75
 
 1  
 /* $Id: LayoutHelper.java 17858 2010-01-12 19:59:48Z 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) 1996-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.layout;
 40  
 
 41  
 import java.awt.Point;
 42  
 import java.awt.Rectangle;
 43  
 import java.awt.Polygon;
 44  
 
 45  
 /** LayoutHelper is a utility class which mainly returns various types
 46  
  *  of routing polygons for different kind of connection lines between
 47  
  *  two nodes. Specific layouters might use these methods to reuse certain
 48  
  *  kinds of diagram lines.
 49  
  *  @stereotype utility
 50  
 */
 51  0
 public class LayoutHelper {
 52  
 
 53  
     /**
 54  
      * A constant bitmask for a direction.
 55  
      */
 56  
     public static final int NORTH = 0;
 57  
 
 58  
     /**
 59  
      * A constant bitmask for a direction.
 60  
      */
 61  
     public static final int NORTHEAST = 1;
 62  
 
 63  
     /**
 64  
      * A constant bitmask for a direction.
 65  
      */
 66  
     public static final int EAST = 2;
 67  
 
 68  
     /**
 69  
      * A constant bitmask for a direction.
 70  
      */
 71  
     public static final int SOUTHEAST = 4;
 72  
 
 73  
     /**
 74  
      * A constant bitmask for a direction.
 75  
      */
 76  
     public static final int SOUTH = 8;
 77  
 
 78  
     /**
 79  
      * A constant bitmask for a direction.
 80  
      */
 81  
     public static final int SOUTHWEST = 16;
 82  
 
 83  
     /**
 84  
      * A constant bitmask for a direction.
 85  
      */
 86  
     public static final int WEST = 32;
 87  
 
 88  
     /**
 89  
      * A constant bitmask for a direction.
 90  
      */
 91  
     public static final int NORTHWEST = 64;
 92  
 
 93  
     /**
 94  
      * @param rect the rectangle
 95  
      * @param direction the direction
 96  
      * @return the point on the perimeter
 97  
      */
 98  
     public static Point getPointOnPerimeter(Rectangle rect, int direction) {
 99  0
         return getPointOnPerimeter(rect, direction, 0, 0);
 100  
     }
 101  
 
 102  
     /**
 103  
      * @param rect the rectangle
 104  
      * @param direction the direction
 105  
      * @param xOff the x offset
 106  
      * @param yOff the y offset
 107  
      * @return the point on the perimeter
 108  
      */
 109  
     public static Point getPointOnPerimeter(Rectangle rect, int direction,
 110  
                                             double xOff, double yOff) {
 111  0
         double x = 0;
 112  0
         double y = 0;
 113  0
         if (direction == NORTH
 114  
                 || direction == NORTHEAST
 115  
                 || direction == NORTHWEST) {
 116  0
             y = rect.getY();
 117  
         }
 118  0
         if (direction == SOUTH
 119  
                 || direction == SOUTHWEST
 120  
                 || direction == SOUTHEAST) {
 121  0
             y = rect.getY() + rect.getHeight();
 122  
         }
 123  0
         if (direction == EAST
 124  
                 || direction == WEST) {
 125  0
             y = rect.getY() + rect.getHeight() / 2.0;
 126  
         }
 127  0
         if (direction == NORTHWEST
 128  
                 || direction == WEST
 129  
                 || direction == SOUTHWEST) {
 130  0
             x = rect.getX();
 131  
         }
 132  0
         if (direction == NORTHEAST
 133  
                 || direction == EAST
 134  
                 || direction == SOUTHEAST) {
 135  0
             x = rect.getX() + rect.getWidth();
 136  
         }
 137  0
         if (direction == NORTH || direction == SOUTH) {
 138  0
             x = rect.getX() + rect.getWidth() / 2.0;
 139  
         }
 140  
 
 141  0
         x += xOff;
 142  0
         y += yOff;
 143  0
         return new Point((int) x, (int) y);
 144  
     }
 145  
 
 146  
     /**
 147  
      * Get a routing polygon for a straightline between two points.
 148  
      *
 149  
      * @param start start of the line
 150  
      * @param end end of the line
 151  
      * @return the routing polygon between start and end
 152  
      */
 153  
     public static Polygon getRoutingPolygonStraightLine(Point start, Point end)
 154  
     {
 155  0
         return getRoutingPolygonStraightLineWithOffset(start, end, 0);
 156  
     }
 157  
 
 158  
     /**
 159  
      * Get a routing polygon with a horizontal offset from the two points.
 160  
      *
 161  
      * @param start start of the line
 162  
      * @param end end of the line
 163  
      * @param offset the given offset
 164  
      * @return the routing polygon between start and end
 165  
      */
 166  
     public static Polygon getRoutingPolygonStraightLineWithOffset(Point start,
 167  
                                                 Point end, int offset) {
 168  0
         Polygon newPoly = new Polygon();
 169  
 
 170  0
         newPoly.addPoint((int) start.getX(), (int) start.getY());
 171  0
         if (offset != 0) {
 172  0
             double newY = 0.0;
 173  0
             if (offset < 0) {
 174  0
                 newY =
 175  
                     Math.min(start.getY() + offset, end.getY() + offset);
 176  
             }
 177  0
             if (offset > 0) {
 178  0
                 newY =
 179  
                     Math.max(start.getY() + offset, end.getY() + offset);
 180  
             }
 181  0
             newPoly.addPoint((int) start.getX(), (int) newY);
 182  0
             newPoly.addPoint((int) end.getX(), (int) newY);
 183  
 
 184  
         }
 185  0
         newPoly.addPoint((int) end.getX(), (int) end.getY());
 186  0
         return newPoly;
 187  
     }
 188  
 
 189  
 }
 190