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

LineHitsSource
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 {
450    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) {
510        super(g);
520        key = new Pair(this, CIRCLE_KEY);
530    }
54  
55     public String getStatus() {
560        return "CircleLayout";
57     }
58     
59     /**
60      * This one is not incremental.
61      */
62     public boolean isIncremental() {
630        return false;
64     }
65  
66     /**
67      * Returns true;
68      */
69     public boolean incrementsAreDone() {
700        return true;
71     }
72  
73     public double getRadius() {
740        return radius;
75     }
76  
77     public void setRadius(double radius) {
780        this.radius = radius;
790    }
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) {
900        List list = Arrays.asList(vertices);
910        Collections.shuffle(list);
920    }
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() {
1000        if (key == null)
1010            key = new Pair(this, CIRCLE_KEY);
1020        return key;
103     }
104  
105     protected void initialize_local_vertex(Vertex v) {
1060        if (v.getUserDatum(getKey()) == null) {
1070            v.addUserDatum(getKey(), new CircleVertexData(), UserData.REMOVE);
108         }
1090    }
110  
1110    protected void initialize_local() {}
112  
113     protected void initializeLocations() {
1140        super.initializeLocations();
115  
1160        Vertex[] vertices =
117         (Vertex[]) getVisibleVertices().toArray(new Vertex[0]);
1180        orderVertices(vertices);
119  
1200        Dimension d = getCurrentSize();
1210        double height = d.getHeight();
1220        double width = d.getWidth();
123  
1240        if (radius <= 0) {
1250            radius = 0.45 * (height < width ? height : width);
126         }
127  
1280        for (int i = 0; i < vertices.length; i++) {
1290            Coordinates coord = getCoordinates(vertices[i]);
130  
1310            double angle = (2 * Math.PI * i) / vertices.length;
1320            coord.setX(Math.cos(angle) * radius + width / 2);
1330            coord.setY(Math.sin(angle) * radius + height / 2);
134  
1350            CircleVertexData data = getCircleData(vertices[i]);
1360            data.setAngle(angle);
137         }
1380    }
139  
140     public CircleVertexData getCircleData(Vertex v) {
1410        return (CircleVertexData) (v.getUserDatum(getKey()));
142     }
143  
144     /**
145      * Do nothing.
146      */
147     public void advancePositions() {
1480    }
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.