com.alveole.studio.web.designer.graph
Class CustomLayout

java.lang.Object
  extended by com.alveole.studio.web.designer.graph.CustomLayout
All Implemented Interfaces:
edu.uci.ics.jung.utils.ChangeEventSupport, edu.uci.ics.jung.visualization.Layout, edu.uci.ics.jung.visualization.LayoutMutable, edu.uci.ics.jung.visualization.SettableVertexLocationFunction, edu.uci.ics.jung.visualization.VertexLocationFunction

public class CustomLayout
extends java.lang.Object
implements edu.uci.ics.jung.visualization.Layout, edu.uci.ics.jung.utils.ChangeEventSupport, edu.uci.ics.jung.visualization.SettableVertexLocationFunction, edu.uci.ics.jung.visualization.LayoutMutable

This class is a custom settable layout. This is a simple implementation of a Jung layout. It embeds a native Jung implementation layout, but enables to change node positions and to save them into project UI preferences.

Author:
sylvain

Field Summary
protected  java.util.Properties currentPackageProps
          Current UI props for the edited package.
protected  java.awt.Dimension currentSize
          The current dimension.
protected  edu.uci.ics.jung.graph.Graph g
          The current graph.
protected  edu.uci.ics.jung.visualization.FRLayout initial
          The default layout.
protected  java.util.ArrayList<javax.swing.event.ChangeListener> listeners
          List of all change listeners.
protected  java.util.ArrayList<edu.uci.ics.jung.graph.Vertex> lockedVertices
          List of licked vertices.
protected  java.util.HashMap<edu.uci.ics.jung.graph.ArchetypeVertex,java.awt.geom.Point2D> vertexPositions
          List of all vertex positions.
protected  edu.uci.ics.jung.graph.Graph visibleGraph
          The visible graph.
 
Constructor Summary
CustomLayout(edu.uci.ics.jung.graph.Graph g, java.util.Properties currentPackageProps, boolean relayout)
          Constructor.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          Add a change listener.
 void advancePositions()
           
 void applyFilter(edu.uci.ics.jung.graph.Graph subgraph)
          Store a visibility mask.
 void fireStateChanged()
          Inform listeners that state changed.
 void forceMove(edu.uci.ics.jung.graph.Vertex picked, double x, double y)
          Moves a vertex to a point.
 javax.swing.event.ChangeListener[] getChangeListeners()
          Get list of change-listeners.
 java.awt.Dimension getCurrentSize()
          Get current size for layout.
 edu.uci.ics.jung.graph.Graph getGraph()
          Get associated graph.
 edu.uci.ics.jung.visualization.Layout getInitial()
          Get initial layout.
 java.awt.geom.Point2D getLocation(edu.uci.ics.jung.graph.ArchetypeVertex v)
          Get a location for the given vertex.
 java.lang.String getStatus()
          Get status.
 edu.uci.ics.jung.graph.Vertex getVertex(double x, double y)
          Get a vertex given its [x,y].
 edu.uci.ics.jung.graph.Vertex getVertex(double x, double y, double maxDistance)
          Get a vertex given its [x,y].
 java.util.Iterator getVertexIterator()
          Get all vertices.
 java.util.Set getVisibleEdges()
          Get visible edges.
 java.util.Set getVisibleVertices()
          Get visible vertices.
 double getX(edu.uci.ics.jung.graph.Vertex v)
          Get X for given vertex.
 double getY(edu.uci.ics.jung.graph.Vertex v)
          Get Y for given vertex.
 boolean incrementsAreDone()
          See parent interface.
 void initialize(java.awt.Dimension currentSize)
          Initialize layout.
 boolean isIncremental()
          Is incremental.
 boolean isLocked(edu.uci.ics.jung.graph.Vertex v)
          Check if a given vertex is locked.
 void lockVertex(edu.uci.ics.jung.graph.Vertex v)
          Lock the given vertex.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Remove a change listener.
 void resize(java.awt.Dimension d)
          Change layout size.
 void restart()
          Restart layout.
 void setInitial(edu.uci.ics.jung.visualization.FRLayout initial)
          Set initial layout.
 void setLocation(edu.uci.ics.jung.graph.ArchetypeVertex v, java.awt.geom.Point2D location)
          Sets a vertex location.
 void unlockVertex(edu.uci.ics.jung.graph.Vertex v)
          Unlock the given vertex.
 void update()
          Update layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

g

protected edu.uci.ics.jung.graph.Graph g
The current graph.


visibleGraph

protected edu.uci.ics.jung.graph.Graph visibleGraph
The visible graph.


initial

protected edu.uci.ics.jung.visualization.FRLayout initial
The default layout.


currentSize

protected java.awt.Dimension currentSize
The current dimension.


lockedVertices

protected java.util.ArrayList<edu.uci.ics.jung.graph.Vertex> lockedVertices
List of licked vertices.


vertexPositions

protected java.util.HashMap<edu.uci.ics.jung.graph.ArchetypeVertex,java.awt.geom.Point2D> vertexPositions
List of all vertex positions.


listeners

protected java.util.ArrayList<javax.swing.event.ChangeListener> listeners
List of all change listeners.


currentPackageProps

protected java.util.Properties currentPackageProps
Current UI props for the edited package.

Constructor Detail

CustomLayout

public CustomLayout(edu.uci.ics.jung.graph.Graph g,
                    java.util.Properties currentPackageProps,
                    boolean relayout)
Constructor.

Parameters:
g - The associated graph.
currentPackageProps - The UI properties of the current package.
Method Detail

advancePositions

public void advancePositions()
Specified by:
advancePositions in interface edu.uci.ics.jung.visualization.Layout

applyFilter

public void applyFilter(edu.uci.ics.jung.graph.Graph subgraph)
Store a visibility mask.

Specified by:
applyFilter in interface edu.uci.ics.jung.visualization.Layout
Parameters:
the - subgraph.

forceMove

public void forceMove(edu.uci.ics.jung.graph.Vertex picked,
                      double x,
                      double y)
Moves a vertex to a point.

Specified by:
forceMove in interface edu.uci.ics.jung.visualization.Layout
Parameters:
picked - The vertex to move.
x - The X.
y - The Y.

getCurrentSize

public java.awt.Dimension getCurrentSize()
Get current size for layout.

Specified by:
getCurrentSize in interface edu.uci.ics.jung.visualization.Layout
Returns:
current layout size.

getGraph

public edu.uci.ics.jung.graph.Graph getGraph()
Get associated graph.

Specified by:
getGraph in interface edu.uci.ics.jung.visualization.Layout
Parameters:
Associated - graph.

getLocation

public java.awt.geom.Point2D getLocation(edu.uci.ics.jung.graph.ArchetypeVertex v)
Get a location for the given vertex.

Specified by:
getLocation in interface edu.uci.ics.jung.visualization.Layout
Specified by:
getLocation in interface edu.uci.ics.jung.visualization.VertexLocationFunction
Parameters:
v - The vertex to find.
Returns:
Its position.

getStatus

public java.lang.String getStatus()
Get status.

Specified by:
getStatus in interface edu.uci.ics.jung.visualization.Layout
Returns:
null.

getVertex

public edu.uci.ics.jung.graph.Vertex getVertex(double x,
                                               double y)
Get a vertex given its [x,y].

Specified by:
getVertex in interface edu.uci.ics.jung.visualization.Layout
Parameters:
x - The X.
y - The Y.
Returns:
The vertex.

getVertex

public edu.uci.ics.jung.graph.Vertex getVertex(double x,
                                               double y,
                                               double maxDistance)
Get a vertex given its [x,y].

Specified by:
getVertex in interface edu.uci.ics.jung.visualization.Layout
Parameters:
x - The X.
y - The Y.
maxDistance - A max distance for lookup.
Returns:
The vertex.

getVertexIterator

public java.util.Iterator getVertexIterator()
Get all vertices.

Specified by:
getVertexIterator in interface edu.uci.ics.jung.visualization.VertexLocationFunction
Returns:
vertives iterator.

getVisibleEdges

public java.util.Set getVisibleEdges()
Get visible edges.

Specified by:
getVisibleEdges in interface edu.uci.ics.jung.visualization.Layout
Returns:
A set of visible edges.

getVisibleVertices

public java.util.Set getVisibleVertices()
Get visible vertices.

Specified by:
getVisibleVertices in interface edu.uci.ics.jung.visualization.Layout
Returns:
A set of visible vertices.

getX

public double getX(edu.uci.ics.jung.graph.Vertex v)
Get X for given vertex.

Specified by:
getX in interface edu.uci.ics.jung.visualization.Layout
Parameters:
v - The vertex.
Returns:
The X.

getY

public double getY(edu.uci.ics.jung.graph.Vertex v)
Get Y for given vertex.

Specified by:
getY in interface edu.uci.ics.jung.visualization.Layout
Parameters:
v - The vertex to lookup.
Returns:
Y.

incrementsAreDone

public boolean incrementsAreDone()
See parent interface.

Specified by:
incrementsAreDone in interface edu.uci.ics.jung.visualization.Layout
Returns:
true.

initialize

public void initialize(java.awt.Dimension currentSize)
Initialize layout.

Specified by:
initialize in interface edu.uci.ics.jung.visualization.Layout
Parameters:
currentSize - The initial size.

isIncremental

public boolean isIncremental()
Is incremental.

Specified by:
isIncremental in interface edu.uci.ics.jung.visualization.Layout
Returns:
false.

isLocked

public boolean isLocked(edu.uci.ics.jung.graph.Vertex v)
Check if a given vertex is locked.

Specified by:
isLocked in interface edu.uci.ics.jung.visualization.Layout
Parameters:
v - The vertex to check.
Returns:
true if locked.

lockVertex

public void lockVertex(edu.uci.ics.jung.graph.Vertex v)
Lock the given vertex.

Specified by:
lockVertex in interface edu.uci.ics.jung.visualization.Layout
Parameters:
v - The vertex to lock.

resize

public void resize(java.awt.Dimension d)
Change layout size.

Specified by:
resize in interface edu.uci.ics.jung.visualization.Layout
Parameters:
d - The new size.

restart

public void restart()
Restart layout.

Specified by:
restart in interface edu.uci.ics.jung.visualization.Layout

unlockVertex

public void unlockVertex(edu.uci.ics.jung.graph.Vertex v)
Unlock the given vertex.

Specified by:
unlockVertex in interface edu.uci.ics.jung.visualization.Layout
Parameters:
v - The vertex to unlock.

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
Add a change listener.

Specified by:
addChangeListener in interface edu.uci.ics.jung.utils.ChangeEventSupport
Parameters:
l - The listener.

fireStateChanged

public void fireStateChanged()
Inform listeners that state changed.

Specified by:
fireStateChanged in interface edu.uci.ics.jung.utils.ChangeEventSupport

getChangeListeners

public javax.swing.event.ChangeListener[] getChangeListeners()
Get list of change-listeners.

Specified by:
getChangeListeners in interface edu.uci.ics.jung.utils.ChangeEventSupport
Returns:
List of change listeners.

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Remove a change listener.

Specified by:
removeChangeListener in interface edu.uci.ics.jung.utils.ChangeEventSupport
Parameters:
l - The listener.

setLocation

public void setLocation(edu.uci.ics.jung.graph.ArchetypeVertex v,
                        java.awt.geom.Point2D location)
Sets a vertex location.

Specified by:
setLocation in interface edu.uci.ics.jung.visualization.SettableVertexLocationFunction
Parameters:
v - The vertex.
location - The new location.

getInitial

public edu.uci.ics.jung.visualization.Layout getInitial()
Get initial layout.

Returns:
Initial layout.

setInitial

public void setInitial(edu.uci.ics.jung.visualization.FRLayout initial)
Set initial layout.

Parameters:
initial - The layout.

update

public void update()
Update layout.

Specified by:
update in interface edu.uci.ics.jung.visualization.LayoutMutable