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