blob: 9b7f56a0a06b289ed6d7bbeade7c5466160d74cf [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2006 IBM Corporation and others.
// 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:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.authoring.gef.edit;
import org.eclipse.draw2d.AbstractConnectionAnchor;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
/**
* Provides support for bottom anchor for a figure's bottom location.
*
* @author Phong Nguyen Le
* @since 1.0
*/
class BottomAnchor extends AbstractConnectionAnchor {
private int offset;
BottomAnchor(IFigure source, int offset) {
super(source);
this.offset = offset;
}
public Point getLocation(Point reference) {
Rectangle r = getOwner().getBounds().getCopy();
getOwner().translateToAbsolute(r);
int off = offset;
if (off == -1)
off = r.width / 2;
if (r.contains(reference) || r.bottom() > reference.y)
return r.getTopLeft().translate(off, 0);
else
return r.getBottomLeft().translate(off, -1);
}
}