package implementation.source.java.nodes; import edu.umd.cs.piccolo.event.PInputEvent; import edu.umd.cs.piccolo.util.PDimension; import edu.umd.cs.piccolox.handles.PHandle; /* * Created on Jan 24, 2006 * * TODO To change the template for this generated file go to * Window - Preferences - Java - Code Style - Code Templates */ /** * @author Timothy Ober * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Style - Code Templates */ public class DFEdgeEndpointHandle extends PHandle { DFEdge edge; DFEndpoint node; DFEndpoint oppositeNode; double xPos; double yPos; /** * @param arg0 */ public DFEdgeEndpointHandle(SetXYLocator l, DFEdge e, DFEndpoint n) { super(l); edge = e; node = n; if (n == edge.getEndFrom()) { oppositeNode = edge.getEndTo(); } else { oppositeNode = edge.getEndFrom(); } double x = oppositeNode.getX() + oppositeNode.getWidth() / 2; double y = oppositeNode.getY() + oppositeNode.getHeight() / 2; double a = x - node.getX() + node.getWidth() / 2; double o = y - node.getY() + node.getHeight() / 2; double h = Math.sqrt(Math.pow(a, 2) + Math.pow(o, 2)); if (h == 0) { return; } SetXYLocator loc = (SetXYLocator)getLocator(); xPos = ((node.getWidth() / 2) * (a / h)); yPos = ((node.getWidth() / 2) * (o / h)); loc.setX(node.getX() + (node.getWidth() / 2) + xPos); loc.setY(node.getY() + (node.getHeight() / 2) + yPos); relocateHandle(); } public void dragHandle(PDimension aLocalDimension, PInputEvent aEvent) { double x = aEvent.getPosition().getX(); double y = aEvent.getPosition().getY(); double a = x - (node.getX() + node.getWidth() / 2); double o = y - (node.getY() + node.getHeight() / 2); double h = Math.sqrt(Math.pow(a, 2) + Math.pow(o, 2)); if (h == 0) { return; } SetXYLocator loc = (SetXYLocator)getLocator(); xPos = ((node.getWidth() / 2) * (a / h)); yPos = ((node.getHeight() / 2) * (o / h)); loc.setX(node.getX() + (node.getWidth() / 2) + xPos); loc.setY(node.getY() + (node.getHeight() / 2) + yPos); relocateHandle(); edge.reset(); edge.drawEdge(); } public void updateHandleLocation() { SetXYLocator loc = (SetXYLocator)getLocator(); loc.setX(node.getBounds().getCenterX() + xPos); loc.setY(node.getBounds().getCenterY() + yPos); relocateHandle(); edge.reset(); edge.drawEdge(); } }