blob: 853d498aa3a38277d66a1d1b2f07b244b8ea9693 [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2019 CEA LIST.
*
*
* 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
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.locators.source;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.papyrus.uml.diagram.clazz.lf.associationlabellayout.locators.AbstractAssociatedSegment;
/**
* This class specializes the abstract label for the source role label.
* Main specialization: the relocate method.
*/
public class RoleSourceLabelLocator extends AbstractSourceLabelLocator {
RoleSourceLabelLocator(IFigure parent, Point offSet, int alignment, SourceLocatorFactory factory) {
super(parent, offSet, alignment, factory);
}
/**
*Calculates the x and y of the source role label.
*/
@Override
public void relocate(IFigure target) {
AbstractAssociatedSegment associatedSegment = getAssociatedSegment(target);
Point distantPoint = associatedSegment.getThePointDistantOf(getDistanceBetweenClassAndLabels());
Rectangle bothLabels = getRectangleForBothLabels(distantPoint);
distantPoint.setX(getBasicXRole(bothLabels));
distantPoint.setY(getBasicYPosition(bothLabels));
Rectangle classBounds = getAssociatedElementBounds(associatedSegment);
if (areLabelsAtTheSameHeightThanAssociatedClass(bothLabels, classBounds)) {
if (doLabelsIntersectAssociatedClassOnTheLeft(bothLabels, classBounds)) {
distantPoint.setX(getXRoleForIntersectOntheLeft(classBounds));
} else if (doLabelsIntersectAssociatedClassOnTheRight(bothLabels, classBounds)) {
distantPoint.setX(getXRoleForIntersectOntheRight(classBounds));
}
}
target.setLocation(distantPoint);
}
}