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.Attribute;
25 import org.vectomatic.common.model.IAttributeValue;
26 import org.vectomatic.common.model.Shape;
27
28
29
30
31 public class SetAttributeCommand extends CommandBase {
32 private Attribute _attr;
33 private List<Shape> _shapes;
34 private List<IAttributeValue> _values;
35
36 public SetAttributeCommand(RepApplication app, Attribute attr, IAttributeValue value) {
37 super(app);
38 _attr = attr;
39 _shapes = new ArrayList<Shape>(_app.getSelection().getSelectedShapes());
40 _values = new ArrayList<IAttributeValue>();
41 for (int i = 0, count = _shapes.size(); i < count; i++) {
42 _values.add(value);
43 }
44 }
45
46 public String getDescription() {
47 return _app.getConstants().setAttributeCommand() + _attr.getName();
48 }
49
50
51 public void execute() {
52 applyAttributeChange();
53 }
54
55 public void unexecute() {
56 applyAttributeChange();
57 }
58
59 private void applyAttributeChange() {
60 for (int i = 0, count = _shapes.size(); i < count; i++) {
61 Shape shape = _shapes.get(i);
62 _values.set(i, shape.setAttribute(_attr, _values.get(i)));
63 }
64 _shapes.get(0).getModel().fireModelHasChanged();
65 _app.getSelection().fireSelectionHasChanged();
66 }
67 }