[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[gef-dev] Proposed additional Anchor for Ellipses
|
package org.eclipse.draw2d;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
/**
* @author as
*
* Created 31.08.2002 23:11:43
*/
public class EllipseAnchor extends AbstractConnectionAnchor {
/**
* Constructor for EllipseAnchor.
*/
public EllipseAnchor() {
}
/**
* Constructor for EllipseAnchor.
* @param owner
*/
public EllipseAnchor(IFigure owner) {
super(owner);
}
/**
* @see org.eclipse.draw2d.ConnectionAnchor#getLocation(Point)
*/
public Point getLocation(Point reference) {
Rectangle r = Rectangle.SINGLETON;
r.setBounds(getOwner().getBounds());
r.translate(-1, -1);
r.resize(1, 1);
getOwner().translateToAbsolute(r);
Point ref = r.getCenter().negate().translate(reference);
if (ref.x == 0)
return new Point(reference.x, (ref.y > 0) ? r.bottom() : r.y);
if (ref.y == 0)
return new Point((ref.x > 0) ? r.right() : r.x, reference.y);
float dx = (ref.x > 0) ? 0.5f : -0.5f;
float dy = (ref.y > 0) ? 0.5f : -0.5f;
// ref.x, ref.y, r.width, r.height != 0 => safe to proceed
float k = (float)(ref.y * r.width) / (ref.x * r.height);
k = k * k;
return r.getCenter().translate(
(int) (r.width * dx / Math.sqrt(1 + k)),
(int) (r.height * dy / Math.sqrt(1 + 1/k)));
}
}