1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.client.rep.controller;
19
20 import java.util.ArrayList;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Set;
24
25 import org.vectomatic.client.rep.RepApplication;
26 import org.vectomatic.client.rep.command.SetAttributeCommand;
27 import org.vectomatic.client.rep.events.IShapeSelectionListener;
28 import org.vectomatic.common.model.Attribute;
29 import org.vectomatic.common.model.FloatAttributeValue;
30 import org.vectomatic.common.model.Shape;
31 import org.vectomatic.common.model.geometry.ShapeGroup;
32
33 import com.google.gwt.user.client.ui.Widget;
34
35
36
37
38
39 public class LineWidthController extends ControllerBase implements IShapeSelectionListener {
40 private FloatAttributeValue _defaultLineWidth;
41 private LineWidthWell _lineWithWell;
42 private Set<FloatAttributeValue> _lineWidths;
43
44 public LineWidthController(RepApplication app) {
45 super(app);
46 _app.getSelection().addShapeSelectionListener(this);
47 _lineWidths = new HashSet<FloatAttributeValue>();
48
49 _defaultLineWidth = new FloatAttributeValue(1f);
50 _lineWithWell = new LineWidthWell(this);
51 _lineWithWell.setLineWidth(_defaultLineWidth);
52 }
53
54 public Widget getWidget() {
55 return _lineWithWell;
56 }
57
58
59 public void selectionChanged(ShapeSelection selection) {
60 _lineWidths.clear();
61 List<Shape> shapes = new ArrayList<Shape>(selection.getSelectedShapes());
62 for (int i = 0, size = shapes.size(); i < size; i++) {
63 Shape shape = shapes.get(i);
64 FloatAttributeValue lineWidth = (FloatAttributeValue)shape.getAttribute(Attribute.LINE_WIDTH);
65 if ((lineWidth == null) && (shape instanceof ShapeGroup)) {
66 shapes.addAll(((ShapeGroup)shape).getShapes());
67 continue;
68 }
69 _lineWidths.add(lineWidth);
70 }
71 if (_lineWidths.size() == 0) {
72 _lineWithWell.setLineWidth(_defaultLineWidth);
73 } else if (_lineWidths.size() == 1) {
74 _lineWithWell.setLineWidth(_lineWidths.iterator().next());
75 } else {
76 _lineWithWell.setLineWidth(null);
77 }
78 }
79
80
81
82
83
84 public void setLineWidth(FloatAttributeValue lineWidth) {
85 RepApplication.app.debugPrint("lineWidth change");
86
87 if (_app.getSelection().hasAttributeChanged(Attribute.LINE_WIDTH, lineWidth)) {
88 SetAttributeCommand setAttributeCommand = new SetAttributeCommand(_app, Attribute.LINE_WIDTH, lineWidth);
89 setAttributeCommand.execute();
90 _app.getHistory().addCommand(setAttributeCommand);
91 }
92 if (_app.getSelection().getSelectedShapes().size() == 0) {
93 _defaultLineWidth = lineWidth;
94 }
95 _lineWithWell.setLineWidth(lineWidth);
96 }
97
98 public FloatAttributeValue getLineWidth() {
99 return _defaultLineWidth;
100 }
101
102 }