Skip to content
Snippets Groups Projects
Commit bc3215f2 authored by MANSOUR Chadi's avatar MANSOUR Chadi
Browse files

not important

parent d0a4191d
No related branches found
No related tags found
No related merge requests found
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) ;
}
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) {
}
}
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) {
}
}
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));
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public abstract class Decorator implements Shape {
}
......@@ -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;
}
......
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) {
}
}
......@@ -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) {
......
......@@ -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);
}
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){
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment