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 @ 58
History | View | Annotate | Download (25.2 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 |
this.btnBrowser.addActionListener(new ActionListener() { |
214 |
|
215 |
public void actionPerformed(ActionEvent e) { |
216 |
doSelectOuputFile(); |
217 |
} |
218 |
}); |
219 |
|
220 |
this.btnAccept.addActionListener(new ActionListener() { |
221 |
|
222 |
public void actionPerformed(ActionEvent e) { |
223 |
canceled = false;
|
224 |
doClose(); |
225 |
listeners.fireActionEvent(new ActionEvent(JLrsCalibrateRouteParamsController.this, 0, "accept")); |
226 |
|
227 |
} |
228 |
}); |
229 |
|
230 |
this.btnCancel.addActionListener(new ActionListener() { |
231 |
|
232 |
public void actionPerformed(ActionEvent e) { |
233 |
canceled = true;
|
234 |
doClose(); |
235 |
listeners.fireActionEvent(new ActionEvent(JLrsCalibrateRouteParamsController.this, 0, "cancel")); |
236 |
} |
237 |
}); |
238 |
|
239 |
setVisibleAceptCancel(false);
|
240 |
canceled = false;
|
241 |
} |
242 |
|
243 |
private void doSelectOuputFile() { |
244 |
final I18nManager i18nManager = ToolsLocator.getI18nManager();
|
245 |
ThreadSafeDialogsManager manager = ToolsSwingLocator.getThreadSafeDialogsManager(); |
246 |
File[] files = manager.showSaveFileDialog(i18nManager.getTranslation("output_file"), null); |
247 |
if (files != null && files.length > 0) { |
248 |
File file = files[0]; |
249 |
String absolutePath = file.getAbsolutePath();
|
250 |
if(!StringUtils.endsWithIgnoreCase(absolutePath, ".shp")){ |
251 |
absolutePath = new StringBuilder().append(absolutePath).append(".shp").toString(); |
252 |
} |
253 |
File outputFile = FileUtils.getFile(absolutePath);
|
254 |
if(outputFile.exists()) {
|
255 |
int resp = JOptionPane.showOptionDialog( |
256 |
this.asJComponent(),
|
257 |
i18nManager.getTranslation("file_already_exists_do_you_want_overwrite_it"),
|
258 |
i18nManager.getTranslation("output_file"),
|
259 |
JOptionPane.OK_CANCEL_OPTION,
|
260 |
JOptionPane.QUESTION_MESSAGE,
|
261 |
null,
|
262 |
null,
|
263 |
JOptionPane.OK_OPTION);
|
264 |
if (resp == JOptionPane.OK_OPTION){ |
265 |
this.txtOutputFile.setText(absolutePath);
|
266 |
} else {
|
267 |
doSelectOuputFile(); |
268 |
} |
269 |
} else {
|
270 |
this.txtOutputFile.setText(absolutePath);
|
271 |
} |
272 |
} |
273 |
|
274 |
} |
275 |
|
276 |
private void doClose() { |
277 |
this.setVisible(false); |
278 |
} |
279 |
|
280 |
public boolean isCanceled() { |
281 |
return this.canceled; |
282 |
} |
283 |
|
284 |
public void setVisibleAceptCancel(boolean visible) { |
285 |
this.btnAccept.setVisible(visible);
|
286 |
this.btnCancel.setVisible(visible);
|
287 |
} |
288 |
|
289 |
public boolean getVisibleAceptCancel() { |
290 |
return this.btnAccept.isVisible(); |
291 |
} |
292 |
|
293 |
public JComponent asJComponent() { |
294 |
return this; |
295 |
} |
296 |
|
297 |
public LrsAlgorithmParams getParams() throws LrsGettingParametersException, LrsNeededParameterException { |
298 |
LrsAlgorithmsManager manager = LrsAlgorithmsLocator.getLrsAlgorithmsManager(); |
299 |
LrsCalibrateRouteAlgorithmParams params = manager.createLrsCalibrateRouteAlgorithmParams(); |
300 |
// Recorrer todo del interfaz y rellenar los parametros
|
301 |
|
302 |
//cmbInputLayer
|
303 |
if (!(this.cmbInputLayer.getSelectedItem() instanceof FLyrVect)){ |
304 |
logger.error("Error getting selected item from cmbInputLayer");
|
305 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbInputLayer", null); |
306 |
} |
307 |
FLyrVect fLyrVect = (FLyrVect) this.cmbInputLayer.getSelectedItem();
|
308 |
IProjection projection= fLyrVect.getProjection(); |
309 |
if (!(fLyrVect.getFeatureStore() instanceof FeatureStore)){ |
310 |
logger.error("Error getting selected item from cmbInputLayer");
|
311 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbInputLayer", null); |
312 |
} |
313 |
FeatureStore sourceFeatureStore = (FeatureStore)fLyrVect.getFeatureStore(); |
314 |
if (sourceFeatureStore == null) { |
315 |
throw new LrsNeededParameterException("need_to_select_a_source_layer", null); |
316 |
} |
317 |
params.setSourceFeatureStore(sourceFeatureStore); |
318 |
|
319 |
//cmbIdRouteField
|
320 |
if (!(this.cmbIdRouteField.getSelectedItem() instanceof FeatureAttributeDescriptor)){ |
321 |
logger.error("Error getting selected item from cmbIdRouteField");
|
322 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbIdRouteField", null); |
323 |
} |
324 |
FeatureAttributeDescriptor idRouteField = (FeatureAttributeDescriptor) this.cmbIdRouteField.getSelectedItem();
|
325 |
if (idRouteField == null) { |
326 |
throw new LrsNeededParameterException("need_to_select_a_route_identifier_field", null); |
327 |
} |
328 |
params.setIdRouteField(idRouteField); |
329 |
|
330 |
//cmbCalibratePointLayer
|
331 |
if (!(this.cmbCalibratePointLayer.getSelectedItem() instanceof FLyrVect)){ |
332 |
logger.error("Error getting selected item from cmbCalibratePointLayer");
|
333 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbCalibratePointLayer", null); |
334 |
} |
335 |
FLyrVect fLyrVectCalibratePoint = (FLyrVect) this.cmbCalibratePointLayer.getSelectedItem();
|
336 |
if (!(fLyrVectCalibratePoint.getFeatureStore() instanceof FeatureStore)){ |
337 |
logger.error("Error getting selected item from cmbCalibratePointLayer");
|
338 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbCalibratePointLayer", null); |
339 |
} |
340 |
FeatureStore calibratePointFeatureStore = (FeatureStore)fLyrVectCalibratePoint.getFeatureStore(); |
341 |
if (calibratePointFeatureStore == null) { |
342 |
throw new LrsNeededParameterException("need_to_select_a_calibrate_point_layer", null); |
343 |
} |
344 |
params.setCalibratePointFeatureStore(calibratePointFeatureStore); |
345 |
|
346 |
//cmbCalibrationPointIdRouteField
|
347 |
if (!(this.cmbCalibrationPointIdRouteField.getSelectedItem() instanceof FeatureAttributeDescriptor)){ |
348 |
logger.error("Error getting selected item from cmbCalibrationPointIdRouteField");
|
349 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbCalibrationPointIdRouteField", null); |
350 |
} |
351 |
FeatureAttributeDescriptor idRouteFieldCalibratePoint = |
352 |
(FeatureAttributeDescriptor) this.cmbCalibrationPointIdRouteField.getSelectedItem();
|
353 |
if (idRouteFieldCalibratePoint == null) { |
354 |
throw new LrsNeededParameterException("need_to_select_a_route_identifier_calibration_point_field", null); |
355 |
} |
356 |
params.setCalibratePointIdRouteField(idRouteFieldCalibratePoint); |
357 |
|
358 |
//cmbFromMeasureField
|
359 |
if (!(this.cmbMeasureField.getSelectedItem() instanceof FeatureAttributeDescriptor)){ |
360 |
logger.error("Error getting selected item from cmbFromMeasureField");
|
361 |
throw new LrsGettingParametersException("error_getting_selected_item_from_cmbFromMeasureField", null); |
362 |
} |
363 |
FeatureAttributeDescriptor fromMeasureField = |
364 |
(FeatureAttributeDescriptor) this.cmbMeasureField.getSelectedItem();
|
365 |
if (fromMeasureField == null) { |
366 |
throw new LrsNeededParameterException("need_to_select_a_from_Measure_field", null); |
367 |
} |
368 |
params.setFromMeasureField(fromMeasureField); |
369 |
|
370 |
//OutputStore
|
371 |
String outputLayerPathFile = this.txtOutputFile.getText(); |
372 |
if(StringUtils.isEmpty(outputLayerPathFile)){
|
373 |
throw new LrsNeededParameterException("need_to_fill_the_target_path", null); |
374 |
} |
375 |
try {
|
376 |
NewFeatureStoreParameters newFeatureStoreParams=JLrsUtils.createFeatureStoreParams(outputLayerPathFile, projection); |
377 |
params.setNewFeatureStoreParameters(newFeatureStoreParams); |
378 |
} catch (Exception e) { |
379 |
throw new LrsNeededParameterException("error_creating_outputStore", e); |
380 |
} |
381 |
|
382 |
|
383 |
LrsMeasureCalculationMethods measureCalculationMethods = (LrsMeasureCalculationMethods) this.cmbMeasureCalcMethod.getSelectedItem();
|
384 |
params.setMeasureCalculationMethods(measureCalculationMethods); |
385 |
DistanceUnits measureUnits = (DistanceUnits) this.cmbMeasureUnits.getSelectedItem();
|
386 |
params.setMeasureUnits(measureUnits); |
387 |
|
388 |
String searchRadius = this.txtSearchRadius.getText(); |
389 |
if (searchRadius!=null && !searchRadius.isEmpty()){ |
390 |
try{
|
391 |
params.setSearchRadius(Double.valueOf(searchRadius));
|
392 |
}catch (Exception e){ |
393 |
params.setSearchRadius(Double.valueOf(0)); |
394 |
} |
395 |
}else {
|
396 |
params.setSearchRadius(0);
|
397 |
} |
398 |
|
399 |
params.setInterpolateBetweenCalibrationPoints(this.chkInterpolateBetweenCalibrationPoints.isSelected());
|
400 |
params.setExtrapolateBeforeCalibrationPoints(this.chkExtrapolateBeforeCalibrationPoints.isSelected());
|
401 |
params.setExtrapolateAfterCalibrationPoints(this.chkExtrapolateAfterCalibrationPoints.isSelected());
|
402 |
params.setIgnoreSpatialGaps(this.chkIgnoreSpatialGaps.isSelected());
|
403 |
params.setIncludeAll(this.chkIncludeAll.isSelected());
|
404 |
|
405 |
return params;
|
406 |
} |
407 |
|
408 |
public void setParams(LrsAlgorithmParams params) { |
409 |
if (params == null) { |
410 |
clear(); |
411 |
return;
|
412 |
} |
413 |
// Rellena los campos con los valores de params
|
414 |
LrsCalibrateRouteAlgorithmParams parameters = (LrsCalibrateRouteAlgorithmParams) params; |
415 |
|
416 |
this.cmbMeasureCalcMethod.setSelectedItem(parameters.getMeasureCalculationMethods());
|
417 |
this.cmbMeasureUnits.setSelectedItem(parameters.getMeasureUnits());
|
418 |
|
419 |
FeatureStore sourceFeatureStore = parameters.getSourceFeatureStore(); |
420 |
if(layers!=null && sourceFeatureStore!=null){ |
421 |
FLayer layer = layers.getLayer(sourceFeatureStore.getName()); |
422 |
this.cmbInputLayer.setSelectedItem(layer);
|
423 |
} |
424 |
FeatureStore calibratePointFeaturesStore=parameters.getCalibratePointFeatureStore(); |
425 |
if(layers!=null && calibratePointFeaturesStore!=null){ |
426 |
FLayer layer = layers.getLayer(calibratePointFeaturesStore.getName()); |
427 |
this.cmbCalibratePointLayer.setSelectedItem(layer);
|
428 |
} |
429 |
NewFeatureStoreParameters newFeatureStoreParameters = parameters.getNewFeatureStoreParameters(); |
430 |
if(newFeatureStoreParameters!=null && newFeatureStoreParameters instanceof SHPNewStoreParameters){ |
431 |
this.txtOutputFile.setText(((SHPNewStoreParameters)newFeatureStoreParameters).getSHPFile().getAbsolutePath());
|
432 |
} |
433 |
|
434 |
this.cmbIdRouteField.setSelectedItem(parameters.getIdRouteField());
|
435 |
this.cmbCalibrationPointIdRouteField.setSelectedItem(parameters.getCalibratePointIdRouteField());
|
436 |
this.cmbMeasureField.setSelectedItem(parameters.getFromMeasureField());
|
437 |
|
438 |
this.txtSearchRadius.setText(String.valueOf(parameters.getSearchRadius())); |
439 |
this.chkInterpolateBetweenCalibrationPoints.setSelected(parameters.interpolateBetweenCalibrationPoints());
|
440 |
this.chkExtrapolateBeforeCalibrationPoints.setSelected(parameters.extrapolateBeforeCalibrationPoints());
|
441 |
this.chkExtrapolateAfterCalibrationPoints.setSelected(parameters.extrapolateAfterCalibrationPoints());
|
442 |
this.chkIgnoreSpatialGaps.setSelected(parameters.ignoreSpatialGaps());
|
443 |
this.chkIncludeAll.setSelected(parameters.includeAll());
|
444 |
|
445 |
} |
446 |
|
447 |
public void clear() { |
448 |
this.txtOutputFile.setText(""); |
449 |
this.txtSearchRadius.setText("0.0"); |
450 |
|
451 |
this.cmbInputLayer.setSelectedIndex(0); |
452 |
Object inputLayerSelected = this.cmbInputLayer.getSelectedItem(); |
453 |
if (inputLayerSelected != null) { |
454 |
this.updateLayerSource((FLyrVect) inputLayerSelected);
|
455 |
} |
456 |
this.cmbCalibratePointLayer.setSelectedIndex(0); |
457 |
Object calibratePointLayerSelected = this.cmbCalibratePointLayer.getSelectedItem(); |
458 |
if (calibratePointLayerSelected != null) { |
459 |
this.updateLayerCalibratePoint((FLyrVect) calibratePointLayerSelected);
|
460 |
} |
461 |
this.cmbIdRouteField.setSelectedIndex(0); |
462 |
this.cmbCalibrationPointIdRouteField.setSelectedIndex(0); |
463 |
this.cmbMeasureField.setSelectedIndex(0); |
464 |
this.cmbMeasureCalcMethod.setSelectedIndex(0); |
465 |
this.cmbMeasureUnits.setSelectedIndex(0); |
466 |
this.chkInterpolateBetweenCalibrationPoints.setSelected(false); |
467 |
this.chkExtrapolateBeforeCalibrationPoints.setSelected(false); |
468 |
this.chkExtrapolateAfterCalibrationPoints.setSelected(false); |
469 |
this.chkIgnoreSpatialGaps.setSelected(false); |
470 |
this.chkIncludeAll.setSelected(false); |
471 |
|
472 |
} |
473 |
|
474 |
private void updateLayerSource(FLyrVect layer) { |
475 |
logger.info(new StringBuilder().append("Setting layer ").append(layer.getName()).toString()); |
476 |
FeatureStore featureStore = layer.getFeatureStore(); |
477 |
try {
|
478 |
FeatureType type = featureStore.getDefaultFeatureType(); |
479 |
// Se renuevan los combos de attributeDescriptors
|
480 |
FeatureAttributeDescriptorsComboBoxModel idRouteFieldComboBoxModel = |
481 |
new FeatureAttributeDescriptorsComboBoxModel();
|
482 |
|
483 |
this.cmbIdRouteField.setModel(idRouteFieldComboBoxModel);
|
484 |
|
485 |
FeatureAttributeDescriptor[] attributeDescriptors = type.getAttributeDescriptors();
|
486 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
487 |
FeatureAttributeDescriptor featureAttributeDescriptor = attributeDescriptors[i]; |
488 |
if (featureAttributeDescriptor.getDataType().getType() != DataTypes.GEOMETRY) {
|
489 |
logger.info(new StringBuilder().append("Adding field ") |
490 |
.append(featureAttributeDescriptor.getName()).toString()); |
491 |
|
492 |
JLrsCalibrateRouteParamsController.this.cmbIdRouteField.addItem(featureAttributeDescriptor); |
493 |
} |
494 |
} |
495 |
this.cmbIdRouteField.invalidate();
|
496 |
this.cmbIdRouteField.setSelectedIndex(0); |
497 |
|
498 |
} catch (DataException e1) {
|
499 |
logger.warn( |
500 |
new StringBuilder().append("Error getting default feature type from layer ").append(layer.getName()) |
501 |
.toString(), e1); |
502 |
} |
503 |
} |
504 |
|
505 |
|
506 |
|
507 |
private void updateLayerCalibratePoint(FLyrVect layer) { |
508 |
logger.info(new StringBuilder().append("Setting layer ").append(layer.getName()).toString()); |
509 |
FeatureStore featureStore = layer.getFeatureStore(); |
510 |
try {
|
511 |
FeatureType type = featureStore.getDefaultFeatureType(); |
512 |
// Se renuevan los combos de attributeDescriptors
|
513 |
FeatureAttributeDescriptorsComboBoxModel calibrationPointIdRouteFieldComboBoxModel = |
514 |
new FeatureAttributeDescriptorsComboBoxModel();
|
515 |
FeatureAttributeDescriptorsComboBoxModel measureFieldComboBoxModel = |
516 |
new FeatureAttributeDescriptorsComboBoxModel();
|
517 |
|
518 |
this.cmbCalibrationPointIdRouteField.setModel(calibrationPointIdRouteFieldComboBoxModel);
|
519 |
this.cmbMeasureField.setModel(measureFieldComboBoxModel);
|
520 |
|
521 |
FeatureAttributeDescriptor[] attributeDescriptors = type.getAttributeDescriptors();
|
522 |
for (int i = 0; i < attributeDescriptors.length; i++) { |
523 |
FeatureAttributeDescriptor featureAttributeDescriptor = attributeDescriptors[i]; |
524 |
if (featureAttributeDescriptor.getDataType().getType() != DataTypes.GEOMETRY) {
|
525 |
logger.info(new StringBuilder().append("Adding field ") |
526 |
.append(featureAttributeDescriptor.getName()).toString()); |
527 |
|
528 |
JLrsCalibrateRouteParamsController.this.cmbCalibrationPointIdRouteField.addItem(featureAttributeDescriptor); |
529 |
if (featureAttributeDescriptor.getDataType().isNumeric()) {
|
530 |
JLrsCalibrateRouteParamsController.this.cmbMeasureField.addItem(featureAttributeDescriptor); |
531 |
} |
532 |
} |
533 |
} |
534 |
this.cmbCalibrationPointIdRouteField.invalidate();
|
535 |
this.cmbCalibrationPointIdRouteField.setSelectedIndex(0); |
536 |
this.cmbMeasureField.invalidate();
|
537 |
this.cmbMeasureField.setSelectedIndex(0); |
538 |
|
539 |
} catch (DataException e1) {
|
540 |
logger.warn( |
541 |
new StringBuilder().append("Error getting default feature type from layer ").append(layer.getName()) |
542 |
.toString(), e1); |
543 |
} |
544 |
} |
545 |
|
546 |
/* (non-Javadoc)
|
547 |
* @see javax.swing.JComponent#getPreferredSize()
|
548 |
*/
|
549 |
@Override
|
550 |
public Dimension getPreferredSize() { |
551 |
return new Dimension(650, 350); |
552 |
} |
553 |
|
554 |
|
555 |
|
556 |
} |