import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

// carlos 09-9785303
// horacio 08-6894387
// sara 09-1626050

public class Dibujo extends JPanel
{
  Dibujo()
    {
      super();
      formas = new ArrayList();
      currentMouseListener = null;
      currentMouseMotionListener = null;
    }
  
  public void paintComponent(Graphics g) 
    {
      super.paintComponent(g);
      Graphics2D g2d=(Graphics2D) g;
      
      for ( int i=0; i<formas.size(); i++)
        ((Forma)formas.get(i)).paintComponent(g2d);
      
    }

  public void changeMouseListener(MouseListener l){
    if (currentMouseListener != null)
      removeMouseListener(currentMouseListener);
    currentMouseListener=l;
    addMouseListener(currentMouseListener);
  }
  
  public void changeMouseMotionListener(MouseMotionListener l){
    if (currentMouseMotionListener != null)
      removeMouseMotionListener(currentMouseMotionListener);
    currentMouseMotionListener=l;
    addMouseMotionListener(currentMouseMotionListener);
  }
  
  public void escalar (Point centro, double factor) 
    {
      for (int i=0; i<formas.size(); i++) 
        ((Forma)formas.get(i)).escalar(centro,factor);
      repaint();
    }
  
  public void rotar (Point centro, double deltaAgulo) 
    {
      for (int i=0; i<formas.size(); i++) 
        ((Forma)formas.get(i)).rotar(centro, deltaAgulo);
      repaint();
    }

  public void trasladar (double dx, double dy) 
    {
      for (int i=0; i<formas.size(); i++) 
        ((Forma)formas.get(i)).trasladar(dx, dy);
      repaint();
    }
  
  public void remueva (Forma f)
    {
      formas.remove(f);
      repaint();
    }
  
  public void incorpore (Forma f)
    {
      formas.add(f);
      repaint();
    }

  private ArrayList formas;
  private MouseListener currentMouseListener;
  private MouseMotionListener currentMouseMotionListener;
}
