diff --git a/src/main/java/shape/AbstractShape.java b/src/main/java/shape/AbstractShape.java deleted file mode 100644 index 50e5d3f09df19b86ce6c26679765f4fa8074ce20..0000000000000000000000000000000000000000 --- 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 22409083238517c3055f864690a14cecf7a0954a..0000000000000000000000000000000000000000 --- 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 0d9a7e2e1e641b54e77b738edfa1969da69e3b47..0000000000000000000000000000000000000000 --- 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 2f7796e48679cd55797b4f307d43646b12523137..503f9b2efa48599949747ef66e285de52f762760 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 c453446859d907efa682e3ae1704686d1f29025a..0000000000000000000000000000000000000000 --- 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 6947a1559eebb83d34f0f2daa6bbd71dbf60a9f0..58dee9e66ece08ac66b84e12d378b1cc4aeec9de 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 c4d135724d40cebe94564d4b2915a66eabb412ef..0000000000000000000000000000000000000000 --- 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 0a2f626c343f0edd949db68ba6d0990796f68692..0fb33727023023b8091fba96bb7f0fdde9281e96 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 66aaf02378b0f77a7ece2220aab8912326502650..1cd824056fd91a940ac735cdf69355ce8a059fb9 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 c475da35dc2d0c04aed3995a24943fd6e86f9849..0000000000000000000000000000000000000000 --- 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){ - } -}