edu.uci.ics.jung.visualization
Class AbstractLayout

java.lang.Object
  extended byedu.uci.ics.jung.visualization.AbstractLayout
All Implemented Interfaces:
Layout
Direct Known Subclasses:
CircleLayout, FRLayout, ISOMLayout, KKLayout, KKLayoutInt, SpringLayout

public abstract class AbstractLayout
extends java.lang.Object
implements Layout

Implements some of the dirty work of writing a layout algorithm, allowing the user to express their major intent more simply. When writing a Layout, there are many shared tasks: handling tracking locked nodes, applying filters, and tracing nearby vertices. This package automates all of those.

Author:
Danyel Fisher, Scott White

Constructor Summary
AbstractLayout(Graph g)
          Constructor.
 
Method Summary
abstract  void advancePositions()
          Implementors must override this method in order to create a Layout.
 void applyFilter(Graph g)
          Applies the filter to the current graph.
 boolean dontMove(Vertex v)
          The set of vertices that have been locked.
 void forceMove(Vertex picked, int x, int y)
          Forcibly moves a vertex to the (x,y) location by setting its x and y locations to the inputted location.
 java.lang.Object getBaseKey()
          Returns a visualization-specific key (that is, specific both to this instance and AbstractLayout) that can be used to access UserData related to the AbstractLayout.
 Coordinates getCoordinates(Vertex v)
          Returns the Coordinates object that stores the vertex' x and y location.
 java.awt.Dimension getCurrentSize()
          Returns the current size of the visualization space, accoring to the last call to resize().
 Edge getEdge(double x, double y)
          Gets the edge nearest to the location of the (x,y) location selected.
 Edge getEdge(double x, double y, double maxDistance)
          Gets the edge nearest to the location of the (x,y) location selected, within a distance of maxDistance, Iterates through all visible edges and checks their distance from the click.
 Graph getGraph()
          Accessor for the graph that represets all vertices.
 java.lang.String getStatus()
          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.By default, an AbstractLayout returns null for its status.
 Vertex getVertex(double x, double y)
          Gets the vertex nearest to the location of the (x,y) location selected.
 Vertex getVertex(double x, double y, double maxDistance)
          Gets the vertex nearest to the location of the (x,y) location selected, within a distance of maxDistance.
 java.util.Set getVisibleEdges()
          Returns the set of edges from the original getGraph that are now visible.
 java.util.Set getVisibleVertices()
          Returns the set of vertices from the original getGraph that are now visible.
 double getX(Vertex v)
          Returns the x coordinate of the vertex from the Coordiantes object.
 double getY(Vertex v)
          Returns the y coordinate of the vertex from the Coordiantes object.
 void initialize(java.awt.Dimension size)
          Initializer, calls intialize_local and initializeLocations to start construction process.
 void lockVertex(Vertex v)
          Adds the vertex to the DontMove list
 void resize(java.awt.Dimension size)
          When a visualizetion is resized, it presumably wants to fix the locations of the vertices and possibly to reinitialize its data.
 void restart()
          Restarts the visualization entirely, as if the the user had pressed the "scramble" button.
 void unlockVertex(Vertex v)
          Removes the vertex from the DontMove list
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.uci.ics.jung.visualization.Layout
incrementsAreDone, isIncremental
 

Constructor Detail

AbstractLayout

public AbstractLayout(Graph g)
Constructor. Initializes the current size to be 100x100, both the graph and the showing graph to the argument, and creates the dontmove set.

Parameters:
g -
Method Detail

dontMove

public boolean dontMove(Vertex v)
The set of vertices that have been locked. When running layout, it is important to check
  if (dontmove( v )) { ... }
 

Returns:
whether this vertex may be legally moved or not

initialize

public void initialize(java.awt.Dimension size)
Initializer, calls intialize_local and initializeLocations to start construction process.

Specified by:
initialize in interface Layout

getBaseKey

public java.lang.Object getBaseKey()
Returns a visualization-specific key (that is, specific both to this instance and AbstractLayout) that can be used to access UserData related to the AbstractLayout.


getStatus

public java.lang.String getStatus()
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.By default, an AbstractLayout returns null for its status.

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

advancePositions

public abstract void advancePositions()
Implementors must override this method in order to create a Layout. If the Layout is the sort that only calculates locations once, this method may be overridden with an empty method.

Note that "locked" vertices are not to be moved; however, it is the policy of the visualization to decide how to handle them, and what to do with the vertices around them. Prototypical code might include a clipping like

  for (Iterator i = getVertices().iterator(); i.hasNext() ) { Vertex v = (Vertex) i.next(); if (! dontmove.contains( v ) ) { ... // handle the node } else { // ignore the node } }
 

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

getCurrentSize

public java.awt.Dimension getCurrentSize()
Returns the current size of the visualization space, accoring to the last call to resize().

Specified by:
getCurrentSize in interface Layout
Returns:
the current size of the screen

getCoordinates

public Coordinates getCoordinates(Vertex v)
Returns the Coordinates object that stores the vertex' x and y location.

Parameters:
v - A Vertex that is a part of the Graph being visualized.
Returns:
A Coordinates object with x and y locations.

getX

public double getX(Vertex v)
Returns the x coordinate of the vertex from the Coordiantes object.

Specified by:
getX in interface Layout
Parameters:
v - The vertex being examined
Returns:
the x coordinate of that vertex
See Also:
Layout.getX(edu.uci.ics.jung.graph.Vertex)

getY

public double getY(Vertex v)
Returns the y coordinate of the vertex from the Coordiantes object.

Specified by:
getY in interface Layout
Parameters:
v - The vertex being examined
Returns:
the y coordinate of that vertex
See Also:
Layout.getX(edu.uci.ics.jung.graph.Vertex)

resize

public void resize(java.awt.Dimension size)
When a visualizetion is resized, it presumably wants to fix the locations of the vertices and possibly to reinitialize its data. The current method calls initializeLocations followed by initialize_local. TODO: A better implementation wouldn't destroy the current information, but would either scale the current visualization, or move the nodes toward the new center.

Specified by:
resize in interface Layout
Parameters:
size -

restart

public void restart()
Restarts the visualization entirely, as if the the user had pressed the "scramble" button. Calls initializeLocation for each vertex. TODO: Is this enough? Should it call the whole initialization process? Why does resize do more?

Specified by:
restart in interface Layout

getVertex

public Vertex getVertex(double x,
                        double y)
Gets the vertex nearest to the location of the (x,y) location selected. Calls the longer form of the call.

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)
Gets the vertex nearest to the location of the (x,y) location selected, within a distance of maxDistance. Iterates through all visible vertices and checks their distance from the click. Override this method to provde a more efficient implementation.

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.

getEdge

public Edge getEdge(double x,
                    double y)
Gets the edge nearest to the location of the (x,y) location selected. Calls the longer form of the call.


getEdge

public Edge getEdge(double x,
                    double y,
                    double maxDistance)
Gets the edge nearest to the location of the (x,y) location selected, within a distance of maxDistance, Iterates through all visible edges and checks their distance from the click. Override this method to provide a more efficient implementation.

Parameters:
x -
y -
maxDistance -
Returns:
Edge closest to the click.

getGraph

public Graph getGraph()
Accessor for the graph that represets all vertices.

Specified by:
getGraph in interface Layout
Returns:
the graph that contains all vertices.

getVisibleEdges

public java.util.Set getVisibleEdges()
Returns the set of edges from the original getGraph that are now visible. These edges are equivalent to the ones passed in from the Graph argument to applyFilter().

Specified by:
getVisibleEdges in interface Layout

getVisibleVertices

public java.util.Set getVisibleVertices()
Returns the set of vertices from the original getGraph that are now visible. These vertices are equivalent to the ones passed in from the Graph argument to applyFilter().

Specified by:
getVisibleVertices in interface Layout

forceMove

public void forceMove(Vertex picked,
                      int x,
                      int y)
Forcibly moves a vertex to the (x,y) location by setting its x and y locations to the inputted location. Does not add the vertex to the "dontmove" list, and (in the default implementation) does not make any adjustments to the rest of the graph.

Specified by:
forceMove in interface Layout
Parameters:
picked -
x -
y -

lockVertex

public void lockVertex(Vertex v)
Adds the vertex to the DontMove list

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

unlockVertex

public void unlockVertex(Vertex v)
Removes the vertex from the DontMove list

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

applyFilter

public void applyFilter(Graph g)
Applies the filter to the current graph. The default implementation merely makes fewer vertices available to the getVisibleVertices and getVisibleEdges methods.

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