RectangleButtonHandler.java 721 B

12345678910111213141516171819202122232425
  1. package drawing;
  2. import javafx.scene.shape.Rectangle;
  3. import javafx.scene.shape.Shape;
  4. /**
  5. * Created by lewandowski on 20/12/2020.
  6. */
  7. public class RectangleButtonHandler extends ShapeButtonHandler {
  8. public RectangleButtonHandler(DrawingPane drawingPane) {
  9. super(drawingPane);
  10. }
  11. @Override
  12. protected Shape createShape() {
  13. double x = Math.min(originX, destinationX);
  14. double y = Math.min(originY, destinationY);
  15. double width = Math.abs(destinationX - originX);
  16. double height = Math.abs(destinationY - originY);
  17. Rectangle rectangle = new Rectangle(x, y, width, height);
  18. rectangle.getStyleClass().add("rectangle");
  19. return rectangle;
  20. }
  21. }