gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.multipoint / src / main / java / org / gvsig / vectorediting / lib / prov / multipoint / MultipointEditingProvider.java @ 333
History | View | Annotate | Download (7.11 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2014 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.vectorediting.lib.prov.multipoint; |
26 |
|
27 |
import java.util.ArrayList; |
28 |
import java.util.LinkedHashMap; |
29 |
import java.util.List; |
30 |
import java.util.Map; |
31 |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
33 |
import org.gvsig.fmap.geom.Geometry; |
34 |
import org.gvsig.fmap.geom.GeometryLocator; |
35 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
36 |
import org.gvsig.fmap.geom.primitive.Point; |
37 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
38 |
import org.gvsig.tools.ToolsLocator; |
39 |
import org.gvsig.tools.dynobject.DynObject; |
40 |
import org.gvsig.tools.exception.BaseException; |
41 |
import org.gvsig.tools.i18n.I18nManager; |
42 |
import org.gvsig.tools.service.spi.ProviderServices; |
43 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
44 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
45 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
46 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
47 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
48 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
49 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
50 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
51 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
52 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
53 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
54 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
55 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
56 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
57 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
58 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
59 |
|
60 |
/**
|
61 |
* @author llmarques
|
62 |
*
|
63 |
*/
|
64 |
public class MultipointEditingProvider extends AbstractEditingProvider |
65 |
implements EditingProvider {
|
66 |
|
67 |
private EditingServiceParameter points;
|
68 |
|
69 |
private List<Point> values; |
70 |
|
71 |
private boolean finish; |
72 |
|
73 |
private FeatureStore featureStore;
|
74 |
|
75 |
/**
|
76 |
* Default constructor.
|
77 |
*
|
78 |
* @param providerServices
|
79 |
* available services for this provider
|
80 |
* @param parameters
|
81 |
* of this provider
|
82 |
*/
|
83 |
public MultipointEditingProvider(DynObject parameters,
|
84 |
ProviderServices services) { |
85 |
super(services);
|
86 |
|
87 |
this.featureStore =
|
88 |
(FeatureStore) parameters |
89 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
90 |
|
91 |
this.finish = false; |
92 |
|
93 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
94 |
|
95 |
EditingProviderServices editingProviderServices = |
96 |
(EditingProviderServices) getProviderServices(); |
97 |
|
98 |
Map<String, String> options = new LinkedHashMap<String, String>(); |
99 |
options.put(i18nManager.getTranslation("key_finish"), "finish"); |
100 |
|
101 |
String consoleMsg =
|
102 |
editingProviderServices.makeConsoleMessage("indicate_new_point",
|
103 |
options); |
104 |
|
105 |
this.points =
|
106 |
new DefaultEditingServiceParameter("indicate_new_point", |
107 |
consoleMsg, options, TYPE.LIST_POSITIONS, TYPE.OPTION); |
108 |
|
109 |
} |
110 |
|
111 |
public EditingServiceParameter next() {
|
112 |
if (finish) {
|
113 |
return null; |
114 |
} else {
|
115 |
return points;
|
116 |
} |
117 |
} |
118 |
|
119 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
120 |
throws DrawServiceException {
|
121 |
DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
|
122 |
EditingProviderManager editingProviderManager = |
123 |
EditingProviderLocator.getProviderManager(); |
124 |
ISymbol pointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
|
125 |
|
126 |
for (Point point : values) { |
127 |
drawingStatus.addStatus(point, pointSymbolEditing, "");
|
128 |
} |
129 |
|
130 |
return drawingStatus;
|
131 |
} |
132 |
|
133 |
public void stop() throws StopServiceException { |
134 |
if (values != null) { |
135 |
values.clear(); |
136 |
} |
137 |
finish = false;
|
138 |
} |
139 |
|
140 |
public List<EditingServiceParameter> getParameters() { |
141 |
List<EditingServiceParameter> parameters =
|
142 |
new ArrayList<EditingServiceParameter>(); |
143 |
parameters.add(points); |
144 |
return parameters;
|
145 |
} |
146 |
|
147 |
public void setValue(Object value) throws InvalidEntryException { |
148 |
EditingServiceParameter parameter = next(); |
149 |
validateAndInsertValue(parameter, value); |
150 |
} |
151 |
|
152 |
private void validateAndInsertValue(EditingServiceParameter parameter, |
153 |
Object value) {
|
154 |
|
155 |
if (parameter == points) {
|
156 |
if (value instanceof Point) { |
157 |
values.add((Point) value);
|
158 |
} else if (value instanceof String) { |
159 |
|
160 |
String option = (String) value; |
161 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
162 |
if (option.equalsIgnoreCase(i18nManager
|
163 |
.getTranslation("key_finish"))) {
|
164 |
finish = true;
|
165 |
} |
166 |
} |
167 |
} |
168 |
} |
169 |
|
170 |
public Geometry finish() throws FinishServiceException { |
171 |
|
172 |
if (values != null && values.size() > 0) { |
173 |
|
174 |
EditingProviderServices editingProviderServices = |
175 |
(EditingProviderServices) getProviderServices(); |
176 |
|
177 |
try {
|
178 |
|
179 |
int subtype = editingProviderServices.getSubType(featureStore);
|
180 |
|
181 |
MultiPoint multiPoint = |
182 |
GeometryLocator.getGeometryManager().createMultiPoint( |
183 |
subtype); |
184 |
|
185 |
for (Point point : values) { |
186 |
multiPoint.addPoint(point); |
187 |
} |
188 |
|
189 |
return multiPoint;
|
190 |
|
191 |
} catch (BaseException e) {
|
192 |
throw new FinishServiceException(e); |
193 |
} |
194 |
} |
195 |
return null; |
196 |
} |
197 |
|
198 |
public void finishAndStore() throws FinishServiceException { |
199 |
Geometry geom = finish(); |
200 |
EditingProviderServices editingProviderServices = |
201 |
(EditingProviderServices) getProviderServices(); |
202 |
editingProviderServices.insertGeometryIntoFeatureStore(geom, |
203 |
featureStore); |
204 |
|
205 |
} |
206 |
|
207 |
public void start() throws StartServiceException, InvalidEntryException { |
208 |
values = new ArrayList<Point>(); |
209 |
} |
210 |
|
211 |
public String getName() { |
212 |
return MultipointEditingProviderFactory.PROVIDER_DESCRIPTION;
|
213 |
} |
214 |
|
215 |
} |