package cnp.ew.diagram;

import java.awt.*;
import java.util.*;

import cnp.ew.lightweight.*;
import cnp.ew.util.*;

// THIS MAY BE MORE GENERALLY A SELECTIONHANDLE which operates on the selection
public class CpMovingHandle extends CpHandle
{
    Point lastHit;
    Vector selectedLcs;
    Vector locations;

    public CpMovingHandle(CpDiagrammableLc newOwner, CpLocator newLocator)
    {
        super(newOwner, newLocator);
    }

    public void startDrag(int x, int y)
	{
	    selectedLcs = owner.getDiagram().getSelectedLcs();
	    locations = new Vector();
	    for (int i = 0; i < selectedLcs.size(); i++) {
	        CpDiagrammableLc lc = (CpDiagrammableLc)selectedLcs.elementAt(i);
	        locations.addElement(lc.location());
	    }
	    lastHit = new Point(x, y);
    }

	public void drag(int x, int y)
	{
	    CpDiagrammableLc lc;

        owner.enableDamageRepair(false);
	    for (int i = 0; i < selectedLcs.size(); i++) {
	        lc = (CpDiagrammableLc)selectedLcs.elementAt(i);
    	    lc.moveBy(x - lastHit.x, y - lastHit.y);
    	}
        owner.enableDamageRepair(true);
        owner.repairDamage();
        owner.getDiagram().notifyObservers(CpEvent.DIAGRAM_SELECTION_MOVESIZE);
	    lastHit = new Point(x, y);
	}

	public void endDrag(int x, int y)
	{
    }
}
