From bc3215f21e0926714ea13955e62d1f370dc79836 Mon Sep 17 00:00:00 2001
From: m19023837 <chadi.mansour@etu.univ-amu.fr>
Date: Fri, 4 Oct 2024 13:25:01 +0200
Subject: [PATCH] not important

---
 src/main/java/shape/AbstractShape.java   | 32 -----------------
 src/main/java/shape/BorderDecorator.java | 23 -------------
 src/main/java/shape/CenterDecorator.java | 23 -------------
 src/main/java/shape/Circle.java          | 18 +++++-----
 src/main/java/shape/Decorator.java       |  8 -----
 src/main/java/shape/Drawer.java          | 13 ++++++-
 src/main/java/shape/Polygon.java         | 44 ------------------------
 src/main/java/shape/Rectangle.java       | 14 +++++++-
 src/main/java/shape/Shape.java           |  2 ++
 src/main/java/shape/ShapeContainer.java  | 18 ----------
 10 files changed, 37 insertions(+), 158 deletions(-)
 delete mode 100644 src/main/java/shape/AbstractShape.java
 delete mode 100644 src/main/java/shape/BorderDecorator.java
 delete mode 100644 src/main/java/shape/CenterDecorator.java
 delete mode 100644 src/main/java/shape/Decorator.java
 delete mode 100644 src/main/java/shape/Polygon.java
 delete mode 100644 src/main/java/shape/ShapeContainer.java

diff --git a/src/main/java/shape/AbstractShape.java b/src/main/java/shape/AbstractShape.java
deleted file mode 100644
index 50e5d3f..0000000
--- a/src/main/java/shape/AbstractShape.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package shape;
-
-import javafx.geometry.Point2D;
-import javafx.scene.canvas.GraphicsContext;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-public abstract class AbstractShape implements Shape {
-
-    protected List<Point2D> points = new ArrayList<>();
-
-    public void addPoints(Point2D... points){
-        this.points.addAll(Arrays.asList(points));
-    }
-
-    public int pointsCount() {
-        return points.size();
-    }
-
-
-    public Point2D point(int index) {
-        if( index >= 0 && index < points.size()){
-            return points.get(index);
-        }else {
-            throw new IndexOutOfBoundsException("Index out of bounds");
-        }
-    }
-
-    public abstract void draw(GraphicsContext context) ;
-}
diff --git a/src/main/java/shape/BorderDecorator.java b/src/main/java/shape/BorderDecorator.java
deleted file mode 100644
index 2240908..0000000
--- a/src/main/java/shape/BorderDecorator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package shape;
-
-import javafx.geometry.Point2D;
-import javafx.scene.canvas.GraphicsContext;
-import javafx.scene.paint.Color;
-
-public class BorderDecorator extends Decorator {
-
-    @Override
-    public void paint(GraphicsContext graphicsContext) {
-
-    }
-
-    @Override
-    public boolean contains(double x, double y) {
-        return false;
-    }
-
-    @Override
-    public void translate(double dx, double dy) {
-
-    }
-}
diff --git a/src/main/java/shape/CenterDecorator.java b/src/main/java/shape/CenterDecorator.java
deleted file mode 100644
index 0d9a7e2..0000000
--- a/src/main/java/shape/CenterDecorator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package shape;
-
-import javafx.geometry.Point2D;
-import javafx.scene.canvas.GraphicsContext;
-import javafx.scene.paint.Color;
-
-public class CenterDecorator extends Decorator{
-
-    @Override
-    public void paint(GraphicsContext graphicsContext) {
-
-    }
-
-    @Override
-    public boolean contains(double x, double y) {
-        return false;
-    }
-
-    @Override
-    public void translate(double dx, double dy) {
-
-    }
-}
diff --git a/src/main/java/shape/Circle.java b/src/main/java/shape/Circle.java
index 2f7796e..503f9b2 100644
--- a/src/main/java/shape/Circle.java
+++ b/src/main/java/shape/Circle.java
@@ -1,19 +1,20 @@
 package shape;
 
-import javafx.geometry.Point2D;
 import javafx.scene.canvas.GraphicsContext;
 import javafx.scene.paint.Color;
 
 public class Circle implements Shape {
 
     private double radius, x, y;
-    private Color fillColor;
+    public Color fillColor;
+    private boolean isFinished;
 
     public Circle(double x, double y, double radius) {
         this.x = x;
         this.y = y;
         this.radius = radius;
         this.fillColor = Color.GREEN;
+        this.isFinished = false;
     }
 
 
@@ -21,7 +22,7 @@ public class Circle implements Shape {
     public void paint(GraphicsContext graphicsContext) {
         graphicsContext.setStroke(Color.BLACK);
         if(isFinished) {
-            graphicsContext.setFill(Color.GREEN);
+            graphicsContext.setFill(fillColor);
             graphicsContext.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
         }
         graphicsContext.strokeOval(x-radius, y-radius, 2 * radius, 2 * radius);
@@ -42,14 +43,15 @@ public class Circle implements Shape {
 
     @Override
     public boolean isFinished() {
-        return true;
-    }
-
-    public void updateRadius(double newX, double newY) {
-        this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2));
+        return isFinished;
     }
 
+    @Override
     public void setFillColor(Color fillColor) {
         this.fillColor = fillColor;
     }
+
+    public void updateRadius(double newX, double newY) {
+        this.radius = Math.sqrt(Math.pow(newX - this.x, 2) + Math.pow(newY - this.y, 2));
+    }
 }
diff --git a/src/main/java/shape/Decorator.java b/src/main/java/shape/Decorator.java
deleted file mode 100644
index c453446..0000000
--- a/src/main/java/shape/Decorator.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package shape;
-
-import javafx.geometry.Point2D;
-import javafx.scene.canvas.GraphicsContext;
-
-public abstract class Decorator implements Shape {
-
-}
diff --git a/src/main/java/shape/Drawer.java b/src/main/java/shape/Drawer.java
index 6947a15..58dee9e 100644
--- a/src/main/java/shape/Drawer.java
+++ b/src/main/java/shape/Drawer.java
@@ -18,6 +18,8 @@ public class Drawer {
 
     private  String currentShapeType = "rectangle";
     private Shape tempShape = null;
+    private boolean isFinished = false;
+
 
     public Drawer(double width, double height) {
 //        this.width = width;
@@ -72,8 +74,16 @@ public class Drawer {
         canvas.setOnMouseReleased(event -> {
             if(event.getButton() == MouseButton.PRIMARY && tempShape != null){
                 shapes.add(tempShape);
-                tempShape = null;
+                if (tempShape instanceof Rectangle){
+                    tempShape.setFillColor(((Rectangle) tempShape).fillColor);
+                    tempShape.isFinished();
+                }else if (tempShape instanceof Circle){
+                    tempShape.setFillColor(((Circle) tempShape).fillColor);
+                    tempShape.isFinished();
+                }
+                isFinished = true;
                 repaint();
+                tempShape = null;
             }
         });
     }
@@ -99,6 +109,7 @@ public class Drawer {
         return null;
     }*/
 
+
     public Canvas getCanvas() {
         return canvas;
     }
diff --git a/src/main/java/shape/Polygon.java b/src/main/java/shape/Polygon.java
deleted file mode 100644
index c4d1357..0000000
--- a/src/main/java/shape/Polygon.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package shape;
-
-import javafx.geometry.Point2D;
-import javafx.scene.canvas.GraphicsContext;
-import javafx.scene.paint.Color;
-
-public class Polygon extends AbstractShape {
-
-    private final Color color;
-
-    public Polygon(Color color, Point2D... points) {
-        this.color = color;
-        addPoints(points);
-    }
-
-
-    @Override
-    public void draw(GraphicsContext context) {
-        context.setStroke(color);
-        context.beginPath();
-        context.moveTo(points.get(0).getX(), points.get(0).getY());
-        for (int i = 1; i < pointsCount() ; i++) {
-            context.lineTo(points.get(i).getX(), points.get(i).getY());
-        }
-        context.closePath();
-        context.stroke();
-
-    }
-
-    @Override
-    public void paint(GraphicsContext graphicsContext) {
-
-    }
-
-    @Override
-    public boolean contains(double x, double y) {
-        return false;
-    }
-
-    @Override
-    public void translate(double dx, double dy) {
-
-    }
-}
diff --git a/src/main/java/shape/Rectangle.java b/src/main/java/shape/Rectangle.java
index 0a2f626..0fb3372 100644
--- a/src/main/java/shape/Rectangle.java
+++ b/src/main/java/shape/Rectangle.java
@@ -10,17 +10,24 @@ public class Rectangle implements Shape{
     private double y;
     private double width;
     private double height;
+    private boolean isFinished;
+    public Color fillColor = Color.RED;
 
     public Rectangle(double x, double y, double width, double height) {
         this.x = x;
         this.y = y;
         this.width = width;
         this.height = height;
+        this.isFinished = false;
     }
 
     @Override
     public void paint(GraphicsContext graphicsContext) {
         graphicsContext.setStroke(Color.BLACK);
+        if(isFinished){
+            graphicsContext.setFill(fillColor);
+            graphicsContext.fillRect(x, y, width, height);
+        }
         graphicsContext.strokeRect(x, y, width, height);
 
     }
@@ -39,7 +46,12 @@ public class Rectangle implements Shape{
 
     @Override
     public boolean isFinished() {
-        return false;
+        return isFinished;
+    }
+
+    @Override
+    public void setFillColor(Color fillColor) {
+        this.fillColor = fillColor;
     }
 
     public void updateSize(double newX, double newY) {
diff --git a/src/main/java/shape/Shape.java b/src/main/java/shape/Shape.java
index 66aaf02..1cd8240 100644
--- a/src/main/java/shape/Shape.java
+++ b/src/main/java/shape/Shape.java
@@ -2,10 +2,12 @@ package shape;
 
 import javafx.geometry.Point2D;
 import javafx.scene.canvas.GraphicsContext;
+import javafx.scene.paint.Color;
 
 public interface Shape {
     void paint(GraphicsContext graphicsContext);
     boolean contains(double x, double y);
     void translate(double dx, double dy);
     boolean isFinished();
+    void setFillColor(Color fillColor);
 }
diff --git a/src/main/java/shape/ShapeContainer.java b/src/main/java/shape/ShapeContainer.java
deleted file mode 100644
index c475da3..0000000
--- a/src/main/java/shape/ShapeContainer.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package shape;
-
-import javafx.scene.canvas.GraphicsContext;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ShapeContainer{
-
-    private List<Shape> shapes = new ArrayList<>();
-
-    public void addShape(Shape shape){
-        shapes.add(shape);
-    }
-
-    public void  draw(GraphicsContext context){
-    }
-}
-- 
GitLab