public void setCentralNode(Object centralNode) {
this.centralNode = centralNode;
}
public void layout(NanoGraph graph) {
GraphModel g = graph.getModel();
double x, y, angle;
Object node;
int counter = 0;
for (int i = 0; i < g.getNodeCount(); i++) {
int nodesOnCircle = (centralNode == null ? g.getNodeCount() : (g.getNodeCount() - 1));
double d = (counter / ((double) nodesOnCircle));
angle = d * 2.0d * Math.PI;
double rotateFactor = 2;
if (nodesOnCircle % 2 == 0) {
rotateFactor = 6;
} else {
rotateFactor = 3;
}
angle += Math.PI / rotateFactor;
angle = angle % (2 * Math.PI);
node = g.getNode(i);
if (centralNode != null && centralNode.equals(node)) {
x = y = radius;
} else {
x = radius + radius * Math.sin(angle);
y = radius + radius * Math.cos(angle);
// only increment the counter when this node wasn't the central node
// or else we get overlapping nodes at 0 degrees and 2 PI degrees
counter++;
}
g.setLocation(node, new Point2D.Double(x+100, y+50));
}
}