com.jgraph.layout

Class JGraphFacade

public class JGraphFacade extends Object

An abstract description of a graph that can be used by a layout algorithm. This abstracts visibility, grouping, directed edges, any root cells, translation and scaling functions. It also stores the actual graph to be acted upon by the layout and provides utility method to determine the characteristics of the contained cells. After the layout has been applied this class stores the result of that layout as a nested attribute map.
Nested Class Summary
interfaceJGraphFacade.CellVisitor
Defines the interface that visitors use to perform operations upon the graph information during depth first search (dfs) or other tree-traversal strategies implemented by subclassers.
classJGraphFacade.DefaultComparator
A default comparator for ordering cell views.
Field Summary
protected JGraphAlgebraalgebra
The default graph algebra used for basic algorithms and functions.
protected Hashtableattributes
The map of attribute changes made be the layout.
protected doublecircleRadiusFactor
The factor by which to multiple the radius of the circle layout
protected booleandirected
Stores whether or not the graph is to be treated as a directed graph.
protected JGraphCostFunctiondistanceCostFunction
The default cost function used for shortest path search.
protected booleanedgePromotion
Whether or not edges connected to collapsed children are promoted to their first visible parent within the facade, not the actual model
protected JGraphgraph
The JGraph to have the layout applied to it.
protected GraphLayoutCachegraphLayoutCache
The layout cache to have the layout applied to it.
protected ListgroupHierarchies
A collection of groups of sibling vertices
protected booleanignoresCellsInGroups
Stores whether or not the layout is to only act on root cells in the model.
protected booleanignoresHiddenCells
Stores whether or not the layout is to act on only visible cells i.e.
protected booleanignoresUnconnectedCells
Stores whether or not the layout is to act on only cells that have at least one connection.
protected GraphModelmodel
The model to have the layout applied to it.
protected Comparatororder
The default comparator to be used where ordering is required in layouts
protected booleanordered
Whether or not cells should be returned in the same order as found in the model.
protected Listroots
The root vertex to be used by tree layouts.
protected SetverticesFilter
If instaniated, this set defines which vertices are to be processed in any layouts.
Constructor Summary
JGraphFacade(JGraph graph)
Constructs a JGraphGraphFacade specifying the graph passed in as the input graph
JGraphFacade(JGraph graph, Object[] roots)
Constructs a JGraphGraphFacade specifying the graph passed in as the input graph
JGraphFacade(JGraph graph, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed)
Constructs a JGraphGraphFacade
JGraphFacade(JGraph graph, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphGraphFacade specifying the graph passed in as the input graph.
JGraphFacade(GraphLayoutCache cache)
Creates a JGraphFacade specifying the graph passed in as the input graph.
JGraphFacade(GraphLayoutCache cache, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphFacade specifying the graph passed in as the input graph.
JGraphFacade(GraphModel model, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphGenericFacade specifying the graph passed in as the input graph.
JGraphFacade(GraphModel model, GraphLayoutCache cache, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphGenericFacade specifying the graph passed in as the input graph.
Method Summary
voidbfs(Object root, JGraphFacade.CellVisitor visitor)
Performs a breath-first search of the input graph from the specified root cell using the specified visitor to extract the tree information.
voidcircle(Collection vertices)
Arrange the specified vertices into a circular shape, with a regular distance between each vertex
MapcreateNestedMap(Map nestedMap)
Creates and returns nested attribute map specifying what changes the layout made to the input graph.
MapcreateNestedMap(boolean ignoreGrid, boolean flushOrigin)
Compatibility method to invoke JGraphFacade with an origin or null depending on flushOrigin.
MapcreateNestedMap(boolean ignoreGrid, Point2D origin)
Creates and returns nested attribute map specifying what changes the layout made to the input graph.
protected voiddetermineLayoutHierarchies()
Divides the graph into groups of sibling vertices, vertices that share the same parent.
voiddfs(Object root, JGraphFacade.CellVisitor visitor)
Performs a depth-first search of the input graph from the specified root cell using the specified visitor to extract the tree information. isVertex must return true on the passed-in root cell in order to continue.
voiddfs(Object parent, Object root, Object previousSibling, JGraphFacade.CellVisitor visitor, Set seen, int layer, int sibling)
Performs a depth-first search of the input graph from the specified root cell using the specified visitor to extract the tree information
voiddfs(Object parent, Object root, Object previousSibling, JGraphFacade.CellVisitor visitor, Set seen, Set ancestors, int layer, int sibling)
Performs a depth-first search of the input graph from the specified root cell using the specified visitor to extract the tree information
voiddisableRouting(Object edge)
Disables per-edge on the specified edge
voidfindTreeRoots()
Utility method to update the array of tree roots in a graph.
protected ListgetAll()
Returns all cells including all descendants.
HashtablegetAttributes()
Returns the nested map that specifies what changes the layout has made to the input graph.
MapgetAttributes(Object cell)
Returns the local attributes for the specified cell.
Rectangle2DgetBounds(List vertices)
Returns the minimal rectangular bounds that enclose the specified vertices
Rectangle2DgetBounds(Object cell)
Returns the current bounds for the specified cell.
double[][]getBounds(Object[] cells)
Same as getLocations, but with width and height added at index 3 and 4 respectively.
Rectangle2DgetCellBounds()
Returns the minimal rectangular bounds that enclose all the elements in the bounds map.
protected CollectiongetCells(Collection cells, boolean edges, boolean ordered)
Returns a collection of cells in the current graph.
ObjectgetCellView(Object cell)
Obtains the cell view corresponding the cell passed in
doublegetCircleRadiusFactor()
ListgetComponents()
Calculates a list of non-connected graph components for the current graph.
JGraphUnionFindgetConnectionComponents(Object[] v, Object[] e)
Returns a union find structure representing the connection components of G=(E,V).
doublegetDistance(Object v1, Object v2, int maxHops)
Returns the length of the shortest path connecting v1 and v2 wrt distanceFunction.
CollectiongetEdges()
Returns all edges in the graph.
Object[]getEdges(Object cell)
Returns the connected edges for a cell.
Object[]getEdges(Object cell, boolean incoming)
Returns the incoming or outgoing edges for cell.
Object[]getEdgesBetween(Object cell1, Object cell2, boolean directed)
Returns the edges between two specified ports or two specified vertices.
Rectangle2DgetGraphBounds()
Returns the minimal rectangular bounds that enclose all the elements in the bounds map.
Point2DgetGraphOrigin()
Returns the origin of the graph (ie the top left corner of the root cells) for the original geometry.
ListgetGroupHierarchies()
ListgetIncomingEdges(Object cell, Set exclude, boolean visibleCells, boolean selfLoops)
Returns the incoming edges for cell.
doublegetLength(Object edge)
Returns the length of the specified edge wrt distanceFunction.
Point2DgetLocation(Object cell)
Returns the current location of the specified cell
double[][]getLocations(Object[] cells)
Returns an array of arrays (index 0 is x-coordinate, index 1 is y-coordinate in the second array) that fast layouts can operate upon.
DimensiongetMaxSize(Collection vertices)
Obtains the maximum width or height dimension of any of the vertices in the specified collection
Object[]getMinimumSpanningTree(Object[] v, JGraphCostFunction cf)
Returns the minimum spanning tree (MST) for the graph defined by G=(E,V).
ListgetNeighbours(Object cell, boolean ordered)
A shortcut method that calls getNeighbours with no cells to exclude.
ListgetNeighbours(Object cell, Set exclude, boolean ordered)
Returns a collection of cells that are connected to the specified cell by edges.
ComparatorgetOrder()
ListgetOutgoingEdges(Object cell, Set exclude, boolean visibleCells, boolean selfLoops)
Returns the outgoing edges for cell.
Object[]getPath(Object v1, Object v2, int steps, JGraphCostFunction cf)
Returns the shortest path connecting v1 and v2 wrt cf with traverses no more than steps edges.
ListgetPoints(Object edge)
Returns the points of the specified edge.
ObjectgetRootAt(int index)
Returns the root at index to be used by tree layouts for tree traversal.
intgetRootCount()
Returns the number of root vertices to be used by tree layouts for tree traversal.
ListgetRoots()
Returns the list of root vertices.
Dimension2DgetSize(Object cell)
Return the size of the specified cell
ObjectgetSource(Object edge)
Returns the vertex that is connected to the source end of the specified edge
ObjectgetSourcePort(Object edge)
Returns the port that is connected to the source end of the specified edge
ObjectgetTarget(Object edge)
Returns the vertex that is connected to the target end of the specified edge
ObjectgetTargetPort(Object edge)
Returns the port that is connected to the target end of the specified edge
CollectiongetUnconnectedVertices(boolean ordered)
Returns all unconnected vertices in the graph.
CollectiongetVertices()
Returns all vertices in the graph.
CollectiongetVertices(Collection cells, boolean ordered)
Returns a collection of vertices found in the specified collection.
SetgetVerticesFilter()
booleanisDirected()
booleanisEdge(Object cell)
Returns whether or not the specified cell is an edge and should be taken into account by the layout
booleanisEdgePromotion()
booleanisIgnoresHiddenCells()
booleanisIgnoresUnconnectedCells()
booleanisMoveable(Object cell)
Returns true if the cell is moveable.
booleanisOrdered()
booleanisRoot(Object cell)
Returns true if cell is a root.
booleanisVertex(Object cell)
Returns whether or not the specified cell is a vertex and should be taken into account by the layout
booleanIsIgnoresCellsInGroups()
doublenorm(Point2D p)
Calculates the euklidische Norm for the point p.
protected voidpopulateGroupHierarchies(Object vertex)
Creates a set of sibling vertices and adds them to the group hierarchy collection.
voidrandomize(Collection vertices, int maxx, int maxy)
Moves the specified vertices to random locations in the x and y axes directions between zero and a specified maximum.
voidresetControlPoints()
Resets the control points of all moveable edges in the graph.
voidresetControlPoints(boolean setRouting, Edge.Routing routing)
Resets the control points of all moveable edges in the graph.
voidrun(JGraphLayout layout, boolean processByGroups)
The main method to execute layouts
voidscale(Rectangle2D frame)
Scales the graph bounds defined in bounds to fit into the specified frame
voidscale(Collection vertices, double scalex, double scaley, double dx, double dy)
Scales the bounds of the specified cells adding dx and dy to the respective location axes of the cell, then by scaling them by scalex and scaley
voidsetAttributes(Hashtable attributes)
Sets the map that stores all attributes that comprise the changes made by the layout to the input graph
voidsetAttributes(Object cell, Map map)
Sets the local attributes for the specified cell.
voidsetBounds(Map nestedMap)
Reads the bounds from the nested map for each cell and invokes setBounds for that cell with a clone of the bounds.
voidsetBounds(Object cell, Rectangle2D rect)
Sets the current bounds for the specified cell.
voidsetBounds(Object[] cells, double[][] locations)
Same as setLocations, but with width and height added at index 3 and 4 respectively.
voidsetCircleRadiusFactor(double circleRadiusFactor)
voidsetDirected(boolean directed)
voidsetEdgePromotion(boolean edgePromotion)
voidsetGroupHierarchies(List groupHierarchies)
voidsetIgnoresCellsInGroups(boolean ignoresCellsInGroups)
voidsetIgnoresHiddenCells(boolean ignoresHiddenCells)
The GraphLayoutCache instance on the JGraphFacade object must be set correctly in order to change this flag.
voidsetIgnoresUnconnectedCells(boolean ignoresUnconnectedCells)
voidsetLocation(Object cell, double x, double y)
Sets the current location of the specified cell.
voidsetLocation(Object cell, double x, double y, boolean moveGroups)
Sets the current location of the specified cell.
voidsetLocations(Object[] cells, double[][] locations)
Sets the locations of the specified cells according to the arrays specified in locations.
voidsetLoggerLevel(Level level)
Sets the logging level of this class
voidsetOrder(Comparator order)
voidsetOrdered(boolean ordered)
voidsetPoints(Object edge, List points)
Sets the points of the specified edge
voidsetRoots(List roots)
voidsetSize(Object cell, double width, double height)
Sets the current size of the specified cell.
voidsetVerticesFilter(Set verticesFilter)
voidtilt(Collection vertices, int maxx, int maxy)
Simulates a 'nudge' to the graph, moving the specified vertices a random distance in the x and y axes directions between zero and a specified maximum.
voidtranslate(Object cell, double dx, double dy)
Moved the specified cell by the specified x and y co-ordinate amounts
voidtranslateCells(Collection cells, double dx, double dy)
Translates the bounds of the specified cells adding dx and dy to the respective location axes of the cell,

Field Detail

algebra

protected transient JGraphAlgebra algebra
The default graph algebra used for basic algorithms and functions.

attributes

protected transient Hashtable attributes
The map of attribute changes made be the layout. Maps from cells to maps.

circleRadiusFactor

protected double circleRadiusFactor
The factor by which to multiple the radius of the circle layout

directed

protected boolean directed
Stores whether or not the graph is to be treated as a directed graph. true means follow edges in target to source direction,y false means treat edges as directionless

distanceCostFunction

protected transient JGraphCostFunction distanceCostFunction
The default cost function used for shortest path search.

edgePromotion

protected boolean edgePromotion
Whether or not edges connected to collapsed children are promoted to their first visible parent within the facade, not the actual model

graph

protected transient JGraph graph
The JGraph to have the layout applied to it. There is no accessor to the graph for the layouts. If you need access to the graph, try to factor out the methods into a custom facade, and pass an instance of that facade to your layout's run method.

graphLayoutCache

protected transient GraphLayoutCache graphLayoutCache
The layout cache to have the layout applied to it. There is no accessor to the graph for the layouts. If you need access to the graph, try to factor out the methods into a custom facade, and pass an instance of that facade to your layout's run method.

groupHierarchies

protected transient List groupHierarchies
A collection of groups of sibling vertices

ignoresCellsInGroups

protected boolean ignoresCellsInGroups
Stores whether or not the layout is to only act on root cells in the model. true means only act on root cells, false means act upon roots and their children. Default is false.

ignoresHiddenCells

protected boolean ignoresHiddenCells
Stores whether or not the layout is to act on only visible cells i.e. true means only act on visible cells, false act on cells regardless of their visibility. Default is true.

ignoresUnconnectedCells

protected boolean ignoresUnconnectedCells
Stores whether or not the layout is to act on only cells that have at least one connection. true means only act on connected cells, false act on cells regardless of their connections. Default is true.

model

protected transient GraphModel model
The model to have the layout applied to it. There is no accessor to the graph for the layouts. If you need access to the graph, try to factor out the methods into a custom facade, and pass an instance of that facade to your layout's run method.

order

protected transient Comparator order
The default comparator to be used where ordering is required in layouts

ordered

protected boolean ordered
Whether or not cells should be returned in the same order as found in the model. Set to true to obtain deterministic results for things such as the order of cells with a particular level of a tree layout. Note that setting this variable to true can cause quadratic performance, therefore it defaults to false.

roots

protected transient List roots
The root vertex to be used by tree layouts.

verticesFilter

protected transient Set verticesFilter
If instaniated, this set defines which vertices are to be processed in any layouts. Set to null to apply no filtered set

Constructor Detail

JGraphFacade

public JGraphFacade(JGraph graph)
Constructs a JGraphGraphFacade specifying the graph passed in as the input graph

Parameters: graph the JGraph to be laid out

JGraphFacade

public JGraphFacade(JGraph graph, Object[] roots)
Constructs a JGraphGraphFacade specifying the graph passed in as the input graph

Parameters: graph the JGraph to be laid out roots the root vertices to be used by tree and hierarchical layouts - NOTE, any roots will be subject to the facade filters at the time of construction.

JGraphFacade

public JGraphFacade(JGraph graph, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed)
Constructs a JGraphGraphFacade

See Also: (JGraph, Object[], boolean, boolean, boolean, boolean, JGraphCostFunction, JGraphAlgebra)

JGraphFacade

public JGraphFacade(JGraph graph, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphGraphFacade specifying the graph passed in as the input graph. Also configures properties of layout, whether or not edge direction is to be taken into account, whether or not invisible cells are to be considered and whether or not only root cells are to be considered or roots and all their children. A root is only used if the isVertex method returns true.

Parameters: graph The graph used as input to the layout roots the root vertices to be used by tree and hierarchical layouts - NOTE, any roots will be subject to the facade filters at the time of construction. ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed distanceCostFunction the cost function that defines the distance metrics algebra the algebra used for basic algorithms and functions

See Also: JGraphFacade ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed

JGraphFacade

public JGraphFacade(GraphLayoutCache cache)
Creates a JGraphFacade specifying the graph passed in as the input graph.

Parameters: cache The GraphLayoutCache to be used as input to the layout

JGraphFacade

public JGraphFacade(GraphLayoutCache cache, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphFacade specifying the graph passed in as the input graph. Also configures properties of layout, whether or not edge direction is to be taken into account, whether or not invisible cells are to be considered and whether or not only root cells are to be considered or roots and all their children. A root is only used if the isVertex method returns true.

Parameters: cache The GraphLayoutCache to be used as input to the layout roots the root vertices to be used by tree and hierarchical layouts - NOTE, any roots will be subject to the facade filters at the time of construction. ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed distanceCostFunction the cost function that defines the distance metrics algebra the algebra used for basic algorithms and functions

See Also: JGraphFacade ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed

JGraphFacade

public JGraphFacade(GraphModel model, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphGenericFacade specifying the graph passed in as the input graph. Also configures properties of layout, whether or not edge direction is to be taken into account, whether or not invisible cells are to be considered and whether or not only root cells are to be considered or roots and all their children. A root is only used if the isVertex method returns true.

Parameters: model The GraphModel to be used as input to the layout roots the root vertices to be used by tree and hierarchical layouts - NOTE, any roots will be subject to the facade filters at the time of construction. ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed distanceCostFunction the cost function that defines the distance metrics algebra the algebra used for basic algorithms and functions

See Also: JGraphFacade ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed

JGraphFacade

public JGraphFacade(GraphModel model, GraphLayoutCache cache, Object[] roots, boolean ignoresHiddenCells, boolean ignoresCellsInGroups, boolean ignoresUnconnectedCells, boolean directed, JGraphCostFunction distanceCostFunction, JGraphAlgebra algebra)
Creates a JGraphGenericFacade specifying the graph passed in as the input graph. Also configures properties of layout, whether or not edge direction is to be taken into account, whether or not invisible cells are to be considered and whether or not only root cells are to be considered or roots and all their children. A root is only used if the isVertex method returns true.

Parameters: model The GraphModel to be used as input to the layout cache The GraphLayoutCache to be used as input to the layout roots the root vertices to be used by tree and hierarchical layouts - NOTE, any roots will be subject to the facade filters at the time of construction. ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed distanceCostFunction the cost function that defines the distance metrics algebra the algebra used for basic algorithms and functions

See Also: JGraphFacade ignoresHiddenCells ignoresCellsInGroups ignoresUnconnectedCells directed

Method Detail

bfs

public void bfs(Object root, JGraphFacade.CellVisitor visitor)
Performs a breath-first search of the input graph from the specified root cell using the specified visitor to extract the tree information.

Parameters: visitor the visitor that defines the operations to be performed upon the graph model

circle

public void circle(Collection vertices)
Arrange the specified vertices into a circular shape, with a regular distance between each vertex

Parameters: vertices the collection of vertices to be arranged

createNestedMap

public Map createNestedMap(Map nestedMap)

Deprecated: as of version 1.1

Creates and returns nested attribute map specifying what changes the layout made to the input graph. After a layout is run this method should be queried to see what positional changes were made. This method applied snapping to the graph if enabled and only fills the map with the bounds values since these are the only values layout change

Returns: a nested Map of the changes the layout made upon the input graph

See Also: JGraphFacade GraphConstants

createNestedMap

public Map createNestedMap(boolean ignoreGrid, boolean flushOrigin)
Compatibility method to invoke JGraphFacade with an origin or null depending on flushOrigin.

Parameters: ignoreGrid whether or not the map returned is snapped to the current grid flushOrigin whether or not the bounds of the graph should be moved to (0,0)

Returns: a nested Map of the changes the layout made upon the input graph

createNestedMap

public Map createNestedMap(boolean ignoreGrid, Point2D origin)
Creates and returns nested attribute map specifying what changes the layout made to the input graph. After a layout is run this method should be queried to see what positional changes were made. This method applied snapping to the graph if enabled and only fills the map with the bounds values since these are the only values layout change

Parameters: ignoreGrid whether or not the map returned is snapped to the current grid origin the new origin to which the graph bounds will be flushed to

Returns: a nested Map of the changes the layout made upon the input graph

determineLayoutHierarchies

protected void determineLayoutHierarchies()
Divides the graph into groups of sibling vertices, vertices that share the same parent. This is mostly used for layouting of cell relative to their group context.

dfs

public void dfs(Object root, JGraphFacade.CellVisitor visitor)
Performs a depth-first search of the input graph from the specified root cell using the specified visitor to extract the tree information. isVertex must return true on the passed-in root cell in order to continue.

Parameters: root the node to start the search from visitor the visitor that defines the operations to be performed upon the graph model

dfs

public void dfs(Object parent, Object root, Object previousSibling, JGraphFacade.CellVisitor visitor, Set seen, int layer, int sibling)
Performs a depth-first search of the input graph from the specified root cell using the specified visitor to extract the tree information

Parameters: parent the parent of the current cell root the node to start the search from previousSibling the last neighbour of the current cell found visitor the visitor that defines the operations to be performed upon the graph model seen the set of cells that have already been seen layer the current layer of the tree sibling the number of siblings to the current cell

dfs

public void dfs(Object parent, Object root, Object previousSibling, JGraphFacade.CellVisitor visitor, Set seen, Set ancestors, int layer, int sibling)
Performs a depth-first search of the input graph from the specified root cell using the specified visitor to extract the tree information

Parameters: parent the parent of the current cell root the node to start the search from previousSibling the last neighbour of the current cell found visitor the visitor that defines the operations to be performed upon the graph model seen the set of cells that have already been seen layer the current layer of the tree sibling the number of siblings to the current cell

disableRouting

public void disableRouting(Object edge)
Disables per-edge on the specified edge

Parameters: edge the edge to have per-edge routing disabled

findTreeRoots

public void findTreeRoots()
Utility method to update the array of tree roots in a graph. This sets all cells that have no incoming and one or more outgoing edges, or the cell with the largest difference between outgoing and incoming edges if no root cells exist.

getAll

protected List getAll()
Returns all cells including all descendants.

getAttributes

public Hashtable getAttributes()
Returns the nested map that specifies what changes the layout has made to the input graph.

Returns: The map that stores all attributes.

getAttributes

public Map getAttributes(Object cell)
Returns the local attributes for the specified cell.

getBounds

public Rectangle2D getBounds(List vertices)
Returns the minimal rectangular bounds that enclose the specified vertices

Parameters: vertices the vertices whose collective bounds are to be determined

Returns: the collective bounds of the input vertices

getBounds

public Rectangle2D getBounds(Object cell)
Returns the current bounds for the specified cell.

Parameters: cell the cell whose bounds are to be determined

Returns: the bounds of the specified cell

getBounds

public double[][] getBounds(Object[] cells)
Same as getLocations, but with width and height added at index 3 and 4 respectively.

Parameters: cells The cells to return the bounds for

Returns: Returns the bounds of the cells as an array of arrays

See Also: (Object[])

getCellBounds

public Rectangle2D getCellBounds()
Returns the minimal rectangular bounds that enclose all the elements in the bounds map. After a layout has completed this method will return the collective bounds of the new laid out graph.

Returns: the collective bounds of the elements in bounds

getCells

protected Collection getCells(Collection cells, boolean edges, boolean ordered)
Returns a collection of cells in the current graph. Roots are flattened and returned also. It can be specified whether or not to return edges in the graph using the appropriate parameter. If the ordered flag is set to true the result will be ordered by the current comparator set for this facade.
Note: This returns a set, for frequent read operations you should turn this into an array, or at least an array list.

Parameters: cells the cells to be filtered and return the correct cell types edges whether or not to return the edges of the graph ordered whether or not to order the returned value in the order of the current order comparator. Be very careful using the default comparator on the default graph model, getIndexOfRoot has linear performance and so sorting the entire model roots will have quadratic performance.

Returns: collection of cells in the graph

getCellView

public Object getCellView(Object cell)
Obtains the cell view corresponding the cell passed in

Parameters: cell the cell whose view is to be obtained

Returns: the cell view, if any, assoicated with this cell

getCircleRadiusFactor

public double getCircleRadiusFactor()

Returns: the circleRadiusFactor

getComponents

public List getComponents()
Calculates a list of non-connected graph components for the current graph.

Returns: a collection of seperate graph components

getConnectionComponents

public JGraphUnionFind getConnectionComponents(Object[] v, Object[] e)
Returns a union find structure representing the connection components of G=(E,V). The union find may be used as follows to determine whether two cells are connected:

Object[] v = facade.getVertices();
Object[] e = facade.getEdges();
JGraphUnionFind uf = facade.getConnectionComponents(v, e);
boolean connected = uf.differ(vertex1, vertex2);

Parameters: v the vertices of the graph e the edges of the graph

Returns: Returns the connection components in G=(E,V)

See Also: (GraphModel, Object[], Object[])

getDistance

public double getDistance(Object v1, Object v2, int maxHops)
Returns the length of the shortest path connecting v1 and v2 wrt distanceFunction. The path has no more than maxHops elements.

Parameters: v1 the source vertex v2 the target vertex maxHops the maximum number of edges the path may have

Returns: Returns the length of the shortest path between v1 and v2

See Also: distanceCostFunction JGraphFacade

getEdges

public Collection getEdges()
Returns all edges in the graph.
Note: This returns a linked list, for frequent read operations you should turn this into an array, or at least an array list.

Returns: Returns all edges that the layout should take into account

See Also: isEdge

getEdges

public Object[] getEdges(Object cell)
Returns the connected edges for a cell. Cell should be a port or a vertex.

Parameters: cell the cell whose edges are to be obtained

Returns: Returns the array of all connected edges

getEdges

public Object[] getEdges(Object cell, boolean incoming)
Returns the incoming or outgoing edges for cell. Cell should be a port or a vertex.

Parameters: cell the graph cell whose edges are to be obtained incoming whether or not to obtain incoming edges only

getEdgesBetween

public Object[] getEdgesBetween(Object cell1, Object cell2, boolean directed)
Returns the edges between two specified ports or two specified vertices. If directed is true then cell1 must be the source of the returned edges.

Parameters: cell1 the first of the pair of cells to find edges between cell2 the second of the pair of cells to find edges between directed whether or not only edges going from cell1 to cell2 should be returned and not edges in the other direction

getGraphBounds

public Rectangle2D getGraphBounds()
Returns the minimal rectangular bounds that enclose all the elements in the bounds map. After a layout has completed this method will return the collective bounds of the new laid out graph. Note this method may return null and should be checked before using.

Returns: the collective bounds of the elements in bounds

getGraphOrigin

public Point2D getGraphOrigin()
Returns the origin of the graph (ie the top left corner of the root cells) for the original geometry.

Returns: The origin of the graph.

getGroupHierarchies

public List getGroupHierarchies()

Returns: the groupHierarchies

getIncomingEdges

public List getIncomingEdges(Object cell, Set exclude, boolean visibleCells, boolean selfLoops)
Returns the incoming edges for cell. Cell should be a port or a vertex.

Parameters: cell The cell from which the incoming edges will be determined exclude The set of edges to ignore when searching visibleCells whether or not only visible cells should be processed selfLoops whether or not to include self loops in the returned list

Returns: Returns the list of incoming edges for cell

getLength

public double getLength(Object edge)
Returns the length of the specified edge wrt distanceFunction.

Parameters: edge the edge whos length is returned

Returns: Returns the length of edge

See Also: distanceCostFunction JGraphFacade

getLocation

public Point2D getLocation(Object cell)
Returns the current location of the specified cell

Parameters: cell the cell whose location is to be determined

Returns: Returns the current location of the specified cell

getLocations

public double[][] getLocations(Object[] cells)
Returns an array of arrays (index 0 is x-coordinate, index 1 is y-coordinate in the second array) that fast layouts can operate upon.

This method is normally used at the beginning of a layout to setup fast internal datastructures. The layout then changes the array in-place and when finished, writes the result back using the setLocations(Object[] cells, double[][] locations) method:

public void run(JGraphFacade facade) { 1. vertices = facade.getVertices().toArray(); 2. locations = facade.getLocations(vertices); 3. perform layout on local arrays 4. return result: facade.setLocations(vertices, locations); }

Parameters: cells The cells to return the locations for

Returns: Returns the locations of the cells as an array of arrays

getMaxSize

public Dimension getMaxSize(Collection vertices)
Obtains the maximum width or height dimension of any of the vertices in the specified collection

Parameters: vertices collection of vertices to be analysed

Returns: the maximum width or height of any of the vertices

getMinimumSpanningTree

public Object[] getMinimumSpanningTree(Object[] v, JGraphCostFunction cf)
Returns the minimum spanning tree (MST) for the graph defined by G=(E,V). The MST is defined as the set of all vertices with minimal lengths that forms no cycles in G.

Parameters: v the vertices of the graph

Returns: Returns the MST as an array of edges

See Also: (GraphModel, Object[], JGraphCostFunction, boolean)

getNeighbours

public List getNeighbours(Object cell, boolean ordered)
A shortcut method that calls getNeighbours with no cells to exclude.

See Also: JGraphFacade

getNeighbours

public List getNeighbours(Object cell, Set exclude, boolean ordered)
Returns a collection of cells that are connected to the specified cell by edges. Any cells specified in the exclude set will be ignored.

Parameters: cell The cell from which the neighbours will be determined exclude The set of cells to ignore when searching ordered whether or not to order the returned value in the order of the current order comparator. Be very careful using the default comparator on the default graph model, getIndexOfRoot has linear performance and so sorting the entire model roots will have quadratic performance.

Returns: Returns the set of neighbours for cell

getOrder

public Comparator getOrder()

Returns: Returns the order.

getOutgoingEdges

public List getOutgoingEdges(Object cell, Set exclude, boolean visibleCells, boolean selfLoops)
Returns the outgoing edges for cell. Cell should be a port or a vertex.

Parameters: cell The cell from which the outgoing edges will be determined exclude The set of edges to ignore when searching visibleCells whether or not only visible cells should be processed selfLoops whether or not to include self loops in the returned list

Returns: Returns the list of outgoing edges for cell

getPath

public Object[] getPath(Object v1, Object v2, int steps, JGraphCostFunction cf)
Returns the shortest path connecting v1 and v2 wrt cf with traverses no more than steps edges. The cost function defines the metric that is used as the edges length.

Parameters: v1 the source vertex v2 the target vertex steps the maximum number of edges in the path cf the cost function that defines the edge lengths

Returns: Returns shortest array of edges connecting v1 and v2

See Also: JGraphAlgebra

getPoints

public List getPoints(Object edge)
Returns the points of the specified edge. The list may contain PortView instances. Do a typecheck when iterating through the elements of this list, and use PortView.getLocation to get the position of the port.

Parameters: edge the cell whose points are returned

Returns: Returns the points of the specified edge

getRootAt

public Object getRootAt(int index)
Returns the root at index to be used by tree layouts for tree traversal.

Returns: the root vertex to be used by tree layouts

See Also: JGraphFacade

getRootCount

public int getRootCount()
Returns the number of root vertices to be used by tree layouts for tree traversal.

Returns: the number of root vertices to be used by tree layouts

getRoots

public List getRoots()
Returns the list of root vertices.

Returns: Returns the roots

getSize

public Dimension2D getSize(Object cell)
Return the size of the specified cell

Parameters: cell the cell whose size is to be returned

Returns: Returns the current size of the specified cell.

getSource

public Object getSource(Object edge)
Returns the vertex that is connected to the source end of the specified edge

Parameters: edge the reference edge

Returns: any vertex connected as the source the specified edge

getSourcePort

public Object getSourcePort(Object edge)
Returns the port that is connected to the source end of the specified edge

Parameters: edge the reference edge

Returns: any vertex connected as the source the specified edge

getTarget

public Object getTarget(Object edge)
Returns the vertex that is connected to the target end of the specified edge

Parameters: edge the reference edge

Returns: any vertex connected as the target the specified edge

getTargetPort

public Object getTargetPort(Object edge)
Returns the port that is connected to the target end of the specified edge

Parameters: edge the reference edge

Returns: any vertex connected as the target the specified edge

getUnconnectedVertices

public Collection getUnconnectedVertices(boolean ordered)
Returns all unconnected vertices in the graph.

Returns: Returns all the unconnected cells that the layout should take into account

getVertices

public Collection getVertices()
Returns all vertices in the graph.
Note: This returns a linked list, for frequent read operations you should turn this into an array, or at least an array list.

Returns: Returns all cells that the layout should take into account

See Also: isVertex

getVertices

public Collection getVertices(Collection cells, boolean ordered)
Returns a collection of vertices found in the specified collection.

Parameters: cells the set of potential vertices ordered whether or not to order the returned value in the order of the current order comparator. Be very careful using the default comparator on the default graph model, getIndexOfRoot has linear performance and so sorting the entire model roots will have quadratic performance.

Returns: Returns the collection of vertices on the collection

See Also: isVertex

getVerticesFilter

public Set getVerticesFilter()

Returns: Returns the verticesFilter.

isDirected

public boolean isDirected()

Returns: Returns the directed.

isEdge

public boolean isEdge(Object cell)
Returns whether or not the specified cell is an edge and should be taken into account by the layout

Parameters: cell the cell that is to be classified as an edge or not

Returns: Returns true if the cell is an edge

isEdgePromotion

public boolean isEdgePromotion()

Returns: Returns the edgePromotion.

isIgnoresHiddenCells

public boolean isIgnoresHiddenCells()

Returns: Returns the ignoresHiddenCells.

isIgnoresUnconnectedCells

public boolean isIgnoresUnconnectedCells()

Returns: Returns the ignoresUnconnectedCells.

isMoveable

public boolean isMoveable(Object cell)
Returns true if the cell is moveable. If this returns false then the cells bounds cannot be changed via the facade. The default implementation checks the moveable attribute. Subclassers can override this eg. to check if a cell is not selected in the graph.

isOrdered

public boolean isOrdered()

Returns: Returns the ordered.

isRoot

public boolean isRoot(Object cell)
Returns true if cell is a root.

Parameters: cell the cell to test

Returns: Returns true if cell is a root

isVertex

public boolean isVertex(Object cell)
Returns whether or not the specified cell is a vertex and should be taken into account by the layout

Parameters: cell the cell that is to be classified as a vertex or not

Returns: Returns true if cell is a vertex

IsIgnoresCellsInGroups

public boolean IsIgnoresCellsInGroups()

Returns: Returns the ignoresCellsInGroups.

norm

public double norm(Point2D p)
Calculates the euklidische Norm for the point p.

Parameters: p the point to calculate the norm for

Returns: the euklidische Norm for the point p

populateGroupHierarchies

protected void populateGroupHierarchies(Object vertex)
Creates a set of sibling vertices and adds them to the group hierarchy collection. The list of hierarchies will naturally form in an order

Parameters: vertex The parent vertex to the returned vertices

randomize

public void randomize(Collection vertices, int maxx, int maxy)
Moves the specified vertices to random locations in the x and y axes directions between zero and a specified maximum. The maximum amounts can be specified seperately for the x and y axes.

Parameters: vertices the collection of vertices to be moved maxx the maximum translation that may occur in the x-axis maxy the maximum translation that may occur in the y-axis

resetControlPoints

public void resetControlPoints()
Resets the control points of all moveable edges in the graph.

resetControlPoints

public void resetControlPoints(boolean setRouting, Edge.Routing routing)
Resets the control points of all moveable edges in the graph. Also set the routing on the edges to the specified value if the parameter flag indicates to do so

run

public void run(JGraphLayout layout, boolean processByGroups)
The main method to execute layouts

Parameters: layout the layout to be executed processByGroups Whether or not to process cell only at the level of their own group When true, children are only processed with siblings and their parent only with its siblings and so on

scale

public void scale(Rectangle2D frame)
Scales the graph bounds defined in bounds to fit into the specified frame

Parameters: frame the frame the bounds map colective bounds is to be scaled to

scale

public void scale(Collection vertices, double scalex, double scaley, double dx, double dy)
Scales the bounds of the specified cells adding dx and dy to the respective location axes of the cell, then by scaling them by scalex and scaley

Parameters: vertices the collection of vertices to be scaled scalex the amount by which the x-axis positions of the vertices will be scaled scaley the amount by which the y-axis positions of the vertices will be scaled dx the amount to be added to be x-axis positions of the vertices before scaling is applied dy the amount to be added to be y-axis positions of the vertices before scaling is applied

setAttributes

public void setAttributes(Hashtable attributes)
Sets the map that stores all attributes that comprise the changes made by the layout to the input graph

Parameters: attributes the new map of cell, map pairs

setAttributes

public void setAttributes(Object cell, Map map)
Sets the local attributes for the specified cell.

Parameters: cell the cell to set the attributes for map the new attributes for the cell

setBounds

public void setBounds(Map nestedMap)
Reads the bounds from the nested map for each cell and invokes setBounds for that cell with a clone of the bounds.

Parameters: nestedMap A map of (cell, map) pairs

See Also: getBounds

setBounds

public void setBounds(Object cell, Rectangle2D rect)
Sets the current bounds for the specified cell.

Parameters: cell the cell whose bounds are to be set rect the new bounds of the specified cell

setBounds

public void setBounds(Object[] cells, double[][] locations)
Same as setLocations, but with width and height added at index 3 and 4 respectively.

Parameters: cells The cells to change the bounds for locations The new bounds as an array of arrays

See Also: (Object[])

setCircleRadiusFactor

public void setCircleRadiusFactor(double circleRadiusFactor)

Parameters: circleRadiusFactor the minCircleRadius to set

setDirected

public void setDirected(boolean directed)

Parameters: directed The directed to set.

setEdgePromotion

public void setEdgePromotion(boolean edgePromotion)

Parameters: edgePromotion The edgePromotion to set.

setGroupHierarchies

public void setGroupHierarchies(List groupHierarchies)

Parameters: groupHierarchies the groupHierarchies to set

setIgnoresCellsInGroups

public void setIgnoresCellsInGroups(boolean ignoresCellsInGroups)

Parameters: ignoresCellsInGroups Sets ignoresCellsInGroups.

setIgnoresHiddenCells

public void setIgnoresHiddenCells(boolean ignoresHiddenCells)
The GraphLayoutCache instance on the JGraphFacade object must be set correctly in order to change this flag. If the graphLayoutCache is null, this flag will be forced to false

Parameters: ignoresHiddenCells The ignoresHiddenCells to set.

setIgnoresUnconnectedCells

public void setIgnoresUnconnectedCells(boolean ignoresUnconnectedCells)

Parameters: ignoresUnconnectedCells The ignoresUnconnectedCells to set.

setLocation

public void setLocation(Object cell, double x, double y)
Sets the current location of the specified cell. This checks if the cell is moveable.

Parameters: cell the cell whose location is to be set x the new x-axs location of the cell y the new y-axs location of the cell

See Also: isMoveable

setLocation

public void setLocation(Object cell, double x, double y, boolean moveGroups)
Sets the current location of the specified cell. This checks if the cell is moveable.

Parameters: cell the cell whose location is to be set x the new x-axs location of the cell y the new y-axs location of the cell moveGroups whether or not to move group cells

See Also: isMoveable

setLocations

public void setLocations(Object[] cells, double[][] locations)
Sets the locations of the specified cells according to the arrays specified in locations. The cells and locations array must contain the same number of elements.

Parameters: cells The cells to change the locations for locations The new locations as an array of arrays

See Also: (Object[])

setLoggerLevel

public void setLoggerLevel(Level level)
Sets the logging level of this class

Parameters: level the logging level to set

setOrder

public void setOrder(Comparator order)

Parameters: order The order to set.

setOrdered

public void setOrdered(boolean ordered)

Parameters: ordered The ordered to set.

setPoints

public void setPoints(Object edge, List points)
Sets the points of the specified edge

Parameters: edge the edge whose points are to be set points the new list of points for the edge

setRoots

public void setRoots(List roots)

Parameters: roots The roots to set.

setSize

public void setSize(Object cell, double width, double height)
Sets the current size of the specified cell.

Parameters: cell the cell whose size is to be set width the new width of the cell height the new height of the cell

setVerticesFilter

public void setVerticesFilter(Set verticesFilter)

Parameters: verticesFilter The verticesFilter to set.

tilt

public void tilt(Collection vertices, int maxx, int maxy)
Simulates a 'nudge' to the graph, moving the specified vertices a random distance in the x and y axes directions between zero and a specified maximum. The maximum amounts can be specified seperately for the x and y axes.

Parameters: vertices the collection of vertices to be moved maxx the maximum translation that may occur in the x-axis maxy the maximum translation that may occur in the y-axis

translate

public void translate(Object cell, double dx, double dy)
Moved the specified cell by the specified x and y co-ordinate amounts

Parameters: cell the cell to be moved dx the amount by which the cell will be translated in the x-axis dy the amount by which the cell will be translated in the y-axis

translateCells

public void translateCells(Collection cells, double dx, double dy)
Translates the bounds of the specified cells adding dx and dy to the respective location axes of the cell,

Parameters: dx the amount to be added to be x-axis positions of the vertices before scaling is applied dy the amount to be added to be y-axis positions of the vertices before scaling is applied

Copyright (C) 2001-2009 JGraph Ltd. All rights reserved.