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 org.vectomatic.client.rep.RepApplication;
21 import org.vectomatic.common.model.Shape;
22 import org.vectomatic.common.model.geometry.Ellipse;
23 import org.vectomatic.common.model.geometry.Path;
24 import org.vectomatic.common.model.geometry.Polyline;
25 import org.vectomatic.common.model.geometry.Rect;
26
27
28
29
30 public class NewShapeCommand extends CommandBase {
31 private Shape _shape;
32
33 public NewShapeCommand(RepApplication app, Shape shape) {
34 super(app);
35 _shape = shape;
36 }
37
38 public String getDescription() {
39 if (_shape instanceof Ellipse) {
40 return _app.getConstants().newEllipseCommand();
41 } else if (_shape instanceof Rect) {
42 return _app.getConstants().newRectCommand();
43 } else if (_shape instanceof Polyline) {
44 return _app.getConstants().newPolylineCommand();
45 } else if (_shape instanceof Path) {
46 return _app.getConstants().newPathCommand();
47 }
48 throw new IllegalStateException();
49 }
50
51 public void unexecute() {
52 _app.getModel().removeShape(_shape);
53 _app.getModel().fireModelHasChanged();
54 }
55
56 public void execute() {
57 _app.getModel().addShape(_shape);
58 _app.getModel().fireModelHasChanged();
59 }
60 }