package cnp.ew.diagram;

import java.util.*;
import java.awt.*;

import cnp.ew.lightweight.*;

public class CpLineSplitterHandle extends CpHandle
{
    CpMoveLinePointHandle movePointHandle;

    public CpLineSplitterHandle(CpDiagrammableLc newOwner, CpLocator newLocator)
    {
        super(newOwner, newLocator);
    }

    public void startDrag(int x, int y)
	{
	    CpDependentLineLc poly = ((CpDependentLineLc)owner);
	    Vector points = poly.getPoints();
	    Point segmentHit = poly.segmentHitBy(x, y);
	    if (segmentHit == null) {
	        return;
	    }
	    int indexHit = segmentHit.y;
	    points.insertElementAt(new Point(x, y), indexHit);
	    poly.setPoints(points);
	    movePointHandle = new CpMoveLinePointHandle(owner, null, indexHit);
	    movePointHandle.startDrag(x, y);
    }

	public void drag(int x, int y)
	{
	    if (movePointHandle != null) {
    	    movePointHandle.drag(x, y);
    	}
	}

	public void endDrag(int x, int y)
	{
	    if (movePointHandle != null) {
    	    movePointHandle.endDrag(x, y);
    	    movePointHandle = null;
    	}
    }
}