y.layout
Class LayoutTool

java.lang.Object
  extended by y.layout.LayoutTool

public class LayoutTool
extends Object

This class is a container for several helper and utility functions for the LayoutGraph class.

See Also:
LayoutGraph
 

Field Summary
static int CENTER
          Constant which can be used for arrangeRectangleRows.
static int JUSTIFIED
          Constant which can be used for arrangeRectangleRows.
static int LEADING
          Constant which can be used for arrangeRectangleRows.
static int TRAILING
          Constant which can be used for arrangeRectangleRows.
 
Constructor Summary
LayoutTool()
           
 
Method Summary
static void applyGraphLayout(LayoutGraph graph, GraphLayout gl)
          Applies a GraphLayout to a LayoutGraph.
static Dimension arrangeRectangleGrid(Rectangle2D[] rects, Rectangle2D finalRect, double viewRatio)
          Reassigns the bounds of the rectangles in rects to fit into a large rectangle, whose bounds will be stored in finalrect.
static int arrangeRectangleRows(Rectangle2D[] rects, Rectangle2D finalRect, double viewRatio)
          Reassigns the bounds of the rectangles in rects to fit in a large rectangle, whose bounds will be stored in finalrect.
static int arrangeRectangleRows(Rectangle2D[] rects, Rectangle2D finalRect, double viewRatio, int alignment)
          Reassigns the bounds of the rectangles in rects to fit into a large rectangle, whose bounds will be stored in finalrect.
static void assignReverseLayout(LayoutGraph graph, Edge e1, Edge e2)
          Set the layout of two parallel edges with different direction identical.
static void clipEdgeOnBB(LayoutGraph gd, Edge e)
          This helper method clips the path of the edge on the bounding box of the start and end points.
static void clipEdgesOnBB(LayoutGraph gd)
          This helper method clips the path of the edge on the bounding box of the start and end points.
static String edgeLayoutString(LayoutGraph gd, Edge edge)
          Returns the path of the layout of a specific edge as a String.
static Rectangle2D getBoundingBox(LayoutGraph graph, EdgeCursor ec)
          Returns the bounding box of the edges accessible through the given edge cursor.
static Rectangle2D getBoundingBox(LayoutGraph graph, NodeCursor nc)
          Returns the bounding box of the nodes accessible through the given node cursor.
static Rectangle2D getBoundingBox(LayoutGraph graph, NodeCursor nc, EdgeCursor ec)
          Returns the bounding box of the nodes and edges accessible through the given cursors.
static Rectangle2D getBoundingBox(LayoutGraph graph, NodeCursor nc, EdgeCursor ec, boolean includeLabels)
          Returns the bounding box of the nodes and edges accessible through the given cursors.
static YPointPath getEdgeClippedOnBB(EdgeLayout edge, NodeLayout sourceNode, NodeLayout targetNode)
          This helper method clips the path of an edge on the bounding box of the start and end vertices.
static YPointPath getEdgeClippedOnBB(EdgeLayout edge, NodeLayout sourceNode, NodeLayout targetNode, double inset)
          This helper method clips the path of an edge on the bounding box of the start and end vertices.
static YPointPath getEdgeClippedOnBB(LayoutGraph gd, Edge edge)
          This helper method clips the path of an edge on the bounding box of the start and end vertices.
static double getNodeDistance(LayoutGraph graph, Node s, Node t)
          Returns the distance between the centers of two nodes
static String getNodePositions(LayoutGraph gd)
          Returns the positions of the nodes of a graph's diagram.
static double getPathLength(LayoutGraph graph, Edge e)
          Returns the length of path of a given edge.
static void initDiagram(LayoutGraph gd)
          This method assigns the position (0,0) to all nodes in the graph, and sets the edges to straight lines with ports in the center of the adjacent node.
static boolean isEdgeOutsideNodes(EdgeLayout edge, NodeLayout sourceNode, NodeLayout targetNode, double inset)
          This helper method tests if the path of an edge is outside the bounding box of the start and end vertices.
static boolean isEdgeOutsideNodes(LayoutGraph gd, Edge edge)
          This helper method tests if the path of an edge is outside the bounding box of the start and end vertices.
static void moveEdge(LayoutGraph g, Edge edge, double dx, double dy)
          Moves the edge points of the given edge by the vector (dx,dy).
static void moveEdges(LayoutGraph g, EdgeCursor edges, double dx, double dy)
          Moves all edges accessible through the given edge cursor by the vector (dx,dy).
static void moveNode(LayoutGraph g, Node node, double dx, double dy)
          Moves the given node by the vector (dx,dy).
static void moveNodes(LayoutGraph g, NodeCursor nodes, double dx, double dy)
          Moves all nodes accessible through the given node cursor by the vector (dx,dy).
static void moveSubgraph(LayoutGraph g, EdgeCursor edges, double dx, double dy)
          Moves the subgraph induced by edges accessible through the given edge cursor by the vector (dx,dy).
static void moveSubgraph(LayoutGraph g, NodeCursor nodes, double dx, double dy)
          Moves the subgraph induced by nodes accessible through the given node cursor by the vector (dx,dy).
static boolean pathIntersectsRect(LayoutGraph graph, Edge e, Rectangle2D rect)
          Checks whether or not the path of an edge intersects the interior of a given rectangular area.
static void removeDuplicateBends(LayoutGraph gd)
          This helper method removes duplicate bends from all edges in the graph
static void removeDuplicateBends(LayoutGraph gd, Edge edge)
          This helper method removes duplicate bends from the given edge in the graph
static void resetPath(LayoutGraph gd, Edge edge)
          This helper method assign an trivial path to an edges which has no control points and the ports are in the center of the nodes.
static void resetPaths(LayoutGraph gd)
          This helper method assign an trivial path to all edges which has no control points and the ports are in the center of the nodes.
static void resetPaths(LayoutGraph gd, boolean resetPorts)
          This helper method assign an trivial path to all edges which has no control points
static void resetPorts(LayoutGraph gd)
          Sets the ports to the center of the nodes.
static void reverseEdgeLayout(EdgeLayout el)
          Reverses the layout of an edge.
static void roundEdgeLayout(LayoutGraph gd, Edge edge)
          Round the values of the controllpoints and ports of an edge.
static void roundLayout(LayoutGraph gd)
          Round the values of the layout of an entire layout.
static void roundNodeLayout(LayoutGraph gd, Node node)
          Round the values of the layout of a node.
static void routeEdgesParallel(LayoutGraph gd, Edge e1, Edge e2, double lineDistance)
          Routes two edges which are incident to the same nodes, in parallel.
static void routeEdgesParallel(LayoutGraph gd, Edge e1, Edge e2, double lineDistance, boolean joinEnds, double absJoinDist, double relJoinDist)
          Routes two edges which are incident to the same nodes, in parallel.
static void routeEdgesParallel(LayoutGraph gd, Edge e1, EdgeList list, double lineDistance)
          Routes a list of edges with are incident to the same nodes, in parallel.
static void routeEdgesParallel(LayoutGraph gd, Edge e1, EdgeList list, double lineDistance, boolean adjustE1, boolean joinEnds, double absJoinDist, double relJoinDist)
          Routes a list of edges which are incident to the same nodes, in parallel.
static void routeSelfLoop(LayoutGraph gd, Edge e)
          Routes a self-loop.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LEADING

public static final int LEADING
Constant which can be used for arrangeRectangleRows. Rectangles in one row will be aligned with the leading edge.

See Also:
Constant Field Values

TRAILING

public static final int TRAILING
Constant which can be used for arrangeRectangleRows. Rectangles in one row will be aligned to the trailing edge.

See Also:
Constant Field Values

JUSTIFIED

public static final int JUSTIFIED
Constant which can be used for arrangeRectangleRows. Rectangles in one row will be justified in the row.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Constant which can be used for arrangeRectangleRows. Rectangles in one row will be centered on the row.

See Also:
Constant Field Values
Constructor Detail

LayoutTool

public LayoutTool()
Method Detail

getNodeDistance

public static double getNodeDistance(LayoutGraph graph,
                                     Node s,
                                     Node t)
Returns the distance between the centers of two nodes


getPathLength

public static double getPathLength(LayoutGraph graph,
                                   Edge e)
Returns the length of path of a given edge. The path starts at the source point traverses through all control points and ends at the target point.


reverseEdgeLayout

public static void reverseEdgeLayout(EdgeLayout el)
Reverses the layout of an edge. This method reverses the order of points and swaps source with target point.


resetPaths

public static void resetPaths(LayoutGraph gd)
This helper method assign an trivial path to all edges which has no control points and the ports are in the center of the nodes.

Parameters:
gd - a graph diagram.

resetPaths

public static void resetPaths(LayoutGraph gd,
                              boolean resetPorts)
This helper method assign an trivial path to all edges which has no control points

Parameters:
gd - a graph diagram.
resetPorts - whether to reset the ports to the center of the nodes.

resetPath

public static void resetPath(LayoutGraph gd,
                             Edge edge)
This helper method assign an trivial path to an edges which has no control points and the ports are in the center of the nodes.

Parameters:
gd - a graph diagram.
edge - an edge in graph.

removeDuplicateBends

public static void removeDuplicateBends(LayoutGraph gd)
This helper method removes duplicate bends from all edges in the graph

Parameters:
gd - a graph diagram.

removeDuplicateBends

public static void removeDuplicateBends(LayoutGraph gd,
                                        Edge edge)
This helper method removes duplicate bends from the given edge in the graph

Parameters:
gd - a graph diagram.
edge - the edge.

moveEdge

public static void moveEdge(LayoutGraph g,
                            Edge edge,
                            double dx,
                            double dy)
Moves the edge points of the given edge by the vector (dx,dy).


moveEdges

public static void moveEdges(LayoutGraph g,
                             EdgeCursor edges,
                             double dx,
                             double dy)
Moves all edges accessible through the given edge cursor by the vector (dx,dy).


moveNode

public static void moveNode(LayoutGraph g,
                            Node node,
                            double dx,
                            double dy)
Moves the given node by the vector (dx,dy).


moveNodes

public static void moveNodes(LayoutGraph g,
                             NodeCursor nodes,
                             double dx,
                             double dy)
Moves all nodes accessible through the given node cursor by the vector (dx,dy).


moveSubgraph

public static void moveSubgraph(LayoutGraph g,
                                EdgeCursor edges,
                                double dx,
                                double dy)
Moves the subgraph induced by edges accessible through the given edge cursor by the vector (dx,dy).


moveSubgraph

public static void moveSubgraph(LayoutGraph g,
                                NodeCursor nodes,
                                double dx,
                                double dy)
Moves the subgraph induced by nodes accessible through the given node cursor by the vector (dx,dy).


getBoundingBox

public static Rectangle2D getBoundingBox(LayoutGraph graph,
                                         NodeCursor nc,
                                         EdgeCursor ec)
Returns the bounding box of the nodes and edges accessible through the given cursors.


getBoundingBox

public static Rectangle2D getBoundingBox(LayoutGraph graph,
                                         NodeCursor nc)
Returns the bounding box of the nodes accessible through the given node cursor.


getBoundingBox

public static Rectangle2D getBoundingBox(LayoutGraph graph,
                                         EdgeCursor ec)
Returns the bounding box of the edges accessible through the given edge cursor.


getBoundingBox

public static Rectangle2D getBoundingBox(LayoutGraph graph,
                                         NodeCursor nc,
                                         EdgeCursor ec,
                                         boolean includeLabels)
Returns the bounding box of the nodes and edges accessible through the given cursors. Optionally, the resulting bounding box will also include the bounds of all node and edge labels attached to the accessible node sand edges.


resetPorts

public static void resetPorts(LayoutGraph gd)
Sets the ports to the center of the nodes.

Parameters:
gd - a graph diagram.

getEdgeClippedOnBB

public static YPointPath getEdgeClippedOnBB(EdgeLayout edge,
                                            NodeLayout sourceNode,
                                            NodeLayout targetNode)
This helper method clips the path of an edge on the bounding box of the start and end vertices.


getEdgeClippedOnBB

public static YPointPath getEdgeClippedOnBB(LayoutGraph gd,
                                            Edge edge)
This helper method clips the path of an edge on the bounding box of the start and end vertices.


getEdgeClippedOnBB

public static YPointPath getEdgeClippedOnBB(EdgeLayout edge,
                                            NodeLayout sourceNode,
                                            NodeLayout targetNode,
                                            double inset)
This helper method clips the path of an edge on the bounding box of the start and end vertices.


isEdgeOutsideNodes

public static boolean isEdgeOutsideNodes(LayoutGraph gd,
                                         Edge edge)
This helper method tests if the path of an edge is outside the bounding box of the start and end vertices.


isEdgeOutsideNodes

public static boolean isEdgeOutsideNodes(EdgeLayout edge,
                                         NodeLayout sourceNode,
                                         NodeLayout targetNode,
                                         double inset)
This helper method tests if the path of an edge is outside the bounding box of the start and end vertices.


clipEdgesOnBB

public static void clipEdgesOnBB(LayoutGraph gd)
This helper method clips the path of the edge on the bounding box of the start and end points.


clipEdgeOnBB

public static void clipEdgeOnBB(LayoutGraph gd,
                                Edge e)
This helper method clips the path of the edge on the bounding box of the start and end points.


edgeLayoutString

public static String edgeLayoutString(LayoutGraph gd,
                                      Edge edge)
Returns the path of the layout of a specific edge as a String.


roundNodeLayout

public static void roundNodeLayout(LayoutGraph gd,
                                   Node node)
Round the values of the layout of a node.


roundEdgeLayout

public static void roundEdgeLayout(LayoutGraph gd,
                                   Edge edge)
Round the values of the controllpoints and ports of an edge.


roundLayout

public static void roundLayout(LayoutGraph gd)
Round the values of the layout of an entire layout.


routeEdgesParallel

public static void routeEdgesParallel(LayoutGraph gd,
                                      Edge e1,
                                      Edge e2,
                                      double lineDistance)
Routes two edges which are incident to the same nodes, in parallel.

See Also:
routeEdgesParallel(LayoutGraph, Edge, Edge, double, boolean, double, double)

routeEdgesParallel

public static void routeEdgesParallel(LayoutGraph gd,
                                      Edge e1,
                                      Edge e2,
                                      double lineDistance,
                                      boolean joinEnds,
                                      double absJoinDist,
                                      double relJoinDist)
Routes two edges which are incident to the same nodes, in parallel.

Parameters:
gd - the graph
e1 - the leading edge
e2 - the edge to be adjusted (may be e1)
lineDistance - the distance between the two edges
joinEnds - whether the end points should all be set to the end points of e1
absJoinDist - the absolute distance between the end points and the beginning to the parallel segment routing
relJoinDist - the relative distance, measured relative to the length of the first/last segments

routeEdgesParallel

public static void routeEdgesParallel(LayoutGraph gd,
                                      Edge e1,
                                      EdgeList list,
                                      double lineDistance)
Routes a list of edges with are incident to the same nodes, in parallel.

See Also:
routeEdgesParallel(LayoutGraph, Edge, EdgeList, double, boolean, boolean, double, double)

routeEdgesParallel

public static void routeEdgesParallel(LayoutGraph gd,
                                      Edge e1,
                                      EdgeList list,
                                      double lineDistance,
                                      boolean adjustE1,
                                      boolean joinEnds,
                                      double absJoinDist,
                                      double relJoinDist)
Routes a list of edges which are incident to the same nodes, in parallel.

Parameters:
gd - the graph
e1 - the leading edge
list - the list of edges that will be aligned to e1
lineDistance - the distance between two edges
adjustE1 - whether e1 should be adjusted if the size of list is odd
joinEnds - whether the end points should all be set to the end points of e1
absJoinDist - the absolute distance between the end points and the beginning to the parallel segment routing
relJoinDist - the relative distance, measured relative to the length of the first/last segments

routeSelfLoop

public static void routeSelfLoop(LayoutGraph gd,
                                 Edge e)
Routes a self-loop.

Parameters:
e - An edge with e.source.equals(e.target).

assignReverseLayout

public static void assignReverseLayout(LayoutGraph graph,
                                       Edge e1,
                                       Edge e2)
Set the layout of two parallel edges with different direction identical.

Parameters:
e1 - the edge for which the points are set.
e2 - the template.

getNodePositions

public static String getNodePositions(LayoutGraph gd)
Returns the positions of the nodes of a graph's diagram.


initDiagram

public static void initDiagram(LayoutGraph gd)
This method assigns the position (0,0) to all nodes in the graph, and sets the edges to straight lines with ports in the center of the adjacent node.


arrangeRectangleRows

public static final int arrangeRectangleRows(Rectangle2D[] rects,
                                             Rectangle2D finalRect,
                                             double viewRatio)
Reassigns the bounds of the rectangles in rects to fit in a large rectangle, whose bounds will be stored in finalrect. This procedure tries to generate a final rectangle, whose aspect ratio is as close as possible to viewRatio. This is achieved by arranging the rectangles in a rows. The number of used rows will be returned. This method invokes arrangeRectangleRows with LEADING as the last argument.

Parameters:
rects - the rectangles whose coordinates will be modified
finalRect - the exact dimension will be placed in this rectangle
viewRatio - the preferred ratio of the resulting bounds
Returns:
the number of used rows

arrangeRectangleGrid

public static final Dimension arrangeRectangleGrid(Rectangle2D[] rects,
                                                   Rectangle2D finalRect,
                                                   double viewRatio)
Reassigns the bounds of the rectangles in rects to fit into a large rectangle, whose bounds will be stored in finalrect. This procedure tries to generate a final rectangle, whose aspect ratio is as close as possible to viewRatio. This is achieved by arranging the rectangles in a grid-like fashion. The dimension of this grid is returned.

Parameters:
rects - the rectangles whose, coordinates will be modified
finalRect - the exact dimension will be placed in this rectangle
viewRatio - the preferred ratio of the grid
Returns:
the dimension of the grid

arrangeRectangleRows

public static final int arrangeRectangleRows(Rectangle2D[] rects,
                                             Rectangle2D finalRect,
                                             double viewRatio,
                                             int alignment)
Reassigns the bounds of the rectangles in rects to fit into a large rectangle, whose bounds will be stored in finalrect. This procedure tries to generate a final rectangle, whose aspect ratio is as close as possible to viewRatio. This is achieved by arranging the rectangles in rows. The number of generated rows is returned.

Parameters:
alignment - determines the alignment policy for rows, that are not completely filled
rects - the rectangles whose coordinates will be modified
finalRect - the exact dimension will be placed in this rectangle
viewRatio - the preferred ratio of the resulting bounds
Returns:
the number of generated rows

pathIntersectsRect

public static boolean pathIntersectsRect(LayoutGraph graph,
                                         Edge e,
                                         Rectangle2D rect)
Checks whether or not the path of an edge intersects the interior of a given rectangular area.


applyGraphLayout

public static void applyGraphLayout(LayoutGraph graph,
                                    GraphLayout gl)
Applies a GraphLayout to a LayoutGraph.

Precondition:
the GraphLayout data must be defined for elements in the given LayoutGraph.

© Copyright 2000-2008,
yWorks GmbH.
All rights reserved.