|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdiva.canvas.connector.ManhattanRouter
public class ManhattanRouter
An object that is used to route a single Manhattan connector. This code is abstracted out into a separate class so that the routing algorithm can be used in other applications. A route consists of a series of segments, which can be created based on the positions and direction of the start and endpoints, and then manipulated to make a more complex route. For example, a segment can be split, adding two new segments to the route. Once the route is complete, a Polyline2D can be extracted from it for the purpose of drawing a connector.
Each segment has a "direction." This is specified as a constant from SwingUtilities, such as SwingUtilities.SOUTH, and indicates the direction of the segment when proceeding from the start to the end of the route.
Each segment in a route can be "pinned." This means that the position of the segment (perpendicular to its direction) will not be changed by any of the routing methods. Typically, if an interactor moves a segment, it will then pin it so that it appears to "stay put." The result is a reasonable compromise between automatic routing and manual control.
Nested Class Summary | |
---|---|
static class |
ManhattanRouter.Segment
Inner class representing a segment of the route. |
static class |
ManhattanRouter.SegmentList
Inner class for a list of segments. |
Constructor Summary | |
---|---|
ManhattanRouter()
Create a new empty router. |
Method Summary | |
---|---|
void |
addSegment(int direction)
Add a new segment to the route. |
Polyline2D |
createShape()
Create a Polyline2D that represents the shape of the current route. |
void |
deleteSegment(int segment)
Delete a segment. |
Rectangle2D |
getRegion(int first,
int last)
Get the region covered by some number of segments. |
ManhattanRouter.Segment |
getSegment(int segment)
Get the segment with the given index |
int |
getSegmentCount()
Get the number of segments |
Point2D |
getStart()
Get the starting point |
static void |
main(String[] argv)
Test this thing... |
void |
route(Point2D start,
int startDir,
Point2D end,
int endDir)
Create a route based on the given start and end points, and the direction leaving and arriving at those points. |
void |
setSegments(ManhattanRouter.SegmentList segments)
Set all segments of the route. |
void |
splitSegment(int segment)
Split a segment. |
String |
toString()
Print the route |
void |
translateEnd(double dx,
double dy)
Reroute the end section of the route. |
int |
translateSegment(int segment,
double x,
double y)
Translate a segment by the given distance. |
void |
translateStart(double dx,
double dy)
Translate and reroute the start section of the route. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ManhattanRouter()
Method Detail |
---|
public void addSegment(int direction)
public Polyline2D createShape()
public void deleteSegment(int segment)
public Rectangle2D getRegion(int first, int last)
public ManhattanRouter.Segment getSegment(int segment)
public int getSegmentCount()
public Point2D getStart()
public void translateEnd(double dx, double dy)
public void translateStart(double dx, double dy)
public void route(Point2D start, int startDir, Point2D end, int endDir)
public void setSegments(ManhattanRouter.SegmentList segments)
public void splitSegment(int segment)
public String toString()
toString
in class Object
public int translateSegment(int segment, double x, double y)
Often, an interactor that calls this method will also pin the segment so that further calls to translateStart() or translateEnd() do not overwrite the new segment location.
public static void main(String[] argv)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |