Line | Hits | Source |
---|---|---|
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; | |
33 | 0 | 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 | */ | |
41 | 0 | public CircularSubLayout(Collection vertices, double radius, Point2D center) { |
42 | 0 | this.radius = radius; |
43 | 0 | this.center = center; |
44 | 0 | initializeLocations(vertices); |
45 | 0 | } |
46 | ||
47 | public double getRadius() { | |
48 | 0 | return radius; |
49 | } | |
50 | ||
51 | public void setRadius(double radius) { | |
52 | 0 | this.radius = radius; |
53 | 0 | } |
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) { | |
63 | 0 | Vertex[] vertexArray = |
64 | (Vertex[]) vertices.toArray(new Vertex[vertices.size()]); | |
65 | ||
66 | 0 | if(center == null) { |
67 | 0 | center = new Point2D.Double(radius, radius); |
68 | } | |
69 | // only apply sublayout if there is more than one vertex | |
70 | 0 | if (vertexArray.length > 1) { |
71 | 0 | for (int i = 0; i < vertexArray.length; i++) { |
72 | 0 | double angle = (2 * Math.PI * i) / vertexArray.length; |
73 | 0 | Point2D point = new Point2D.Double( |
74 | (Math.cos(angle) * radius + center.getX()), (Math | |
75 | .sin(angle) | |
76 | * radius + center.getY())); | |
77 | 0 | map.put(vertexArray[i], point); |
78 | } | |
79 | } | |
80 | 0 | } |
81 | ||
82 | public Point2D getLocation(ArchetypeVertex v) { | |
83 | 0 | return (Point2D)map.get(v); |
84 | } | |
85 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |