//LineaHandler.java

import java.awt.event.*;
import java.awt.*;
import java.awt.geom.*;
/**Clase que maneja la excepcion por creacion de Lineas
 * @author Luis Espinoza Severino.
 */
class LineaHandler implements ActionListener
{
//Atributos
   private EditorPanel panel;
   private Linea linea;
   private boolean activo;
   private Point extremo;
   
/**Constructor
 * @param panel
 */
   public LineaHandler(EditorPanel panel)
     {
	this.panel = panel;
	activo = false;
     }

   public void actionPerformed(ActionEvent e)
     {
	panel.changeMouseListener(new MouseHandler());
	panel.changeMouseMotionListener(new MouseMotionHandler());
	activo = false;
	panel.nomanipular();
	
     }
   
   class MouseHandler extends MouseAdapter
     {
	public void mousePressed(MouseEvent e)
	  {
	     if(!activo)
	       {
		  extremo = e.getPoint();
		  linea = new Linea (extremo.getX(), extremo.getY(), extremo.getX(), extremo.getY());
		  linea.setP1(extremo);
		  panel.incorpore(linea);
		  activo = true;
		  panel.repaint();
	       }
	  }
	public void mouseReleased(MouseEvent event)
	  {
	     activo = false;
	  }
     }
   class MouseMotionHandler extends MouseMotionAdapter
     {
	public void mouseDragged(MouseEvent e)
	  {
	     if (activo)
	       {
		  
		  linea.setP2(e.getPoint());
		  panel.repaint();
	       }
	  }
     }
}
