# Coverage details for edu.uci.ics.jung.visualization.contrib.CircleLayout

Line | Hits | Source
--- | --- | ---
1 |  | `/*`
2 |  | `* Copyright (c) 2003, the JUNG Project and the Regents of the University`
3 |  | `* of California`
4 |  | `* All rights reserved.`
5 |  | `*`
6 |  | `* This software is open-source under the BSD license; see either`
7 |  | `* "license.txt" or`
8 |  | `* http://jung.sourceforge.net/license.txt for a description.`
9 |  | `*/`
10 |  | `/*`
11 |  | `* Created on Dec 4, 2003`
12 |  | `*/`
13 |  | `package edu.uci.ics.jung.visualization.contrib;`
14 |  | ``
15 |  | `/**`
16 |  | `*`
17 |  | `* @author danyelf`
18 |  | `*/`
19 |  | `/*`
20 |  | `* This source is under the same license with JUNG.`
21 |  | `* http://jung.sourceforge.net/license.txt for a description.`
22 |  | `*/`
23 |  | `//package edu.uci.ics.jung.visualization;`
24 |  | `//package org.ingrid.nexas.graph;`
25 |  | ``
26 |  | `import java.awt.Dimension;`
27 |  | `import java.util.Arrays;`
28 |  | `import java.util.Collections;`
29 |  | `import java.util.List;`
30 |  | ``
31 |  | `import edu.uci.ics.jung.graph.Graph;`
32 |  | `import edu.uci.ics.jung.graph.Vertex;`
33 |  | `import edu.uci.ics.jung.utils.Pair;`
34 |  | `import edu.uci.ics.jung.utils.UserData;`
35 |  | `import edu.uci.ics.jung.visualization.AbstractLayout;`
36 |  | `import edu.uci.ics.jung.visualization.Coordinates;`
37 |  | ``
38 |  | `/**`
39 |  | `* Positions vertices equally spaced on a regular circle.`
40 |  | `* Does not respect filter calls.`
41 |  | `*`
42 |  | `* @author Masanori Harada`
43 |  | `*/`
44 |  | `public class CircleLayout extends AbstractLayout {`
45 | 0 | `private static final Object CIRCLE_KEY =`
46 |  | `"jung.Circle_Visualization_Key";`
47 |  | `private Pair key;`
48 |  | `private double radius;`
49 |  | ``
50 |  | `public CircleLayout(Graph g) {`
51 | 0 | `super(g);`
52 | 0 | `key = new Pair(this, CIRCLE_KEY);`
53 | 0 | `}`
54 |  | ``
55 |  | `public String getStatus() {`
56 | 0 | `return "CircleLayout";`
57 |  | `}`
58 |  | ``
59 |  | `/**`
60 |  | `* This one is not incremental.`
61 |  | `*/`
62 |  | `public boolean isIncremental() {`
63 | 0 | `return false;`
64 |  | `}`
65 |  | ``
66 |  | `/**`
67 |  | `* Returns true;`
68 |  | `*/`
69 |  | `public boolean incrementsAreDone() {`
70 | 0 | `return true;`
71 |  | `}`
72 |  | ``
73 |  | `public double getRadius() {`
74 | 0 | `return radius;`
75 |  | `}`
76 |  | ``
77 |  | `public void setRadius(double radius) {`
78 | 0 | `this.radius = radius;`
79 | 0 | `}`
80 |  | ``
81 |  | `/**`
82 |  | `* Specifies the order of vertices. The first element of the`
83 |  | `* specified array will be positioned with angle 0 (on the X`
84 |  | `* axis), and the second one will be positioned with angle 1/n,`
85 |  | `* and the third one will be positioned with angle 2/n, and so on.`
86 |  | `* <p>`
87 |  | `* The default implemention shuffles elements randomly.`
88 |  | `*/`
89 |  | `public void orderVertices(Vertex[] vertices) {`
90 | 0 | `List list = Arrays.asList(vertices);`
91 | 0 | `Collections.shuffle(list);`
92 | 0 | `}`
93 |  | ``
94 |  | `/**`
95 |  | `* Returns a visualization-specific key (that is, specific both`
96 |  | `* to this instance and <tt>AbstractLayout</tt>) that can be used`
97 |  | `* to access UserData related to the <tt>AbstractLayout</tt>.`
98 |  | `*/`
99 |  | `public Object getKey() {`
100 | 0 | `if (key == null)`
101 | 0 | `key = new Pair(this, CIRCLE_KEY);`
102 | 0 | `return key;`
103 |  | `}`
104 |  | ``
105 |  | `protected void initialize_local_vertex(Vertex v) {`
106 | 0 | `if (v.getUserDatum(getKey()) == null) {`
107 | 0 | `v.addUserDatum(getKey(), new CircleVertexData(), UserData.REMOVE);`
108 |  | `}`
109 | 0 | `}`
110 |  | ``
111 | 0 | `protected void initialize_local() {}`
112 |  | ``
113 |  | `protected void initializeLocations() {`
114 | 0 | `super.initializeLocations();`
115 |  | ``
116 | 0 | `Vertex[] vertices =`
117 |  | `(Vertex[]) getVisibleVertices().toArray(new Vertex[0]);`
118 | 0 | `orderVertices(vertices);`
119 |  | ``
120 | 0 | `Dimension d = getCurrentSize();`
121 | 0 | `double height = d.getHeight();`
122 | 0 | `double width = d.getWidth();`
123 |  | ``
124 | 0 | `if (radius <= 0) {`
125 | 0 | `radius = 0.45 * (height < width ? height : width);`
126 |  | `}`
127 |  | ``
128 | 0 | `for (int i = 0; i < vertices.length; i++) {`
129 | 0 | `Coordinates coord = getCoordinates(vertices[i]);`
130 |  | ``
131 | 0 | `double angle = (2 * Math.PI * i) / vertices.length;`
132 | 0 | `coord.setX(Math.cos(angle) * radius + width / 2);`
133 | 0 | `coord.setY(Math.sin(angle) * radius + height / 2);`
134 |  | ``
135 | 0 | `CircleVertexData data = getCircleData(vertices[i]);`
136 | 0 | `data.setAngle(angle);`
137 |  | `}`
138 | 0 | `}`
139 |  | ``
140 |  | `public CircleVertexData getCircleData(Vertex v) {`
141 | 0 | `return (CircleVertexData) (v.getUserDatum(getKey()));`
142 |  | `}`
143 |  | ``
144 |  | `/**`
145 |  | `* Do nothing.`
146 |  | `*/`
147 |  | `public void advancePositions() {`
148 | 0 | `}`
149 |  | ``
150 |  | `public static class CircleVertexData {`
151 |  | `private double angle;`
152 |  | ``
153 |  | `public double getAngle() {`
154 |  | `return angle;`
155 |  | `}`
156 |  | ``
157 |  | `public void setAngle(double angle) {`
158 |  | `this.angle = angle;`
159 |  | `}`
160 |  | ``
161 |  | `public String toString() {`
162 |  | `return "CircleVertexData: angle=" + angle;`
163 |  | `}`
164 |  | `}`
165 |  | `}`

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.