gvsig-lrs / org.gvsig.lrs / trunk / org.gvsig.lrs / org.gvsig.lrs.swing / org.gvsig.lrs.swing.impl / src / main / java / org / gvsig / lrs / swing / impl / JLrsCalibrateRouteParamsController.java @ 16
History | View | Annotate | Download (25.5 KB)
1 |
/*
|
---|---|
2 |
* Copyright 2015 DiSiD Technologies S.L.L. All rights reserved.
|
3 |
*
|
4 |
* Project : DiSiD org.gvsig.lrs.swing.impl
|
5 |
* SVN Id : $Id$
|
6 |
*/
|
7 |
package org.gvsig.lrs.swing.impl; |
8 |
|
9 |
import java.awt.event.ActionEvent; |
10 |
import java.awt.event.ActionListener; |
11 |
import java.awt.event.ItemEvent; |
12 |
import java.awt.event.ItemListener; |
13 |
import java.io.File; |
14 |
import java.util.Iterator; |
15 |
import java.util.Locale; |
16 |
|
17 |
import javax.swing.ComboBoxModel; |
18 |
import javax.swing.DefaultComboBoxModel; |
19 |
import javax.swing.JComponent; |
20 |
import javax.swing.JOptionPane; |
21 |
import javax.swing.ListCellRenderer; |
22 |
|
23 |
import org.apache.commons.io.FileUtils; |
24 |
import org.apache.commons.lang3.StringUtils; |
25 |
import org.cresques.cts.IProjection; |
26 |
import org.gvsig.fmap.dal.DALLocator; |
27 |
import org.gvsig.fmap.dal.DataManager; |
28 |
import org.gvsig.fmap.dal.DataStoreParameters; |
29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.exception.ReadException; |
31 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
32 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
33 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
34 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
35 |
import org.gvsig.fmap.dal.feature.FeatureType; |
36 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
37 |
import org.gvsig.fmap.dal.store.shp.SHPNewStoreParameters; |
38 |
import org.gvsig.fmap.geom.DataTypes; |
39 |
import org.gvsig.fmap.geom.Geometry; |
40 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
41 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
42 |
import org.gvsig.fmap.geom.GeometryException; |
43 |
import org.gvsig.fmap.geom.GeometryLocator; |
44 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
45 |
import org.gvsig.fmap.mapcontext.layers.operations.LayerCollection; |
46 |
import org.gvsig.fmap.mapcontext.layers.operations.LayersVisitor; |
47 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
48 |
import org.gvsig.lrs.lib.api.DistanceUnits; |
49 |
import org.gvsig.lrs.lib.api.LrsAlgorithmParams; |
50 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsLocator; |
51 |
import org.gvsig.lrs.lib.api.LrsAlgorithmsManager; |
52 |
import org.gvsig.lrs.lib.api.LrsCalibrateRouteAlgorithmParams; |
53 |
import org.gvsig.lrs.lib.api.LrsMeasureCalculationMethods; |
54 |
import org.gvsig.lrs.lib.api.exceptions.LrsGettingParametersException; |
55 |
import org.gvsig.lrs.lib.api.exceptions.LrsNeededParameterException; |
56 |
import org.gvsig.lrs.swing.api.JLrsAlgorithmParams; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.exception.BaseException; |
59 |
import org.gvsig.tools.i18n.I18nManager; |
60 |
import org.gvsig.tools.locator.LocatorException; |
61 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
62 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
63 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
64 |
import org.gvsig.tools.visitor.VisitCanceledException; |
65 |
import org.slf4j.Logger; |
66 |
import org.slf4j.LoggerFactory; |
67 |
|
68 |
public class JLrsCalibrateRouteParamsController extends JLrsCalibrateRouteParamsView implements JLrsAlgorithmParams{ |
69 |
|
70 |
/**
|
71 |
*
|
72 |
*/
|
73 |
private static final long serialVersionUID = -9145489136943076981L; |
74 |
|
75 |
private static final Logger logger = LoggerFactory.getLogger(JLrsCalibrateRouteParamsController.class); |
76 |
|
77 |
private boolean canceled; |
78 |
private ActionListenerSupport listeners = ToolsSwingLocator.getToolsSwingManager().createActionListenerSupport();
|
79 |
|
80 |
private LayerCollection layers;
|
81 |
|
82 |
/**
|
83 |
* @param layers
|
84 |
* @throws LrsNeededParameterException
|
85 |
*
|
86 |
*/
|
87 |
public JLrsCalibrateRouteParamsController(LayerCollection layers, LrsAlgorithmParams params) throws LrsNeededParameterException { |
88 |
super();
|
89 |
this.layers = layers;
|
90 |
initComponents(); |
91 |
translate(); |
92 |
setParams(params); |
93 |
} |
94 |
|
95 |
public void addActionListener(ActionListener listener) { |
96 |
listeners.addActionListener(listener); |
97 |
} |
98 |
|
99 |
public void removeActionListener(ActionListener listener) { |
100 |
listeners.removeActionListener(listener); |
101 |
} |
102 |
|
103 |
private void translate() { |
104 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
105 |
|
106 |
lblInputLayer.setText(i18nManager.getTranslation(lblInputLayer.getText())); |
107 |
lblIdRouteField.setText(i18nManager.getTranslation(lblIdRouteField.getText())); |
108 |
lblCalibratePointLayer.setText(i18nManager.getTranslation(lblCalibratePointLayer.getText())); |
109 |
lblCalibrationPointIdRouteField.setText(i18nManager.getTranslation(lblCalibrationPointIdRouteField.getText())); |
110 |
lblFromMeasureField.setText(i18nManager.getTranslation(lblFromMeasureField.getText())); |
111 |
lblOutputFile.setText(i18nManager.getTranslation(lblOutputFile.getText())); |
112 |
lblMeasureCalcMethod.setText(i18nManager.getTranslation(lblMeasureCalcMethod.getText())); |
113 |
lblSearchRadius.setText(i18nManager.getTranslation(lblSearchRadius.getText())); |
114 |
lblMeasureUnits.setText(i18nManager.getTranslation(lblMeasureUnits.getText())); |
115 |
chkInterpolateBetweenCalibrationPoints.setText(i18nManager.getTranslation(chkInterpolateBetweenCalibrationPoints.getText())); |
116 |
chkExtrapolateBeforeCalibrationPoints.setText(i18nManager.getTranslation(chkExtrapolateBeforeCalibrationPoints.getText())); |
117 |
chkExtrapolateAfterCalibrationPoints.setText(i18nManager.getTranslation(chkExtrapolateAfterCalibrationPoints.getText())); |
118 |
chkIgnoreSpatialGaps.setText(i18nManager.getTranslation(chkIgnoreSpatialGaps.getText())); |
119 |
chkIncludeAll.setText(i18nManager.getTranslation(chkIncludeAll.getText())); |
120 |
btnBrowser.setText("\u2026");
|
121 |
btnAccept.setText(i18nManager.getTranslation(btnAccept.getText())); |
122 |
btnCancel.setText(i18nManager.getTranslation(btnCancel.getText())); |
123 |
|
124 |
} |
125 |
|
126 |
/**
|
127 |
*
|
128 |
*/
|
129 |
public void setLocate(Locale locale) { |
130 |
Locale l = super.getLocale(); |
131 |
if (!l.equals(locale)) {
|
132 |
translate(); |
133 |
} |
134 |
super.setLocale(locale);
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Validates the layers:
|
139 |
* - At least 2 layers
|
140 |
* - At least 1 curve layer with at least 1 non-geometric field
|
141 |
* - At least 1 point layer with at least 1 non-geometric field and 1 numeric field
|
142 |
* if they are not correct throws an exception
|
143 |
* @throws LrsNeededParameterException
|
144 |
*/
|
145 |
public static void validateLayers(LayerCollection layers)throws LrsNeededParameterException { |
146 |
logger.debug("Validating layers for Calibrate Route");
|
147 |
if (layers==null||layers.getLayersCount()<2){ |
148 |
logger.error("Two or more layers are needed");
|
149 |
throw new LrsNeededParameterException("two_or_more_layers_are_needed", null); |
150 |
} |
151 |
|
152 |
if (!JLrsUtilsController.validatedCurveAndPointLayer(layers)){
|
153 |
logger.error("Impossible to find the layers needed");
|
154 |
throw new LrsNeededParameterException("impossible_to_find_needed_layers",null); |
155 |
} |
156 |
} |
157 |
|
158 |
/**
|
159 |
* @throws LrsNeededParameterException
|
160 |
*/
|
161 |
private void initComponents() throws LrsNeededParameterException { |
162 |
|
163 |
validateLayers(layers); |
164 |
|
165 |
// Modelos de los combos
|
166 |
FLayersComboBoxModel inputLayerModel = new FLayersComboBoxModel(this.layers); |
167 |
FeatureAttributeDescriptorsComboBoxModel idRouteFieldComboBoxModel = |
168 |
new FeatureAttributeDescriptorsComboBoxModel();
|
169 |
|
170 |
PointLayersComboBoxModel calibratePointLayerModel = new PointLayersComboBoxModel(this.layers); |
171 |
FeatureAttributeDescriptorsComboBoxModel idCalibrationPointFieldComboBoxModel = |
172 |
new FeatureAttributeDescriptorsComboBoxModel();
|
173 |
FeatureAttributeDescriptorsComboBoxModel fromMeasureFieldComboBoxModel = |
174 |
new FeatureAttributeDescriptorsComboBoxModel();
|
175 |
|
176 |
|
177 |
// Renderer para los combos de attributeDescriptors
|
178 |
ListCellRenderer featureAttributeDescriptorCellRenderer = new FLayersAttributeDescriptorCellRenderer(); |
179 |
// asignaci?n de renderers y modelos
|
180 |
cmbIdRouteField.setRenderer(featureAttributeDescriptorCellRenderer); |
181 |
cmbCalibrationPointIdRouteField.setRenderer(featureAttributeDescriptorCellRenderer); |
182 |
cmbFromMeasureField.setRenderer(featureAttributeDescriptorCellRenderer); |
183 |
cmbIdRouteField.setModel(idRouteFieldComboBoxModel); |
184 |
cmbCalibrationPointIdRouteField.setModel(idCalibrationPointFieldComboBoxModel); |
185 |
cmbFromMeasureField.setModel(fromMeasureFieldComboBoxModel); |
186 |
|
187 |
// renderer para el combo de capas
|
188 |
ListCellRenderer layerNameCellRenderer=new FLayersLayerNameCellRenderer(); |
189 |
cmbInputLayer.setRenderer(layerNameCellRenderer); |
190 |
cmbCalibratePointLayer.setRenderer(layerNameCellRenderer); |
191 |
// asignaci?n modelo al combo de capas
|
192 |
cmbInputLayer.setModel(inputLayerModel); |
193 |
cmbCalibratePointLayer.setModel(calibratePointLayerModel); |
194 |
// listener del combo de capas para que actualice el resto de
|
195 |
// componentes
|
196 |
cmbInputLayer.addItemListener(new ItemListener() { |
197 |
|
198 |
public void itemStateChanged(ItemEvent e) { |
199 |
Object item = e.getItem();
|
200 |
if (item instanceof FLyrVect) { |
201 |
FLyrVect layer = (FLyrVect) item; |
202 |
updateLayerSource(layer); |
203 |
} |
204 |
} |
205 |
}); |
206 |
cmbCalibratePointLayer.addItemListener(new ItemListener() { |
207 |
|
208 |
public void itemStateChanged(ItemEvent e) { |
209 |
Object item = e.getItem();
|
210 |
if (item instanceof FLyrVect) { |
211 |
FLyrVect layer = (FLyrVect) item; |
212 |
updateLayerCalibratePoint(layer); |
213 |
} |
214 |
} |
215 |
}); |
216 |
|
217 |
ComboBoxModel<LrsMeasureCalculationMethods> measureCalculationMethodsModel =
|
218 |
new DefaultComboBoxModel<LrsMeasureCalculationMethods>(LrsMeasureCalculationMethods.values()); |
219 |
|
220 |
cmbMeasureCalcMethod.setModel(measureCalculationMethodsModel); |
221 |
|
222 |
ComboBoxModel<DistanceUnits> measureUnitsModel =
|
223 |
new DefaultComboBoxModel<DistanceUnits>(DistanceUnits.values()); |
224 |
|
225 |
cmbMeasureUnits.setModel(measureUnitsModel); |
226 |
|
227 |
txtSearchRadius.setValue(new Double(0)); |
228 |
|
229 |
this.btnBrowser.addActionListener(new ActionListener() { |
230 |
|
231 |
public void actionPerformed(ActionEvent e) { |
232 |
doSelectOuputFile(); |
233 |
} |
234 |
}); |
235 |
|
236 |
this.btnAccept.addActionListener(new ActionListener() { |
237 |
|
238 |
public void actionPerformed(ActionEvent e) { |
239 |
canceled = false;
|
240 |
doClose(); |
241 |
listeners.fireActionEvent(new ActionEvent(JLrsCalibrateRouteParamsController.this, 0, "accept")); |
242 |
|
243 |
} |
244 |
}); |
245 |
|
246 |
this.btnCancel.addActionListener(new ActionListener() { |
247 |
|
248 |
public void actionPerformed(ActionEvent e) { |
249 |
canceled = true;
|
250 |
doClose(); |
251 |
listeners.fireActionEvent(new ActionEvent(JLrsCalibrateRouteParamsController.this, 0, "cancel")); |
252 |
} |
253 |
}); |
254 |
|
255 |
setVisibleAceptCancel(false);
|
256 |
canceled = false;
|
257 |
} |
258 |
|
259 |
private void doSelectOuputFile() { |
260 |
final I18nManager i18nManager = ToolsLocator.getI18nManager();
|
261 |
ThreadSafeDialogsManager manager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
262 |
File[] files = manager.showSaveFileDialog(i18nManager.getTranslation("output_file"), null); |
263 |
if (files != null && files.length > 0) { |
264 |
File file = files[0]; |
265 |
String absolutePath = file.getAbsolutePath();
|
266 |
if(!StringUtils.endsWithIgnoreCase(absolutePath, ".shp")){ |
267 |
absolutePath = new StringBuilder().append(absolutePath).append(".shp").toString(); |
268 |
} |
269 |
File outputFile = FileUtils.getFile(absolutePath);
|
270 |
if(outputFile.exists()) {
|
271 |
int resp = JOptionPane.showOptionDialog( |
272 |
this.asJComponent(),
|
273 |
i18nManager.getTranslation("file_already_exists_do_you_want_overwrite_it"),
|
274 |
i18nManager.getTranslation("output_file"),
|
275 |
JOptionPane.OK_CANCEL_OPTION,
|
276 |
JOptionPane.QUESTION_MESSAGE,
|
277 |
null,
|
278 |
null,
|
279 |
JOptionPane.OK_OPTION);
|
280 |
if (resp == JOptionPane.OK_OPTION){ |
281 |
this.txtOutputFile.setText(absolutePath);
|
282 |
} else {
|
283 |
doSelectOuputFile(); |
284 |
} |
285 |
} else {
|
286 |
this.txtOutputFile.setText(absolutePath);
|
287 |
} |
288 |
} |
289 |
|
290 |
} |
291 |
|
292 |
private void doClose() { |
293 |
this.setVisible(false); |
294 |
} |
295 |
|
296 |
public boolean isCanceled() { |
297 |
return this.canceled; |
298 |
} |
299 |
|
300 |
public void setVisibleAceptCancel(boolean visible) { |
301 |
this.btnAccept.setVisible(visible);
|
302 |
this.btnCancel.setVisible(visible);
|
303 |
} |
304 |
|
305 |
public boolean getVisibleAceptCancel() { |
306 |
return this.btnAccept.isVisible(); |
307 |
} |
308 |
|
309 |
public JComponent asJComponent() { |
310 |
return this; |
311 |
} |
312 |
|
313 |
public LrsAlgorithmParams getParams() throws LrsGettingParametersException, LrsNeededParameterException { |
314 |
LrsAlgorithmsManager manager = LrsAlgorithmsLocator.getLrsAlgorithmsManager(); |
315 |
LrsCalibrateRouteAlgorithmParams params = manager.createLrsCalibrateRouteAlgorithmParams(); |
316 |
// Recorrer todo del interfaz y rellenar los parametros
|
317 |
|
318 |
//cmbInputLayer
|
319 |
if (!(this.cmbInputLayer.getSelectedItem() instanceof FLyrVect)){ |
320 |
logger.error("Error getting selected item from cmbInputLayer");
|
321 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbInputLayer", null); |
322 |
} |
323 |
FLyrVect fLyrVect = (FLyrVect) this.cmbInputLayer.getSelectedItem();
|
324 |
IProjection projection= fLyrVect.getProjection(); |
325 |
if (!(fLyrVect.getFeatureStore() instanceof FeatureStore)){ |
326 |
logger.error("Error getting selected item from cmbInputLayer");
|
327 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbInputLayer", null); |
328 |
} |
329 |
FeatureStore sourceFeatureStore = (FeatureStore)fLyrVect.getFeatureStore(); |
330 |
if (sourceFeatureStore == null) { |
331 |
throw new LrsNeededParameterException("need_to_select_a_source_layer", null); |
332 |
} |
333 |
params.setSourceFeatureStore(sourceFeatureStore); |
334 |
|
335 |
//cmbIdRouteField
|
336 |
if (!(this.cmbIdRouteField.getSelectedItem() instanceof FeatureAttributeDescriptor)){ |
337 |
logger.error("Error getting selected item from cmbIdRouteField");
|
338 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbIdRouteField", null); |
339 |
} |
340 |
FeatureAttributeDescriptor idRouteField = (FeatureAttributeDescriptor) this.cmbIdRouteField.getSelectedItem();
|
341 |
if (idRouteField == null) { |
342 |
throw new LrsNeededParameterException("need_to_select_a_route_identifier_field", null); |
343 |
} |
344 |
params.setIdRouteField(idRouteField); |
345 |
|
346 |
//cmbCalibratePointLayer
|
347 |
if (!(this.cmbCalibratePointLayer.getSelectedItem() instanceof FLyrVect)){ |
348 |
logger.error("Error getting selected item from cmbCalibratePointLayer");
|
349 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbCalibratePointLayer", null); |
350 |
} |
351 |
FLyrVect fLyrVectCalibratePoint = (FLyrVect) this.cmbCalibratePointLayer.getSelectedItem();
|
352 |
if (!(fLyrVectCalibratePoint.getFeatureStore() instanceof FeatureStore)){ |
353 |
logger.error("Error getting selected item from cmbCalibratePointLayer");
|
354 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbCalibratePointLayer", null); |
355 |
} |
356 |
FeatureStore calibratePointFeatureStore = (FeatureStore)fLyrVectCalibratePoint.getFeatureStore(); |
357 |
if (calibratePointFeatureStore == null) { |
358 |
throw new LrsNeededParameterException("need_to_select_a_calibrate_point_layer", null); |
359 |
} |
360 |
params.setCalibratePointFeatureStore(calibratePointFeatureStore); |
361 |
|
362 |
//cmbCalibrationPointIdRouteField
|
363 |
if (!(this.cmbCalibrationPointIdRouteField.getSelectedItem() instanceof FeatureAttributeDescriptor)){ |
364 |
logger.error("Error getting selected item from cmbCalibrationPointIdRouteField");
|
365 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbCalibrationPointIdRouteField", null); |
366 |
} |
367 |
FeatureAttributeDescriptor idRouteFieldCalibratePoint = |
368 |
(FeatureAttributeDescriptor) this.cmbCalibrationPointIdRouteField.getSelectedItem();
|
369 |
if (idRouteFieldCalibratePoint == null) { |
370 |
throw new LrsNeededParameterException("need_to_select_a_route_identifier_calibration_point_field", null); |
371 |
} |
372 |
params.setCalibratePointIdRouteField(idRouteFieldCalibratePoint); |
373 |
|
374 |
//cmbFromMeasureField
|
375 |
if (!(this.cmbFromMeasureField.getSelectedItem() instanceof FeatureAttributeDescriptor)){ |
376 |
logger.error("Error getting selected item from cmbFromMeasureField");
|
377 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbFromMeasureField", null); |
378 |
} |
379 |
FeatureAttributeDescriptor fromMeasureField = |
380 |
(FeatureAttributeDescriptor) this.cmbFromMeasureField.getSelectedItem();
|
381 |
if (fromMeasureField == null) { |
382 |
throw new LrsNeededParameterException("need_to_select_a_from_Measure_field", null); |
383 |
} |
384 |
params.setFromMeasureField(fromMeasureField); |
385 |
|
386 |
//OutputStore
|
387 |
String outputLayerPathFile = this.txtOutputFile.getText(); |
388 |
if(StringUtils.isEmpty(outputLayerPathFile)){
|
389 |
throw new LrsNeededParameterException("need_to_fill_the_target_path", null); |
390 |
} |
391 |
try {
|
392 |
NewFeatureStoreParameters newFeatureStoreParams=JLrsUtilsController.createFeatureStoreParams(outputLayerPathFile, projection); |
393 |
params.setNewFeatureStoreParameters(newFeatureStoreParams); |
394 |
} catch (Exception e) { |
395 |
throw new LrsNeededParameterException("error_creating_outputStore", e); |
396 |
} |
397 |
|
398 |
|
399 |
LrsMeasureCalculationMethods measureCalculationMethods = (LrsMeasureCalculationMethods) this.cmbMeasureCalcMethod.getSelectedItem();
|
400 |
params.setMeasureCalculationMethods(measureCalculationMethods); |
401 |
DistanceUnits measureUnits = (DistanceUnits) this.cmbMeasureUnits.getSelectedItem();
|
402 |
params.setMeasureUnits(measureUnits); |
403 |
|
404 |
Object searchRadius = this.txtSearchRadius.getValue(); |
405 |
if (searchRadius!=null && searchRadius instanceof Double){ |
406 |
params.setSearchRadius((Double)searchRadius);
|
407 |
}else {
|
408 |
params.setSearchRadius(0);
|
409 |
} |
410 |
|
411 |
params.setInterpolateBetweenCalibrationPoints(this.chkInterpolateBetweenCalibrationPoints.isSelected());
|
412 |
params.setExtrapolateBeforeCalibrationPoints(this.chkExtrapolateBeforeCalibrationPoints.isSelected());
|
413 |
params.setExtrapolateAfterCalibrationPoints(this.chkExtrapolateAfterCalibrationPoints.isSelected());
|
414 |
params.setIgnoreSpatialGaps(this.chkIgnoreSpatialGaps.isSelected());
|
415 |
params.setIncludeAll(this.chkIncludeAll.isSelected());
|
416 |
|
417 |
return params;
|
418 |
} |
419 |
|
420 |
public void setParams(LrsAlgorithmParams params) { |
421 |
if (params == null) { |
422 |
clear(); |
423 |
return;
|
424 |
} |
425 |
// Rellena los campos con los valores de params
|
426 |
LrsCalibrateRouteAlgorithmParams parameters = (LrsCalibrateRouteAlgorithmParams) params; |
427 |
|
428 |
this.cmbMeasureCalcMethod.setSelectedItem(parameters.getMeasureCalculationMethods());
|
429 |
this.cmbMeasureUnits.setSelectedItem(parameters.getMeasureUnits());
|
430 |
|
431 |
FeatureStore sourceFeatureStore = parameters.getSourceFeatureStore(); |
432 |
if(layers!=null && sourceFeatureStore!=null){ |
433 |
FLayer layer = layers.getLayer(sourceFeatureStore.getName()); |
434 |
this.cmbInputLayer.setSelectedItem(layer);
|
435 |
} |
436 |
FeatureStore calibratePointFeaturesStore=parameters.getCalibratePointFeatureStore(); |
437 |
if(layers!=null && calibratePointFeaturesStore!=null){ |
438 |
FLayer layer = layers.getLayer(calibratePointFeaturesStore.getName()); |
439 |
this.cmbCalibratePointLayer.setSelectedItem(layer);
|
440 |
} |
441 |
NewFeatureStoreParameters newFeatureStoreParameters = parameters.getNewFeatureStoreParameters(); |
442 |
if(newFeatureStoreParameters!=null && newFeatureStoreParameters instanceof SHPNewStoreParameters){ |
443 |
this.txtOutputFile.setText(((SHPNewStoreParameters)newFeatureStoreParameters).getSHPFile().getAbsolutePath());
|
444 |
} |
445 |
|
446 |
this.cmbIdRouteField.setSelectedItem(parameters.getIdRouteField());
|
447 |
this.cmbCalibrationPointIdRouteField.setSelectedItem(parameters.getCalibratePointIdRouteField());
|
448 |
this.cmbFromMeasureField.setSelectedItem(parameters.getFromMeasureField());
|
449 |
|
450 |
this.txtSearchRadius.setValue(parameters.getSearchRadius());
|
451 |
this.chkInterpolateBetweenCalibrationPoints.setSelected(parameters.interpolateBetweenCalibrationPoints());
|
452 |
this.chkExtrapolateBeforeCalibrationPoints.setSelected(parameters.extrapolateBeforeCalibrationPoints());
|
453 |
this.chkExtrapolateAfterCalibrationPoints.setSelected(parameters.extrapolateAfterCalibrationPoints());
|
454 |
this.chkIgnoreSpatialGaps.setSelected(parameters.ignoreSpatialGaps());
|
455 |
this.chkIncludeAll.setSelected(parameters.includeAll());
|
456 |
|
457 |
} |
458 |
|
459 |
public void clear() { |
460 |
this.txtOutputFile.setText(""); |
461 |
this.txtSearchRadius.setValue(0.0); |
462 |
|
463 |
this.cmbInputLayer.setSelectedIndex(0); |
464 |
Object inputLayerSelected = this.cmbInputLayer.getSelectedItem(); |
465 |
if (inputLayerSelected != null) { |
466 |
this.updateLayerSource((FLyrVect) inputLayerSelected);
|
467 |
} |
468 |
this.cmbCalibratePointLayer.setSelectedIndex(0); |
469 |
Object calibratePointLayerSelected = this.cmbCalibratePointLayer.getSelectedItem(); |
470 |
if (calibratePointLayerSelected != null) { |
471 |
this.updateLayerCalibratePoint((FLyrVect) calibratePointLayerSelected);
|
472 |
} |
473 |
this.cmbIdRouteField.setSelectedIndex(0); |
474 |
this.cmbCalibrationPointIdRouteField.setSelectedIndex(0); |
475 |
// this.cmbFromMeasureField.setSelectedIndex(0);
|
476 |
this.cmbMeasureCalcMethod.setSelectedIndex(0); |
477 |
this.cmbMeasureUnits.setSelectedIndex(0); |
478 |
this.chkInterpolateBetweenCalibrationPoints.setSelected(false); |
479 |
this.chkExtrapolateBeforeCalibrationPoints.setSelected(false); |
480 |
this.chkExtrapolateAfterCalibrationPoints.setSelected(false); |
481 |
this.chkIgnoreSpatialGaps.setSelected(false); |
482 |
this.chkIncludeAll.setSelected(false); |
483 |
|
484 |
} |
485 |
|
486 |
private void updateLayerSource(FLyrVect layer) { |
487 |
logger.info(new StringBuilder().append("Setting layer ").append(layer.getName()).toString()); |
488 |
FeatureStore featureStore = layer.getFeatureStore(); |
489 |
try {
|
490 |
FeatureType type = featureStore.getDefaultFeatureType(); |
491 |
// Se renuevan los combos de attributeDescriptors
|
492 |
FeatureAttributeDescriptorsComboBoxModel idRouteFieldComboBoxModel = |
493 |
new FeatureAttributeDescriptorsComboBoxModel();
|
494 |
|
495 |
this.cmbIdRouteField.setModel(idRouteFieldComboBoxModel);
|
496 |
|
497 |
FeatureAttributeDescriptor[] attributeDescriptors = type.getAttributeDescriptors();
|
498 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
499 |
FeatureAttributeDescriptor featureAttributeDescriptor = attributeDescriptors[i]; |
500 |
if (featureAttributeDescriptor.getDataType().getType() != DataTypes.GEOMETRY) {
|
501 |
logger.info(new StringBuilder().append("Adding field ") |
502 |
.append(featureAttributeDescriptor.getName()).toString()); |
503 |
|
504 |
JLrsCalibrateRouteParamsController.this.cmbIdRouteField.addItem(featureAttributeDescriptor); |
505 |
} |
506 |
} |
507 |
this.cmbIdRouteField.invalidate();
|
508 |
|
509 |
} catch (DataException e1) {
|
510 |
logger.warn( |
511 |
new StringBuilder().append("Error getting default feature type from layer ").append(layer.getName()) |
512 |
.toString(), e1); |
513 |
} |
514 |
} |
515 |
|
516 |
|
517 |
|
518 |
private void updateLayerCalibratePoint(FLyrVect layer) { |
519 |
logger.info(new StringBuilder().append("Setting layer ").append(layer.getName()).toString()); |
520 |
FeatureStore featureStore = layer.getFeatureStore(); |
521 |
try {
|
522 |
FeatureType type = featureStore.getDefaultFeatureType(); |
523 |
// Se renuevan los combos de attributeDescriptors
|
524 |
FeatureAttributeDescriptorsComboBoxModel calibrationPointIdRouteFieldComboBoxModel = |
525 |
new FeatureAttributeDescriptorsComboBoxModel();
|
526 |
FeatureAttributeDescriptorsComboBoxModel fromMeasureFieldComboBoxModel = |
527 |
new FeatureAttributeDescriptorsComboBoxModel();
|
528 |
|
529 |
this.cmbCalibrationPointIdRouteField.setModel(calibrationPointIdRouteFieldComboBoxModel);
|
530 |
this.cmbFromMeasureField.setModel(fromMeasureFieldComboBoxModel);
|
531 |
|
532 |
FeatureAttributeDescriptor[] attributeDescriptors = type.getAttributeDescriptors();
|
533 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
534 |
FeatureAttributeDescriptor featureAttributeDescriptor = attributeDescriptors[i]; |
535 |
if (featureAttributeDescriptor.getDataType().getType() != DataTypes.GEOMETRY) {
|
536 |
logger.info(new StringBuilder().append("Adding field ") |
537 |
.append(featureAttributeDescriptor.getName()).toString()); |
538 |
|
539 |
JLrsCalibrateRouteParamsController.this.cmbCalibrationPointIdRouteField.addItem(featureAttributeDescriptor); |
540 |
if (featureAttributeDescriptor.getDataType().isNumeric()) {
|
541 |
JLrsCalibrateRouteParamsController.this.cmbFromMeasureField.addItem(featureAttributeDescriptor); |
542 |
} |
543 |
} |
544 |
} |
545 |
this.cmbCalibrationPointIdRouteField.invalidate();
|
546 |
this.cmbFromMeasureField.invalidate();
|
547 |
|
548 |
} catch (DataException e1) {
|
549 |
logger.warn( |
550 |
new StringBuilder().append("Error getting default feature type from layer ").append(layer.getName()) |
551 |
.toString(), e1); |
552 |
} |
553 |
} |
554 |
|
555 |
|
556 |
|
557 |
|
558 |
} |