diff --git a/src/main/TP5/serializer/App.java b/src/main/TP5/serializer/App.java deleted file mode 100644 index 7fd12812c2279a0ee88c2a6ddb3ef64748eb874b..0000000000000000000000000000000000000000 --- a/src/main/TP5/serializer/App.java +++ /dev/null @@ -1,31 +0,0 @@ -package serializer; - -import javafx.application.Application; -import javafx.scene.Group; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.stage.Stage; - -public class App extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - Group root = new Group(); - DrawerWithSave container = new DrawerWithSave(800, 600); - root.getChildren().add(container); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - Button save = new Button("save"); - root.getChildren().add(save); - save.setLayoutX(0); - save.setLayoutY(0); - root.setOnKeyPressed(event->container.context.keyPressed(event)); - //save.setOnKeyPressed(event->container.context.keyPressed(event)); - save.setOnAction(event -> container.write()); - - } -} \ No newline at end of file diff --git a/src/main/TP5/serializer/DrawerWithSave.java b/src/main/TP5/serializer/DrawerWithSave.java deleted file mode 100644 index 2852edf47f756a132226ce5463599bdf1b95601c..0000000000000000000000000000000000000000 --- a/src/main/TP5/serializer/DrawerWithSave.java +++ /dev/null @@ -1,52 +0,0 @@ -package serializer; - -import javafx.scene.canvas.Canvas; -import javafx.scene.control.Alert; -import javafx.stage.FileChooser; -import shape.Shape; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; - - -public class DrawerWithSave extends state.Drawer { - - public DrawerWithSave(int width, int height) { - super(width, height); - } - - void write(){ - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Save"); - File file = fileChooser.showSaveDialog(getScene().getWindow()); - if (file == null) return; - try { - ShapeWriter.write(file, super.shapes); - } - catch (IOException e) { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Error Dialog"); - alert.setHeaderText(null); - alert.setContentText("Ooops, there was an error!"); - alert.showAndWait(); - } - } - public void load() { - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Load"); - File file = fileChooser.showOpenDialog(getScene().getWindow()); - if (file == null) return; - try { - super.shapes = ShapeReader.read(file); - repaint(); - } catch (IOException e) { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Error Dialog"); - alert.setHeaderText(null); - alert.setContentText("Ooops, there was an error!"); - alert.showAndWait(); - } - } -} diff --git a/src/main/TP5/serializer/ShapeReader.java b/src/main/TP5/serializer/ShapeReader.java deleted file mode 100644 index 4905948e502223776ff4e2f8367b633669915e01..0000000000000000000000000000000000000000 --- a/src/main/TP5/serializer/ShapeReader.java +++ /dev/null @@ -1,20 +0,0 @@ -package serializer; - -import shape.Shape; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collector; - -public class ShapeReader { - public static List<Shape> read(File file) throws IOException { - BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); - /*for(String line : bufferedReader.lines().toList()) { - System.out.println(line); - }*/ - return null; - } -} diff --git a/src/main/TP5/serializer/ShapeWriter.java b/src/main/TP5/serializer/ShapeWriter.java deleted file mode 100644 index 6a76ef8f7616a2a5ec8e21e533b3b09060e6d2c3..0000000000000000000000000000000000000000 --- a/src/main/TP5/serializer/ShapeWriter.java +++ /dev/null @@ -1,15 +0,0 @@ -package serializer; - -import shape.Shape; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; - -public class ShapeWriter { - public static void write (File file, List<Shape> shapes) throws IOException { - PrintWriter printWriter = new PrintWriter(file); - printWriter.println("Coucou"); - } -} diff --git a/src/main/TP5/shape/Abstractshape.java b/src/main/TP5/shape/Abstractshape.java deleted file mode 100644 index b6a4e2fa345b49ad6a31cca3e72e5041b20cbc1b..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/Abstractshape.java +++ /dev/null @@ -1,40 +0,0 @@ -package shape; -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import java.util.List; - - -public abstract class Abstractshape implements Shape { - private List<Point2D> points; - - public Abstractshape(List<Point2D> points) { - this.points = points; - } - public void addPoints(Point2D... points){ - for (Point2D point: points) - this.points.add(point); - } - @Override - public int pointsCount() { - return points.size(); - } - - @Override - public Point2D point(int index) { - return index < points.size() ? points.get(index) : null; - } - - @Override - public void draw(GraphicsContext context) { - if (pointsCount()>0){ - context.beginPath(); - context.moveTo(point(0).getX(), point(0).getY()); - for (int i = 1; i<pointsCount(); i++){ - context.lineTo(point(i).getX(),point(i).getY()); - } - context.closePath(); - context.stroke(); - } - - } -} \ No newline at end of file diff --git a/src/main/TP5/shape/App.java b/src/main/TP5/shape/App.java deleted file mode 100644 index 1a519e1401fe032f06aeee35967a27e48ca362fe..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/App.java +++ /dev/null @@ -1,35 +0,0 @@ -package shape; - -import javafx.application.Application; -import javafx.geometry.Point2D; -import javafx.scene.Group; -import javafx.scene.Scene; -import javafx.scene.canvas.Canvas; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; -import javafx.stage.Stage; - - - -public class App extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - Group root = new Group(); - Canvas canvas = new Canvas(130, 110); - GraphicsContext graphicsContext = canvas.getGraphicsContext2D(); - ShapeContainer shapeContainer = new ShapeContainer(); - graphicsContext.setFill(Color.AQUAMARINE); - graphicsContext.fillOval(10,10,10,10); - shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(10,10), new Point2D(40,40))); - shapeContainer.draw(graphicsContext); - root.getChildren().add(canvas); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - } -} \ No newline at end of file diff --git a/src/main/TP5/shape/BorderDecorator.java b/src/main/TP5/shape/BorderDecorator.java deleted file mode 100644 index efdd00aef9559f884f86c6e789b9566bd79d4d1e..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/BorderDecorator.java +++ /dev/null @@ -1,24 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; - - -public class BorderDecorator extends Decorator { - - private double radius; - - public BorderDecorator(Shape decoratedShape ,double radius) { - super(decoratedShape); - this.radius = radius; - } - protected void drawDecoration(GraphicsContext context) { - context.setStroke(Color.BLACK); - context.setLineWidth(2); - for (int i=0; i<pointsCount(); i++){ - Point2D point = point(i); - context.strokeOval(point.getX() - radius, point.getY()- radius,radius*2,radius*2); - } - } -} diff --git a/src/main/TP5/shape/CenterDecorator.java b/src/main/TP5/shape/CenterDecorator.java deleted file mode 100644 index 93769c9afc58e2a42b2ccfb7dbbb3ba175144211..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/CenterDecorator.java +++ /dev/null @@ -1,27 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; - -public class CenterDecorator extends Decorator{ - private double radius; - public CenterDecorator(Shape decoratedShape, double radius) { - super(decoratedShape); - this.radius = radius; - } - protected void drawDecoration(GraphicsContext context) { - double centerX = 0; - double centerY = 0; - for (int i =0; i<pointsCount(); i++){ - Point2D point = point(i); - centerX += point.getX(); - centerY += point.getY(); - } - centerX /= pointsCount(); - centerY /= pointsCount(); - context.setStroke(Color.RED); - context.setLineWidth(2); - context.strokeOval(centerX-radius, centerY-radius, radius*2,radius*2); - } -} \ No newline at end of file diff --git a/src/main/TP5/shape/Circle.java b/src/main/TP5/shape/Circle.java deleted file mode 100644 index 530a52144e0e8a68b67135c34336bd907e07323a..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/Circle.java +++ /dev/null @@ -1,31 +0,0 @@ -package shape; - -import javafx.scene.canvas.GraphicsContext; - -public class Circle implements Shape { - private double x, y, radius; - - public Circle(double x, double y, double radius) { - this.x = x; - this.y = y; - this.radius = radius; - } - - @Override - public void paint(GraphicsContext gc) { - gc.strokeOval(x - radius, y - radius, 2 * radius, 2 * radius); - } - - @Override - public boolean contains(double x, double y) { - double dx = x - this.x; - double dy = y - this.y; - return dx * dx + dy * dy <= radius * radius; - } - - @Override - public void translate(double dx, double dy) { - this.x += dx; - this.y += dy; - } -} diff --git a/src/main/TP5/shape/Decorator.java b/src/main/TP5/shape/Decorator.java deleted file mode 100644 index 5a11efdb8f2f2b06f9c0b4035350354cc73ccab0..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/Decorator.java +++ /dev/null @@ -1,28 +0,0 @@ -package shape; -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; - -public abstract class Decorator implements Shape { - protected Shape decoratedshape; - public Decorator(Shape decoratedShape) { - this.decoratedshape = decoratedShape; - } - @Override - public int pointsCount() { - return decoratedshape.pointsCount(); - } - - @Override - public Point2D point(int index) { - return decoratedshape.point(index); - } - - @Override - public void draw(GraphicsContext context) { - decoratedshape.draw(context); - drawDecoration(context); - } - protected void drawDecoration(GraphicsContext context) { - - } -} \ No newline at end of file diff --git a/src/main/TP5/shape/Polygon.java b/src/main/TP5/shape/Polygon.java deleted file mode 100644 index 775c7da8dfcdfbdaebd78a590ba903c6037e338b..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/Polygon.java +++ /dev/null @@ -1,34 +0,0 @@ -package shape; -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; - -import java.util.List; - -public class Polygon extends Abstractshape { - - private Color color; - - public Polygon(Color color, Point2D... points) { - super(List.of(points)); - this.color = color; - } - - @Override - public int pointsCount() { - return super.pointsCount(); - } - - @Override - public Point2D point(int index) { - return super.point(index); - } - - @Override - public void draw(GraphicsContext context) { - context.setFill(color); - super.draw(context); - context.fill(); - - } -} \ No newline at end of file diff --git a/src/main/TP5/shape/Rectangle.java b/src/main/TP5/shape/Rectangle.java deleted file mode 100644 index 3e9e4f10f4c22211d1ea445af068fbbe2bc77124..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/Rectangle.java +++ /dev/null @@ -1,30 +0,0 @@ -package shape; - -import javafx.scene.canvas.GraphicsContext; - -public class Rectangle implements Shape { - private double x, y, width, height; - - public Rectangle(double x, double y, double width, double height) { - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - @Override - public void paint(GraphicsContext gc) { - gc.strokeRect(x, y, width, height); - } - - @Override - public boolean contains(double x, double y) { - return x >= this.x && x <= this.x + width && y >= this.y && y <= this.y + height; - } - - @Override - public void translate(double dx, double dy) { - this.x += dx; - this.y += dy; - } -} diff --git a/src/main/TP5/shape/Shape.java b/src/main/TP5/shape/Shape.java deleted file mode 100644 index 02cf9044a247ae4f24eb2383d9a405bb51acffb7..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/Shape.java +++ /dev/null @@ -1,9 +0,0 @@ -package shape; - -import javafx.scene.canvas.GraphicsContext; - -public interface Shape { - void paint(GraphicsContext gc); - boolean contains(double x, double y); - void translate(double dx, double dy); -} diff --git a/src/main/TP5/shape/ShapeContainer.java b/src/main/TP5/shape/ShapeContainer.java deleted file mode 100644 index 3ed1776809cbb5d396ccb4880fbeb51c4fa423b0..0000000000000000000000000000000000000000 --- a/src/main/TP5/shape/ShapeContainer.java +++ /dev/null @@ -1,20 +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){ - for(Shape shape : shapes) - shape.draw(context); - } -} \ No newline at end of file diff --git a/src/main/TP5/state/App.java b/src/main/TP5/state/App.java deleted file mode 100644 index 09f71cfcd001774eae6aab16480707e102a24332..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/App.java +++ /dev/null @@ -1,22 +0,0 @@ -package state; - -import javafx.application.Application; -import javafx.scene.Group; -import javafx.scene.Scene; -import javafx.stage.Stage; - -public class App extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - Group root = new Group(); - Drawer container = new Drawer(800, 600); - root.getChildren().add(container); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - } -} \ No newline at end of file diff --git a/src/main/TP5/state/CircleDrawerState0 b/src/main/TP5/state/CircleDrawerState0 deleted file mode 100644 index c488204ca251bcf89f29879bafb26a9e551ad2f2..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/CircleDrawerState0 +++ /dev/null @@ -1,17 +0,0 @@ - -public class CircleDrawerState0 implements DrawerState { - @Override - public void mousePressed(DrawerContext context, double x, double y) { - context.setState(new CircleDrawerState1(x, y)); - } - - @Override - public void mouseReleased(DrawerContext context, double x, double y) {} - - @Override - public void mouseMoved(DrawerContext context, double x, double y) {} - - @Override - public void paint(GraphicsContext gc) {} -} - diff --git a/src/main/TP5/state/CircleDrawerState1 b/src/main/TP5/state/CircleDrawerState1 deleted file mode 100644 index 42f8214648d8c633360c8edf4315913c262204c4..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/CircleDrawerState1 +++ /dev/null @@ -1,24 +0,0 @@ -public class CircleDrawerState1 implements DrawerState { - private double x, y; - - public CircleDrawerState1(double x, double y) { - this.x = x; - this.y = y; - } - - @Override - public void mousePressed(DrawerContext context, double x, double y) {} - - @Override - public void mouseReleased(DrawerContext context, double x, double y) { - double radius = Math.hypot(this.x - x, this.y - y); - context.getDrawer().add(new Circle(this.x, this.y, radius)); - context.setState(new CircleDrawerState0()); // Reset to initial state - } - - @Override - public void mouseMoved(DrawerContext context, double x, double y) {} - - @Override - public void paint(GraphicsContext gc) {} -} \ No newline at end of file diff --git a/src/main/TP5/state/Drawer.java b/src/main/TP5/state/Drawer.java deleted file mode 100644 index 5468857f04fa00b59835a76d5b6d753dab8a7005..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/Drawer.java +++ /dev/null @@ -1,36 +0,0 @@ -package state; - -import javafx.scene.canvas.GraphicsContext; -import java.util.ArrayList; -import java.util.List; - -public class Drawer { - private List<Shape> shapes; - private double width, height; - - public Drawer(double width, double height) { - this.width = width; - this.height = height; - this.shapes = new ArrayList<>(); - } - - public void add(Shape shape) { - shapes.add(shape); - } - - public void repaint(GraphicsContext gc) { - gc.clearRect(0, 0, width, height); // Clear canvas - for (Shape shape : shapes) { - shape.paint(gc); - } - } - - public Shape shapeContaining(double x, double y) { - for (Shape shape : shapes) { - if (shape.contains(x, y)) { - return shape; - } - } - return null; - } -} diff --git a/src/main/TP5/state/DrawerContext.java b/src/main/TP5/state/DrawerContext.java deleted file mode 100644 index 74b12cb1a6df21f4462fe3d89597f21f26e0d882..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/DrawerContext.java +++ /dev/null @@ -1,59 +0,0 @@ -package state; - - -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseEvent; - -public class DrawerContext { - private Drawer drawer; - private DrawerState currentState; - - public DrawerContext(Drawer drawer) { - this.drawer = drawer; - this.currentState = new NullDrawerState(); // Default state - } - - public void setState(DrawerState state) { - this.currentState = state; - } - - public void paint(GraphicsContext gc) { - currentState.paint(gc); - } - - public void mousePressed(MouseEvent event) { - currentState.mousePressed(this, event.getX(), event.getY()); - } - - public void mouseReleased(MouseEvent event) { - currentState.mouseReleased(this, event.getX(), event.getY()); - } - - public void mouseMoved(MouseEvent event) { - currentState.mouseMoved(this, event.getX(), event.getY()); - } - - public void keyPressed(KeyEvent event) { - switch (event.getText()) { - case "r": - setState(new RectangleDrawerState0()); - break; - case "c": - setState(new CircleDrawerState0()); - break; - case "m": - Shape shape = getDrawer().shapeContaining(lastMouseX, lastMouseY); - if (shape != null) { - setState(new MoveShapeState(shape, lastMouseX, lastMouseY)); - } - break; - } - } - - public Drawer getDrawer() { - return drawer; - } - -} - diff --git a/src/main/TP5/state/DrawerState.java b/src/main/TP5/state/DrawerState.java deleted file mode 100644 index c185dfe45cb2840ab93121d535731f4c84d2f8a9..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/DrawerState.java +++ /dev/null @@ -1,8 +0,0 @@ -package state; - -interface DrawerState { - void mousePressed(DrawerContext context, double x, double y); - void mouseReleased(DrawerContext context, double x, double y); - void mouseMoved(DrawerContext context, double x, double y); - void paint(GraphicsContext gc); -} \ No newline at end of file diff --git a/src/main/TP5/state/MoveShapeState b/src/main/TP5/state/MoveShapeState deleted file mode 100644 index 6069a6e9e9985c2af7f6025f4aebea92a5835ace..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/MoveShapeState +++ /dev/null @@ -1,33 +0,0 @@ -public class MoveShapeState implements DrawerState { - private Shape selectedShape; - private double lastX, lastY; - - public MoveShapeState(Shape selectedShape, double x, double y) { - this.selectedShape = selectedShape; - this.lastX = x; - this.lastY = y; - } - - @Override - public void mousePressed(DrawerContext context, double x, double y) {} - - @Override - public void mouseReleased(DrawerContext context, double x, double y) { - context.setState(new NullDrawerState()); // Return to the default state after moving - } - - @Override - public void mouseMoved(DrawerContext context, double x, double y) { - if (selectedShape != null) { - double dx = x - lastX; - double dy = y - lastY; - selectedShape.translate(dx, dy); - lastX = x; - lastY = y; - context.getDrawer().repaint(context.getDrawer().getGraphicsContext()); - } - } - - @Override - public void paint(GraphicsContext gc) {} -} diff --git a/src/main/TP5/state/NullDrawerState b/src/main/TP5/state/NullDrawerState deleted file mode 100644 index 8572e06b7d6fb9ecea3e0d3002f2ab1c0ce2c05f..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/NullDrawerState +++ /dev/null @@ -1,13 +0,0 @@ -public class NullDrawerState implements DrawerState { - @Override - public void mousePressed(DrawerContext context, double x, double y) {} - - @Override - public void mouseReleased(DrawerContext context, double x, double y) {} - - @Override - public void mouseMoved(DrawerContext context, double x, double y) {} - - @Override - public void paint(GraphicsContext gc) {} -} diff --git a/src/main/TP5/state/RectangleDrawerState0 b/src/main/TP5/state/RectangleDrawerState0 deleted file mode 100644 index 3349108266816f19ee79c0913290fb509dde97be..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/RectangleDrawerState0 +++ /dev/null @@ -1,41 +0,0 @@ -public class RectangleDrawerState0 implements DrawerState { - @Override - public void mousePressed(DrawerContext context, double x, double y) { - context.setState(new RectangleDrawerState1(x, y)); - } - - @Override - public void mouseReleased(DrawerContext context, double x, double y) {} - - @Override - public void mouseMoved(DrawerContext context, double x, double y) {} - - @Override - public void paint(GraphicsContext gc) {} -} - -public class RectangleDrawerState1 implements DrawerState { - private double x, y; - - public RectangleDrawerState1(double x, double y) { - this.x = x; - this.y = y; - } - - @Override - public void mousePressed(DrawerContext context, double x, double y) {} - - @Override - public void mouseReleased(DrawerContext context, double x, double y) { - double width = Math.abs(this.x - x); - double height = Math.abs(this.y - y); - context.getDrawer().add(new Rectangle(Math.min(this.x, x), Math.min(this.y, y), width, height)); - context.setState(new RectangleDrawerState0()); // Reset to initial state - } - - @Override - public void mouseMoved(DrawerContext context, double x, double y) {} - - @Override - public void paint(GraphicsContext gc) {} -} diff --git a/src/main/TP5/state/RectangleDrawerState1 b/src/main/TP5/state/RectangleDrawerState1 deleted file mode 100644 index 17a711648913865c5eb28d069e882f0289cb24ff..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/RectangleDrawerState1 +++ /dev/null @@ -1,25 +0,0 @@ -public class RectangleDrawerState1 implements DrawerState { - private double x, y; - - public RectangleDrawerState1(double x, double y) { - this.x = x; - this.y = y; - } - - @Override - public void mousePressed(DrawerContext context, double x, double y) {} - - @Override - public void mouseReleased(DrawerContext context, double x, double y) { - double width = Math.abs(this.x - x); - double height = Math.abs(this.y - y); - context.getDrawer().add(new Rectangle(Math.min(this.x, x), Math.min(this.y, y), width, height)); - context.setState(new RectangleDrawerState0()); // Reset to initial state - } - - @Override - public void mouseMoved(DrawerContext context, double x, double y) {} - - @Override - public void paint(GraphicsContext gc) {} -} \ No newline at end of file diff --git a/src/main/TP5/state/StateCircle0.java b/src/main/TP5/state/StateCircle0.java deleted file mode 100644 index 073c48176cc7b838435f9dd78295558b55eada72..0000000000000000000000000000000000000000 --- a/src/main/TP5/state/StateCircle0.java +++ /dev/null @@ -1,13 +0,0 @@ -package state; - -public class StateCircle0 implements DrawerState { - @Override - public void mousePressed(DrawerContext context, double x, double y) { - - } - - @Override - public void mouseReleased(DrawerContext context, double x, double y) { - - } -} diff --git a/src/main/java/serializer/App.java b/src/main/java/serializer/App.java deleted file mode 100644 index 7fd12812c2279a0ee88c2a6ddb3ef64748eb874b..0000000000000000000000000000000000000000 --- a/src/main/java/serializer/App.java +++ /dev/null @@ -1,31 +0,0 @@ -package serializer; - -import javafx.application.Application; -import javafx.scene.Group; -import javafx.scene.Scene; -import javafx.scene.control.Button; -import javafx.stage.Stage; - -public class App extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - Group root = new Group(); - DrawerWithSave container = new DrawerWithSave(800, 600); - root.getChildren().add(container); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - Button save = new Button("save"); - root.getChildren().add(save); - save.setLayoutX(0); - save.setLayoutY(0); - root.setOnKeyPressed(event->container.context.keyPressed(event)); - //save.setOnKeyPressed(event->container.context.keyPressed(event)); - save.setOnAction(event -> container.write()); - - } -} \ No newline at end of file diff --git a/src/main/java/serializer/DrawerWithSave.java b/src/main/java/serializer/DrawerWithSave.java deleted file mode 100644 index 2852edf47f756a132226ce5463599bdf1b95601c..0000000000000000000000000000000000000000 --- a/src/main/java/serializer/DrawerWithSave.java +++ /dev/null @@ -1,52 +0,0 @@ -package serializer; - -import javafx.scene.canvas.Canvas; -import javafx.scene.control.Alert; -import javafx.stage.FileChooser; -import shape.Shape; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; - - -public class DrawerWithSave extends state.Drawer { - - public DrawerWithSave(int width, int height) { - super(width, height); - } - - void write(){ - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Save"); - File file = fileChooser.showSaveDialog(getScene().getWindow()); - if (file == null) return; - try { - ShapeWriter.write(file, super.shapes); - } - catch (IOException e) { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Error Dialog"); - alert.setHeaderText(null); - alert.setContentText("Ooops, there was an error!"); - alert.showAndWait(); - } - } - public void load() { - FileChooser fileChooser = new FileChooser(); - fileChooser.setTitle("Load"); - File file = fileChooser.showOpenDialog(getScene().getWindow()); - if (file == null) return; - try { - super.shapes = ShapeReader.read(file); - repaint(); - } catch (IOException e) { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle("Error Dialog"); - alert.setHeaderText(null); - alert.setContentText("Ooops, there was an error!"); - alert.showAndWait(); - } - } -} diff --git a/src/main/java/serializer/ShapeReader.java b/src/main/java/serializer/ShapeReader.java deleted file mode 100644 index 4905948e502223776ff4e2f8367b633669915e01..0000000000000000000000000000000000000000 --- a/src/main/java/serializer/ShapeReader.java +++ /dev/null @@ -1,20 +0,0 @@ -package serializer; - -import shape.Shape; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collector; - -public class ShapeReader { - public static List<Shape> read(File file) throws IOException { - BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); - /*for(String line : bufferedReader.lines().toList()) { - System.out.println(line); - }*/ - return null; - } -} diff --git a/src/main/java/serializer/ShapeWriter.java b/src/main/java/serializer/ShapeWriter.java deleted file mode 100644 index 6a76ef8f7616a2a5ec8e21e533b3b09060e6d2c3..0000000000000000000000000000000000000000 --- a/src/main/java/serializer/ShapeWriter.java +++ /dev/null @@ -1,15 +0,0 @@ -package serializer; - -import shape.Shape; - -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; - -public class ShapeWriter { - public static void write (File file, List<Shape> shapes) throws IOException { - PrintWriter printWriter = new PrintWriter(file); - printWriter.println("Coucou"); - } -} diff --git a/src/main/java/shape/Abstractshape.java b/src/main/java/shape/Abstractshape.java deleted file mode 100644 index b6a4e2fa345b49ad6a31cca3e72e5041b20cbc1b..0000000000000000000000000000000000000000 --- a/src/main/java/shape/Abstractshape.java +++ /dev/null @@ -1,40 +0,0 @@ -package shape; -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import java.util.List; - - -public abstract class Abstractshape implements Shape { - private List<Point2D> points; - - public Abstractshape(List<Point2D> points) { - this.points = points; - } - public void addPoints(Point2D... points){ - for (Point2D point: points) - this.points.add(point); - } - @Override - public int pointsCount() { - return points.size(); - } - - @Override - public Point2D point(int index) { - return index < points.size() ? points.get(index) : null; - } - - @Override - public void draw(GraphicsContext context) { - if (pointsCount()>0){ - context.beginPath(); - context.moveTo(point(0).getX(), point(0).getY()); - for (int i = 1; i<pointsCount(); i++){ - context.lineTo(point(i).getX(),point(i).getY()); - } - context.closePath(); - context.stroke(); - } - - } -} \ No newline at end of file diff --git a/src/main/java/shape/App.java b/src/main/java/shape/App.java deleted file mode 100644 index 1a519e1401fe032f06aeee35967a27e48ca362fe..0000000000000000000000000000000000000000 --- a/src/main/java/shape/App.java +++ /dev/null @@ -1,35 +0,0 @@ -package shape; - -import javafx.application.Application; -import javafx.geometry.Point2D; -import javafx.scene.Group; -import javafx.scene.Scene; -import javafx.scene.canvas.Canvas; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; -import javafx.scene.paint.Paint; -import javafx.stage.Stage; - - - -public class App extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - Group root = new Group(); - Canvas canvas = new Canvas(130, 110); - GraphicsContext graphicsContext = canvas.getGraphicsContext2D(); - ShapeContainer shapeContainer = new ShapeContainer(); - graphicsContext.setFill(Color.AQUAMARINE); - graphicsContext.fillOval(10,10,10,10); - shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(10,10), new Point2D(40,40))); - shapeContainer.draw(graphicsContext); - root.getChildren().add(canvas); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - } -} \ No newline at end of file diff --git a/src/main/java/shape/BorderDecorator.java b/src/main/java/shape/BorderDecorator.java deleted file mode 100644 index efdd00aef9559f884f86c6e789b9566bd79d4d1e..0000000000000000000000000000000000000000 --- a/src/main/java/shape/BorderDecorator.java +++ /dev/null @@ -1,24 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; - - -public class BorderDecorator extends Decorator { - - private double radius; - - public BorderDecorator(Shape decoratedShape ,double radius) { - super(decoratedShape); - this.radius = radius; - } - protected void drawDecoration(GraphicsContext context) { - context.setStroke(Color.BLACK); - context.setLineWidth(2); - for (int i=0; i<pointsCount(); i++){ - Point2D point = point(i); - context.strokeOval(point.getX() - radius, point.getY()- radius,radius*2,radius*2); - } - } -} diff --git a/src/main/java/shape/CenterDecorator.java b/src/main/java/shape/CenterDecorator.java deleted file mode 100644 index 93769c9afc58e2a42b2ccfb7dbbb3ba175144211..0000000000000000000000000000000000000000 --- a/src/main/java/shape/CenterDecorator.java +++ /dev/null @@ -1,27 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; - -public class CenterDecorator extends Decorator{ - private double radius; - public CenterDecorator(Shape decoratedShape, double radius) { - super(decoratedShape); - this.radius = radius; - } - protected void drawDecoration(GraphicsContext context) { - double centerX = 0; - double centerY = 0; - for (int i =0; i<pointsCount(); i++){ - Point2D point = point(i); - centerX += point.getX(); - centerY += point.getY(); - } - centerX /= pointsCount(); - centerY /= pointsCount(); - context.setStroke(Color.RED); - context.setLineWidth(2); - context.strokeOval(centerX-radius, centerY-radius, radius*2,radius*2); - } -} \ No newline at end of file diff --git a/src/main/java/shape/Circle.java b/src/main/java/shape/Circle.java deleted file mode 100644 index 81d9175dc3977c5c95dec3693569c12ad12d8315..0000000000000000000000000000000000000000 --- a/src/main/java/shape/Circle.java +++ /dev/null @@ -1,25 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; - -public class Circle implements Shape { - - public Circle(double x, double y, double sqrt) { - } - - @Override - public int pointsCount() { - return 0; - } - - @Override - public Point2D point(int index) { - return null; - } - - @Override - public void draw(GraphicsContext context) { - - } -} diff --git a/src/main/java/shape/Decorator.java b/src/main/java/shape/Decorator.java deleted file mode 100644 index 5a11efdb8f2f2b06f9c0b4035350354cc73ccab0..0000000000000000000000000000000000000000 --- a/src/main/java/shape/Decorator.java +++ /dev/null @@ -1,28 +0,0 @@ -package shape; -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; - -public abstract class Decorator implements Shape { - protected Shape decoratedshape; - public Decorator(Shape decoratedShape) { - this.decoratedshape = decoratedShape; - } - @Override - public int pointsCount() { - return decoratedshape.pointsCount(); - } - - @Override - public Point2D point(int index) { - return decoratedshape.point(index); - } - - @Override - public void draw(GraphicsContext context) { - decoratedshape.draw(context); - drawDecoration(context); - } - protected void drawDecoration(GraphicsContext context) { - - } -} \ No newline at end of file diff --git a/src/main/java/shape/Polygon.java b/src/main/java/shape/Polygon.java deleted file mode 100644 index 775c7da8dfcdfbdaebd78a590ba903c6037e338b..0000000000000000000000000000000000000000 --- a/src/main/java/shape/Polygon.java +++ /dev/null @@ -1,34 +0,0 @@ -package shape; -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; - -import java.util.List; - -public class Polygon extends Abstractshape { - - private Color color; - - public Polygon(Color color, Point2D... points) { - super(List.of(points)); - this.color = color; - } - - @Override - public int pointsCount() { - return super.pointsCount(); - } - - @Override - public Point2D point(int index) { - return super.point(index); - } - - @Override - public void draw(GraphicsContext context) { - context.setFill(color); - super.draw(context); - context.fill(); - - } -} \ No newline at end of file diff --git a/src/main/java/shape/Rectangle.java b/src/main/java/shape/Rectangle.java deleted file mode 100644 index 09df336e483488df1798d84f9cfd54e91426ee4a..0000000000000000000000000000000000000000 --- a/src/main/java/shape/Rectangle.java +++ /dev/null @@ -1,32 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; -import javafx.scene.paint.Color; -import java.util.List; - -public class Rectangle extends Abstractshape{ - private Color color; - Rectangle(Color color, Point2D point0, Point2D point1){ - super(List.of(point0, new Point2D(point1.getX(),point0.getY()), - point1,new Point2D(point0.getX(),point1.getY()))); - this.color = color; - } - - @Override - public int pointsCount() { - return super.pointsCount(); - } - - @Override - public Point2D point(int index) { - return super.point(index); - } - - @Override - public void draw(GraphicsContext context) { - context.setFill(color); - super.draw(context); - context.fill(); - } -} \ No newline at end of file diff --git a/src/main/java/shape/Shape.java b/src/main/java/shape/Shape.java deleted file mode 100644 index 16766e4f3e3128b1582a817d665eb65d32c26047..0000000000000000000000000000000000000000 --- a/src/main/java/shape/Shape.java +++ /dev/null @@ -1,10 +0,0 @@ -package shape; - -import javafx.geometry.Point2D; -import javafx.scene.canvas.GraphicsContext; - -public interface Shape { - int pointsCount(); - Point2D point(int index); - void draw(GraphicsContext context); -} diff --git a/src/main/java/shape/ShapeContainer.java b/src/main/java/shape/ShapeContainer.java deleted file mode 100644 index 3ed1776809cbb5d396ccb4880fbeb51c4fa423b0..0000000000000000000000000000000000000000 --- a/src/main/java/shape/ShapeContainer.java +++ /dev/null @@ -1,20 +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){ - for(Shape shape : shapes) - shape.draw(context); - } -} \ No newline at end of file diff --git a/src/main/java/state/App.java b/src/main/java/state/App.java deleted file mode 100644 index 09f71cfcd001774eae6aab16480707e102a24332..0000000000000000000000000000000000000000 --- a/src/main/java/state/App.java +++ /dev/null @@ -1,22 +0,0 @@ -package state; - -import javafx.application.Application; -import javafx.scene.Group; -import javafx.scene.Scene; -import javafx.stage.Stage; - -public class App extends Application { - - public static void main(String[] args) { - launch(args); - } - - @Override - public void start(Stage primaryStage) { - Group root = new Group(); - Drawer container = new Drawer(800, 600); - root.getChildren().add(container); - primaryStage.setScene(new Scene(root)); - primaryStage.show(); - } -} \ No newline at end of file diff --git a/src/main/java/state/Drawer.java b/src/main/java/state/Drawer.java deleted file mode 100644 index 67b9e1c37ec55c09b9965103ca38cab002b1d815..0000000000000000000000000000000000000000 --- a/src/main/java/state/Drawer.java +++ /dev/null @@ -1,28 +0,0 @@ -package state; - -import javafx.scene.canvas.Canvas; -import shape.Circle; -import shape.Shape; - -import java.util.ArrayList; -import java.util.List; - - -public class Drawer extends Canvas { - protected List<Shape> shapes = new ArrayList<>(); - public DrawerContext context = new DrawerContext(this); - - public Drawer(int width, int height) { - super(width,height); - setFocusTraversable(true); - setOnMousePressed(event->context.mousePressed(event)); - setOnMouseReleased(event->context.mouseReleased(event)); - setOnMouseMoved(event->context.mouseMoved(event)); - setOnMouseDragged(event->context.mouseMoved(event)); - //setOnKeyPressed(event -> context.keyPressed(event)); - } - - public void repaint(){ - this.getGraphicsContext2D().clearRect(0,0,this.getWidth(),this.getHeight()); - } -} diff --git a/src/main/java/state/DrawerContext.java b/src/main/java/state/DrawerContext.java deleted file mode 100644 index f82de3953ba8ae28f267393fdcb01fd7dcd3b6c2..0000000000000000000000000000000000000000 --- a/src/main/java/state/DrawerContext.java +++ /dev/null @@ -1,33 +0,0 @@ -package state; - - -import javafx.scene.input.KeyEvent; -import javafx.scene.input.MouseEvent; - -public class DrawerContext { - - Drawer drawer; - DrawerState currentState; - - public DrawerContext(Drawer drawer) { - this.drawer = drawer; - } - - void mousePressed(MouseEvent event){ - currentState.mousePressed(this,event.getX(),event.getY()); - - } - - void mouseReleased(MouseEvent event){ - currentState.mouseReleased(this,event.getX(),event.getY()); - } - - void mouseMoved(MouseEvent event){} - - public void keyPressed(KeyEvent event) { - switch (event.getText()) { - case "c": - currentState = new StateCircle0(); - } - } -} diff --git a/src/main/java/state/DrawerState.java b/src/main/java/state/DrawerState.java deleted file mode 100644 index 680324c78948ecab7c870f28f0901f15bf4d8045..0000000000000000000000000000000000000000 --- a/src/main/java/state/DrawerState.java +++ /dev/null @@ -1,6 +0,0 @@ -package state; - -public interface DrawerState { - void mousePressed(DrawerContext context, double x, double y); - void mouseReleased(DrawerContext context, double x, double y); -} diff --git a/src/main/java/state/StateCircle0.java b/src/main/java/state/StateCircle0.java deleted file mode 100644 index 073c48176cc7b838435f9dd78295558b55eada72..0000000000000000000000000000000000000000 --- a/src/main/java/state/StateCircle0.java +++ /dev/null @@ -1,13 +0,0 @@ -package state; - -public class StateCircle0 implements DrawerState { - @Override - public void mousePressed(DrawerContext context, double x, double y) { - - } - - @Override - public void mouseReleased(DrawerContext context, double x, double y) { - - } -}