-
Notifications
You must be signed in to change notification settings - Fork 0
/
MoveCommand.java
43 lines (32 loc) · 958 Bytes
/
MoveCommand.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
38
39
40
41
42
43
import java.awt.Point;
import java.util.Enumeration;
import java.util.Vector;
public class MoveCommand extends Command {
private Point translationPoint;
private Point originalPoint;
private Vector itemTypes;
public MoveCommand(Point StartPoint, Point Endpoint) {
itemTypes = new Vector();
model.fillType(itemTypes);
int dx = Endpoint.x - StartPoint.x;
int dy = Endpoint.y - StartPoint.y;
translationPoint = new Point(dx, dy);
int dxx = StartPoint.x - Endpoint.x;
int dyy = StartPoint.y - Endpoint.y;
originalPoint = new Point(dxx, dyy);
}
public boolean undo() {
model.moveItems(originalPoint, itemTypes);
return true;
}
public boolean redo() {
execute();
return true;
}
public void execute() {
model.moveItems(translationPoint, itemTypes);
}
public boolean end() {
return true;
}
}