1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.vectomatic.svg.edit.client.command.add;
19
20 import org.vectomatic.dom.svg.OMSVGLineElement;
21 import org.vectomatic.dom.svg.OMSVGPoint;
22 import org.vectomatic.dom.svg.impl.SVGElement;
23 import org.vectomatic.dom.svg.utils.SVGConstants;
24 import org.vectomatic.svg.edit.client.SvgrealApp;
25 import org.vectomatic.svg.edit.client.command.FactoryInstantiatorBase;
26 import org.vectomatic.svg.edit.client.command.IFactoryInstantiator;
27 import org.vectomatic.svg.edit.client.event.MouseDownProcessor;
28 import org.vectomatic.svg.edit.client.event.MouseMoveProcessor;
29 import org.vectomatic.svg.edit.client.event.MouseUpProcessor;
30 import org.vectomatic.svg.edit.client.model.ModelConstants;
31
32 import com.google.gwt.core.client.GWT;
33 import com.google.gwt.event.dom.client.MouseDownEvent;
34 import com.google.gwt.event.dom.client.MouseMoveEvent;
35 import com.google.gwt.event.dom.client.MouseUpEvent;
36
37
38
39
40
41 public class AddLineCommandFactory extends AddCommandFactoryBase implements MouseDownProcessor, MouseMoveProcessor, MouseUpProcessor {
42 @SuppressWarnings("serial")
43 public static final IFactoryInstantiator<AddLineCommandFactory> INSTANTIATOR = new FactoryInstantiatorBase<AddLineCommandFactory>(ModelConstants.INSTANCE.addLineCmdFactory(), ModelConstants.INSTANCE.addLineCmdFactoryDesc()) {
44 @Override
45 public AddLineCommandFactory create() {
46 return new AddLineCommandFactory();
47 }
48 };
49
50
51
52
53 protected OMSVGLineElement line;
54
55
56
57 protected OMSVGPoint p;
58
59 @Override
60 public IFactoryInstantiator<?> getInstantiator() {
61 return INSTANTIATOR;
62 }
63
64 @Override
65 public void start(Object requester) {
66 GWT.log("AddLineCommandFactory.start(" + requester + ")");
67 super.start(requester);
68 updateStatus(ModelConstants.INSTANCE.addLineCmdFactory1());
69 }
70
71 @Override
72 public boolean processMouseDown(MouseDownEvent event) {
73 if (owner != null && line != null) {
74 owner.getTwinGroup().removeChild(line);
75 }
76 updateStatus(ModelConstants.INSTANCE.addLineCmdFactory2());
77 owner = SvgrealApp.getApp().getActiveModel();
78 p = owner.getCoordinates(event, true);
79 line = new OMSVGLineElement(p.getX(), p.getY(), p.getX(), p.getY());
80 applyCssContextStyle((SVGElement) line.getElement().cast());
81 line.getStyle().setSVGProperty(SVGConstants.CSS_VISIBILITY_PROPERTY, SVGConstants.CSS_VISIBLE_VALUE);
82 owner.getTwinGroup().appendChild(line);
83 return true;
84 }
85
86 @Override
87 public boolean processMouseUp(MouseUpEvent event) {
88 if (owner != null) {
89 updateStatus(ModelConstants.INSTANCE.addLineCmdFactory1());
90 if (line.getX1().getBaseVal() == line.getX2().getBaseVal()
91 && line.getY1().getBaseVal() == line.getY2().getBaseVal()) {
92 owner.getTwinGroup().removeChild(line);
93 } else {
94 createCommand(line);
95 }
96 line = null;
97 owner = null;
98 }
99 return true;
100 }
101
102 @Override
103 public boolean processMouseMove(MouseMoveEvent event) {
104 if (owner != null) {
105 p = owner.getCoordinates(event, true);
106 line.getX2().getBaseVal().setValue(p.getX());
107 line.getY2().getBaseVal().setValue(p.getY());
108 }
109 return true;
110 }
111 }