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.
1
package
com.example.graphics.command;
2
3
import
com.example.graphics.model.Shape;
4
import
java.util.List;
5
10
public
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
}
com.example.graphics.command.RemoveShapeCommand.RemoveShapeCommand
RemoveShapeCommand(List< Shape > shapes, Shape shape)
Definition
RemoveShapeCommand.java:20
com.example.graphics.command.RemoveShapeCommand.undo
void undo()
Definition
RemoveShapeCommand.java:34
com.example.graphics.command.RemoveShapeCommand.execute
void execute()
Definition
RemoveShapeCommand.java:26
com.example.graphics.command.RemoveShapeCommand.shapes
final List< Shape > shapes
Definition
RemoveShapeCommand.java:11
com.example.graphics.command.RemoveShapeCommand.shape
final Shape shape
Definition
RemoveShapeCommand.java:12
com.example.graphics.command.RemoveShapeCommand.index
int index
Definition
RemoveShapeCommand.java:13
com.example.graphics.command.Command
Definition
Command.java:7
com.example.graphics.model.Shape
Definition
Shape.java:10
src
main
java
com
example
graphics
command
RemoveShapeCommand.java
Generated on
for Graphic Rendering System by
1.14.0