Skip to content
Snippets Groups Projects
Commit 4a9193b8 authored by 1380's avatar 1380
Browse files

Décorateur de formes

parent 25e4881d
No related branches found
No related tags found
No related merge requests found
Pipeline #18504 failed
......@@ -8,7 +8,7 @@
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="11" />
<option name="gradleJvm" value="jbr-11" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="corretto-16" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="jbr-11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
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;
@Override
public int pointsCount() {
return points.size();
}
@Override
public Point2D point(int index) {
return points.get(index);
}
@Override
abstract public void draw(GraphicsContext context) ;
public void addPoints(List<Point2D> points) {
points.addAll(points);
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import java.util.ArrayList;
import java.util.List;
public class BorderDecorator extends Decorator{
private double radius;
public BorderDecorator(Shape decoratedShape, double radius) {
super(decoratedShape);
this.radius = radius;
}
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
List<Point2D> list = new ArrayList<>();
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
abstract public 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);
}
protected abstract void drawDecoration(GraphicsContext graphicsContext);
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
import java.util.ArrayList;
import java.util.List;
public class Polygon extends AbstractShape {
Color color;
public Polygon(Color color , List<Point2D> points){
this.color = color;
addPoints(points);
}
@Override
public void draw(GraphicsContext context) {
double[] coordinateX = new double[pointsCount()];
double[] coordinateY = new double[pointsCount()];
for(int index = 0 ; index<pointsCount() ; index++){
coordinateX[index]=point(index).getX();
coordinateY[index]=point(index).getY();
}
context.strokePolygon(coordinateX,coordinateY,pointsCount());
}
}
......@@ -4,24 +4,22 @@ import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Rectangle implements Shape{
import java.util.ArrayList;
import java.util.List;
public class Rectangle extends AbstractShape implements Shape{
Color color;
Rectangle(Color color, Point2D point0, Point2D point1){
this.color = color;
}
@Override
public int pointsCount() {
return 0;
}
@Override
public Point2D point(int index) {
return null;
List<Point2D> list = new ArrayList<>();
list.add(point0);
list.add(point1);
addPoints(list);
}
@Override
public void draw(GraphicsContext context) {
context.strokeRect(point(0).getX(),point(0).getY(),point(1).getX()-point(0).getX(),
point(1).getY()-point(0).getY());
}
}
}
\ No newline at end of file
......@@ -9,7 +9,9 @@ public class ShapeContainer{
private List<Shape> shapes = new ArrayList<>();
public void addShape(Shape shape){}
public void addShape(Shape shape){
shapes.add(shape);
}
public void draw(GraphicsContext context){
for(Shape shape : shapes)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment