/*****************************************************************************
* Copyright (c) 2010 Atos Origin.
*
*
* 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:
* Atos Origin - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.activity.locator;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.papyrus.uml.diagram.common.locator.AdvancedBorderItemLocator;
/**
* This class is used to constrain the position of an Expansion Node
*
* TODO : The node is not re-sizable
*/
public class ExpansionNodePositionLocator extends AdvancedBorderItemLocator {
/** Constructor **/
public ExpansionNodePositionLocator(IFigure parentFigure) {
super(parentFigure);
}
/** Constructor **/
public ExpansionNodePositionLocator(IFigure borderItem, IFigure parentFigure, Rectangle constraint) {
super(borderItem, parentFigure, constraint);
}
/** Constructor **/
public ExpansionNodePositionLocator(IFigure parentFigure, int preferredSide) {
super(parentFigure, preferredSide);
}
/**
* {@inheritDoc}
*/
@Override
public Rectangle getValidLocation(Rectangle proposedLocation, IFigure borderItem) {
Rectangle realLocation = new Rectangle(proposedLocation);
int side = findClosestSideOfParent(proposedLocation, getParentBorder());
Point newTopLeft = locateOnBorder(realLocation.getTopLeft(), side, 0, borderItem);
realLocation.setLocation(newTopLeft);
return realLocation;
}
@Override
public void relocate(IFigure borderItem) {
// reset bounds of borderItem
Dimension size = getSize(borderItem);
Rectangle rectSuggested = getConstraint().getCopy();
if(rectSuggested.getTopLeft().x == 0 && rectSuggested.getTopLeft().y == 0) {
rectSuggested.setLocation(getPreferredLocation(borderItem));
} else {
// recovered constraint must be translated with the parent location
// to be absolute
rectSuggested.setLocation(rectSuggested.getLocation().translate(getParentBorder().getTopLeft()));
}
rectSuggested.setSize(size);
Rectangle validLocation = getValidLocation(rectSuggested, borderItem);
// the constraint is not reset, but the item bounds are
borderItem.setBounds(validLocation);
// ensure the side property is correctly set
setCurrentSideOfParent(findClosestSideOfParent(borderItem.getBounds(), getParentBorder()));
}
}