edu.uci.ics.jung.visualization.contrib
Class KKLayoutInt

java.lang.Object
  extended by edu.uci.ics.jung.visualization.AbstractLayout
      extended by edu.uci.ics.jung.visualization.contrib.KKLayoutInt
All Implemented Interfaces:
ChangeEventSupport, Layout, VertexLocationFunction

public class KKLayoutInt
extends AbstractLayout

Implements the Kamada-Kawai algorithm for node layout, tweaked to store vertex distances as integers. Uses less memory than the classic KKLayout, but doesn't respect non-integer edge distances or lengths. Does not respect filter calls, and sometimes crashes when the view changes to it.

Author:
Masanori Harada
See Also:
"Tomihisa Kamada and Satoru Kawai: An algorithm for drawing general indirect graphs. Information Processing Letters 31(1):7-15, 1989", "Tomihisa Kamada: On visualization of abstract objects and relations. Ph.D. dissertation, Dept. of Information Science, Univ. of Tokyo, Dec. 1988."

Field Summary
protected  int diameter
          The diameter of the visible graph.
protected  UnweightedShortestPath unweightedShortestPaths
          Stores graph distances between vertices of the visible graph
 
Fields inherited from class edu.uci.ics.jung.visualization.AbstractLayout
changeSupport, vertex_locations
 
Constructor Summary
KKLayoutInt(Graph g)
           
 
Method Summary
 void adjustForGravity()
          Shift all vertices so that the center of gravity is located at the center of the screen.
 void advancePositions()
          Implementors must override this method in order to create a Layout.
 boolean getAdjustForGravity()
          Returns true if gravity point adjusting is enabled.
protected  int getDistance(Vertex v1, Vertex v2)
          Gets a distance (a length of the shortest path) between the specified vertices.
 boolean getExchangeVertices()
          Returns true if the local minimum escape technique by exchanging vertices is enabled.
 String getStatus()
          Returns the current status of the sytem, or null if there is no particular status to report.By default, an AbstractLayout returns null for its status.
 boolean incrementsAreDone()
          Returns true once the current iteration has passed the maximum count.
protected  void initialize_local_vertex(Vertex v)
          Initializes the local information on a single vertex.
protected  void initialize_local()
          Initializes all local information, and is called immediately within the initialize() process.
protected  void initializeLocations()
          This method calls initialize_local_vertex for each vertex, and also adds initial coordinate information for each vertex.
 boolean isIncremental()
          This one is an incremental visualization.
 void setAdjustForGravity(boolean on)
          Enable or disable gravity point adjusting.
 void setExchangeVertices(boolean on)
          Enable or disable the local minimum escape technique by exchanging vertices.
 void setMaxIterations(int maxIterations)
           
 
Methods inherited from class edu.uci.ics.jung.visualization.AbstractLayout
addChangeListener, applyFilter, dontMove, fireStateChanged, forceMove, getAVertex, getBaseKey, getChangeListeners, getCoordinates, getCurrentSize, getEdge, getEdge, getGraph, getLocation, getVertex, getVertex, getVertexIterator, getVisibleEdges, getVisibleGraph, getVisibleVertices, getX, getY, initialize, initialize, initializeLocation, isLocked, lockVertex, offsetVertex, postInitialize, removeChangeListener, resize, restart, unlockVertex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

unweightedShortestPaths

protected UnweightedShortestPath unweightedShortestPaths
Stores graph distances between vertices of the visible graph


diameter

protected int diameter
The diameter of the visible graph. In other words, length of the longest shortest path between any two vertices of the visible graph.

Constructor Detail

KKLayoutInt

public KKLayoutInt(Graph g)
Method Detail

getStatus

public String getStatus()
Description copied from class: AbstractLayout
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
Overrides:
getStatus in class AbstractLayout
Returns:
the status, as a string

setMaxIterations

public void setMaxIterations(int maxIterations)

isIncremental

public boolean isIncremental()
This one is an incremental visualization.


incrementsAreDone

public boolean incrementsAreDone()
Returns true once the current iteration has passed the maximum count.


initialize_local

protected void initialize_local()
Description copied from class: AbstractLayout
Initializes all local information, and is called immediately within the initialize() process. The user is responsible for overriding this method to do any construction that may be necessary: for example, to initialize local per-edge or graph-wide data.

Overrides:
initialize_local in class AbstractLayout

initializeLocations

protected void initializeLocations()
Description copied from class: AbstractLayout
This method calls initialize_local_vertex for each vertex, and also adds initial coordinate information for each vertex. (The vertex's initial location is set by calling initializeLocation.

Overrides:
initializeLocations in class AbstractLayout

getDistance

protected int getDistance(Vertex v1,
                          Vertex v2)
Gets a distance (a length of the shortest path) between the specified vertices. Returned value is used for computing the strength of an embedded spring. You may override this method to visualize a graph with weighted edges.

The original Kamada-Kawai algorithm requires a connected graph. That is, pathes must be exist between every pair of vertices in the graph. To visualize a non-connected graph, this method returns (diameter + 1) for vertices that are not connected.

The default implementation is as follows:

   int dist = unweightedShortestPaths.getShortestPath(v1, v2);
   if (dist < 0)
      return diameter + 1;
   else
      return dist;
 


initialize_local_vertex

protected void initialize_local_vertex(Vertex v)
Description copied from class: AbstractLayout
Initializes the local information on a single vertex. The user is responsible for overriding this method to do any vertex-level construction that may be necessary: for example, to attach vertex-level information to each vertex.

Specified by:
initialize_local_vertex in class AbstractLayout

advancePositions

public void advancePositions()
Description copied from class: AbstractLayout
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
Specified by:
advancePositions in class AbstractLayout
See Also:
Layout.advancePositions()

adjustForGravity

public void adjustForGravity()
Shift all vertices so that the center of gravity is located at the center of the screen.


setAdjustForGravity

public void setAdjustForGravity(boolean on)
Enable or disable gravity point adjusting.


getAdjustForGravity

public boolean getAdjustForGravity()
Returns true if gravity point adjusting is enabled.


setExchangeVertices

public void setExchangeVertices(boolean on)
Enable or disable the local minimum escape technique by exchanging vertices.


getExchangeVertices

public boolean getExchangeVertices()
Returns true if the local minimum escape technique by exchanging vertices is enabled.