blob: ac593325fbf690b103fe23621ae9bda1d23ef1f2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/*****************************************************************************
* Copyright (c) 2018 CEA LIST, EclipseSource and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* EclipseSource - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.sequence.locator;
import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.ConnectionLocator;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
/** ConnectionLocator that provides the location of the intersection point of two PointLists. */
public class IntersectionPointSelectionLocator extends ConnectionLocator {
private PointList pointList1;
private PointList pointList2;
/**
* Constructor.
*
* @param connection
*/
public IntersectionPointSelectionLocator(Connection connection, PointList pointList1, PointList pointList2) {
super(connection);
this.pointList1 = pointList1;
this.pointList2 = pointList2;
}
@Override
protected Point getLocation(PointList points) {
if (pointList1 == null || pointList2 == null) {
return super.getLocation(points);
}
Rectangle intersect = pointList1.getBounds().intersect(pointList2.getBounds());
if (!intersect.isEmpty()) {
return intersect.getLocation();
}
// fallback to default (middle point)
return super.getLocation(points);
}
}
|