scratch.danyel.sample
Class CircleLayout

java.lang.Object
  extended by scratch.danyel.sample.CircleLayout
All Implemented Interfaces:
Layout, VertexLocationFunction

public class CircleLayout
extends Object
implements Layout

The CircleLayout package represents a visualization of a set of nodes. CircleLayouts simply place all nodes in a circle around a center. This is a rather trivial algorithm, and fails in a few cases. In particular, it re-places nodes poorly. [Possible: Steps attempt to swap pairs of vertices to improve the layout]

Author:
danyelf

Nested Class Summary
static class CircleLayout.CircleEdgeData
           
static class CircleLayout.CircleVertexData
           
static interface CircleLayout.LengthFunction
          If the edge is weighted, then override this method to show what the visualized length is.
 class CircleLayout.SpringDimensionChecker
           
 
Field Summary
protected  Dimension currentSize
           
protected  Set dontmove
           
static CircleLayout.LengthFunction UNITLENGTHFUNCTION
           
 
Constructor Summary
CircleLayout(Graph g)
          Constructor for a SpringVisualizer for a raw graph with associated dimension--the input knows how big the graph is.
 
Method Summary
 void advancePositions()
          Does nothing: this method is non-incremental.'
 void advanceVisualization()
          Relaxation step.
 void applyFilter(Graph g)
          Sets this filtered graph to be the applicable graph.
 void forceMove(Vertex picked, double x, double y)
          Forces a node to be moved to location x,y
protected  Iterator getAllVertices()
           
protected  Vertex getAVertex(Edge e)
           
 CircleLayout.CircleVertexData getCircleData(Vertex v)
           
 Object getCircleKey()
           
 Dimension getCurrentSize()
          Returns the current size of the visualization's space.
 Graph getGraph()
          Returns the full graph (the one that was passed in at construction time) that this Layout refers to.
 Point2D getLocation(ArchetypeVertex v)
           
 Point2D getLocation(Vertex v)
           
 CircleLayout.CircleEdgeData getSpringData(Edge e)
           
 String getStatus()
          Returns the current status of the sytem, or null if there is no particular status to report.
 Vertex getVertex(double x, double y)
          Finds the closest vertex to an input (x,y) coordinate.
 Vertex getVertex(double x, double y, double maxDistance)
          Finds the closest vertex to an input (x,y) coordinate.
 Iterator getVertexIter()
           
 Iterator getVertexIterator()
           
 Set getVisibleEdges()
          Returns all currently showing edges
 Set getVisibleVertices()
          Returns all currently visible vertices
 double getX(Vertex v)
          Returns the x coordinate of vertex v at this stage in the iteration.
 double getY(Vertex v)
          Returns the y coordinate of vertex v at this stage in the iteration.
 boolean incrementsAreDone()
          Shouldn't be used.
 void initialize(Dimension d)
          Initializes fields in the node that may not have been set during the constructor.
 boolean isIncremental()
          Returns false.
 boolean isLocked(Vertex v)
          Returns true if the position of vertex v is locked.
 void lockVertex(Vertex v)
          Sets a flag which fixes this vertex in place.
 void resize(Dimension size)
          Resets the size of the visualization.
 void restart()
          Resets the vertex positions to their initial locations.
 void unlockVertex(Vertex v)
          Allows this vertex to be moved.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dontmove

protected Set dontmove

currentSize

protected Dimension currentSize

UNITLENGTHFUNCTION

public static final CircleLayout.LengthFunction UNITLENGTHFUNCTION
Constructor Detail

CircleLayout

public CircleLayout(Graph g)
Constructor for a SpringVisualizer for a raw graph with associated dimension--the input knows how big the graph is. Defaults to the unit length function

Method Detail

getCircleKey

public Object getCircleKey()

getCurrentSize

public Dimension getCurrentSize()
Description copied from interface: Layout
Returns the current size of the visualization's space.

Specified by:
getCurrentSize in interface Layout

getGraph

public Graph getGraph()
Description copied from interface: Layout
Returns the full graph (the one that was passed in at construction time) that this Layout refers to.

Specified by:
getGraph in interface Layout

getStatus

public String getStatus()
Description copied from interface: Layout
Returns the current status of the sytem, or null if there is no particular status to report. Useful for reporting things like number of iterations passed, temperature, and so on.

Specified by:
getStatus in interface Layout
Returns:
the status, as a string

initialize

public void initialize(Dimension d)
Description copied from interface: Layout
Initializes fields in the node that may not have been set during the constructor. Must be called before the iterations begin.

Specified by:
initialize in interface Layout

advanceVisualization

public void advanceVisualization()
Relaxation step. Moves all nodes a smidge.


getAVertex

protected Vertex getAVertex(Edge e)

getCircleData

public CircleLayout.CircleVertexData getCircleData(Vertex v)

getSpringData

public CircleLayout.CircleEdgeData getSpringData(Edge e)

getX

public double getX(Vertex v)
Description copied from interface: Layout
Returns the x coordinate of vertex v at this stage in the iteration.

Specified by:
getX in interface Layout
Parameters:
v - The vertex being examined
Returns:
the x coordinate of that vertex

getY

public double getY(Vertex v)
Description copied from interface: Layout
Returns the y coordinate of vertex v at this stage in the iteration.

Specified by:
getY in interface Layout
Parameters:
v - The vertex being examined
Returns:
the y coordinate of that vertex

resize

public void resize(Dimension size)
Description copied from interface: Layout
Resets the size of the visualization. One cannot count on a Visualizaton knowing its own size correctly until the following sequence has been called:
 Layout l = new XXXLayout( g )
 l.initialize();
 l.resize( this.getSize() );
 

Specified by:
resize in interface Layout

restart

public void restart()
Description copied from interface: Layout
Resets the vertex positions to their initial locations.

Specified by:
restart in interface Layout

getAllVertices

protected Iterator getAllVertices()

getVertex

public Vertex getVertex(double x,
                        double y)
Description copied from interface: Layout
Finds the closest vertex to an input (x,y) coordinate. Useful for mouse clicks.

Specified by:
getVertex in interface Layout
Parameters:
x - The x coordinate of the input
y - The y coordinate of the input
Returns:
The nearest vertex. It is up to the user to check if it is satisfactorily close.

getVertex

public Vertex getVertex(double x,
                        double y,
                        double maxDistance)
Description copied from interface: Layout
Finds the closest vertex to an input (x,y) coordinate. Useful for mouse clicks.

Specified by:
getVertex in interface Layout
Parameters:
x - The x coordinate of the input
y - The y coordinate of the input
maxDistance - The maximum acceptable distance. Beyond this, vertices are ignored.
Returns:
The nearest vertex. It is up to the user to check if it is satisfactorily close.

forceMove

public void forceMove(Vertex picked,
                      double x,
                      double y)
Description copied from interface: Layout
Forces a node to be moved to location x,y

Specified by:
forceMove in interface Layout

lockVertex

public void lockVertex(Vertex v)
Description copied from interface: Layout
Sets a flag which fixes this vertex in place.

Specified by:
lockVertex in interface Layout
Parameters:
v - vertex
See Also:
Layout.unlockVertex(Vertex), Layout.isLocked(Vertex)

unlockVertex

public void unlockVertex(Vertex v)
Description copied from interface: Layout
Allows this vertex to be moved.

Specified by:
unlockVertex in interface Layout
Parameters:
v - vertex
See Also:
Layout.lockVertex(Vertex), Layout.isLocked(Vertex)

isLocked

public boolean isLocked(Vertex v)
Description copied from interface: Layout
Returns true if the position of vertex v is locked.

Specified by:
isLocked in interface Layout
See Also:
Layout.lockVertex(Vertex), Layout.unlockVertex(Vertex)

applyFilter

public void applyFilter(Graph g)
Description copied from interface: Layout
Sets this filtered graph to be the applicable graph. It is an error for the subgraph to not be a subgraph of the main graph.

Specified by:
applyFilter in interface Layout
Parameters:
g - a filtered graph that is a subgraph of the Graph returned by getGraph

getVisibleEdges

public Set getVisibleEdges()
Description copied from interface: Layout
Returns all currently showing edges

Specified by:
getVisibleEdges in interface Layout

getVisibleVertices

public Set getVisibleVertices()
Description copied from interface: Layout
Returns all currently visible vertices

Specified by:
getVisibleVertices in interface Layout

getVertexIter

public Iterator getVertexIter()

advancePositions

public void advancePositions()
Does nothing: this method is non-incremental.'

Specified by:
advancePositions in interface Layout
See Also:
Layout.advancePositions()

isIncremental

public boolean isIncremental()
Returns false.

Specified by:
isIncremental in interface Layout
See Also:
Layout.isIncremental()

incrementsAreDone

public boolean incrementsAreDone()
Shouldn't be used. Returns false.

Specified by:
incrementsAreDone in interface Layout
See Also:
Layout.incrementsAreDone()

getLocation

public Point2D getLocation(Vertex v)

getLocation

public Point2D getLocation(ArchetypeVertex v)
Specified by:
getLocation in interface Layout
Specified by:
getLocation in interface VertexLocationFunction

getVertexIterator

public Iterator getVertexIterator()
Specified by:
getVertexIterator in interface VertexLocationFunction