Graphic Rendering System 1.0
A Java-based graphic rendering system implementing various design patterns
Loading...
Searching...
No Matches
RemoveShapeCommand.java
Go to the documentation of this file.
1package com.example.graphics.command;
2
3import com.example.graphics.model.Shape;
4import java.util.List;
5
10public class RemoveShapeCommand implements Command {
11 private final List<Shape> shapes;
12 private final Shape shape;
13 private int index;
14
20 public RemoveShapeCommand(List<Shape> shapes, Shape shape) {
21 this.shapes = shapes;
22 this.shape = shape;
23 }
24
25 @Override
26 public void execute() {
27 index = shapes.indexOf(shape);
28 if (index != -1) {
29 shapes.remove(index);
30 }
31 }
32
33 @Override
34 public void undo() {
35 if (index != -1 && index <= shapes.size()) {
36 shapes.add(index, shape);
37 } else if (index == -1) {
38 shapes.add(shape);
39 }
40 }
41}
RemoveShapeCommand(List< Shape > shapes, Shape shape)