package dessin;

import javax.swing.*;

import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.BasicStroke;
import java.util.*;

class Grid extends JComponent {
    public void paint(Graphics g) {
        g.drawRect (10, 10, 800, 500);    

        for (int i = 10; i <= 800; i+= 10)
            g.drawLine (i, 10, i, 510);

        for (int i = 10; i <= 500; i+= 10)
            g.drawLine (10, i, 810, i);
    }
}


public class draw extends JPanel {

	
	 
	 public void paintComponent(Graphics g) {
		 Graphics2D g2d = (Graphics2D)g;
		 
		  List l = new LinkedList();
		  ArrayList figure = new ArrayList();
		  
		  ArrayList<Rectangle> obj = new ArrayList<Rectangle>();
		
		    super.paintComponent(g);
		    g.setColor(Color.blue);
		    g.drawRect(10, 10, 80, 30);
		    g.drawRoundRect(100, 10, 80, 30, 15, 15);
		 
		    int thickness = 4;
		 
		    for (int i = 0; i <= thickness; i++)
		      g.draw3DRect(200 - i, 10 - i, 80 + 2 * i, 30 + 2 * i, true);
		    for (int i = 0; i < thickness; i++)
		      g.draw3DRect(200 - i, 50 - i, 80 + 2 * i, 30 + 2 * i, false);
		 
		    g.drawOval(10, 100, 80, 30);
		    
		    g.setColor(Color.RED);
		    
		    figure.add(new Rectangle(20, 20 , 100, 200));
		    
		    figure.add(new Rectangle(20, 20, 60, 60));
		    figure.add(new Rectangle(130, 30, 80, 11));
		    figure.add(new Rectangle(200, 30, 20, 140));
		    
		    
		    obj.add(new Rectangle(20, 20, 60, 60));
		    obj.add(new Rectangle(130, 30, 80, 11));
		    obj.add(new Rectangle(200, 30, 20, 140));
		    
		    Rectangle a = obj.get(0);
		    int pipo = a.x0;
		    
		    Object aqw = figure.get(0);
		    
		    
		    
		    Iterator iter = figure.iterator();
		    
		   /* while (iter.hasNext()) // tant que j'ai un element non parcouru
		    {
		    
		      Objet o= maMap.get(iter.next());
		      //mes opérations
		    }*/
		    
		  /*  System.out.println("infos" + figure.size());
		    
		    for(int i = 0; i < figure.size(); i++)

		    {

		      System.out.println("donnée à l'indice " + i + " = " + figure.get(i));

		    }*/
		    
		    
		  /*  for (int i = 0; i < figure.size(); i++) {
				List child = (List) figure.get(i);
				for (int j = 0; j < child.size(); j++) {
					System.out.println(child.get(j));
				}
			}*/
		    
		    /*for (Rectangle rect : figure) {
               // g2d.draw(rect);
            }*/
		    
		    
		   // g2d.setStroke(new BasicStroke(1.0f));  
		   // g2d.drawRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());  
		
		    Rectangle r = new Rectangle(30, 30 , 100, 200);
		    figure.add(r);
		    g2d.setStroke(new BasicStroke(1.0f));  
		    g2d.drawRect(r.getX(), r.getY(), r.getWidth(), r.getHeight());  
		     
		    double x = r.getX();
		    double y = r.getY();
		    double w = r.getWidth();
		    double h = r.getHeight();
		     
		    g2d.fillRect(r.getX()-3, r.getY()-3, 6, 6);
		     
		   
		      
	/*	     g2d.fillRect(new Rectangle.Double(r.getX() + w * 0.5 - 3.0, y - 3.0, 6.0,
		              6.0));
		     g2d.fillRect(new Rectangle.Double(x + w - 3.0, y - 3.0, 6.0, 6.0));
		     g2d.fillRect.fill(new Rectangle.Double(x - 3.0, y + h * 0.5 - 3.0, 6.0,
		              6.0));
		     g2d.fillRect.fill(new Rectangle.Double(x + w - 3.0, y + h * 0.5 - 3.0, 6.0,
		          6.0));
		     g2d.fillRect.fill(new Rectangle.Double(x - 3.0, y + h - 3.0, 6.0, 6.0));
		     g2d.fillRect.fill(new Rectangle.Double(x + w * 0.5 - 3.0, y + h - 3.0, 6.0,
		          6.0));
		     g2d.fillRect.fill(new Rectangle.Double(x + w - 3.0, y + h - 3.0, 6.0, 6.0));
		     
		  
		  */
		     g.drawLine(10, 10, 50, 10);
		  // sauvegarde de l'épaisseur du trait
		/*  Stroke s = g.getStroke();
		  // trait épais
		  g.setStroke(new BasicStroke(5));
		  g.drawLine(10, 40, 50, 40);
		  // retour au trait "normal"
		  g.setStroke(s);
		  g.drawLine(10, 70, 50, 70);*/
		     
		     //Highlight Circle When Mouse Over
		     
		  }
	 
	 
/*	 public void drawHighlightSquares(Graphics2D g2D, Rectangle r)
	 {
	      double x = r.getX();
	      double y = r.getY();
	      double w = r.getWidth();
	      double h = r.getHeight();
	      g2D.setColor(Color.black);

	      g2D.fill(x - 3, y - 3, 6, 6);
	      
	      g2D.fill(new Rectangle.Double(x + w * 0.5 - 3.0, y - 3.0, 6.0,
	              6.0));
	      g2D.fill(new Rectangle.Double(x + w - 3.0, y - 3.0, 6.0, 6.0));
	      g2D
	          .fill(new Rectangle.Double(x - 3.0, y + h * 0.5 - 3.0, 6.0,
	              6.0));
	      g2D.fill(new Rectangle.Double(x + w - 3.0, y + h * 0.5 - 3.0, 6.0,
	          6.0));
	      g2D.fill(new Rectangle.Double(x - 3.0, y + h - 3.0, 6.0, 6.0));
	      g2D.fill(new Rectangle.Double(x + w * 0.5 - 3.0, y + h - 3.0, 6.0,
	          6.0));
	      g2D.fill(new Rectangle.Double(x + w - 3.0, y + h - 3.0, 6.0, 6.0));
	    }*/
	 
	/* public boolean contains(int x, int y)
	  {
	    return (x >= this.x && x <= this.x + this.width
	            && y >= this.y && y <= this.y + this.height);
	  } */  
	 
	 public class Point {
		    public int x = 0;
		    public int y = 0;
		    //constructor
		    public Point(int a, int b) {
		        x = a;
		        y = b;
		    }
		}
	 
	 public class Rectangle {
		    public int x0 = 0;
		    public int y0 = 0;
		    
		    public int width = 0;
		    public int height = 0;
		    
		    public Point origin;
		    
		    Color couleur;

		    public Color getColor(){
		    	return couleur ;
		    }

		    // four constructors
		    public Rectangle() {
		        origin = new Point(0, 0);
		    }
		    public Rectangle(Point p) {
		        origin = p;
		    }
		    public Rectangle(int w, int h) {
		        origin = new Point(0, 0);
		        width = w;
		        height = h;
		    }
		    public Rectangle(int x, int y, int w, int h) {
		    	x0 = x;	
		    	y0 = y;
		    	width = w;
		        height = h;
		    }
		    
		    public int getX()
		    {
		        return x0;
		    }

		    public int getY()
		    {
		        return y0;
		    }

		    public void setX(int x) 
		    {
		  		this.x0 = x;
		  	}
		    
		    public void setY(int y) 
		    {
		  		this.y0 = y;
		  	}
		      
		      
		    public int getWidth() 
		    {
			   return width;
			}

			public int getHeight()
			{
			    return height;
			}
		      

		    // a method for moving the rectangle
		    public void move(int x, int y) {
		        origin.x = x;
		        origin.y = y;
		    }

		    // a method for computing the area of the rectangle
		    public int getArea() {
		        return width * height;
		    }
		    
		    
		    
		    
		}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
			System.out.println("coucou");
			
			
			/*DrawRect(int x,
	                int y,
	                int width,
	                int height,
	                Style style)*/
			// Rectangle r = new Rectangle(xPos,yPos,width,height);
			
			 JFrame frame = new JFrame();
			 frame.setTitle("DrawRect");
			 frame.setSize(300, 200);
			
			 Container contentPane = frame.getContentPane();
			 contentPane.add(new Grid());
			 contentPane.add(new draw());
			 
			 
			 frame.setVisible(true);
			 
			
	}

}
//http://www.java2s.com/Code/Java/2D-Graphics-GUI/Mousedraganddroptodraw.htm
//http://stackoverflow.com/questions/14648224/how-do-i-store-an-object-in-arraylist


//http://www.java2s.com/Code/Java/Collections-Data-Structure/Storeuserdefinedobjectsinarraylist.htm