GraphModel model = _controller.getGraphModel();
FigureLayer layer = _controller.getGraphPane().getForegroundLayer();
Object tail = model.getTail(edge);
Object head = model.getHead(edge);
Connector connector = (Connector) _controller.getFigure(edge);
Figure tailFigure = _controller.getFigure(tail);
Figure headFigure = _controller.getFigure(head);
Site tailSite;
Site headSite;
// If the tail is not attached,
if (tailFigure == null) {
// Then try to find the old tail site.
if (connector != null) {
tailSite = connector.getTailSite();
} else {
// FIXME try to manufacture a site.
//throw new RuntimeException("drawEdge failed: could not find" +
// " a tail site.");
return null;
}
} else {
// Get a new tail site based on the tail figure.
Rectangle2D bounds = tailFigure.getBounds();
tailSite = getConnectorTarget().getTailSite(tailFigure,
bounds.getCenterX(), bounds.getCenterY());
}
// If the head is not attached,
if (headFigure == null) {
// Then try to find the old head site.
if (connector != null) {
headSite = connector.getHeadSite();
} else {
// FIXME try to manufacture a site.
//throw new RuntimeException("drawEdge failed: could not find" +
// " a head site.");
return null;
}
} else {
// Get a new head site based on the head figure.
Rectangle2D bounds = headFigure.getBounds();
headSite = getConnectorTarget().getHeadSite(headFigure,
bounds.getCenterX(), bounds.getCenterY());
}
// If we did have an old figure, throw it away.
if (connector != null) {
clearEdge(edge);
}
// Create the figure
Connector c = render(edge, layer, tailSite, headSite);
_controller.dispatch(new GraphViewEvent(this,
GraphViewEvent.EDGE_DRAWN, edge));
return c;
}