import java.awt.event.*;
import java.awt.*;
import java.lang.Math;

class TrasladarHandler implements ActionListener
{
	private EditorPanel panel;
	private boolean active;
	private Forma forma;
	private Point previo;

	public TrasladarHandler(EditorPanel panel)
	{
		this.panel = panel;
		active=false;

	}
	
	public void actionPerformed(ActionEvent e)
	{
		panel.changeMouseListener(new MouseHandler());
		panel.changeMouseMotionListener(new MouseMotionHandler());
		panel.manipulating();
		active=false;
	}
	
	class MouseHandler extends MouseAdapter
	{
		public void mousePressed (MouseEvent event)
		{
			Point punto=event.getPoint();
			forma=(Forma)panel.find(punto);		
			
			if(forma!=null)
			{	
				active=true;
				previo=punto;
			}
		}
	
		public void MouseReleased (MouseEvent event)
		{
			active=false;	

		}

	}
	class MouseMotionHandler extends MouseMotionAdapter
	{
		public void mouseDragged(MouseEvent event)
		{
        		Point p;
			if(active)
		        {
				p = event.getPoint();
        			double deltaX = p.getX()-previo.getX();
        			double deltaY = p.getY()-previo.getY();			
				forma.trasladar(deltaX,deltaY);
				previo = p;
				panel.repaint();
			}
		}
	}
}

