Revision 80
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingProviderLibrary.java | ||
---|---|---|
11 | 11 |
import org.gvsig.tools.library.LibraryException; |
12 | 12 |
import org.gvsig.vectorediting.lib.prov.circlecr.CircleCREditingProviderFactory; |
13 | 13 |
import org.gvsig.vectorediting.lib.prov.insertpoint.InsertPointEditingProviderFactory; |
14 |
import org.gvsig.vectorediting.lib.prov.internalpolygon.InternalPolygonEditingProviderFactory; |
|
14 | 15 |
import org.gvsig.vectorediting.lib.prov.polyline.PolylineEditingProviderFactory; |
15 | 16 |
import org.gvsig.vectorediting.lib.prov.symmetry.SymmetryEditingProviderFactory; |
16 | 17 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLibrary; |
... | ... | |
41 | 42 |
manager.addProviderFactory(new CircleCREditingProviderFactory()); |
42 | 43 |
manager.addProviderFactory(new PolylineEditingProviderFactory()); |
43 | 44 |
manager.addProviderFactory(new SymmetryEditingProviderFactory()); |
45 |
manager.addProviderFactory(new InternalPolygonEditingProviderFactory()); |
|
44 | 46 |
|
45 | 47 |
} |
46 | 48 |
|
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/src/main/java/org/gvsig/vectorediting/lib/impl/DefaultEditingService.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import java.util.List; |
10 | 10 |
|
11 |
import org.gvsig.fmap.geom.Geometry; |
|
11 | 12 |
import org.gvsig.fmap.geom.primitive.Point; |
12 |
import org.gvsig.fmap.mapcontext.exceptions.StopEditionLayerException; |
|
13 | 13 |
import org.gvsig.tools.service.Manager; |
14 | 14 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
15 | 15 |
import org.gvsig.vectorediting.lib.api.EditingService; |
... | ... | |
53 | 53 |
provider.stop(); |
54 | 54 |
} |
55 | 55 |
|
56 |
public void finish() throws FinishServiceException { |
|
57 |
provider.finish(); |
|
56 |
public void finishAndStore() throws FinishServiceException {
|
|
57 |
provider.finishAndStore();
|
|
58 | 58 |
} |
59 |
|
|
60 |
public Geometry finish() throws FinishServiceException{ |
|
61 |
return provider.finish(); |
|
62 |
} |
|
59 | 63 |
|
60 | 64 |
public void start() throws StartServiceException { |
61 | 65 |
this.provider.start(); |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.impl/pom.xml | ||
---|---|---|
44 | 44 |
org.gvsig.vectorediting.lib.prov.symmetry |
45 | 45 |
</artifactId> |
46 | 46 |
</dependency> |
47 |
<dependency> |
|
48 |
<groupId>org.gvsig</groupId> |
|
49 |
<artifactId> |
|
50 |
org.gvsig.vectorediting.lib.prov.internalpolygon |
|
51 |
</artifactId> |
|
52 |
</dependency> |
|
47 | 53 |
</dependencies> |
48 | 54 |
</project> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.internalpolygon/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.vectorediting.lib.prov</artifactId> |
|
6 |
<version>1.0.0-SNAPSHOT</version> |
|
7 |
</parent> |
|
8 |
<artifactId>org.gvsig.vectorediting.lib.prov.internalpolygon</artifactId> |
|
9 |
<name>org.gvsig.vectorediting.lib.prov.internalpolygon</name> |
|
10 |
</project> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.internalpolygon/src/main/java/org/gvsig/vectorediting/lib/prov/internalpolygon/InternalPolygonEditingProvider.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.prov.internalpolygon |
|
5 |
* SVN Id : $Id$ |
|
6 |
*/ |
|
7 |
package org.gvsig.vectorediting.lib.prov.internalpolygon; |
|
8 |
|
|
9 |
import java.util.ArrayList; |
|
10 |
import java.util.HashMap; |
|
11 |
import java.util.List; |
|
12 |
import java.util.Map; |
|
13 |
|
|
14 |
import org.gvsig.fmap.dal.exception.DataException; |
|
15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
16 |
import org.gvsig.fmap.dal.feature.Feature; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
18 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
19 |
import org.gvsig.fmap.geom.Geometry; |
|
20 |
import org.gvsig.fmap.geom.primitive.Point; |
|
21 |
import org.gvsig.tools.ToolsLocator; |
|
22 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
23 |
import org.gvsig.tools.dynobject.DynObject; |
|
24 |
import org.gvsig.tools.i18n.I18nManager; |
|
25 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
26 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
|
27 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
28 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
|
29 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
|
30 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
31 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
|
32 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
|
33 |
import org.gvsig.vectorediting.lib.api.exceptions.StopServiceException; |
|
34 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
|
35 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
|
36 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
|
37 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
38 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
|
39 |
|
|
40 |
public class InternalPolygonEditingProvider extends AbstractEditingProvider |
|
41 |
implements EditingProvider { |
|
42 |
|
|
43 |
private I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
44 |
|
|
45 |
private EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
|
46 |
|
|
47 |
private EditingServiceParameter selectionParameter = new DefaultEditingServiceParameter( |
|
48 |
"Select geometry", i18nManager.getTranslation("selection"), |
|
49 |
TYPE.SELECTION); |
|
50 |
|
|
51 |
private EditingServiceParameter geometryParameter = new DefaultEditingServiceParameter( |
|
52 |
"Draw geometry", i18nManager.getTranslation("draw_geometry"), |
|
53 |
TYPE.GEOMETRY); |
|
54 |
|
|
55 |
private FeatureStore featureStore; |
|
56 |
|
|
57 |
private Map<EditingServiceParameter, Object> values; |
|
58 |
|
|
59 |
public InternalPolygonEditingProvider(ProviderServices services, |
|
60 |
DynObject parameters) { |
|
61 |
super(services); |
|
62 |
this.featureStore = (FeatureStore) parameters |
|
63 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
|
64 |
} |
|
65 |
|
|
66 |
public EditingServiceParameter next() { |
|
67 |
if (values.get(selectionParameter) == null) { |
|
68 |
return selectionParameter; |
|
69 |
} |
|
70 |
else if (values.get(geometryParameter) == null) { |
|
71 |
return geometryParameter; |
|
72 |
} |
|
73 |
|
|
74 |
return null; |
|
75 |
} |
|
76 |
|
|
77 |
public DrawingStatus draw(Point mousePosition) throws DrawServiceException { |
|
78 |
return null; |
|
79 |
} |
|
80 |
|
|
81 |
public void stop() throws StopServiceException {} |
|
82 |
|
|
83 |
public List<EditingServiceParameter> getParameters() { |
|
84 |
List<EditingServiceParameter> list = new ArrayList<EditingServiceParameter>(); |
|
85 |
list.add(selectionParameter); |
|
86 |
list.add(geometryParameter); |
|
87 |
return list; |
|
88 |
} |
|
89 |
|
|
90 |
public void value(Object value) throws InvalidEntryException { |
|
91 |
EditingServiceParameter param = next(); |
|
92 |
validateAndInsertValue(param, value); |
|
93 |
} |
|
94 |
|
|
95 |
private void validateAndInsertValue(EditingServiceParameter param, |
|
96 |
Object value) { |
|
97 |
if (param == selectionParameter) { |
|
98 |
if (value instanceof FeatureSelection) { |
|
99 |
values.put(param, value); |
|
100 |
return; |
|
101 |
} |
|
102 |
} |
|
103 |
else if (param == geometryParameter) { |
|
104 |
if (value instanceof Geometry) { |
|
105 |
values.put(param, value); |
|
106 |
return; |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
|
|
111 |
public void finishAndStore() throws FinishServiceException { |
|
112 |
FeatureSelection selected = (FeatureSelection) values |
|
113 |
.get(selectionParameter); |
|
114 |
Geometry geometry = (Geometry) values.get(geometryParameter); |
|
115 |
try { |
|
116 |
if (!selected.isEmpty()) { |
|
117 |
DisposableIterator it; |
|
118 |
it = selected.fastIterator(); |
|
119 |
|
|
120 |
while (it.hasNext()) { |
|
121 |
Feature feature = (Feature) it.next(); |
|
122 |
Geometry geom = (Geometry) feature.getDefaultGeometry() |
|
123 |
.cloneGeometry(); |
|
124 |
Geometry newGeom = geom.difference(geometry); |
|
125 |
EditableFeature editableFeature = feature.getEditable(); |
|
126 |
editableFeature.setDefaultGeometry(newGeom); |
|
127 |
editingProviderServices.updateFeatureInFeatureStore(editableFeature, |
|
128 |
featureStore); |
|
129 |
} |
|
130 |
} |
|
131 |
} |
|
132 |
catch (Exception e) { |
|
133 |
throw new FinishServiceException("Can't finalize " + this.getName(), e); |
|
134 |
} |
|
135 |
|
|
136 |
} |
|
137 |
|
|
138 |
public Geometry finish() throws FinishServiceException { |
|
139 |
return null; |
|
140 |
} |
|
141 |
|
|
142 |
public void start() throws StartServiceException { |
|
143 |
this.values = new HashMap<EditingServiceParameter, Object>(); |
|
144 |
FeatureSelection selected = null; |
|
145 |
if (featureStore != null) { |
|
146 |
try { |
|
147 |
selected = featureStore.getFeatureSelection(); |
|
148 |
} |
|
149 |
catch (DataException e) { |
|
150 |
throw new StartServiceException(e); |
|
151 |
} |
|
152 |
if (selected != null && selected.getSelectedCount() > 0) { |
|
153 |
values.put(selectionParameter, selected); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
public String getName() { |
|
159 |
return InternalPolygonEditingProviderFactory.PROVIDER_NAME; |
|
160 |
} |
|
161 |
|
|
162 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.internalpolygon/src/main/java/org/gvsig/vectorediting/lib/prov/internalpolygon/InternalPolygonEditingProviderFactory.java | ||
---|---|---|
1 |
/* |
|
2 |
* Copyright 2014 DiSiD Technologies S.L.L. All rights reserved. |
|
3 |
* |
|
4 |
* Project : DiSiD org.gvsig.vectorediting.lib.prov.internalpolygon |
|
5 |
* SVN Id : $Id$ |
|
6 |
*/ |
|
7 |
package org.gvsig.vectorediting.lib.prov.internalpolygon; |
|
8 |
|
|
9 |
import org.gvsig.fmap.geom.Geometry; |
|
10 |
import org.gvsig.tools.ToolsLocator; |
|
11 |
import org.gvsig.tools.dynobject.DynClass; |
|
12 |
import org.gvsig.tools.dynobject.DynObject; |
|
13 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
14 |
import org.gvsig.tools.service.spi.AbstractProviderFactory; |
|
15 |
import org.gvsig.tools.service.spi.Provider; |
|
16 |
import org.gvsig.tools.service.spi.ProviderServices; |
|
17 |
import org.gvsig.vectorediting.lib.api.EditingServiceInfo; |
|
18 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
|
19 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceinfo; |
|
20 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
|
21 |
|
|
22 |
public class InternalPolygonEditingProviderFactory extends AbstractProviderFactory |
|
23 |
implements EditingProviderFactory { |
|
24 |
|
|
25 |
public final static String PROVIDER_NAME = "internal-polygon"; |
|
26 |
|
|
27 |
public final static String PROVIDER_DESCRIPTION = ""; |
|
28 |
|
|
29 |
public void initialize() {} |
|
30 |
|
|
31 |
public EditingServiceInfo getServiceInfo() { |
|
32 |
EditingServiceInfo serviceInfo = new DefaultEditingServiceinfo( |
|
33 |
PROVIDER_NAME, "", true, null, null, new int[] { |
|
34 |
Geometry.TYPES.SURFACE, Geometry.TYPES.MULTISURFACE }); |
|
35 |
|
|
36 |
return serviceInfo; |
|
37 |
} |
|
38 |
|
|
39 |
public EditingServiceParameter getServiceParameterInfo() { |
|
40 |
// TODO Auto-generated method stub |
|
41 |
return null; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
protected Provider doCreate(DynObject parameters, ProviderServices services) { |
|
46 |
return new InternalPolygonEditingProvider(services, parameters); |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected DynClass createParametersDynClass() { |
|
51 |
DynObjectManager dynObjectManager = ToolsLocator.getDynObjectManager(); |
|
52 |
DynClass dynclass = dynObjectManager.createDynClass( |
|
53 |
PROVIDER_NAME, PROVIDER_DESCRIPTION); |
|
54 |
|
|
55 |
dynclass.addDynFieldString(PROVIDER_NAME_FIELD); |
|
56 |
dynclass.addDynFieldObject(FEATURE_STORE_FIELD); |
|
57 |
|
|
58 |
return dynclass; |
|
59 |
} |
|
60 |
|
|
61 |
public DynObject createParameters() { |
|
62 |
DynObject parameters = super.createParameters(); |
|
63 |
parameters.setDynValue(PROVIDER_NAME_FIELD, PROVIDER_NAME); |
|
64 |
return parameters; |
|
65 |
} |
|
66 |
|
|
67 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.circlecr/src/main/java/org/gvsig/vectorediting/lib/prov/circlecr/CircleCREditingProvider.java | ||
---|---|---|
38 | 38 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
39 | 39 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
40 | 40 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
41 |
import org.slf4j.Logger; |
|
42 |
import org.slf4j.LoggerFactory; |
|
43 | 41 |
|
44 | 42 |
public class CircleCREditingProvider extends AbstractEditingProvider implements |
45 | 43 |
EditingProvider { |
46 | 44 |
|
47 |
private static final Logger logger = LoggerFactory |
|
48 |
.getLogger(CircleCREditingProvider.class); |
|
49 |
|
|
50 | 45 |
private I18nManager i18nManager = ToolsLocator.getI18nManager(); |
51 | 46 |
|
52 | 47 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
... | ... | |
74 | 69 |
if (values.get(center) != null) { |
75 | 70 |
Point centerPoint = (Point) values.get(center); |
76 | 71 |
try { |
77 |
Curve line = ((EditingProviderServices) getProviderServices()) |
|
78 |
.createLine(centerPoint.getX(), centerPoint.getY(), |
|
79 |
mousePosition.getX(), mousePosition.getY(), featureStore); |
|
72 |
Curve line = ((EditingProviderServices) getProviderServices())
|
|
73 |
.createLine(centerPoint.getX(), centerPoint.getY(),
|
|
74 |
mousePosition.getX(), mousePosition.getY(), featureStore);
|
|
80 | 75 |
Arc circle = ((EditingProviderServices) getProviderServices()) |
81 | 76 |
.createArc(centerPoint, mousePosition.distance(centerPoint), 0, |
82 | 77 |
2 * Math.PI, featureStore); |
83 |
geometries.addGeometry(circle); |
|
84 |
geometries.addGeometry(centerPoint); |
|
85 |
geometries.addGeometry(line); |
|
78 |
geometries.addGeometry(circle);
|
|
79 |
geometries.addGeometry(centerPoint);
|
|
80 |
geometries.addGeometry(line);
|
|
86 | 81 |
|
87 | 82 |
} |
88 | 83 |
catch (Exception e) { |
89 |
throw new DrawServiceException(e);
|
|
84 |
throw new DrawServiceException(e); |
|
90 | 85 |
} |
91 | 86 |
|
92 | 87 |
return geometries; |
... | ... | |
111 | 106 |
} |
112 | 107 |
|
113 | 108 |
private void validateAndInsertValue(EditingServiceParameter param, |
114 |
Object value) throws InvalidEntryException { |
|
109 |
Object value) |
|
110 |
throws InvalidEntryException { |
|
115 | 111 |
if (param == center) { |
116 | 112 |
if (value instanceof Point) { |
117 | 113 |
values.put(param, value); |
... | ... | |
149 | 145 |
return list; |
150 | 146 |
} |
151 | 147 |
|
152 |
public void value(Object value) throws InvalidEntryException{ |
|
148 |
public void value(Object value) throws InvalidEntryException {
|
|
153 | 149 |
EditingServiceParameter param = next(); |
154 | 150 |
validateAndInsertValue(param, value); |
155 | 151 |
} |
156 | 152 |
|
157 |
public void finish() throws FinishServiceException{ |
|
153 |
public void finishAndStore() throws FinishServiceException { |
|
154 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
|
155 |
Geometry geometry = finish(); |
|
156 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, featureStore); |
|
157 |
} |
|
158 |
|
|
159 |
public Geometry finish() throws FinishServiceException { |
|
158 | 160 |
Point centerPoint = (Point) values.get(center); |
159 | 161 |
double radiusValue = (Double) values.get(radius); |
160 | 162 |
EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
161 | 163 |
try { |
162 |
GeometryType storeGeomType = editingProviderServices |
|
163 |
.getGeomType(featureStore); |
|
164 |
Geometry geometry = null; |
|
165 |
if (storeGeomType.isTypeOf(SURFACE)) { |
|
164 |
GeometryType storeGeomType = editingProviderServices
|
|
165 |
.getGeomType(featureStore);
|
|
166 |
Geometry geometry = null;
|
|
167 |
if (storeGeomType.isTypeOf(SURFACE)) {
|
|
166 | 168 |
geometry = editingProviderServices.createCircle(centerPoint, |
167 | 169 |
radiusValue, featureStore); |
168 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
169 |
featureStore); |
|
170 |
} |
|
171 |
else if (storeGeomType.isTypeOf(CURVE)) { |
|
170 |
} |
|
171 |
else if (storeGeomType.isTypeOf(CURVE)) { |
|
172 | 172 |
geometry = editingProviderServices.createArc(centerPoint, radiusValue, |
173 | 173 |
0, 2 * Math.PI, featureStore); |
174 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
175 |
featureStore); |
|
176 |
} |
|
177 |
else if (storeGeomType.isTypeOf(MULTISURFACE)) { |
|
174 |
} |
|
175 |
else if (storeGeomType.isTypeOf(MULTISURFACE)) { |
|
178 | 176 |
geometry = editingProviderServices.createCircle(centerPoint, |
179 | 177 |
radiusValue, featureStore); |
180 |
MultiSurface multisurface; |
|
178 |
MultiSurface multisurface;
|
|
181 | 179 |
multisurface = geomManager.createMultiSurface(storeGeomType |
182 | 180 |
.getSubType()); |
183 |
multisurface.addSurface((Circle) geometry); |
|
184 |
editingProviderServices.insertGeometryIntoFeatureStore(multisurface, |
|
185 |
featureStore); |
|
186 |
} |
|
187 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
181 |
multisurface.addSurface((Circle) geometry); |
|
182 |
} |
|
183 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
188 | 184 |
geometry = editingProviderServices.createArc(centerPoint, radiusValue, |
189 | 185 |
0, 2 * Math.PI, featureStore); |
190 |
MultiCurve multicurve; |
|
191 |
multicurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
192 |
multicurve.addCurve((Arc) geometry); |
|
193 |
editingProviderServices.insertGeometryIntoFeatureStore(multicurve, |
|
194 |
featureStore); |
|
195 |
|
|
186 |
MultiCurve multicurve; |
|
187 |
multicurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
188 |
multicurve.addCurve((Arc) geometry); |
|
189 |
} |
|
190 |
return geometry; |
|
196 | 191 |
} |
197 |
else { |
|
198 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
199 |
featureStore); |
|
200 |
} |
|
201 |
} |
|
202 | 192 |
catch (Exception e) { |
203 | 193 |
throw new FinishServiceException(e); |
204 | 194 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/pom.xml | ||
---|---|---|
13 | 13 |
<module>org.gvsig.vectorediting.lib.prov.circlecr</module> |
14 | 14 |
<module>org.gvsig.vectorediting.lib.prov.polyline</module> |
15 | 15 |
<module>org.gvsig.vectorediting.lib.prov.symmetry</module> |
16 |
<module> |
|
17 |
org.gvsig.vectorediting.lib.prov.internalpolygon |
|
18 |
</module> |
|
16 | 19 |
</modules> |
17 | 20 |
<dependencies> |
18 | 21 |
<dependency> |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.symmetry/src/main/java/org/gvsig/vectorediting/lib/prov/symmetry/SymmetryEditingProvider.java | ||
---|---|---|
246 | 246 |
validateAndInsertValue(param, value); |
247 | 247 |
} |
248 | 248 |
|
249 |
public void finish() throws FinishServiceException { |
|
249 |
public void finishAndStore() throws FinishServiceException {
|
|
250 | 250 |
|
251 | 251 |
FeatureSelection selected = (FeatureSelection) values |
252 | 252 |
.get(selectionParameter); |
... | ... | |
300 | 300 |
throw new FinishServiceException(e); |
301 | 301 |
} |
302 | 302 |
} |
303 |
|
|
304 |
public Geometry finish() throws FinishServiceException{ |
|
305 |
return null; |
|
306 |
} |
|
303 | 307 |
|
304 | 308 |
public void start() throws StartServiceException { |
305 | 309 |
this.values = new HashMap<EditingServiceParameter, Object>(); |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.polyline/src/main/java/org/gvsig/vectorediting/lib/prov/polyline/PolylineEditingProvider.java | ||
---|---|---|
283 | 283 |
} |
284 | 284 |
} |
285 | 285 |
|
286 |
public void finish() throws FinishServiceException { |
|
286 |
public void finishAndStore() throws FinishServiceException {
|
|
287 | 287 |
try { |
288 | 288 |
GeometryType storeGeomType = editingProviderServices |
289 | 289 |
.getGeomType(featureStore); |
290 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
290 |
|
|
291 |
Geometry geometry = finish(); |
|
292 |
if (geometry == null) { |
|
293 |
if (storeGeomType.isTypeOf(CURVE)) { |
|
294 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
295 |
for (Geometry geom : finalGeometries.getGeometries()) { |
|
296 |
editingProviderServices.insertGeometryIntoFeatureStore(geom, |
|
297 |
featureStore); |
|
298 |
} |
|
299 |
} |
|
300 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
301 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
302 |
MultiCurve multiCurve; |
|
303 |
multiCurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
304 |
for (Geometry geom : finalGeometries.getGeometries()) { |
|
305 |
multiCurve.addCurve((Curve) geom); |
|
306 |
} |
|
307 |
editingProviderServices.insertGeometryIntoFeatureStore(multiCurve, |
|
308 |
featureStore); |
|
309 |
} |
|
310 |
} |
|
311 |
else { |
|
312 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
313 |
featureStore); |
|
314 |
} |
|
315 |
} |
|
316 |
catch (Exception e) { |
|
317 |
throw new FinishServiceException(e); |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
public Geometry finish() throws FinishServiceException { |
|
322 |
try { |
|
323 |
GeometryType storeGeomType = editingProviderServices |
|
324 |
.getGeomType(featureStore); |
|
291 | 325 |
if (storeGeomType.isTypeOf(SURFACE)) { |
326 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
292 | 327 |
Surface surface = geomManager.createPolygon(storeGeomType.getSubType()); |
293 | 328 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
294 | 329 |
surface.addVertex((Point) geometry); |
295 | 330 |
} |
296 | 331 |
surface = closeSurfaceIfNecessary(surface); |
297 |
editingProviderServices.insertGeometryIntoFeatureStore(surface, |
|
298 |
featureStore); |
|
332 |
return (Geometry) surface; |
|
299 | 333 |
} |
300 |
else if (storeGeomType.isTypeOf(CURVE)) { |
|
301 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
302 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
|
303 |
featureStore); |
|
304 |
} |
|
305 |
} |
|
306 | 334 |
else if (storeGeomType.isTypeOf(MULTISURFACE)) { |
335 |
DrawingStatus finalGeometries = calculatePolyline(null); |
|
307 | 336 |
MultiSurface multiSurface; |
308 | 337 |
multiSurface = geomManager.createMultiSurface(storeGeomType |
309 | 338 |
.getSubType()); |
... | ... | |
318 | 347 |
} |
319 | 348 |
surface = closeSurfaceIfNecessary(surface); |
320 | 349 |
multiSurface.addSurface(surface); |
321 |
editingProviderServices.insertGeometryIntoFeatureStore(multiSurface, |
|
322 |
featureStore); |
|
350 |
return (Geometry) multiSurface; |
|
323 | 351 |
} |
324 |
else if (storeGeomType.isTypeOf(MULTICURVE)) { |
|
325 |
MultiCurve multiCurve; |
|
326 |
multiCurve = geomManager.createMultiCurve(storeGeomType.getSubType()); |
|
327 |
for (Geometry geometry : finalGeometries.getGeometries()) { |
|
328 |
multiCurve.addCurve((Curve) geometry); |
|
329 |
} |
|
330 |
editingProviderServices.insertGeometryIntoFeatureStore(multiCurve, |
|
331 |
featureStore); |
|
332 |
} |
|
352 |
return null; |
|
333 | 353 |
} |
334 | 354 |
catch (Exception e) { |
335 | 355 |
throw new FinishServiceException(e); |
... | ... | |
581 | 601 |
} |
582 | 602 |
|
583 | 603 |
public void stop() { |
584 |
if(values != null){
|
|
604 |
if (values != null) {
|
|
585 | 605 |
values.clear(); |
586 | 606 |
} |
587 | 607 |
points.setDescription(i18nManager.getTranslation("indicates_new_point")); |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.insertpoint/src/main/java/org/gvsig/vectorediting/lib/prov/insertpoint/InsertPointEditingProvider.java | ||
---|---|---|
9 | 9 |
import java.util.ArrayList; |
10 | 10 |
import java.util.List; |
11 | 11 |
|
12 |
import org.apache.log4j.Logger; |
|
13 |
import org.gvsig.fmap.dal.exception.DataException; |
|
12 | 14 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
15 |
import org.gvsig.fmap.geom.Geometry; |
|
16 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
13 | 17 |
import org.gvsig.fmap.geom.primitive.Point; |
14 | 18 |
import org.gvsig.tools.ToolsLocator; |
15 | 19 |
import org.gvsig.tools.dynobject.DynObject; |
... | ... | |
32 | 36 |
implements EditingProvider { |
33 | 37 |
|
34 | 38 |
private EditingProviderServices editingProviderServices = (EditingProviderServices) getProviderServices(); |
35 |
|
|
39 |
|
|
36 | 40 |
private I18nManager i18nManager = ToolsLocator.getI18nManager(); |
37 | 41 |
|
38 | 42 |
private EditingServiceParameter point = new DefaultEditingServiceParameter( |
39 |
"Insert point", i18nManager.getTranslation("indicate_new_point"), TYPE.POSITION); |
|
43 |
"Insert point", i18nManager.getTranslation("indicate_new_point"), |
|
44 |
TYPE.POSITION); |
|
40 | 45 |
|
41 | 46 |
private Point valuePoint; |
42 | 47 |
|
... | ... | |
59 | 64 |
return null; |
60 | 65 |
} |
61 | 66 |
|
62 |
public void stop(){ |
|
67 |
public void stop() {
|
|
63 | 68 |
|
64 | 69 |
} |
65 | 70 |
|
... | ... | |
85 | 90 |
if (isValidValue(param, value)) { |
86 | 91 |
this.valuePoint = (Point) value; |
87 | 92 |
} |
88 |
else{ |
|
93 |
else {
|
|
89 | 94 |
throw new InvalidEntryException(null); |
90 | 95 |
} |
91 | 96 |
} |
92 | 97 |
|
93 |
public void finish() throws FinishServiceException { |
|
94 |
try{
|
|
95 |
Point geometry = editingProviderServices.createPoint(valuePoint.getX(),
|
|
96 |
valuePoint.getY(), featureStore);
|
|
98 |
public void finishAndStore() throws FinishServiceException {
|
|
99 |
Geometry geometry = null;
|
|
100 |
try {
|
|
101 |
geometry = finish();
|
|
97 | 102 |
editingProviderServices.insertGeometryIntoFeatureStore(geometry, |
98 | 103 |
featureStore); |
99 |
} catch(Exception e){ |
|
100 |
// TODO |
|
101 | 104 |
} |
105 |
catch (Exception e) { |
|
106 |
throw new FinishServiceException("Can't finalize " + this.getName() |
|
107 |
+ "with X=" + valuePoint.getX() + " Y= " + valuePoint.getY(), e); |
|
108 |
} |
|
102 | 109 |
} |
103 | 110 |
|
104 | 111 |
public void start() throws StartServiceException { |
... | ... | |
108 | 115 |
public String getName() { |
109 | 116 |
return InsertPointEditingProviderFactory.PROVIDER_NAME; |
110 | 117 |
} |
118 |
|
|
119 |
public Geometry finish() throws FinishServiceException { |
|
120 |
Point geometry = null; |
|
121 |
try { |
|
122 |
geometry = editingProviderServices.createPoint(valuePoint.getX(), |
|
123 |
valuePoint.getY(), featureStore); |
|
124 |
} |
|
125 |
catch (Exception e) { |
|
126 |
throw new FinishServiceException("Can't finalize " + this.getName() |
|
127 |
+ "with X=" + valuePoint.getX() + " Y= " + valuePoint.getY(), e); |
|
128 |
} |
|
129 |
return geometry; |
|
130 |
} |
|
111 | 131 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.api/src/main/java/org/gvsig/vectorediting/lib/api/EditingService.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import java.util.List; |
10 | 10 |
|
11 |
import org.gvsig.fmap.geom.Geometry; |
|
11 | 12 |
import org.gvsig.fmap.geom.primitive.Point; |
12 | 13 |
import org.gvsig.tools.service.Service; |
13 | 14 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
... | ... | |
72 | 73 |
|
73 | 74 |
/** |
74 | 75 |
* Finalizes service. Gets stored values, creates geometries with this values |
75 |
* and inserts/updates/removes into associated featured.
|
|
76 |
* and return geometry created.
|
|
76 | 77 |
* |
78 |
* @return Geometry created. |
|
77 | 79 |
* @throws FinishServiceException if there are some error getting values, |
78 | 80 |
* creating geometries or inserting/updating/removing geometries |
79 | 81 |
* from feature store. |
80 | 82 |
*/ |
81 |
public void finish() throws FinishServiceException; |
|
83 |
public Geometry finish() throws FinishServiceException; |
|
84 |
|
|
85 |
/** |
|
86 |
* |
|
87 |
* @throws FinishServiceException |
|
88 |
*/ |
|
89 |
public void finishAndStore () throws FinishServiceException; |
|
82 | 90 |
|
83 | 91 |
/** |
84 | 92 |
* Starts service initializing its parameters. |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.api/src/main/java/org/gvsig/vectorediting/lib/api/exceptions/FinishServiceException.java | ||
---|---|---|
17 | 17 |
public FinishServiceException(Throwable ex) { |
18 | 18 |
super(MESSAGE, ex, KEY, serialVersionUID); |
19 | 19 |
} |
20 |
|
|
20 |
|
|
21 |
public FinishServiceException(String message, Throwable ex){ |
|
22 |
super(message, ex, KEY, serialVersionUID); |
|
23 |
} |
|
21 | 24 |
} |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.spi/src/main/java/org/gvsig/vectorediting/lib/spi/EditingProvider.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import java.util.List; |
10 | 10 |
|
11 |
import org.gvsig.fmap.geom.Geometry; |
|
11 | 12 |
import org.gvsig.fmap.geom.primitive.Point; |
12 | 13 |
import org.gvsig.tools.service.spi.Provider; |
13 | 14 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
... | ... | |
74 | 75 |
|
75 | 76 |
/** |
76 | 77 |
* Finalizes service. Gets stored values, creates geometries with this values |
77 |
* and inserts/updates/removes into associated featured.
|
|
78 |
* and return geometry created.
|
|
78 | 79 |
* |
80 |
* @return Geometry created. |
|
79 | 81 |
* @throws FinishServiceException if there are some error getting values, |
80 | 82 |
* creating geometries or inserting/updating/removing geometries |
81 | 83 |
* from feature store. |
82 | 84 |
*/ |
83 |
public void finish() throws FinishServiceException;
|
|
84 |
|
|
85 |
public Geometry finish() throws FinishServiceException;
|
|
86 |
|
|
85 | 87 |
/** |
88 |
* |
|
89 |
* @throws FinishServiceException |
|
90 |
*/ |
|
91 |
public void finishAndStore () throws FinishServiceException; |
|
92 |
|
|
93 |
/** |
|
86 | 94 |
* Starts service initializing its parameters. |
87 | 95 |
* |
88 | 96 |
* @throws StartServiceException if there are some error starting service. |
org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.swing/org.gvsig.vectorediting.swing.impl/src/main/java/org/gvsig/vectorediting/swing/impl/DefaultEditingBehavior.java | ||
---|---|---|
11 | 11 |
import java.awt.Graphics; |
12 | 12 |
import java.awt.Image; |
13 | 13 |
import java.awt.event.MouseEvent; |
14 |
import java.awt.geom.Point2D; |
|
15 | 14 |
import java.awt.image.BufferedImage; |
16 | 15 |
import java.util.HashMap; |
17 | 16 |
import java.util.Iterator; |
18 | 17 |
import java.util.List; |
19 | 18 |
import java.util.Map; |
19 |
import java.util.Stack; |
|
20 | 20 |
|
21 |
import org.cresques.cts.IProjection; |
|
22 |
import org.gvsig.andami.PluginServices; |
|
23 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
|
24 | 21 |
import org.gvsig.fmap.dal.exception.DataException; |
25 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
|
26 | 22 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
27 | 23 |
import org.gvsig.fmap.geom.Geometry; |
28 | 24 |
import org.gvsig.fmap.geom.primitive.Point; |
... | ... | |
57 | 53 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
58 | 54 |
import org.gvsig.vectorediting.lib.api.exceptions.ChangeCurrentLayerException; |
59 | 55 |
import org.gvsig.vectorediting.lib.api.exceptions.CreateEditingBehaviorException; |
56 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
|
60 | 57 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
61 | 58 |
import org.gvsig.vectorediting.lib.api.exceptions.ParsePointException; |
62 | 59 |
import org.gvsig.vectorediting.lib.api.exceptions.ParseValueException; |
... | ... | |
69 | 66 |
|
70 | 67 |
public class DefaultEditingBehavior extends Behavior implements EditingBehavior { |
71 | 68 |
|
72 |
private static final Logger logger = LoggerFactory
|
|
73 |
.getLogger(DefaultEditingBehavior.class);
|
|
69 |
private static final Logger logger = LoggerFactory
|
|
70 |
.getLogger(DefaultEditingBehavior.class);
|
|
74 | 71 |
|
75 |
private Map<FLyrVect, EditingService> serviceRegistration;
|
|
72 |
private Map<FLyrVect, EditingService> serviceRegistration;
|
|
76 | 73 |
|
77 |
private MapControl mapControl;
|
|
74 |
private Stack<EditingService> serviceStack;
|
|
78 | 75 |
|
79 |
private FLyrVect currentLayer; |
|
80 |
private FeatureStore featureStore; |
|
81 |
private FeatureSelection featureSelection; |
|
76 |
private MapControl mapControl; |
|
82 | 77 |
|
83 |
private EditingService activeService;
|
|
78 |
private FLyrVect currentLayer;
|
|
84 | 79 |
|
85 |
private EditingServiceParameter currentParam;
|
|
80 |
private FeatureStore featureStore;
|
|
86 | 81 |
|
87 |
private Point adjustedPoint;
|
|
82 |
private EditingServiceParameter currentParam;
|
|
88 | 83 |
|
89 |
// private StatusBarListener sbl = null;
|
|
84 |
private Point adjustedPoint;
|
|
90 | 85 |
|
91 |
private JConsole console;
|
|
86 |
// private StatusBarListener sbl = null;
|
|
92 | 87 |
|
93 |
private JDockPanel dockConsole = null;
|
|
88 |
private JConsole console;
|
|
94 | 89 |
|
95 |
private boolean isShowConsole;
|
|
90 |
private JDockPanel dockConsole = null;
|
|
96 | 91 |
|
97 |
protected ResponseAdapter consoleResponseAdapter;
|
|
92 |
private boolean isShowConsole;
|
|
98 | 93 |
|
99 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
94 |
protected ResponseAdapter consoleResponseAdapter;
|
|
100 | 95 |
|
101 |
private EditingCompoundBehavior compoundBehavior;
|
|
96 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
|
102 | 97 |
|
103 |
private static final Image imageCursor = new BufferedImage(32, 32, |
|
104 |
BufferedImage.TYPE_INT_ARGB); |
|
105 |
static { |
|
106 |
Graphics g = imageCursor.getGraphics(); |
|
107 |
int size1 = 15; |
|
108 |
int x = 16; |
|
109 |
int y = 16; |
|
110 |
g.setColor(Color.MAGENTA); |
|
111 |
g.drawLine((x - size1), (y), (x + size1), (y)); |
|
112 |
g.drawLine((x), (y - size1), (x), (y + size1)); |
|
113 |
g.drawRect((x - 6), (y - 6), 12, 12); |
|
114 |
g.drawRect((x - 3), (y - 3), 6, 6); |
|
115 |
} |
|
98 |
private EditingCompoundBehavior compoundBehavior; |
|
116 | 99 |
|
117 |
private LayerListener layerListener = new LayerListener() { |
|
100 |
private static final Image imageCursor = new BufferedImage(32, 32, |
|
101 |
BufferedImage.TYPE_INT_ARGB); |
|
102 |
static { |
|
103 |
Graphics g = imageCursor.getGraphics(); |
|
104 |
int size1 = 15; |
|
105 |
int x = 16; |
|
106 |
int y = 16; |
|
107 |
g.setColor(Color.MAGENTA); |
|
108 |
g.drawLine((x - size1), (y), (x + size1), (y)); |
|
109 |
g.drawLine((x), (y - size1), (x), (y + size1)); |
|
110 |
g.drawRect((x - 6), (y - 6), 12, 12); |
|
111 |
g.drawRect((x - 3), (y - 3), 6, 6); |
|
112 |
} |
|
118 | 113 |
|
119 |
public void activationChanged(LayerEvent e) { |
|
120 |
FLayer layer = e.getSource(); |
|
121 |
if (layer instanceof FLyrVect) { |
|
114 |
private LayerListener layerListener = new LayerListener() { |
|
122 | 115 |
|
123 |
if (layer.isActive() && layer.isEditing()) { |
|
124 |
showConsole(); |
|
125 |
getMapControl().setTool("VectorEditing"); |
|
126 |
} else if (!layer.isEditing() && layer.isActive()) { |
|
127 |
// changeCurrentLayer((FLyrVect) layer); |
|
128 |
hideConsole(); |
|
129 |
getMapControl().setTool("zoomIn"); |
|
130 |
} |
|
131 |
try { |
|
132 |
changeCurrentLayer((FLyrVect) layer); |
|
133 |
} catch (ChangeCurrentLayerException e1) { |
|
134 |
logger.error(e1.getMessage(), e1); |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
116 |
public void activationChanged(LayerEvent e) { |
|
117 |
FLayer layer = e.getSource(); |
|
118 |
if (layer instanceof FLyrVect) { |
|
138 | 119 |
|
139 |
public void drawValueChanged(LayerEvent e) { |
|
140 |
} |
|
120 |
if (layer.isActive() && layer.isEditing()) { |
|
121 |
showConsole(); |
|
122 |
getMapControl().setTool("VectorEditing"); |
|
123 |
} |
|
124 |
else if (!layer.isEditing() && layer.isActive()) { |
|
125 |
// try{ |
|
126 |
// // changeCurrentLayer((FLyrVect) layer); |
|
127 |
// } |
|
128 |
// catch (ChangeCurrentLayerException e1) { |
|
129 |
// //TODO Auto-generated catch block |
|
130 |
// e1.printStackTrace(); |
|
131 |
// } |
|
132 |
hideConsole(); |
|
133 |
getMapControl().setTool("zoomIn"); |
|
134 |
} |
|
135 |
try { |
|
136 |
changeCurrentLayer((FLyrVect) layer); |
|
137 |
} |
|
138 |
catch (ChangeCurrentLayerException e1) { |
|
139 |
// TODO Auto-generated catch block |
|
140 |
e1.printStackTrace(); |
|
141 |
} |
|
141 | 142 |
|
142 |
public void editionChanged(LayerEvent e) { |
|
143 |
} |
|
143 |
} |
|
144 | 144 |
|
145 |
public void nameChanged(LayerEvent e) { |
|
146 |
} |
|
145 |
} |
|
147 | 146 |
|
148 |
public void visibilityChanged(LayerEvent e) { |
|
149 |
} |
|
150 |
}; |
|
147 |
public void drawValueChanged(LayerEvent e) {} |
|
151 | 148 |
|
152 |
public void cleanBehavior() { |
|
153 |
activeService = null; |
|
154 |
currentParam = null; |
|
155 |
this.enableSelection(false); |
|
149 |
public void editionChanged(LayerEvent e) {} |
|
156 | 150 |
|
157 |
showConsoleMessage("\n" + i18nManager.getTranslation("select_new_tool") |
|
158 |
+ "\n"); |
|
159 |
} |
|
151 |
public void nameChanged(LayerEvent e) {} |
|
160 | 152 |
|
161 |
public DefaultEditingBehavior(MapControl mapControl) |
|
162 |
throws CreateEditingBehaviorException { |
|
163 |
if (mapControl != null) { |
|
164 |
this.mapControl = mapControl; |
|
165 |
serviceRegistration = new HashMap<FLyrVect, EditingService>(); |
|
166 |
// sbl = new StatusBarListener(mapControl); |
|
167 |
initMapControlListeners(mapControl); |
|
168 |
initConsolePanelListeners(getConsolePanel()); |
|
169 |
FLayers layers = mapControl.getMapContext().getLayers(); |
|
170 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
171 |
if (layers.getLayer(i) instanceof FLyrVect |
|
172 |
&& layers.getLayer(i).isActive()) |
|
173 |
try { |
|
174 |
changeCurrentLayer((FLyrVect) layers.getLayer(i)); |
|
175 |
} catch (ChangeCurrentLayerException e) { |
|
176 |
throw new CreateEditingBehaviorException(e); |
|
177 |
} |
|
178 |
} |
|
153 |
public void visibilityChanged(LayerEvent e) {} |
|
154 |
}; |
|
179 | 155 |
|
180 |
} |
|
181 |
} |
|
156 |
public void cleanBehavior() { |
|
157 |
serviceStack.clear(); |
|
158 |
currentParam = null; |
|
159 |
this.enableSelection(false); |
|
182 | 160 |
|
183 |
private void initConsolePanelListeners(JConsole jConsole) { |
|
184 |
consoleResponseAdapter = new ResponseAdapter(); |
|
185 |
jConsole.addResponseListener(consoleResponseAdapter); |
|
186 |
addConsoleListener("ViewEditing", new ResponseListener() { |
|
161 |
showConsoleMessage("\n" + i18nManager.getTranslation("select_new_tool") |
|
162 |
+ "\n"); |
|
163 |
} |
|
187 | 164 |
|
188 |
public void acceptResponse(String response) { |
|
189 |
try { |
|
190 |
textEntered(response); |
|
191 |
} catch (InvalidEntryException e) { |
|
192 |
showConsoleMessage(i18nManager |
|
193 |
.getTranslation("invalid_option")); |
|
194 |
} catch (StopServiceException e) { |
|
195 |
logger.error(i18nManager |
|
196 |
.getTranslation("cant_stop_the_service")+ " " + activeService.getName(), e); |
|
197 |
} finally { |
|
198 |
if (activeService != null) { |
|
199 |
getNextParameter(); |
|
200 |
} |
|
201 |
} |
|
202 |
} |
|
203 |
}); |
|
165 |
public DefaultEditingBehavior(MapControl mapControl) |
|
166 |
throws CreateEditingBehaviorException { |
|
167 |
if (mapControl != null) { |
|
168 |
this.mapControl = mapControl; |
|
169 |
serviceRegistration = new HashMap<FLyrVect, EditingService>(); |
|
170 |
serviceStack = new Stack<EditingService>(); |
|
171 |
// sbl = new StatusBarListener(mapControl); |
|
172 |
initMapControlListeners(mapControl); |
|
173 |
initConsolePanelListeners(getConsolePanel()); |
|
174 |
FLayers layers = mapControl.getMapContext().getLayers(); |
|
175 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
176 |
if (layers.getLayer(i) instanceof FLyrVect |
|
177 |
&& layers.getLayer(i).isActive()) try { |
|
178 |
changeCurrentLayer((FLyrVect) layers.getLayer(i)); |
|
179 |
} |
|
180 |
catch (ChangeCurrentLayerException e) { |
|
181 |
throw new CreateEditingBehaviorException(e); |
|
182 |
} |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
204 | 186 |
|
205 |
} |
|
187 |
private void initConsolePanelListeners(JConsole jConsole) { |
|
188 |
consoleResponseAdapter = new ResponseAdapter(); |
|
189 |
jConsole.addResponseListener(consoleResponseAdapter); |
|
190 |
addConsoleListener("ViewEditing", new ResponseListener() { |
|
206 | 191 |
|
192 |
public void acceptResponse(String response) { |
|
193 |
try { |
|
194 |
textEntered(response); |
|
195 |
} |
|
196 |
catch (InvalidEntryException e) { |
|
197 |
showConsoleMessage(i18nManager.getTranslation("invalid_option")); |
|
198 |
} |
|
199 |
catch (StopServiceException e) { |
|
200 |
logger.error(i18nManager.getTranslation("cant_stop_the_service") |
|
201 |
+ " " + getActiveService().getName(), e); |
|
202 |
} |
|
203 |
finally { |
|
204 |
if (getActiveService() != null) { |
|
205 |
getNextParameter(); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
}); |
|
210 |
|
|
211 |
} |
|
212 |
|
|
207 | 213 |
public void activateService(String name) { |
208 | 214 |
|
209 |
EditingManager manager = EditingLocator.getManager();
|
|
215 |
EditingManager manager = EditingLocator.getManager();
|
|
210 | 216 |
|
211 |
if (currentLayer != null) { |
|
212 |
EditingService service = serviceRegistration.get(currentLayer); |
|
213 |
if (service == null || !service.getName().equals(name)) { |
|
214 |
service = (EditingService) manager.getEditingService(name, |
|
215 |
currentLayer.getFeatureStore()); |
|
216 |
serviceRegistration.put(currentLayer, service); |
|
217 |
} |
|
218 |
if (service != null) { |
|
219 |
this.enableSelection(false); |
|
220 |
this.activeService = service; |
|
221 |
try { |
|
222 |
service.start(); |
|
223 |
} catch (StartServiceException e) { |
|
224 |
logger.error(String.format("Can't start the service %(s)", |
|
225 |
service.getName()), e); |
|
226 |
} |
|
227 |
getNextParameter(); |
|
228 |
} |
|
229 |
} |
|
230 |
} |
|
217 |
if (currentLayer != null) { |
|
218 |
EditingService service = serviceRegistration.get(currentLayer); |
|
219 |
if (service == null || !service.getName().equals(name)) { |
|
220 |
service = (EditingService) manager.getEditingService(name, |
|
221 |
currentLayer.getFeatureStore()); |
|
222 |
serviceRegistration.put(currentLayer, service); |
|
223 |
} |
|
224 |
if (service != null) { |
|
225 |
this.enableSelection(false); |
|
226 |
try { |
|
227 |
service.start(); |
|
228 |
} |
|
229 |
catch (StartServiceException e) { |
|
230 |
logger.error( |
|
231 |
String.format("Can't start the service %(s)", service.getName()), |
|
232 |
e); |
|
233 |
} |
|
234 |
if (serviceStack.isEmpty() |
|
235 |
|| getActiveService().next().getTypes() |
|
236 |
.contains(EditingServiceParameter.TYPE.GEOMETRY)) { |
|
237 |
setActiveService(service); |
|
238 |
} |
|
239 |
else { |
|
240 |
serviceStack.clear(); |
|
241 |
setActiveService(service); |
|
242 |
} |
|
243 |
getNextParameter(); |
|
244 |
} |
|
245 |
} |
|
246 |
} |
|
231 | 247 |
|
232 | 248 |
/** |
233 | 249 |
* Shows description of parameter on console. |
234 | 250 |
*/ |
235 |
private void askQuestion(EditingServiceParameter param) {
|
|
236 |
if (getConsolePanel() != null) {
|
|
237 |
showConsoleMessage("\n#" + param.getDescription() + " > ");
|
|
238 |
}
|
|
239 |
}
|
|
251 |
private void askQuestion(EditingServiceParameter param) {
|
|
252 |
if (getConsolePanel() != null) {
|
|
253 |
showConsoleMessage("\n#" + param.getDescription() + " > ");
|
|
254 |
}
|
|
255 |
}
|
|
240 | 256 |
|
241 |
private void showConsoleMessage(String text) {
|
|
242 |
getConsolePanel().addText(text, JConsole.MESSAGE);
|
|
243 |
}
|
|
257 |
private void showConsoleMessage(String text) {
|
|
258 |
getConsolePanel().addText(text, JConsole.MESSAGE);
|
|
259 |
}
|
|
244 | 260 |
|
245 |
@Override
|
|
246 |
public ToolListener getListener() {
|
|
247 |
return new ToolListener() {
|
|
261 |
@Override
|
|
262 |
public ToolListener getListener() {
|
|
263 |
return new ToolListener() {
|
|
248 | 264 |
|
249 |
/**
|
|
265 |
/**
|
|
250 | 266 |
* |
251 | 267 |
*/ |
252 |
public boolean cancelDrawing() {
|
|
253 |
return false;
|
|
254 |
}
|
|
268 |
public boolean cancelDrawing() {
|
|
269 |
return false;
|
|
270 |
}
|
|
255 | 271 |
|
256 |
/**
|
|
272 |
/**
|
|
257 | 273 |
* |
258 | 274 |
*/ |
259 |
public Image getImageCursor() {
|
|
260 |
return imageCursor;
|
|
261 |
}
|
|
262 |
};
|
|
263 |
}
|
|
275 |
public Image getImageCursor() {
|
|
276 |
return imageCursor;
|
|
277 |
}
|
|
278 |
};
|
|
279 |
}
|
|
264 | 280 |
|
265 | 281 |
/** |
266 | 282 |
* Gets next parameter of {@link #activateService(String)} and sets |
267 | 283 |
* {@link #currentParam}. If currentParam is null means all service parameters |
268 | 284 |
* have value and service doesn't need more values. |
269 | 285 |
*/ |
270 |
private void getNextParameter() { |
|
271 |
currentParam = activeService.next(); |
|
272 |
if (currentParam == null) { |
|
273 |
finishAndStartService(); |
|
274 |
} else { |
|
275 |
askQuestion(currentParam); |
|
276 |
if (currentParam.getTypes().contains( |
|
277 |
EditingServiceParameter.TYPE.SELECTION)) { |
|
278 |
enableSelection(true); |
|
279 |
} |
|
280 |
setCaretPosition(); |
|
281 |
} |
|
286 |
private void getNextParameter() { |
|
287 |
currentParam = getActiveService().next(); |
|
288 |
if (currentParam == null) { |
|
289 |
finishService(); |
|
290 |
} |
|
291 |
else { |
|
292 |
askQuestion(currentParam); |
|
293 |
if (currentParam.getTypes().contains( |
|
294 |
EditingServiceParameter.TYPE.SELECTION)) { |
|
295 |
enableSelection(true); |
|
296 |
} |
|
297 |
setCaretPosition(); |
|
298 |
} |
|
282 | 299 |
|
283 |
}
|
|
300 |
}
|
|
284 | 301 |
|
285 |
private void finishAndStartService() { |
|
286 |
try { |
|
287 |
activeService.finish(); |
|
288 |
} catch (VectorEditingException e) { |
|
289 |
logger.error("An error ocurred when try to finish service", e); |
|
290 |
} |
|
291 |
mapControl.rePaintDirtyLayers(); |
|
292 |
try { |
|
293 |
activeService.start(); |
|
294 |
} catch (StartServiceException e) { |
|
295 |
logger.error( |
|
296 |
String.format("Can't start the service %(s)", |
|
297 |
activeService.getName()), e); |
|
298 |
} |
|
299 |
getNextParameter(); |
|
300 |
} |
|
302 |
private EditingService getActiveService() { |
|
303 |
if (!serviceStack.isEmpty()) { |
|
304 |
return serviceStack.peek(); |
|
305 |
} |
|
306 |
return null; |
|
307 |
} |
|
301 | 308 |
|
302 |
private void initMapControlListeners(MapControl mapControl) { |
|
309 |
private void setActiveService(EditingService service) { |
|
310 |
serviceStack.add(service); |
|
311 |
} |
|
303 | 312 |
|
304 |
MapContext context = mapControl.getMapContext(); |
|
305 |
FLayers layers = context.getLayers(); |
|
306 |
layers.addLayerListener(layerListener); |
|
313 |
private void initMapControlListeners(MapControl mapControl) { |
|
307 | 314 |
|
308 |
layers.addLayerCollectionListener(new LayerCollectionListener() { |
|
315 |
MapContext context = mapControl.getMapContext(); |
|
316 |
FLayers layers = context.getLayers(); |
|
317 |
layers.addLayerListener(layerListener); |
|
309 | 318 |
|
310 |
public void layerAdded(LayerCollectionEvent e) { |
|
311 |
FLayers layers2 = e.getLayers(); |
|
312 |
for (int i = 0; i < layers2.getLayersCount(); i++) { |
|
313 |
FLayer layer = layers2.getLayer(i); |
|
314 |
if (layer instanceof FLyrVect) { |
|
315 |
((FLyrVect) layer).addLayerListener(layerListener); |
|
316 |
} |
|
317 |
} |
|
318 |
} |
|
319 |
layers.addLayerCollectionListener(new LayerCollectionListener() { |
|
319 | 320 |
|
320 |
public void layerAdding(LayerCollectionEvent e) |
|
321 |
throws CancelationException { |
|
322 |
} |
|
321 |
public void layerAdded(LayerCollectionEvent e) { |
|
322 |
FLayers layers2 = e.getLayers(); |
|
323 |
for (int i = 0; i < layers2.getLayersCount(); i++) { |
|
324 |
FLayer layer = layers2.getLayer(i); |
|
325 |
if (layer instanceof FLyrVect) { |
|
326 |
((FLyrVect) layer).addLayerListener(layerListener); |
|
327 |
} |
|
328 |
} |
|
329 |
} |
|
323 | 330 |
|
324 |
public void layerMoved(LayerPositionEvent e) {
|
|
325 |
}
|
|
331 |
public void layerAdding(LayerCollectionEvent e)
|
|
332 |
throws CancelationException {}
|
|
326 | 333 |
|
327 |
public void layerMoving(LayerPositionEvent e) |
|
328 |
throws CancelationException { |
|
329 |
} |
|
334 |
public void layerMoved(LayerPositionEvent e) {} |
|
330 | 335 |
|
331 |
public void layerRemoved(LayerCollectionEvent e) { |
|
332 |
FLayers layers2 = e.getLayers(); |
|
333 |
for (int i = 0; i < layers2.getLayersCount(); i++) { |
|
334 |
FLayer layer = layers2.getLayer(i); |
|
335 |
if (layer instanceof FLyrVect) { |
|
336 |
((FLyrVect) layer).removeLayerListener(layerListener); |
|
337 |
} |
|
338 |
} |
|
339 |
} |
|
336 |
public void layerMoving(LayerPositionEvent e) throws CancelationException {} |
|
340 | 337 |
|
341 |
public void layerRemoving(LayerCollectionEvent e) |
|
342 |
throws CancelationException { |
|
343 |
} |
|
338 |
public void layerRemoved(LayerCollectionEvent e) { |
|
339 |
FLayers layers2 = e.getLayers(); |
|
340 |
for (int i = 0; i < layers2.getLayersCount(); i++) { |
|
341 |
FLayer layer = layers2.getLayer(i); |
|
342 |
if (layer instanceof FLyrVect) { |
|
343 |
((FLyrVect) layer).removeLayerListener(layerListener); |
|
344 |
} |
|
345 |
} |
|
346 |
} |
|
344 | 347 |
|
345 |
public void visibilityChanged(LayerCollectionEvent e) |
|
346 |
throws CancelationException { |
|
347 |
} |
|
348 |
}); |
|
349 |
} |
|
348 |
public void layerRemoving(LayerCollectionEvent e) |
|
349 |
throws CancelationException {} |
|
350 | 350 |
|
351 |
public void mouseClicked(MouseEvent e) { |
|
352 |
ViewPort vp = mapControl.getViewPort(); |
|
353 |
if (activeService != null) { |
|
354 |
if (currentParam != null) { |
|
355 |
List<TYPE> typesOfParam = currentParam.getTypes(); |
|
356 |
if (typesOfParam.contains(TYPE.LIST_POSITIONS)) { |
|
357 |
if (e.getClickCount() == 2) { |
|
358 |
finishAndStartService(); |
|
359 |
return; |
|
360 |
} |
|
361 |
Point point; |
|
362 |
point = vp.convertToMapPoint(e.getX(), e.getY()); |
|
363 |
try { |
|
364 |
this.activeService.value(point); |
|
365 |
} catch (VectorEditingException ex) { |
|
366 |
logger.error("Invalid value %s", new Object[] { point }); |
|
367 |
} |
|
368 |
} |
|
369 |
if (typesOfParam.contains(TYPE.POSITION)) { |
|
370 |
Point point; |
|
371 |
point = vp.convertToMapPoint(e.getX(), e.getY()); |
|
372 |
try { |
|
373 |
this.activeService.value(point); |
|
374 |
} catch (VectorEditingException ex) { |
|
375 |
logger.error("Invalid value %s", new Object[] { point }); |
|
376 |
} |
|
377 |
// TODO: Comprobar el resto de casos: |
|
378 |
// TYPE.VALUE, |
|
379 |
// TYPE.OPTION, TYPE.SELECTION, |
|
380 |
// TYPE.GEOMETRY: |
|
381 |
} |
|
382 |
if (typesOfParam.contains(TYPE.SELECTION)) { |
|
383 |
// Do nothing |
|
384 |
} |
|
351 |
public void visibilityChanged(LayerCollectionEvent e) |
|
352 |
throws CancelationException {} |
|
353 |
}); |
|
354 |
} |
|
385 | 355 |
|
386 |
getNextParameter(); |
|
387 |
} |
|
388 |
} |
|
389 |
} |
|
356 |
public void mouseClicked(MouseEvent e) { |
|
357 |
ViewPort vp = mapControl.getViewPort(); |
|
358 |
if (getActiveService() != null) { |
|
359 |
if (currentParam != null) { |
|
360 |
List<TYPE> typesOfParam = currentParam.getTypes(); |
|
361 |
if (typesOfParam.contains(TYPE.LIST_POSITIONS)) { |
|
362 |
if (e.getClickCount() == 2) { |
|
363 |
finishService(); |
|
364 |
return; |
|
365 |
} |
|
366 |
Point point; |
|
367 |
point = vp.convertToMapPoint(e.getX(), e.getY()); |
|
368 |
try { |
|
369 |
getActiveService().value(point); |
|
370 |
} |
|
371 |
catch (VectorEditingException ex) { |
|
372 |
logger.error("Invalid value %s", new Object[] { point }); |
|
373 |
} |
|
374 |
} |
|
375 |
if (typesOfParam.contains(TYPE.POSITION)) { |
|
376 |
Point point; |
|
377 |
point = vp.convertToMapPoint(e.getX(), e.getY()); |
|
378 |
try { |
|
379 |
getActiveService().value(point); |
|
380 |
} |
|
381 |
catch (VectorEditingException ex) { |
|
382 |
logger.error("Invalid value %s", new Object[] { point }); |
|
383 |
} |
|
384 |
} |
|
385 |
if (typesOfParam.contains(TYPE.SELECTION)) { |
|
386 |
// Do nothing |
|
387 |
} |
|
388 |
getNextParameter(); |
|
389 |
} |
|
390 |
} |
|
391 |
} |
|
390 | 392 |
|
391 |
public void mouseEntered(MouseEvent e) throws BehaviorException { |
|
392 |
// TODO Auto-generated method stub |
|
393 |
} |
|
393 |
private void finishService() { |
|
394 |
EditingService lastService = serviceStack.pop(); |
|
395 |
try { |
|
396 |
if (serviceStack.isEmpty()) { |
|
397 |
lastService.finishAndStore(); |
|
398 |
mapControl.rePaintDirtyLayers(); |
|
399 |
setActiveService(lastService); |
|
400 |
} |
|
401 |
else if (getActiveService().next().getTypes() |
|
402 |
.contains(EditingServiceParameter.TYPE.GEOMETRY)) { |
|
403 |
Object geometry = lastService.finish(); |
|
404 |
getActiveService().value(geometry); |
|
405 |
} |
|
406 |
lastService.stop(); |
|
407 |
lastService.start(); |
|
408 |
} |
|
409 |
catch (InvalidEntryException ex) { |
|
410 |
showConsoleMessage(i18nManager.getTranslation("invalid_option")); |
|
411 |
} |
|
412 |
catch (FinishServiceException ex) { |
|
413 |
logger.error("", ex); |
|
414 |
} |
|
415 |
catch (StopServiceException ex) { |
|
416 |
logger.error("", ex); |
|
417 |
} |
|
418 |
catch (StartServiceException ex) { |
|
419 |
logger.error("", ex); |
|
420 |
} |
|
421 |
getNextParameter(); |
|
422 |
} |
|
394 | 423 |
|
395 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
396 |
ViewPort vp = mapControl.getViewPort(); |
|
397 |
adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY()); |
|
398 |
// showCoords(e.getPoint()); |
|
424 |
public void mouseEntered(MouseEvent e) throws BehaviorException {} |
|
399 | 425 |
|
400 |
getMapControl().repaint(); |
|
401 |
} |
|
426 |
public void mouseMoved(MouseEvent e) throws BehaviorException { |
|
427 |
ViewPort vp = mapControl.getViewPort(); |
|
428 |
adjustedPoint = vp.convertToMapPoint(e.getX(), e.getY()); |
|
429 |
// showCoords(e.getPoint()); |
|
430 |
getMapControl().repaint(); |
|
431 |
} |
|
402 | 432 |
|
403 |
public void mousePressed(MouseEvent e) throws BehaviorException { |
|
404 |
// TODO Auto-generated method stub |
|
405 |
} |
|
433 |
public void mousePressed(MouseEvent e) throws BehaviorException {} |
|
406 | 434 |
|
407 |
public void mouseReleased(MouseEvent e) throws BehaviorException { |
|
408 |
// TODO Auto-generated method stub |
|
409 |
} |
|
435 |
public void mouseReleased(MouseEvent e) throws BehaviorException {} |
|
410 | 436 |
|
411 |
public void paintComponent(MapControlDrawer mapControlDrawer) {
|
|
412 |
super.paintComponent(mapControlDrawer);
|
|
413 |
if (activeService == null || adjustedPoint == null) {
|
|
414 |
return;
|
|
415 |
}
|
|
437 |
public void paintComponent(MapControlDrawer mapControlDrawer) {
|
|
438 |
super.paintComponent(mapControlDrawer);
|
|
439 |
if (getActiveService() == null || adjustedPoint == null) {
|
|
440 |
return;
|
|
441 |
}
|
|
416 | 442 |
|
417 |
DrawingStatus helperGeo = null; |
|
418 |
try { |
|
419 |
helperGeo = activeService.draw(adjustedPoint); |
|
420 |
} catch (VectorEditingException e) { |
|
421 |
logger.error("An error ocurred when draw service geometries", e); |
|
422 |
} |
|
423 |
if (helperGeo != null) { |
|
443 |
DrawingStatus helperGeo = null; |
|
444 |
try { |
|
445 |
helperGeo = getActiveService().draw(adjustedPoint); |
|
446 |
} |
|
447 |
catch (VectorEditingException e) { |
|
448 |
logger.error("An error ocurred when draw service geometries", e); |
|
449 |
} |
|
450 |
if (helperGeo != null) { |
|
424 | 451 |
for (@SuppressWarnings("rawtypes") |
425 | 452 |
Iterator iterator = helperGeo.getGeometries().iterator(); iterator |
426 |
.hasNext();) { |
|
427 |
Geometry geometry = (Geometry) iterator.next(); |
|
428 |
mapControl.getMapControlDrawer().draw( |
|
429 |
geometry, |
|
430 |
MapControlLocator.getMapControlManager() |
|
431 |
.getAxisReferenceSymbol()); |
|
432 |
} |
|
433 |
} |
|
434 |
} |
|
453 |
.hasNext();) { |
|
454 |
Geometry geometry = (Geometry) iterator.next(); |
|
455 |
mapControl.getMapControlDrawer().draw(geometry, |
|
456 |
MapControlLocator.getMapControlManager().getAxisReferenceSymbol()); |
|
457 |
} |
|
458 |
} |
|
459 |
} |
|
435 | 460 |
|
436 |
private void setCaretPosition() {
|
|
461 |
private void setCaretPosition() {
|
|
437 | 462 |
|
438 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
|
439 |
jeta.requestFocusInWindow(); |
|
440 |
jeta.setCaretPosition(jeta.getText().length()); |
|
463 |
JEditTextArea jeta = getConsolePanel().getTxt(); |
|
464 |
jeta.requestFocusInWindow(); |
|
465 |
jeta.setCaretPosition(jeta.getText().length()); |
Also available in: Unified diff