-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecordedCommand.java
37 lines (30 loc) · 998 Bytes
/
RecordedCommand.java
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
import java.util.*;
public abstract class RecordedCommand implements Command{
public abstract void undoMe();
public abstract void redoMe();
private static ArrayList<RecordedCommand> undoList = new ArrayList<>();
private static ArrayList<RecordedCommand> redoList = new ArrayList<>();
protected static void addUndoCommand(RecordedCommand cmd){
undoList.add(cmd);
}
protected static void addRedoCommand(RecordedCommand cmd){
redoList.add(cmd);
}
protected static void clearRedoList(){
redoList.clear();
}
public static void undoOneCommand(){
if(undoList.size()!=0)
undoList.remove(undoList.size()-1).undoMe();
else{
System.out.println("Nothing to undo.");
}
}
public static void redoOneCommand(){
if(redoList.size()!=0)
redoList.remove(redoList.size()-1).redoMe();
else{
System.out.println("Nothing to redo.");
}
}
}