Coverage details for edu.uci.ics.jung.visualization.subLayout.CircularSubLayout

LineHitsSource
1 /*
2  * Copyright (c) 2005, the JUNG Project and the Regents of the University of
3  * California All rights reserved.
4  *
5  * This software is open-source under the BSD license; see either "license.txt"
6  * or http://jung.sourceforge.net/license.txt for a description.
7  *
8  * Created on Aug 23, 2005
9  */
10 package edu.uci.ics.jung.visualization.subLayout;
11  
12 import java.awt.geom.Point2D;
13 import java.util.Collection;
14 import java.util.LinkedHashMap;
15 import java.util.Map;
16  
17 import edu.uci.ics.jung.graph.ArchetypeVertex;
18 import edu.uci.ics.jung.graph.Vertex;
19  
20 /**
21  * An implementation of SubLayout that places its collection of
22  * Vertices in a circle. The center and radius are settable
23  * properties.
24  *
25  * @author Tom Nelson - RABA Technologies
26  *
27  *
28  */
29 public class CircularSubLayout implements SubLayout {
30  
31     protected double radius;
32     protected Point2D center;
330    protected final Map map = new LinkedHashMap();
34  
35     /**
36      * create an instance with passed values
37      * @param vertices the collection of vertices to arrange in a circle
38      * @param radius the radius of the circle
39      * @param center the center of the circle
40      */
410    public CircularSubLayout(Collection vertices, double radius, Point2D center) {
420        this.radius = radius;
430        this.center = center;
440        initializeLocations(vertices);
450    }
46  
47     public double getRadius() {
480        return radius;
49     }
50  
51     public void setRadius(double radius) {
520        this.radius = radius;
530    }
54  
55     /**
56      * Map the Vertices in the passed collection to their
57      * locations, distributed about the circumference of
58      * a circle
59      *
60      * @param vertices
61      */
62     private void initializeLocations(Collection vertices) {
630        Vertex[] vertexArray =
64             (Vertex[]) vertices.toArray(new Vertex[vertices.size()]);
65         
660        if(center == null) {
670            center = new Point2D.Double(radius, radius);
68         }
69         // only apply sublayout if there is more than one vertex
700        if (vertexArray.length > 1) {
710            for (int i = 0; i < vertexArray.length; i++) {
720                double angle = (2 * Math.PI * i) / vertexArray.length;
730                Point2D point = new Point2D.Double(
74                         (Math.cos(angle) * radius + center.getX()), (Math
75                                 .sin(angle)
76                                 * radius + center.getY()));
770                map.put(vertexArray[i], point);
78             }
79         }
800    }
81     
82     public Point2D getLocation(ArchetypeVertex v) {
830        return (Point2D)map.get(v);
84     }
85 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.