-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathCommandBaseImpl.java
More file actions
47 lines (36 loc) · 1.07 KB
/
CommandBaseImpl.java
File metadata and controls
47 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package javacodes.lightdraw;
import java.util.Arrays;
import java.util.Stack;
public class CommandBaseImpl implements CommandBase {
private final Stack<DrawCommand> commands = new Stack<DrawCommand>();
private final Stack<DrawCommand> undoStack = new Stack<DrawCommand>();
private static CommandBase SINGLETON;
public static CommandBase getInstance() {
if (SINGLETON == null) {
SINGLETON = new CommandBaseImpl();
}
return SINGLETON;
}
@Override
public void executeCommand(DrawCommand drawCommand) {
drawCommand.draw();
undoStack.clear();
commands.push(drawCommand);
}
@Override
public void undo() {
DrawCommand command = commands.pop();
command.undo();
undoStack.push(command);
}
@Override
public void redo() {
DrawCommand command = undoStack.pop();
command.draw();
commands.push(command);
}
@Override
public void showCurrentCommands() {
System.out.println(Arrays.toString(commands.toArray()));
}
}