Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: cfb9bc76b0ac340ca0d976e8703054a8eace1af1 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*****************************************************************************
 * Copyright (c) 2010 CEA LIST.
 *
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.diagram.clazz.custom.locator;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator;
import org.eclipse.papyrus.diagram.common.figure.node.PackageNodePlateFigure;


/**
 * The Class ContainmentCircleOnPackageLocator.
 */
public class ContainmentCircleOnPackageLocator extends BorderItemLocator {

	/** The Constant DEFAULT_BORDER_ITEM_OFFSET. */
	private static final Dimension DEFAULT_BORDER_ITEM_OFFSET = new Dimension(1, 1);

	/** The Constant DEFAULT_SIZE. */
	private static final Dimension DEFAULT_SIZE = new Dimension(20, 20);

	private Dimension originalBorderItemOffset = DEFAULT_BORDER_ITEM_OFFSET;

	/**
	 * Instantiates a new containment circle on package locator.
	 * 
	 * @param parentFigure
	 *        the parent figure
	 */
	public ContainmentCircleOnPackageLocator(IFigure parentFigure) {
		super(parentFigure);
	}

	/**
	 * Instantiates a new containment circle on package locator.
	 * 
	 * @param borderItem
	 *        the border item
	 * @param parentFigure
	 *        the parent figure
	 * @param constraint
	 *        the constraint
	 */
	public ContainmentCircleOnPackageLocator(IFigure borderItem, IFigure parentFigure, Rectangle constraint) {
		super(borderItem, parentFigure, constraint);
	}

	/**
	 * Instantiates a new containment circle on package locator.
	 * 
	 * @param parentFigure
	 *        the parent figure
	 * @param preferredSide
	 *        the preferred side
	 */
	public ContainmentCircleOnPackageLocator(IFigure parentFigure, int preferredSide) {
		super(parentFigure, preferredSide);
		setConstraint(new Rectangle(new Point(0, 0), DEFAULT_SIZE));
	}

	/**
	 * @see org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator#setConstraint(org.eclipse.draw2d.geometry.Rectangle)
	 * 
	 * @param theConstraint
	 */

	@Override
	public void setConstraint(Rectangle theConstraint) {
		super.setConstraint(new Rectangle(theConstraint.getTopLeft(), DEFAULT_SIZE));
	}

	/**
	 * @see org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator#locateOnParent(org.eclipse.draw2d.geometry.Point, int,
	 *      org.eclipse.draw2d.IFigure)
	 * 
	 * @param suggestedLocation
	 * @param suggestedSide
	 * @param borderItem
	 * @return
	 */

	@Override
	protected Point locateOnParent(Point suggestedLocation, int suggestedSide, IFigure borderItem) {
		PackageNodePlateFigure parent = (PackageNodePlateFigure)getParentFigure();
		Rectangle headerBounds = parent.getPackageFigure().getHeader();
		if(suggestedSide == PositionConstants.NORTH && !isOnHeader(suggestedLocation, headerBounds)) {
			setBorderItemOffset(new Dimension(originalBorderItemOffset.width, headerBounds.height));
		} else {
			setBorderItemOffset(originalBorderItemOffset);
		}
		Point result = super.locateOnParent(suggestedLocation, suggestedSide, borderItem);
		setBorderItemOffset(originalBorderItemOffset);
		return result;
	}

	/**
	 * Checks if is on header.
	 * 
	 * @param p
	 *        the p
	 * @param headerBounds
	 *        the header bounds
	 * @return true, if is on header
	 */
	private boolean isOnHeader(Point p, Rectangle headerBounds) {
		return p.x < headerBounds.getTopRight().x;
	}


}

Back to the top