svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.exportto / org.gvsig.exportto.lib / org.gvsig.exportto.lib.api / src / main / java / org / gvsig / export / spi / AbstractExportParametersGeometry.java @ 44411
History | View | Annotate | Download (8.8 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.spi; |
7 |
|
8 |
import org.cresques.cts.ICoordTrans; |
9 |
import org.cresques.cts.IProjection; |
10 |
import org.gvsig.export.ExportParameters; |
11 |
import org.gvsig.fmap.geom.GeometryLocator; |
12 |
import org.gvsig.fmap.geom.GeometryManager; |
13 |
import org.gvsig.fmap.geom.type.GeometryType; |
14 |
import org.gvsig.export.ExportParametersGeometry; |
15 |
import org.gvsig.tools.ToolsLocator; |
16 |
import org.gvsig.tools.dynobject.DynStruct; |
17 |
import org.gvsig.tools.persistence.PersistenceManager; |
18 |
import org.gvsig.tools.persistence.PersistentState; |
19 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
20 |
|
21 |
/**
|
22 |
*
|
23 |
* @author jjdelcerro
|
24 |
*/
|
25 |
public abstract class AbstractExportParametersGeometry |
26 |
extends AbstractExportParameters
|
27 |
implements ExportParametersGeometry {
|
28 |
|
29 |
private IProjection contextProjection;
|
30 |
private IProjection sourceProjection;
|
31 |
private IProjection targetProjection;
|
32 |
|
33 |
private ICoordTrans sourceTransformation;
|
34 |
private ICoordTrans targetTransformation;
|
35 |
|
36 |
private int geometryChecks; |
37 |
private int geometryChecksAction; |
38 |
private boolean tryToFixGeometry; |
39 |
private String geometryFieldName; |
40 |
private int geometryType; |
41 |
private int geometrySubtype; |
42 |
|
43 |
public AbstractExportParametersGeometry(ExportServiceFactory factory) {
|
44 |
super(factory);
|
45 |
} |
46 |
|
47 |
@Override
|
48 |
public boolean needsSelectTargetProjection() { |
49 |
return true; |
50 |
} |
51 |
|
52 |
@Override
|
53 |
public void setContextProjection(IProjection projection) { |
54 |
this.contextProjection = projection;
|
55 |
} |
56 |
|
57 |
@Override
|
58 |
public IProjection getContextProjection() {
|
59 |
return this.contextProjection; |
60 |
} |
61 |
|
62 |
@Override
|
63 |
public void setSourceProjection(IProjection sourceProjection) { |
64 |
this.sourceProjection = sourceProjection;
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
public IProjection getSourceProjection() {
|
69 |
return sourceProjection;
|
70 |
} |
71 |
|
72 |
@Override
|
73 |
public ICoordTrans getSourceTransformation() {
|
74 |
return sourceTransformation;
|
75 |
} |
76 |
|
77 |
@Override
|
78 |
public void setSourceTransformation(ICoordTrans contextTransformation) { |
79 |
this.sourceTransformation = contextTransformation;
|
80 |
} |
81 |
|
82 |
@Override
|
83 |
public void setTargetProjection(IProjection targetProjection) { |
84 |
this.targetProjection = targetProjection;
|
85 |
} |
86 |
|
87 |
@Override
|
88 |
public IProjection getTargetProjection() {
|
89 |
if (this.targetProjection == null) { |
90 |
return this.sourceProjection; |
91 |
} |
92 |
return this.targetProjection; |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public void setTargetTransformation(ICoordTrans transformation) { |
97 |
this.targetTransformation = transformation;
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public ICoordTrans getTargetTransformation() {
|
102 |
return targetTransformation;
|
103 |
} |
104 |
|
105 |
@Override
|
106 |
public int getGeometryChecks() { |
107 |
return this.geometryChecks; |
108 |
} |
109 |
|
110 |
@Override
|
111 |
public int getGeometryChecksAction() { |
112 |
return this.geometryChecksAction; |
113 |
} |
114 |
|
115 |
@Override
|
116 |
public boolean getTryToFixGeometry() { |
117 |
return this.tryToFixGeometry; |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public void setGeometryChecks(int geometryChecks) { |
122 |
this.geometryChecks = geometryChecks;
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public void setGeometryChecksAction(int geometryChecksAction) { |
127 |
this.geometryChecksAction = geometryChecksAction;
|
128 |
} |
129 |
|
130 |
@Override
|
131 |
public void setTryToFixGeometry(boolean tryToFixGeometry) { |
132 |
this.tryToFixGeometry = tryToFixGeometry;
|
133 |
} |
134 |
|
135 |
@Override
|
136 |
public String getSourceGeometryFieldName() { |
137 |
return this.geometryFieldName; |
138 |
} |
139 |
|
140 |
@Override
|
141 |
public void setSourceGeometryFieldName(String geometryFieldName) { |
142 |
this.geometryFieldName = geometryFieldName;
|
143 |
} |
144 |
|
145 |
@Override
|
146 |
public int getTargetGeometryTypeAsInt() { |
147 |
return geometryType;
|
148 |
} |
149 |
|
150 |
@Override
|
151 |
public int getTargetGeometrySubtype() { |
152 |
return geometrySubtype;
|
153 |
} |
154 |
|
155 |
@Override
|
156 |
public void setTargetGeometryType(int geometryType) { |
157 |
this.geometryType = geometryType;
|
158 |
} |
159 |
|
160 |
@Override
|
161 |
public void setTargetGeometrySubtype(int subtype) { |
162 |
this.geometrySubtype = subtype;
|
163 |
} |
164 |
|
165 |
@Override
|
166 |
public void setTargetGeometryType(GeometryType type) { |
167 |
this.geometryType = type.getType();
|
168 |
this.geometrySubtype = type.getSubType();
|
169 |
} |
170 |
|
171 |
@Override
|
172 |
public GeometryType getTargetGeometryType() {
|
173 |
try {
|
174 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
175 |
GeometryType type = geomManager.getGeometryType( |
176 |
geometryType, |
177 |
geometryType |
178 |
); |
179 |
return type;
|
180 |
} catch (Exception ex) { |
181 |
throw new RuntimeException("Can't create geoemtry type from type " + geometryType + ", subtype " + geometrySubtype + ".", ex); |
182 |
} |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public ExportParameters clone() throws CloneNotSupportedException { |
187 |
AbstractExportParametersGeometry clone = (AbstractExportParametersGeometry) super.clone();
|
188 |
clone.setContextProjection(this.contextProjection);
|
189 |
clone.setSourceProjection(this.sourceProjection);
|
190 |
clone.setTargetProjection(this.targetProjection);
|
191 |
clone.setSourceTransformation(this.sourceTransformation);
|
192 |
clone.setTargetTransformation(this.targetTransformation);
|
193 |
clone.setSourceGeometryFieldName(this.geometryFieldName);
|
194 |
clone.setGeometryChecks(this.geometryChecks);
|
195 |
clone.setGeometryChecksAction(this.geometryChecksAction);
|
196 |
clone.setTryToFixGeometry(this.tryToFixGeometry);
|
197 |
clone.setTargetGeometryType(this.geometryType);
|
198 |
clone.setTargetGeometrySubtype(this.geometrySubtype);
|
199 |
return clone;
|
200 |
} |
201 |
|
202 |
public static void registerPersistence() { |
203 |
|
204 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
205 |
if (manager.getDefinition("AbstractExportParametersGeometry") == null) { |
206 |
DynStruct definition = manager.addDefinition(AbstractExportParametersGeometry.class, |
207 |
"AbstractExportParametersGeometry", "AbstractExportParametersGeometry persistence definition", null, null); |
208 |
definition.addDynFieldObject("contextProjection").setClassOfValue(IProjection.class);
|
209 |
definition.addDynFieldObject("sourceProjection").setClassOfValue(IProjection.class);
|
210 |
definition.addDynFieldObject("targetProjection").setClassOfValue(IProjection.class);
|
211 |
definition.addDynFieldObject("sourceTransformation").setClassOfValue(ICoordTrans.class);
|
212 |
definition.addDynFieldObject("targetTransformation").setClassOfValue(ICoordTrans.class);
|
213 |
definition.addDynFieldInt("geometryChecks");
|
214 |
definition.addDynFieldInt("geometryChecksAction");
|
215 |
definition.addDynFieldBoolean("tryToFixGeometry");
|
216 |
definition.addDynFieldString("geometryFieldName");
|
217 |
definition.addDynFieldInt("geometryType");
|
218 |
definition.addDynFieldInt("geometrySubtype");
|
219 |
definition.extend(manager.getDefinition("AbstractExportParameters"));
|
220 |
} |
221 |
} |
222 |
|
223 |
public void saveToState(PersistentState state) throws PersistenceException { |
224 |
super.saveToState(state);
|
225 |
state.set("contextProjection", this.contextProjection); |
226 |
state.set("sourceProjection", this.sourceProjection); |
227 |
state.set("targetProjection", this.targetProjection); |
228 |
state.set("sourceTransformation", this.sourceTransformation); |
229 |
state.set("targetTransformation", this.targetTransformation); |
230 |
state.set("geometryChecks", this.geometryChecks); |
231 |
state.set("geometryChecksAction", this.geometryChecksAction); |
232 |
state.set("tryToFixGeometry", this.tryToFixGeometry); |
233 |
state.set("geometryFieldName", this.geometryFieldName); |
234 |
state.set("geometryType", this.geometryType); |
235 |
state.set("geometrySubtype", this.geometrySubtype); |
236 |
} |
237 |
|
238 |
public void loadFromState(PersistentState state) throws PersistenceException { |
239 |
super.loadFromState(state);
|
240 |
this.contextProjection = (IProjection) state.get("contextProjection"); |
241 |
this.sourceProjection = (IProjection) state.get("sourceProjection"); |
242 |
this.targetProjection = (IProjection) state.get("targetProjection"); |
243 |
this.sourceTransformation = (ICoordTrans) state.get("sourceTransformation"); |
244 |
this.targetTransformation = (ICoordTrans) state.get("targetTransformation"); |
245 |
this.geometryChecks = state.getInt("geometryChecks"); |
246 |
this.geometryChecksAction = state.getInt("geometryChecksAction"); |
247 |
this.tryToFixGeometry = state.getBoolean("tryToFixGeometry"); |
248 |
this.geometryFieldName = state.getString("geometryFieldName"); |
249 |
this.geometryType = state.getInt("geometryType"); |
250 |
this.geometrySubtype = state.getInt("geometrySubtype"); |
251 |
} |
252 |
|
253 |
} |