package org.CG.drawings;

import java.util.LinkedList;
import javax.media.opengl.GL;
import org.CG.infrastructure.Drawing;

/**
 *
 * @author ldavid
 */
public class Polygon extends Drawing {

    int[] lastPoint;
    LinkedList<Line> edges;

    public Polygon() {
        super();

        finished = false;
        edges = new LinkedList<>();
    }

    @Override
    public Drawing setStart(int[] start) {
        super.setStart(start);
        lastPoint = start;

        return setNextCoordinate(start);
    }

    @Override
    public Drawing translate(int[] point) {
        return this;
    }

    @Override
    public Drawing updateLastCoordinate(int[] point) {
        lastPoint = new int[]{point[0], point[1]};
        edges.getLast().updateLastCoordinate(point);

        return this;
    }

    @Override
    public Drawing setNextCoordinate(int[] point) {
        super.setNextCoordinate(point);

        Line l = new Line();
        
        l.setColor(color).setStart(lastPoint).updateLastCoordinate(point);
        
        lastPoint = new int[]{point[0], point[1]};

        edges.add(l);

        return this;
    }

    @Override
    public Drawing setFinished(boolean finish) {
        // Draws the last vector, linking the last coordinate with the first one.
        if (finish) {
            setNextCoordinate(start);
        }
        
        return super.setFinished(finish);
    }
    
    @Override
    public void draw(GL gl) {
        edges.stream().forEach((edge) -> {
            edge.draw(gl);
        });
    }
}

@@ -222,20 +222,23 @@
 kedList%3C
-Line
+Drawing
 %3E edges;
@@ -920,17 +920,18 @@
     
-Line l = 
+edges.add(
 new 
@@ -936,36 +936,29 @@
 w Line()
-;%0A 
+%0A
        
-%0A 
      
-  l
 .setColo
@@ -965,16 +965,29 @@
 r(color)
+%0A            
 .setStar
@@ -998,16 +998,29 @@
 stPoint)
+%0A            
 .updateL
@@ -1039,26 +1039,19 @@
 e(point)
+)
 ;%0A
-        
 %0A       
@@ -1098,32 +1098,8 @@
 %5D%7D;%0A
-%0A        edges.add(l);%0A%0A
     

Update Polygon.java