net.goui.util
Class GraphLayout.Path

java.lang.Object
  extended bynet.goui.util.GraphLayout.Path
Direct Known Subclasses:
GoLayout.Row
Enclosing class:
GraphLayout

public static class GraphLayout.Path
extends java.lang.Object

Author:
David Beaumont, Copyright 2005

This class allows an ordered sequence of edges to be laid out with a layout graph. At least one instance of this class is required before any layout procedure occur. Multiple path instances may exist and can be laid out sequentially to provide an overall layout of the graph.


Constructor Summary
GraphLayout.Path()
          Construct an empty path instance.
 
Method Summary
 GraphLayout.Edge getEdge(int index)
          The method returns the Edge at the specified index from this Path.
 int getEdgeCount()
          This method obtains the number of Edges in this Path.
 void layout()
          This method provides the main functionality for the GraphLayout class by laying out a Path in accordance with the constraints of the edges which make it up.
 void setBounds(int firstPos, int lastPos)
          Set the positions of the first and last Vertices in this Path prior to layout.
 void setPath(GraphLayout.Edge[] edgeList, boolean copy)
          Constructs a Path instance from the given sequence of Edges.
 void setPath(java.util.List edgeList)
          Constructs a Path instance from the given sequence of Edges.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphLayout.Path

public GraphLayout.Path()
Construct an empty path instance. A sequence of Edges can be set for this Path by calling the setPath() method.

Method Detail

setPath

public final void setPath(GraphLayout.Edge[] edgeList,
                          boolean copy)
Constructs a Path instance from the given sequence of Edges. The given edges must form an ordered sequence of adjacent edges in the layout. If the list is null then the Path will be cleared, but a new sequence of edges must be set before any layout can occur.

If the given copy flag is false then the given array will be used directly by the Path and it is up to the caller to ensure that no modification is made to the Edges within this array while it remains in use by this Path.

Warning This method is unsynchronised and it is up to the user to ensure that concurrent modification of the Path data does not occur.

Parameters:
edgeList - The edge array specifying an ordered sequence of edges.
copy - A flag specifying whether the contents of the given list should be copied or used directly.
Throws:
java.lang.IllegalArgumentException - If the array has no elements or the specified edges do not form an adjacent sequence.

setPath

public final void setPath(java.util.List edgeList)
Constructs a Path instance from the given sequence of Edges. The given edges must form an ordered sequence of adjacent edges in the layout. If the list is null then the Path will be cleared, but a new sequence of edges must be set before any layout can occur.

Warning This method is unsynchronised and it is up to the user to ensure that concurrent modification of the Path data does not occur.

Parameters:
edgeList - The edge list specifying an ordered sequence of edges.
Throws:
java.lang.IllegalArgumentException - If the list has no elements or the specified edges do not form an adjacent sequence.

getEdgeCount

public int getEdgeCount()
This method obtains the number of Edges in this Path. In conjunction with the getEdge() method is can be used to enumerate the set of Edges in order.

Returns:
The number of edges in this Path instance or zero if no path has been set.

getEdge

public GraphLayout.Edge getEdge(int index)
The method returns the Edge at the specified index from this Path. This can be used to obtain the first and last Edges, and from them the end Vertices in order to explicitly set the Vertex positions prior to a layout operation.

Parameters:
index - The index of the desired Edge.
Returns:
The non-null Edge corresponding to the given index in the Path or null if no path has been set.
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid

setBounds

public void setBounds(int firstPos,
                      int lastPos)
Set the positions of the first and last Vertices in this Path prior to layout. Note that it is possible that the given positions cannot be set for these Vertices due to existing constraints within the layout graph. If this occurs, the nearest valid position will be set.

Warning This method is unsynchronised and it is up to the user to ensure that concurrent modification of the layout graph does not occur.

Parameters:
firstPos - The desired position of the first Vertex in this Path.
lastPos - The desired position of the first Vertex in this Path.
Throws:
java.lang.IllegalStateException - if no path has been set.

layout

public final void layout()
This method provides the main functionality for the GraphLayout class by laying out a Path in accordance with the constraints of the edges which make it up.

It is required that the Vertices at either end of the path have their position set prior to this method being called; they can either be explicitly placed by a call to setPosition() or they can have been placed as part of the layout of a different path.

When the layout is complete, all the Vertices along this path will have been positioned in accordance to the constraints of the edges between them. The minimum size constraints of the edges will not be violated and where possible the edges will be sized according to their weighting and maximum size.

It is possible that the layout graph is not acyclic and if this is detected then an IllegalArgumentException will be thrown. In this case it will be impossible to continue to use the GraphLayout layout until all cycles are removed. This situation should be considered a development time error only and it is up to any application using this class to ensure that the layout graph is acyclic at all times.

Warning This method is unsynchronised and it is up to the user to ensure that concurrent modification of the layout graph does not occur.

Throws:
java.lang.IllegalStateException - if the end Vertices of this path have not had their positions set, no path has been set or if a cycle is detected within the layout graph.