/*
* JFLAP - Formal Languages and Automata Package
*
*
* Susan H. Rodger
* Computer Science Department
* Duke University
* August 27, 2009
* Copyright (c) 2002-2009
* All rights reserved.
* JFLAP is open source software. Please see the LICENSE for terms.
*
*/
package automata.graph.layout;
import java.util.Set;
import java.util.ArrayList;
import java.awt.Dimension;
import java.awt.geom.Point2D;
import automata.graph.Graph;
import automata.graph.LayoutAlgorithm;
/**
* A layout algorithm that lays out groupings of vertices in circles. Each grouping
* consists of all vertices between which a path exists between any two vertices, and no
* vertices in different groupings will have an edge between them. If all vertices are
* reachable from every one of the other vertices along a path, only one circle will be
* drawn, with some edge minimizing code helping reduce edge intersections.
*
* @author Chris Morgan
*/
public class CircleLayoutAlgorithm extends LayoutAlgorithm {
/**
* This list contains all the boxes that are used in this algorithm.
*/
private ArrayList boxes;
/**
* Assigns some default values.
*/
public CircleLayoutAlgorithm() {
super();
}
/**
* Constructor allowing the user to customize certain values.
*
* @param pSize
* value for size
.
* @param vDim
* value for vertexDim
.
* @param vBuffer
* value for vertexBuffer
.
*/
public CircleLayoutAlgorithm(Dimension pSize, Dimension vDim, double vBuffer) {
super(pSize, vDim, vBuffer);
}
public void layout(Graph graph, Set notMoving) {
ArrayList vertices = getMovableVertices(graph, notMoving);
if (graph==null || vertices.size() == 0)
return;
boxes = new ArrayList();
for (int i=0; i0; i--)
mergeIfPossible((Box) boxes.get(i), i);
for (int i=0; i=0; j--) {
toSearch = (Box) boxes.get(j);
for (int k=0; kCircleChain with some additional code for placing it in the
* graph so that no box will be on top of another.
*
* @author Chris Morgan
*/
private class Box extends CircleChain {
/**
* The size of the square in which only this box may layout values.
*/
public Dimension size;
/**
* Pointers to boxes immediately to the right and below this box. They allow for the
* boxes to form a linked list according to how they are laid out.
*/
public Box down, right;
/**
* The point in the upper left corner of the box. All points determined by the
* CircleChain
layout functions are relative to this point.
*/
public Point2D upperLeft;
/**
* Constructor.
*
* @param g
* the graph from which edge information is processed.
* @param vDim
* value for vertexDim
.
* @param vBuffer
* value for vertexBuffer
.
*/
public Box(Graph g, Dimension vDim, double vBuffer) {
super(g, vDim, vBuffer);
upperLeft = new Point2D.Double(0, 0);
right = null;
down = null;
}
/**
* Moves all vertices in the box given into this box.
*
* @param b the box whose vertices will be added to this one.
*/
public void merge(Box b) {
for (int i=0; iCircleChain.layoutInCircle().
*/
public void layoutInCircleAndPack() {
layoutInCircle();
polarToCartesian(graph, getVertices());
size = new Dimension((int) (2 * (getRadius() + vertexBuffer) + vertexDim.width),
(int) (2 * (getRadius() + vertexBuffer) + vertexDim.height));
if (boxes.indexOf(this) != 0) {
setUpperLeft((Box) boxes.get(0));
for (int i=0; i