Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: bcdf550a45068f209872becf46e9713e8114c63a (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.eclipse.papyrus.infra.gmfdiag.common.linklf;

import org.eclipse.draw2d.AbstractPointListShape;
import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.ScalablePolygonShape;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
import org.eclipse.gmf.runtime.draw2d.ui.figures.IBorderItemLocator;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;

public class LinksLFNodeFigure extends DefaultSizeNodeFigure {

	private final GraphicalEditPart myHost;

	public LinksLFNodeFigure(GraphicalEditPart hostEP, int width, int height) {
		super(width, height);
		myHost = hostEP;
	}

	@Override
	protected ConnectionAnchor createAnchor(PrecisionPoint p) {
		if(p == null) {
			// If the old terminal for the connection anchor cannot be resolved (by SlidableAnchor) a null
			// PrecisionPoint will passed in - this is handled here
			return createDefaultAnchor();
		}
		SlidableSnapToGridAnchor result = new SlidableSnapToGridAnchor(this, p);
		result.setEditPartViewer(myHost.getViewer());
		return result;
	}

	@Override
	protected double getSlidableAnchorArea() {
		return 0.9;
	}

	protected ConnectionAnchor createConnectionAnchor(Point p) {
		if(p == null) {
			return getConnectionAnchor(szAnchor);
		} else {
			Point temp = p.getCopy();
			translateToRelative(temp);
			PrecisionPoint pt = BaseSlidableAnchor.getAnchorRelativeLocation(temp, getBounds());
			if(isDefaultAnchorArea(pt)) {
				return getConnectionAnchor(szAnchor);
			}
			
			if (myHost instanceof IBorderItemEditPart) {
				IBorderItemLocator locator = ((IBorderItemEditPart) myHost).getBorderItemLocator();
				switch (locator.getCurrentSideOfParent()) {
				case PositionConstants.WEST:
				case PositionConstants.EAST:
					pt.setPreciseX(pt.preciseX() > 0.5 ? 1.0 : 0.0);
					break;
				case PositionConstants.SOUTH:
				case PositionConstants.NORTH:
					pt.setPreciseY(pt.preciseY() > 0.5 ? 1.0 : 0.0);
					break;
				}
			}

			return createAnchor(pt);
		}
	}

	@Override
	public PointList getPolygonPoints() {
		if(getChildren().size() == 1) {
			IFigure primaryShape = (IFigure)getChildren().get(0);
			if(primaryShape instanceof ScalablePolygonShape) {
				ScalablePolygonShape scalable = (ScalablePolygonShape)primaryShape;
				PointList result = scalable.getScaledPoints().getCopy();
				result.translate(scalable.getLocation());
				return result;
			}
			if(primaryShape instanceof AbstractPointListShape) {
				return ((AbstractPointListShape)primaryShape).getPoints().getCopy();
			}
		}
		return super.getPolygonPoints();
	}

}

Back to the top