1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.client.rep.command;
19
20 import java.util.ArrayList;
21 import java.util.List;
22
23 import org.vectomatic.client.rep.RepApplication;
24 import org.vectomatic.common.model.Shape;
25
26
27
28
29 public class ChangeOrderingCommand extends CommandBase {
30 public static final int BRING_TO_FRONT = 0;
31 public static final int SEND_TO_BACK = 1;
32 public static final int BRING_FORWARD = 2;
33 public static final int SEND_BACKWARD = 3;
34 private int _direction;
35 private List<Shape> _shapes;
36 private List<Float> _orders;
37
38 public ChangeOrderingCommand(RepApplication app, int direction) {
39 super(app);
40 _direction = direction;
41 _shapes = new ArrayList<Shape>(_app.getSelection().getSelectedShapes());
42 }
43
44 public void execute() {
45 switch(_direction) {
46 case BRING_TO_FRONT:
47 _orders = _app.getModel().bringToFront(_shapes);
48 break;
49 case SEND_TO_BACK:
50 _orders = _app.getModel().sendToBack(_shapes);
51 break;
52 case BRING_FORWARD:
53 _orders = _app.getModel().bringForward(_shapes);
54 break;
55 case SEND_BACKWARD:
56 _orders = _app.getModel().sendBackward(_shapes);
57 break;
58 }
59 }
60
61 public String getDescription() {
62 String description = null;
63 switch(_direction) {
64 case BRING_TO_FRONT:
65 description = _app.getConstants().bringToFrontCommand();
66 break;
67 case SEND_TO_BACK:
68 description = _app.getConstants().sendToBackCommand();
69 break;
70 case BRING_FORWARD:
71 description = _app.getConstants().bringForwardCommand();
72 break;
73 case SEND_BACKWARD:
74 description = _app.getConstants().sendBackwardCommand();
75 break;
76 }
77 return description;
78 }
79
80 public void unexecute() {
81 _app.getModel().reorder(_shapes, _orders);
82 }
83 }