Package se.conciliate.extensions.router
Interface EdgeRouter
public interface EdgeRouter
The
Instances of this class will be considered stateless.
EdgeRouter
is responsible for layout of lines and curves as well
as the construction of the points that make up a lines and curves. It's main
responsiblity is to provide a shape given a list of points in space and to
assist in the creation of that shape through transformations of a list of
points. All operations in an EdgeRouter
is considered free of
side-effects except moveSegment(List, Point[], Map, Point, Shape, Shape, List)
moveSegment} wich takes a mutable map.Instances of this class will be considered stateless.
- Author:
- Richard
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
The adjust info is a helper class to facilitate parameter passing toadjust(Collection)
adjust(Collection)} andadjust(Collection, Set)
adjust(Collection, Set)}. -
Method Summary
Modifier and TypeMethodDescriptionaddControlPoint
(List<Point> controlPoints, Point toAdd) Adds a control point to the edge.void
adjust
(Collection<EdgeRouter.AdjustInfo> controlPoints) Adjusts control points from different edges to each other.void
adjust
(Collection<EdgeRouter.AdjustInfo> controlPoints, Set<Shape> avoid) Adjusts control points from different edges to each other.Returns a new list of control points where the given pointp
is taken into account while routing.boolean
Returns true if the pointp
lies on the path given by the control points.createShape
(List<Point> points, List<IntersectionPoint> intersections, List<OverlappingSegment> overlappingSegments) Returns a shape of the line.getBreakdownLocation
(List<Point> controlPoints) Returns the point where the breakdown decorator should be drawn.getDefaultControlPoints
(Shape from, Shape to) Returns a default set of control points from one shape to another.getDefaultControlPoints
(Shape from, Shape to, double fromAngle, double toAngle) Returns a default set of control points from one shape to another, giving preferred angles (in radians) that curves or lines will have with respect to the center of the respective shape.getDefaultLabelBounds
(Dimension dim, List<Point> controlPoints) Returns the default label bounds.getID()
Returns a unique id for this edge router, e.g.Returns a user friendly name for this edge router in the specified locale or, if a name is not available in that locale, a user friendly default name.getNewLabelBounds
(Rectangle oldBounds, List<Point> controlPoints) Returns new label bounds that are "snapped" to the edge path in some way decided by the router.
Note thatcontrolPoints
must not be modified, and neither must the Point objects in it.Point[]
getSegment
(List<Point> points, Point p) Returns an array representing the segment closest to the pointp
onpoints
.
Note thatpoints
must not be modified, and neither must the Point objects in it.moveControlPoint
(List<Point> points, Point controlPoint, Point offset, Shape from, Shape to, List<Point[]> otherSegments) Returns a new list of control points where the given pointp
has moved by the specified offset.moveSegment
(List<Point> points, Point[] segment, Map<Point, Point> changes, Point offset, Shape from, Shape to, List<Point[]> otherSegments) Returns a new list of control points where the given segment has moved by the specified offset.Returns a new list of control points where the given pointp
is no longer taken into account while routing.double
rotateLabelToFollowShape
(Rectangle labelBounds, List<Point> controlPoints) Without mutating any parameter, returns an angle that the given label bounds should be rotated by to make the label "follow" the shape of an edge made up of the given control points.updateEndpoints
(List<Point> controlPoints, List<Point> modifiedPoints, Shape oldFrom, Shape newFrom, Shape oldTo, Shape newTo, Point relativeOffset) Returns the updated control points when shapes connected by the given control points has moved.
-
Method Details
-
getID
String getID()Returns a unique id for this edge router, e.g. a UUID. The returned string may be no longer than 50 charachters.- Returns:
- a unique id for this edge router
-
getName
Returns a user friendly name for this edge router in the specified locale or, if a name is not available in that locale, a user friendly default name.- Parameters:
locale
- The locale that the name applies to- Returns:
- A user friendly name for this edge router
-
contains
Returns true if the pointp
lies on the path given by the control points. The exact result of this method is implementation dependant.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- the control points that makes up the linep
- the point we are interested in- Returns:
- true if p lies on the path, false otherwise
-
createShape
Shape createShape(List<Point> points, List<IntersectionPoint> intersections, List<OverlappingSegment> overlappingSegments) Returns a shape of the line. Implementations must be able to handle a list that is about to be constructed, i.e any number of points. However, this method (as with other methods) will never be called for point lists constructed or routed by other routers.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- the control points that makes up the line. This list can contain any number of points but will always be constructed by instances of this router's class.intersections
- points where intersections should be rendered.overlappingSegments
- segments that are overlapping with other edges and therefor should not be rendered.- Returns:
- a shape that makes up the line
-
updateEndpoints
List<Point> updateEndpoints(List<Point> controlPoints, List<Point> modifiedPoints, Shape oldFrom, Shape newFrom, Shape oldTo, Shape newTo, Point relativeOffset) Returns the updated control points when shapes connected by the given control points has moved. The old connected shapes are given as well as the new connected shapes. The exact effects of this method is implementation dependant but the returned list must always connectnewFrom
withnewTo
. However, all other parameters may be disregarded by some implementations.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
controlPoints
- the control points of the path going fromoldFrom
tooldTo
modifiedPoints
- A list of points.oldFrom
- the shape that the sent in control points start atnewFrom
- the shape that the returned control points should start atoldTo
- the shape that the sent in control points end atnewTo
- the shape that the returned control points should end atrelativeOffset
- An offset.- Returns:
- a new list of control points
-
appendControlPoint
List<Point> appendControlPoint(List<Point> points, Point p, Shape from, Shape to, List<Point[]> otherSegments) Returns a new list of control points where the given pointp
is taken into account while routing. The points parameter can be any size (including empty). This method will be called while constructing a new edge (but may be called at any time) and must therefore be able to handle a point-list of any size. However, the points will never be routed or constructed by other routers than instances of this router's class. The exact effects of this method is implementation dependant but the returned list must always connectfrom
withto
. Other parameters may be disregarded by some implementations.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- A list of points to re-route taking the new point p into account as being added to the list of points. It can be of any size but is never routed by other routers.p
- The point to append (what this means is up to the implementation and callers can not assume that the returned value will contain the point).from
- The shape that the points-list should be routed fromto
- The shape that the points-list should be routed tootherSegments
- A list of segments.- Returns:
- A re-routed list of points.
-
removeControlPoint
Returns a new list of control points where the given pointp
is no longer taken into account while routing. The effect of removing a point is implementation dependant but the returned list must always connectfrom
withto
.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- The list of points to re-route, exluding the pointp
p
- The point to excludefrom
- the shape that the control points should start atto
- the shape that the control points should end at- Returns:
- a new list of control points where the point
p
is no longer taken into account while routing.
-
moveControlPoint
List<Point> moveControlPoint(List<Point> points, Point controlPoint, Point offset, Shape from, Shape to, List<Point[]> otherSegments) Returns a new list of control points where the given pointp
has moved by the specified offset. The exact effects of this method is implementation dependant but must always connectfrom
withto
. Other parameters may be disregarded by some implementations. Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- A list of control points to transform taking the sent incontrolPoint
s andoffset
into account.controlPoint
- The point to move. This point must be contained inpoints
.offset
- The offset by wich thecontrolPoint
should move.from
- the shape that the control points should start atto
- the shape that the control points should end atotherSegments
- A list of segments.- Returns:
- a new list of control points where the give point
p
has moved by the specified offset.
-
moveSegment
List<Point> moveSegment(List<Point> points, Point[] segment, Map<Point, Point> changes, Point offset, Shape from, Shape to, List<Point[]> otherSegments) Returns a new list of control points where the given segment has moved by the specified offset. This method, in contrast to other operations on this object, will have side effects since it will change the sent in map. No other side effects are allowed. The exact effects of this method is implementation dependant but should always connectfrom
withto
. Other parameters may be disregarded by some implemenations.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- The points to transformsegment
- The segment that should be movedchanges
- A mapping from the points insegment
to the corresponding point in the result of this call (the returned value). This parameter may be null and its intention is to be able to track where the points on the sent in segment ends up after this call is done. If it is null, it might not be used. Otherwise, the map will be cleared and new point mappings put in. Ex:changes.get(segment[0])
will return a point that is in the returned list.offset
- The offset to where the segment should move, relative to its current positionfrom
- the shape that the control points should start atto
- the shape that the control points should end atotherSegments
- A list of segments.- Returns:
- a new list of control points where the given segment has moved by the given offset.
- Throws:
IllegalArgumentException
- if the segment is not a valid segment inpoints
-
getSegment
Returns an array representing the segment closest to the pointp
onpoints
.
Note thatpoints
must not be modified, and neither must the Point objects in it.- Parameters:
points
- The points describing the path where the caller is looking for a segment close top
p
- a point on the line- Returns:
- the segment closest to
p
onpoints
-
rotateLabelToFollowShape
Without mutating any parameter, returns an angle that the given label bounds should be rotated by to make the label "follow" the shape of an edge made up of the given control points. What "follow" means is up to the router to determine (so always returning 0 is valid). For straight lines, a good return value is the angle of the line closest to the bounds. For curves, a more intricate algorithm may be provided (maybe the mean slope of some curve segment close to the label bounds).- Parameters:
labelBounds
- The bounds of the label.controlPoints
- The control points that will make up a fully constructed edge.- Returns:
- The angle to rotate the bounds by.
-
getNewLabelBounds
Returns new label bounds that are "snapped" to the edge path in some way decided by the router.
Note thatcontrolPoints
must not be modified, and neither must the Point objects in it.oldBounds
must not be modified.- Parameters:
oldBounds
- The old bounds of the label.controlPoints
- The current control points of the relation.- Returns:
- The new bounds of the label.
-
getDefaultLabelBounds
Returns the default label bounds. The dimension of the bounds is given as a parameter. With this dimension in mind, the method will return a rectangle (with the same dimension) located at a default position on the edge that the given control points make up. What is meant by "default" is up to the implementation.- Parameters:
dim
- The dimension that the return value must have. This is given as a parameter mainly to let implementations calculate a good "center" of the bounds.controlPoints
- The points of the edge. Must not be empty.- Returns:
- A rectangle with the given dimension that is positioned in a default way. Note that an implementation is free to, but discourage from, always returning a rectangle at position (0, 0) (or any other fixed arbitrary point).
-
getDefaultControlPoints
Returns a default set of control points from one shape to another, giving preferred angles (in radians) that curves or lines will have with respect to the center of the respective shape. As an example, if fromAngle is 2pi (or 0) and toAngle is pi/2, the curves or line going out from the from shape should do so on the right side of the shape and the curve or line going in to the to shape should do so on the top side of the shape.
Depending on the implementation, these preferred angles may or may not be strictly adhered to. For example, an edge router that only draws vertical and horizontal lines, a fromAngle of 3pi/4 might be interpreted exactly as pi/2 (or pi). An edge router that only draws lines from the center of the shapes might completely disregard the angles.- Parameters:
from
- the from shapeto
- the to shapefromAngle
- the preferred angle at which a line or curve should exit the from shapetoAngle
- the preferred angle at which a line or curve should enter the to shape- Returns:
- a default set of control points
-
getDefaultControlPoints
Returns a default set of control points from one shape to another.- Parameters:
from
- The "from" shape.to
- The "to" shape.- Returns:
- A list of valid control points for an edge between
from
andto
.
-
addControlPoint
Adds a control point to the edge. The exact effect of this method is implementation dependant and all parameters may be disregarded by some implementations.- Parameters:
controlPoints
- The current control points.toAdd
- The new point to add. The implementation should try to add the new point as close as possible totoAdd
.- Returns:
- The new control points
-
getBreakdownLocation
Returns the point where the breakdown decorator should be drawn.- Parameters:
controlPoints
- A list of control points.- Returns:
- the point where the breakdown decorator should be drawn.
-
adjust
Adjusts control points from different edges to each other. The router is responsible for determining how the edges should be aligned to each other. The router can assume that all adjust infos (edges) sent, have been routed by instances of this edge router's class.
NOTE: This method is a best effort method and callers can not assume that anything will happen. A perfectly acceptable implementation is to return directly when called - without even setting the new values of the adjust infos.- Parameters:
controlPoints
- A collection of adjust infos, each describing the current state of an edge.
-
adjust
Adjusts control points from different edges to each other. The router is responsible for determining how the edges should be aligned to each other. The router can assume that all adjust infos (edges) sent, have been routed by instances of this edge router's class.
NOTE: This method is a best effort method and callers can not assume that anything will happen. A perfectly acceptable implementation is to return directly when called - without even setting the new values of the adjust infos.- Parameters:
controlPoints
- A collection of adjust infos, each describing the current state of an edge.avoid
- A set of shapes to make a best effort to try and avoid.
-