*/
public void mouseReleased(EditorMouseEvent event) {
double mx = event.getX(), my = event.getY();
DiagramElement elem = editor.getDiagram().getChildAt(mx, my);
if (source != null && isValidTarget(elem)) {
UmlNode target = (UmlNode) elem;
Association assoc =
editor.getDiagram().getElementFactory().createAssociation(
(UmlNode) source, target);
List<Point2D> points = linebuilder.calculateLineSegments(anchor.getX(),
anchor.getY(), tmpPos.getX(), tmpPos.getY(), Orientation.HORIZONTAL);
List<Point2D> linepoints = new LinkedList<Point2D>();
for (Point2D point : points) {
linepoints.add(point);
}
// calculate intersections with the nodes
Line2D line = new Line2D.Double();
// first
// check if we could start at the second segment
line.setLine(points.get(1), points.get(2));
// if not, start at the first segment
if (source.intersects(line)) {
linepoints.remove(0);
} else {
line.setLine(points.get(0), points.get(1));
}
source.calculateIntersection(line, linepoints.get(0));
// last
// check if we could end at the segment before the last one
line.setLine(points.get(points.size() - 3),
points.get(points.size() - 2));
if (target.intersects(line)) {
linepoints.remove(linepoints.size() - 1);
} else {
line.setLine(points.get(points.size() - 2),
points.get(points.size() - 1));
}
target.calculateIntersection(line, linepoints.get(linepoints.size() - 1));
assoc.setPoints(linepoints);
AddElementCommand command = new AddElementCommand(editor,
editor.getDiagram(), assoc);
editor.execute(command);
}