Skip to content
Snippets Groups Projects
Commit 9dbc3e92 authored by GHOMARI Ilyes's avatar GHOMARI Ilyes
Browse files

Fini TP3

parent 05c59e56
No related branches found
No related tags found
No related merge requests found
......@@ -4,11 +4,8 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="delegatedBuild" value="true" />
<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="openjdk-21" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
......
......@@ -4,7 +4,7 @@
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
......@@ -3,6 +3,7 @@ package shape;
import javafx.geometry.Point2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
......@@ -13,10 +14,7 @@ public abstract class AbstractShape implements Shape {
}
public void addPoints(Point2D... points){
for (Point2D point : points) {
points.add()
points[points.length] = point;
}
Collections.addAll(this.points, points);
}
}
......@@ -26,8 +26,17 @@ public class App extends Application {
ShapeContainer shapeContainer = new ShapeContainer();
graphicsContext.setFill(Color.PAPAYAWHIP);
graphicsContext.fillOval(10,10,10,10);
shapeContainer.addShape(new Rectangle(Color.BLUE,new Point2D(10,10), new Point2D(40,40)));
Rectangle rec = new Rectangle(Color.BLUE,new Point2D(10,10), new Point2D(40,40));
BorderDecorator borderDecorator = new BorderDecorator(rec,5) ;
shapeContainer.addShape(rec);
shapeContainer.addShape(borderDecorator);
Polygon polygon = new Polygon(Color.RED,new Point2D(40,40), new Point2D(60,60), new Point2D(80,40));
CenterDecorator centerDecorator = new CenterDecorator(polygon, 5);
shapeContainer.addShape(polygon);
shapeContainer.addShape(centerDecorator);
shapeContainer.draw(graphicsContext);
root.getChildren().add(canvas);
primaryStage.setScene(new Scene(root));
primaryStage.show();
......
......@@ -21,15 +21,7 @@ public class BorderDecorator extends Decorator {
}
}
@Override
public int pointsCount() {
return decoratedShape.pointsCount();
}
@Override
public Point2D point(int index) {
return decoratedShape.point(index);
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public class CenterDecorator extends Decorator{
private final double radius;
protected CenterDecorator(Shape decoratedShape, double radius) {
super(decoratedShape);
this.radius = radius;
}
@Override
protected void drawDecoration(GraphicsContext graphicsContext) {
double xAll = 0, yAll = 0;
for (int i = 0; i < decoratedShape.pointsCount(); i++) {
xAll += decoratedShape.point(i).getX();
yAll += decoratedShape.point(i).getY();
}
graphicsContext.fillOval((xAll/pointsCount())-radius,(yAll/pointsCount())-radius,radius*2,radius*2);
}
}
package shape;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
public abstract class Decorator implements Shape{
......@@ -14,4 +15,13 @@ public abstract class Decorator implements Shape{
drawDecoration(context);
}
abstract void drawDecoration(GraphicsContext graphicsContext);
public int pointsCount() {
return decoratedShape.pointsCount();
}
@Override
public Point2D point(int index) {
return decoratedShape.point(index);
}
}
......@@ -36,5 +36,7 @@ public class Polygon implements Shape{
}
context.fillPolygon(xPoints, yPoints, points.length);
context.setFill(Color.BLACK);
}
}
......@@ -32,6 +32,6 @@ public class Rectangle implements Shape{
double h = points[1].getY() - y;
context.setFill(color);
context.fillRect(x,y,w,h);
context.setFill(Color.BLACK);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment