blob: 41b4dd452a66f9586e5b82556623974afeaa08f4 [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 multiplicity label.
* Main specialization: the relocate method.
*
*/
public class MultiplicitySourceLabelLocator extends AbstractSourceLabelLocator {
protected MultiplicitySourceLabelLocator(IFigure parent, Point offSet, int alignment, SourceLocatorFactory geoUtils) {
super(parent, offSet, alignment, geoUtils);
}
/**
* Calculates the x and y of the source multiplicity label.
*/
@Override
public void relocate(IFigure target) {
AbstractAssociatedSegment associatedSegment = getAssociatedSegment(target);
Point distantPoint = associatedSegment.getThePointDistantOf(getDistanceBetweenClassAndLabels());
Rectangle bothLabels = getRectangleForBothLabels(distantPoint);
distantPoint.setX(getBasicXMultiplicity(bothLabels));
distantPoint.setY(getBasicYPosition(bothLabels));
Rectangle classBounds = getAssociatedElementBounds(associatedSegment);
if (areLabelsAtTheSameHeightThanAssociatedClass(bothLabels, classBounds)) {
if (doLabelsIntersectAssociatedClassOnTheLeft(bothLabels, classBounds)) {
distantPoint.setX(getXMultiplicityForIntersectOntheLeft(classBounds));
} else if (doLabelsIntersectAssociatedClassOnTheRight(bothLabels, classBounds)) {
distantPoint.setX(getXMultiplicityForIntersectOntheRight(classBounds));
}
}
target.setLocation(distantPoint);
}
}