scratch.scott
Class AestheticSpringVisualizer

java.lang.Object
  extended by scratch.scott.AestheticSpringVisualizer
All Implemented Interfaces:
Layout, VertexLocationFunction

public class AestheticSpringVisualizer
extends Object
implements Layout

The SpringVisualizer package represents a visualization of a set of nodes. The SpringVisualizer, which is initialized with a Graph, assigns X/Y locations to each node. When called relax(), the SpringVisualizer moves the visualization forward one step.

Author:
danyelf $Log: AestheticSpringVisualizer.java,v $ Revision 1.18 2006/03/17 01:56:46 e-flat added isLocked() to Layouts in scratch/ Revision 1.17 2005/09/23 06:41:05 e-flat renamed *LocationDecorator to *LocationFunction added documentation Revision 1.16 2005/08/04 00:34:33 tomnelson removed transformer code Revision 1.15 2005/07/27 00:00:52 tomnelson changed Layout.forceMove(Vertex v, int x, int y) to forceMove(Vertex v, double x, double y) Now that Layout is not tied to pixels on the screen, we need the precision in extreme zoom cases Revision 1.14 2005/07/23 06:46:09 e-flat changes to support static and heritable layouts: based on VertexLocationFunction Revision 1.13 2005/07/20 00:26:36 e-flat fixed layout compilation problems Revision 1.12 2004/10/16 01:48:16 e-flat SpringLayout now has setters and getters for vertex repulsion range, edge stretchiness, and edge force multiplier; those of these that were public constants are now protected instance variables Revision 1.11 2003/07/30 08:40:25 offkey Added copyright notice (and cleaned up imports) Revision 1.10 2003/07/29 02:20:32 sdcoder merge Revision 1.9 2003/07/26 01:11:20 offkey tweaks on viz system Revision 1.8 2003/07/17 18:15:39 sdcoder added Coordinates class, refactored, changed names as agreed upon Revision 1.7 2003/07/17 01:51:41 offkey Created AbstratVisualizer; upgraded old visualizers to use it. Improved TestGraphDraw Revision 1.6 2003/07/08 22:38:18 e-flat REMOVED: ArchetypeGraph.getVertexByID() signature ArchetypeGraph.getVertexID() signature AbstractSparseGraph.getVertexID() GraphUtils.getCorrespondingEdge(Graph, Edge) a lot of unused imports, some unused variables (some just commented out) DDED: ArchetypeVertex.getEquivalentVertex() ArchetypeEdge.getEquivalentEdge() [may throw if does not uniquely exist] HANGED: several unit tests no longer check/compare IDs but do check vertex/edge equivalences AbstractSparseGraph.getVertexByID() now package-visible method (this is where friend classes would be useful, as Danyel pointed out :> ) Indexer: now defined in terms of Archetype{Graph, Vertex} SparseXY now called XSparseY (X: {Directed, Undirected}; Y: {Graph, Edge, Vertex}) added to ReleaseNotes: need to put license agreement text at top of every (released) source file Sparse[Un]DirectedVertex: has separate storage for incident edge set(s); edge->vertex maps removed Revision 1.5 2003/07/03 15:36:09 sdcoder added back in code Revision 1.4 2003/06/24 04:16:29 offkey Minor fixes for updates Revision 1.3 2003/06/24 03:47:43 e-flat changed XImpl to SparseX (e.g., DirectedGraphImpl -> DirectedSparseGraph) moved UserData, UserDataContainer to jung.utils Revision 1.2 2003/06/24 02:14:32 offkey ClusteringDemo of graph API possibilities Revision 1.1 2003/06/21 00:37:15 sdcoder *** empty log message *** Revision 1.16 2003/05/12 15:13:22 offkey *** empty log message *** Revision 1.15 2003/05/10 07:29:20 offkey FPS calculations and debugging instrumentation Revision 1.14 2003/05/10 06:21:10 offkey Layout has some debugging code. Set FadeRenderer.debug to FALSE if you dont want to see it. Revision 1.13 2003/05/09 07:44:09 offkey *** empty log message *** Revision 1.12 2003/05/09 06:02:18 offkey Working on viz updates Revision 1.11 2003/05/09 03:53:36 offkey New filter mechanism Revision 1.10 2003/05/07 19:54:53 offkey New filter mechanism is cool! Revision 1.9 2003/05/05 04:55:59 offkey *** empty log message *** Revision 1.8 2003/05/03 06:25:44 e-flat changed Edge.getVertices() to Edge.getIncidentVertices() Revision 1.7 2003/04/29 16:50:52 offkey filter alternative tests Revision 1.6 2003/04/26 20:18:26 sdcoder Took out unused variables, imports, etc. Revision 1.5 2003/04/25 00:58:25 offkey *** empty log message *** Revision 1.3 2003/04/23 17:43:16 offkey Better and better demos! Getting ready to implement fitlered graphs; already have click response working Revision 1.2 2003/04/23 07:37:40 offkey Improvements--response to clicks now built in Revision 1.1 2003/04/23 04:22:55 offkey Added initial visualization code

Nested Class Summary
static interface AestheticSpringVisualizer.LengthFunction
          If the edge is weighted, then override this method to show what the visualized length is.
 class AestheticSpringVisualizer.SpringDimensionChecker
           
static class AestheticSpringVisualizer.SpringEdgeData
           
static class AestheticSpringVisualizer.SpringVertexData
           
 
Field Summary
protected  Dimension currentSize
           
protected  Set dontmove
           
static int RANGE
           
static Object SPRING_KEY
           
static int STRETCH
           
static AestheticSpringVisualizer.LengthFunction UNITLENGTHFUNCTION
           
 
Constructor Summary
AestheticSpringVisualizer(Graph g)
          Constructor for a SpringVisualizer for a raw graph with associated dimension--the input knows how big the graph is.
AestheticSpringVisualizer(Graph g, AestheticSpringVisualizer.LengthFunction f, Dimension d)
          Constructor for a SpringVisualizer for a raw graph with associated component.
AestheticSpringVisualizer(Graph g, AestheticSpringVisualizer.LengthFunction f, JComponent jc)
          Constructor for a SpringVisualizer for a raw graph with associated component.
AestheticSpringVisualizer(Graph g, Dimension d)
          Constructor for a SpringVisualizer for a raw graph with associated dimension--the input knows how big the graph is.
AestheticSpringVisualizer(Graph g, JComponent jc)
          Constructor for a SpringVisualizer for a raw graph with associated component.
 
Method Summary
 void advancePositions()
          Relaxation step.
 void applyFilter(Graph subgraph)
          Sets this filtered graph to be the applicable graph.
protected  void calcEdgeLength(AestheticSpringVisualizer.SpringEdgeData sed, AestheticSpringVisualizer.LengthFunction f)
           
 void forceMove(Vertex picked, double x, double y)
          Forces a node to be moved to location x,y
protected  Iterator getAllEdges()
           
protected  Iterator getAllVertices()
           
protected  Vertex getAVertex(Edge e)
           
 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.
 double getLength(Edge e)
           
 Point2D getLocation(ArchetypeVertex v)
           
 AestheticSpringVisualizer.SpringEdgeData getSpringData(Edge e)
           
 AestheticSpringVisualizer.SpringVertexData getSpringData(Vertex v)
           
 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 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()
          This incremental version doesn't end.
 void initialize(Dimension d)
          Initializes fields in the node that may not have been set during the constructor.
 boolean isIncremental()
          This is an incremental visualization.
 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.
protected  void moveNodes()
           
 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

RANGE

public static int RANGE

dontmove

protected Set dontmove

SPRING_KEY

public static final Object SPRING_KEY

currentSize

protected Dimension currentSize

STRETCH

public static int STRETCH

UNITLENGTHFUNCTION

public static final AestheticSpringVisualizer.LengthFunction UNITLENGTHFUNCTION
Constructor Detail

AestheticSpringVisualizer

public AestheticSpringVisualizer(Graph g,
                                 JComponent jc)
Constructor for a SpringVisualizer for a raw graph with associated component. Defaults to the unit length function.


AestheticSpringVisualizer

public AestheticSpringVisualizer(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


AestheticSpringVisualizer

public AestheticSpringVisualizer(Graph g,
                                 Dimension d)
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


AestheticSpringVisualizer

public AestheticSpringVisualizer(Graph g,
                                 AestheticSpringVisualizer.LengthFunction f,
                                 JComponent jc)
Constructor for a SpringVisualizer for a raw graph with associated component. Registers a listener on the component to pay attention to its current size.

Parameters:
g - the input Graph
f - the Graph length function
jc - the component to be registered

AestheticSpringVisualizer

public AestheticSpringVisualizer(Graph g,
                                 AestheticSpringVisualizer.LengthFunction f,
                                 Dimension d)
Constructor for a SpringVisualizer for a raw graph with associated component.

Parameters:
g - the input Graph
f - the Graph length function
d - the dimension to be registered
Method Detail

getCurrentSize

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

Specified by:
getCurrentSize in interface Layout

applyFilter

public void applyFilter(Graph subgraph)
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:
subgraph - a filtered graph that is a subgraph of the Graph returned by getGraph

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

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

calcEdgeLength

protected void calcEdgeLength(AestheticSpringVisualizer.SpringEdgeData sed,
                              AestheticSpringVisualizer.LengthFunction f)

advancePositions

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

Specified by:
advancePositions in interface Layout

getAVertex

protected Vertex getAVertex(Edge e)

getAllEdges

protected Iterator getAllEdges()

moveNodes

protected void moveNodes()

getSpringData

public AestheticSpringVisualizer.SpringVertexData getSpringData(Vertex v)

getSpringData

public AestheticSpringVisualizer.SpringEdgeData 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

getLength

public double getLength(Edge e)

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.isLocked(Vertex)

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

isIncremental

public boolean isIncremental()
This is an incremental visualization.

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

incrementsAreDone

public boolean incrementsAreDone()
This incremental version doesn't end.

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

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