svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / gui / newpattern / GeocoNewPatternPanel.java @ 27140
History | View | Annotate | Download (22.2 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 Prodevelop S.L. vsanjaime Programador
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.gui.newpattern; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.ArrayList; |
32 |
import java.util.List; |
33 |
|
34 |
import javax.swing.DefaultCellEditor; |
35 |
import javax.swing.DefaultComboBoxModel; |
36 |
import javax.swing.ImageIcon; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.table.DefaultTableModel; |
39 |
import javax.swing.table.TableModel; |
40 |
|
41 |
import org.gvsig.fmap.dal.exception.DataException; |
42 |
import org.gvsig.fmap.dal.exception.ReadException; |
43 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
45 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
46 |
import org.gvsig.geocoding.extension.GeocoController; |
47 |
import org.gvsig.geocoding.patterns.Component; |
48 |
import org.gvsig.geocoding.patterns.Patterngeocoding; |
49 |
import org.gvsig.geocoding.utils.GeocoUtils; |
50 |
import org.slf4j.Logger; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
54 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
55 |
import com.iver.utiles.XMLEntity; |
56 |
import com.iver.utiles.XMLException; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Form to create new pattern
|
61 |
*
|
62 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
63 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
64 |
*/
|
65 |
|
66 |
public class GeocoNewPatternPanel extends javax.swing.JPanel implements IWindow { |
67 |
|
68 |
private static final long serialVersionUID = 1L; |
69 |
private static final Logger log = PluginServices.getLogger(); |
70 |
|
71 |
private Patterngeocoding pattern = null; |
72 |
private GeocoController control = null; |
73 |
private List<FLyrVect> lyrs = null; |
74 |
private List<String> components = null; |
75 |
|
76 |
private javax.swing.JButton jButCancel;
|
77 |
private javax.swing.JButton jButSave;
|
78 |
private javax.swing.JComboBox jComboLayers;
|
79 |
private javax.swing.JLabel jLabAccuracy;
|
80 |
private javax.swing.JLabel jLabLayers;
|
81 |
private javax.swing.JLabel jLabMaxResults;
|
82 |
private javax.swing.JLabel jLabPercent1;
|
83 |
private javax.swing.JLabel jLabPercent2;
|
84 |
private javax.swing.JLabel jLabQuality;
|
85 |
private javax.swing.JPanel jPanButtons;
|
86 |
private javax.swing.JPanel jPanDataSource;
|
87 |
private javax.swing.JPanel jPanElements;
|
88 |
private javax.swing.JPanel jPanSettings;
|
89 |
private javax.swing.JScrollPane jScrollElements;
|
90 |
private javax.swing.JTable jTableElements;
|
91 |
private javax.swing.JTextField jTextAccuracy;
|
92 |
private javax.swing.JTextField jTextMaxResults;
|
93 |
private javax.swing.JTextField jTextQuality;
|
94 |
|
95 |
/**
|
96 |
* Constructor
|
97 |
*
|
98 |
* @param _control
|
99 |
*/
|
100 |
public GeocoNewPatternPanel(GeocoController _control) {
|
101 |
this.control = _control;
|
102 |
|
103 |
initComponents(); |
104 |
setMessages(); |
105 |
setImages(); |
106 |
|
107 |
pattern = new Patterngeocoding();
|
108 |
|
109 |
/* load the address components list */
|
110 |
components = control.getListAddressComponents(); |
111 |
/* load the available layers and load into the combo */
|
112 |
lyrs = control.getListgvSIGLayers(); |
113 |
if (lyrs.size() > 0) { |
114 |
DefaultComboBoxModel comboModel = getModelListLayers(lyrs);
|
115 |
jComboLayers.setModel(comboModel); |
116 |
} else {
|
117 |
jComboLayers.setModel(new DefaultComboBoxModel()); |
118 |
} |
119 |
/* fill the Table with the fields */
|
120 |
if (lyrs.size() > 0) { |
121 |
updateTable(lyrs.get(0));
|
122 |
} else {
|
123 |
updateTable(); |
124 |
} |
125 |
/* enable the button save */
|
126 |
if (jComboLayers.getModel().getSize() > 0) { |
127 |
jButSave.setEnabled(true);
|
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Initialize components
|
133 |
*/
|
134 |
private void initComponents() { |
135 |
java.awt.GridBagConstraints gridBagConstraints; |
136 |
|
137 |
jPanDataSource = new javax.swing.JPanel();
|
138 |
jLabLayers = new javax.swing.JLabel();
|
139 |
jComboLayers = new javax.swing.JComboBox();
|
140 |
jPanElements = new javax.swing.JPanel();
|
141 |
jScrollElements = new javax.swing.JScrollPane();
|
142 |
jTableElements = new javax.swing.JTable();
|
143 |
jPanSettings = new javax.swing.JPanel();
|
144 |
jLabMaxResults = new javax.swing.JLabel();
|
145 |
jTextMaxResults = new javax.swing.JTextField();
|
146 |
jLabAccuracy = new javax.swing.JLabel();
|
147 |
jTextAccuracy = new javax.swing.JTextField();
|
148 |
jLabPercent1 = new javax.swing.JLabel();
|
149 |
jLabQuality = new javax.swing.JLabel();
|
150 |
jTextQuality = new javax.swing.JTextField();
|
151 |
jLabPercent2 = new javax.swing.JLabel();
|
152 |
jPanButtons = new javax.swing.JPanel();
|
153 |
jButSave = new javax.swing.JButton();
|
154 |
jButCancel = new javax.swing.JButton();
|
155 |
|
156 |
setLayout(new java.awt.GridBagLayout());
|
157 |
|
158 |
jPanDataSource.setBorder(javax.swing.BorderFactory |
159 |
.createTitledBorder("Data source"));
|
160 |
jPanDataSource.setLayout(new java.awt.GridBagLayout());
|
161 |
|
162 |
jLabLayers.setText("jLabel1");
|
163 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
164 |
gridBagConstraints.gridx = 0;
|
165 |
gridBagConstraints.gridy = 0;
|
166 |
gridBagConstraints.insets = new java.awt.Insets(2, 10, 2, 5); |
167 |
jPanDataSource.add(jLabLayers, gridBagConstraints); |
168 |
|
169 |
jComboLayers.setModel(new javax.swing.DefaultComboBoxModel(
|
170 |
new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); |
171 |
jComboLayers.addActionListener(new java.awt.event.ActionListener() {
|
172 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
173 |
evChangeLayer(evt); |
174 |
} |
175 |
}); |
176 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
177 |
gridBagConstraints.gridx = 1;
|
178 |
gridBagConstraints.gridy = 0;
|
179 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
180 |
gridBagConstraints.weightx = 1.0;
|
181 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10); |
182 |
jPanDataSource.add(jComboLayers, gridBagConstraints); |
183 |
|
184 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
185 |
gridBagConstraints.gridx = 0;
|
186 |
gridBagConstraints.gridy = 0;
|
187 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
188 |
gridBagConstraints.weightx = 1.0;
|
189 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
190 |
add(jPanDataSource, gridBagConstraints); |
191 |
|
192 |
jPanElements.setBorder(javax.swing.BorderFactory |
193 |
.createTitledBorder("Elements"));
|
194 |
jPanElements.setLayout(new java.awt.GridBagLayout());
|
195 |
|
196 |
jTableElements.setModel(new javax.swing.table.DefaultTableModel(
|
197 |
new Object[][] { { null, null }, { null, null }, |
198 |
{ null, null }, { null, null } }, new String[] { |
199 |
"Folders", "Elements" }) { |
200 |
boolean[] canEdit = new boolean[] { true, false }; |
201 |
|
202 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
203 |
return canEdit[columnIndex];
|
204 |
} |
205 |
}); |
206 |
jScrollElements.setViewportView(jTableElements); |
207 |
|
208 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
209 |
gridBagConstraints.gridx = 0;
|
210 |
gridBagConstraints.gridy = 0;
|
211 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
212 |
gridBagConstraints.weightx = 1.0;
|
213 |
gridBagConstraints.weighty = 1.0;
|
214 |
jPanElements.add(jScrollElements, gridBagConstraints); |
215 |
|
216 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
217 |
gridBagConstraints.gridx = 0;
|
218 |
gridBagConstraints.gridy = 1;
|
219 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
220 |
gridBagConstraints.weightx = 1.0;
|
221 |
gridBagConstraints.weighty = 1.0;
|
222 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
223 |
add(jPanElements, gridBagConstraints); |
224 |
|
225 |
jPanSettings.setBorder(javax.swing.BorderFactory |
226 |
.createTitledBorder("Settings"));
|
227 |
jPanSettings.setLayout(new java.awt.GridBagLayout());
|
228 |
|
229 |
jLabMaxResults.setText("maxresults");
|
230 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
231 |
gridBagConstraints.gridx = 0;
|
232 |
gridBagConstraints.gridy = 0;
|
233 |
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); |
234 |
jPanSettings.add(jLabMaxResults, gridBagConstraints); |
235 |
|
236 |
jTextMaxResults.setText(Integer.toString(control.getGmodel().DEFMAX));
|
237 |
jTextMaxResults.setPreferredSize(new java.awt.Dimension(30, 19)); |
238 |
jTextMaxResults.addFocusListener(new java.awt.event.FocusAdapter() {
|
239 |
public void focusLost(java.awt.event.FocusEvent evt) { |
240 |
evValidateMaxResults(evt); |
241 |
} |
242 |
}); |
243 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
244 |
gridBagConstraints.gridx = 1;
|
245 |
gridBagConstraints.gridy = 0;
|
246 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 15); |
247 |
jPanSettings.add(jTextMaxResults, gridBagConstraints); |
248 |
|
249 |
jLabAccuracy.setText("accuracy");
|
250 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
251 |
gridBagConstraints.gridx = 2;
|
252 |
gridBagConstraints.gridy = 0;
|
253 |
jPanSettings.add(jLabAccuracy, gridBagConstraints); |
254 |
|
255 |
jTextAccuracy.setText(Integer.toString(control.getGmodel().DEFACCU));
|
256 |
jTextAccuracy.setPreferredSize(new java.awt.Dimension(30, 19)); |
257 |
jTextAccuracy.addFocusListener(new java.awt.event.FocusAdapter() {
|
258 |
public void focusLost(java.awt.event.FocusEvent evt) { |
259 |
evValidateAccuracy(evt); |
260 |
} |
261 |
}); |
262 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
263 |
gridBagConstraints.gridx = 3;
|
264 |
gridBagConstraints.gridy = 0;
|
265 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2); |
266 |
jPanSettings.add(jTextAccuracy, gridBagConstraints); |
267 |
|
268 |
jLabPercent1.setText("%");
|
269 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
270 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 15); |
271 |
jPanSettings.add(jLabPercent1, gridBagConstraints); |
272 |
|
273 |
jLabQuality.setText("quality");
|
274 |
jPanSettings.add(jLabQuality, new java.awt.GridBagConstraints());
|
275 |
|
276 |
jTextQuality.setText(Integer.toString(control.getGmodel().DEFQUALI));
|
277 |
jTextQuality.setMinimumSize(new java.awt.Dimension(15, 19)); |
278 |
jTextQuality.setPreferredSize(new java.awt.Dimension(30, 19)); |
279 |
jTextQuality.addFocusListener(new java.awt.event.FocusAdapter() {
|
280 |
public void focusLost(java.awt.event.FocusEvent evt) { |
281 |
evValidateQuality(evt); |
282 |
} |
283 |
}); |
284 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
285 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2); |
286 |
jPanSettings.add(jTextQuality, gridBagConstraints); |
287 |
|
288 |
jLabPercent2.setText("%");
|
289 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
290 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10); |
291 |
jPanSettings.add(jLabPercent2, gridBagConstraints); |
292 |
|
293 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
294 |
gridBagConstraints.gridx = 0;
|
295 |
gridBagConstraints.gridy = 2;
|
296 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
297 |
gridBagConstraints.weightx = 1.0;
|
298 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
299 |
add(jPanSettings, gridBagConstraints); |
300 |
|
301 |
jPanButtons.setLayout(new java.awt.GridBagLayout());
|
302 |
|
303 |
jButSave.setText("jButton1");
|
304 |
jButSave.setEnabled(false);
|
305 |
jButSave.addActionListener(new java.awt.event.ActionListener() {
|
306 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
307 |
evSave(evt); |
308 |
} |
309 |
}); |
310 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
311 |
gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 10); |
312 |
jPanButtons.add(jButSave, gridBagConstraints); |
313 |
|
314 |
jButCancel.setText("jButton2");
|
315 |
jButCancel.addActionListener(new java.awt.event.ActionListener() {
|
316 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
317 |
evCancel(evt); |
318 |
} |
319 |
}); |
320 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
321 |
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); |
322 |
jPanButtons.add(jButCancel, gridBagConstraints); |
323 |
|
324 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
325 |
gridBagConstraints.gridx = 0;
|
326 |
gridBagConstraints.gridy = 3;
|
327 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
328 |
gridBagConstraints.weightx = 1.0;
|
329 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
330 |
add(jPanButtons, gridBagConstraints); |
331 |
} |
332 |
|
333 |
/**
|
334 |
*
|
335 |
* @param evt
|
336 |
*/
|
337 |
private void evChangeLayer(java.awt.event.ActionEvent evt) { |
338 |
/* Get selected layer */
|
339 |
int posCapa = (int) jComboLayers.getSelectedIndex(); |
340 |
if (posCapa >= 0 && lyrs.size() > 0) { |
341 |
FLyrVect lyr = lyrs.get(posCapa); |
342 |
updateTable(lyr); |
343 |
jTableElements.validate(); |
344 |
} |
345 |
} |
346 |
|
347 |
/**
|
348 |
*
|
349 |
* @param evt
|
350 |
*/
|
351 |
private void evValidateMaxResults(java.awt.event.FocusEvent evt) { |
352 |
String max = jTextMaxResults.getText().trim();
|
353 |
int maxresults;
|
354 |
try {
|
355 |
maxresults = Integer.parseInt(max);
|
356 |
if (maxresults < 1) { |
357 |
maxresults = 1;
|
358 |
jTextMaxResults.setText(Integer.toString(maxresults));
|
359 |
} |
360 |
} catch (Exception e) { |
361 |
maxresults = control.getGmodel().DEFMAX; |
362 |
jTextMaxResults.setText(Integer.toString(maxresults));
|
363 |
} |
364 |
} |
365 |
|
366 |
/**
|
367 |
*
|
368 |
* @param evt
|
369 |
*/
|
370 |
private void evValidateAccuracy(java.awt.event.FocusEvent evt) { |
371 |
String accura = jTextAccuracy.getText().trim();
|
372 |
int accuracy;
|
373 |
try {
|
374 |
accuracy = Integer.parseInt(accura);
|
375 |
if (accuracy < 0) { |
376 |
accuracy = 1;
|
377 |
jTextAccuracy.setText(Integer.toString(accuracy));
|
378 |
} |
379 |
if (accuracy > 100) { |
380 |
accuracy = 100;
|
381 |
jTextAccuracy.setText(Integer.toString(accuracy));
|
382 |
} |
383 |
} catch (Exception e) { |
384 |
accuracy = control.getGmodel().DEFACCU; |
385 |
jTextAccuracy.setText(Integer.toString(accuracy));
|
386 |
} |
387 |
} |
388 |
|
389 |
/**
|
390 |
*
|
391 |
* @param evt
|
392 |
*/
|
393 |
private void evValidateQuality(java.awt.event.FocusEvent evt) { |
394 |
String qual = jTextQuality.getText().trim();
|
395 |
int quality;
|
396 |
try {
|
397 |
quality = Integer.parseInt(qual);
|
398 |
if (quality < 0) { |
399 |
quality = 0;
|
400 |
jTextQuality.setText(Integer.toString(quality));
|
401 |
} |
402 |
if (quality > 100) { |
403 |
quality = 100;
|
404 |
jTextQuality.setText(Integer.toString(quality));
|
405 |
} |
406 |
} catch (Exception e) { |
407 |
quality = control.getGmodel().DEFQUALI; |
408 |
jTextQuality.setText(Integer.toString(quality));
|
409 |
} |
410 |
} |
411 |
|
412 |
/**
|
413 |
*
|
414 |
* @param evt
|
415 |
*/
|
416 |
private void evSave(java.awt.event.ActionEvent evt) { |
417 |
/* PreSave */
|
418 |
preSave(); |
419 |
|
420 |
/* save the new pattern in the model */
|
421 |
control.getGmodel().setPattern(pattern); |
422 |
|
423 |
/* save pattern */
|
424 |
boolean apto = control.savePattern();
|
425 |
|
426 |
/* close the panel */
|
427 |
if (apto) {
|
428 |
IWindow[] iws = PluginServices.getMDIManager().getAllWindows();
|
429 |
for (int i = 0; i < iws.length; i++) { |
430 |
if (iws[i] instanceof GeocoNewPatternPanel) { |
431 |
PluginServices.getMDIManager().closeWindow(iws[i]); |
432 |
} |
433 |
} |
434 |
control.updateGeocoGUI(); |
435 |
|
436 |
// enable components
|
437 |
if (control.getPattern() != null) { |
438 |
control.getGpanel().enableComponents(); |
439 |
control.getGpanel().getOneA().enableComponents(true);
|
440 |
} |
441 |
} |
442 |
} |
443 |
|
444 |
/**
|
445 |
*
|
446 |
* @param evt
|
447 |
*/
|
448 |
private void evCancel(java.awt.event.ActionEvent evt) { |
449 |
/* Close the window */
|
450 |
IWindow[] iws = PluginServices.getMDIManager().getAllWindows();
|
451 |
for (int i = 0; i < iws.length; i++) { |
452 |
if (iws[i] instanceof GeocoNewPatternPanel) { |
453 |
PluginServices.getMDIManager().closeWindow(iws[i]); |
454 |
} |
455 |
} |
456 |
} |
457 |
|
458 |
/**
|
459 |
*
|
460 |
*/
|
461 |
public Object getWindowProfile() { |
462 |
return null; |
463 |
} |
464 |
|
465 |
/**
|
466 |
* This method updates all labels of the panel from properties file
|
467 |
*/
|
468 |
private void setMessages() { |
469 |
|
470 |
PluginServices ps = PluginServices.getPluginServices(this);
|
471 |
|
472 |
jPanDataSource.setBorder(GeocoUtils.getTitledBorder(ps |
473 |
.getText("datasource")));
|
474 |
this.jLabLayers.setText(ps.getText("selectedlayer")); |
475 |
jPanElements.setBorder(GeocoUtils.getTitledBorder(ps |
476 |
.getText("components")));
|
477 |
jPanSettings.setBorder(GeocoUtils.getTitledBorder(ps |
478 |
.getText("settings")));
|
479 |
jLabMaxResults.setText(ps.getText("maxresults"));
|
480 |
jLabAccuracy.setText(ps.getText("accuracy"));
|
481 |
jLabQuality.setText(ps.getText("quality"));
|
482 |
jTextMaxResults.setToolTipText(ps.getText("maxresultstip"));
|
483 |
jTextAccuracy.setToolTipText(ps.getText("accuracytip"));
|
484 |
jTextQuality.setToolTipText(ps.getText("qualitytip"));
|
485 |
jButCancel.setText(ps.getText("cancel"));
|
486 |
jButSave.setText(ps.getText("save"));
|
487 |
} |
488 |
|
489 |
/**
|
490 |
* This method updates all labels of the panel from properties file
|
491 |
*/
|
492 |
private void setImages() { |
493 |
|
494 |
String baseDir = PluginServices.getPluginServices(this) |
495 |
.getClassLoader().getBaseDir(); |
496 |
|
497 |
jButSave.setIcon(new ImageIcon(baseDir + File.separator + "images" |
498 |
+ File.separator + "icons16" + File.separator |
499 |
+ "media-floppy.png"));
|
500 |
jButCancel.setIcon(new ImageIcon(baseDir + File.separator + "images" |
501 |
+ File.separator + "icons16" + File.separator |
502 |
+ "process-stop.png"));
|
503 |
} |
504 |
|
505 |
/**
|
506 |
* WindowInfo
|
507 |
*/
|
508 |
public WindowInfo getWindowInfo() {
|
509 |
WindowInfo info = new WindowInfo(WindowInfo.MODALDIALOG
|
510 |
| WindowInfo.RESIZABLE); |
511 |
|
512 |
info.setMinimumSize(this.getMinimumSize());
|
513 |
info.setWidth(400);
|
514 |
info.setHeight(300);
|
515 |
info.setTitle(PluginServices.getText(this, "new_geocoding_pattern")); |
516 |
|
517 |
return info;
|
518 |
} |
519 |
|
520 |
/**
|
521 |
* This method loads the layers names into the combo
|
522 |
*
|
523 |
* @param list
|
524 |
* vectorial layers
|
525 |
* @return combo model
|
526 |
*/
|
527 |
private DefaultComboBoxModel getModelListLayers(List<FLyrVect> layers) { |
528 |
|
529 |
DefaultComboBoxModel comboModel = new DefaultComboBoxModel(); |
530 |
|
531 |
if (layers.size() > 0) { |
532 |
for (int i = 0; i < layers.size(); i++) { |
533 |
comboModel.addElement((layers.get(i)).getName()); |
534 |
} |
535 |
} |
536 |
return comboModel;
|
537 |
} |
538 |
|
539 |
/**
|
540 |
* This method creates the table model
|
541 |
*
|
542 |
* @param nameFields
|
543 |
* @return
|
544 |
*/
|
545 |
private DefaultTableModel getModelTableResults(List<String> nameFields) { |
546 |
|
547 |
DefaultTableModel tmod = new DefaultTableModel(); |
548 |
int fils = nameFields.size();
|
549 |
String deftext = PluginServices.getText(this, "combodefaulttext"); |
550 |
String namefields = PluginServices.getText(this, "combonamefields"); |
551 |
String elements = PluginServices.getText(this, "comboaddresselements"); |
552 |
Object[][] data = new String[fils][2]; |
553 |
Object[] titles = new String[] { namefields, elements }; |
554 |
for (int i = 0; i < fils; i++) { |
555 |
data[i][0] = nameFields.get(i);
|
556 |
data[i][1] = deftext;
|
557 |
} |
558 |
tmod.setDataVector(data, titles); |
559 |
return tmod;
|
560 |
} |
561 |
|
562 |
/**
|
563 |
* This method saves same pattern's attributes
|
564 |
*/
|
565 |
private void preSave() { |
566 |
|
567 |
/* save the layer selected */
|
568 |
String layerEntity = getLayerEntity();
|
569 |
pattern.getSource().setLayerSource(layerEntity); |
570 |
|
571 |
/* save the parameters */
|
572 |
pattern.getSettings().setResults( |
573 |
Integer.parseInt(jTextMaxResults.getText().trim()));
|
574 |
pattern.getSettings().setAccuracy( |
575 |
Integer.parseInt(jTextAccuracy.getText().trim()));
|
576 |
pattern.getSettings().setQuality( |
577 |
Integer.parseInt(jTextQuality.getText().trim()));
|
578 |
|
579 |
/* list components */
|
580 |
List<Component> relations = getRelationsFolderComponent(); |
581 |
pattern.getSource().setAddressComponents(relations); |
582 |
} |
583 |
|
584 |
/**
|
585 |
* Update the table with folders of layer
|
586 |
*
|
587 |
* @param lyr
|
588 |
*/
|
589 |
private void updateTable(FLyrVect lyr) { |
590 |
List<String> names = new ArrayList<String>(); |
591 |
FeatureStore store = null;
|
592 |
FeatureType type = null;
|
593 |
if (lyr != null) { |
594 |
try {
|
595 |
store = lyr.getFeatureStore(); |
596 |
type = store.getDefaultFeatureType(); |
597 |
} catch (ReadException e) {
|
598 |
log.error("Reading the layer",e);
|
599 |
} catch (DataException e) {
|
600 |
log.error("Getting the type",e);
|
601 |
} |
602 |
|
603 |
for (int i = 0; i < type.size(); i++) { |
604 |
names.add(type.getAttributeDescriptor(i).getName()); |
605 |
} |
606 |
} |
607 |
String[] colnames = { PluginServices.getText(null, "components"), |
608 |
PluginServices.getText(null, "folders") }; |
609 |
DefaultTableModel model = new DefaultTableModel(colnames, |
610 |
names.size()); |
611 |
jTableElements.setModel(model); |
612 |
jTableElements.getColumnModel().getColumn(0).setCellEditor(
|
613 |
new DefaultCellEditor(createComboComponents())); |
614 |
jTableElements.getColumnModel().getColumn(1).setCellEditor(
|
615 |
new DefaultCellEditor(createComboFolders(names))); |
616 |
|
617 |
jTableElements.validate(); |
618 |
} |
619 |
|
620 |
/**
|
621 |
* Update the table with folders of layer
|
622 |
*
|
623 |
* @param lyr
|
624 |
*/
|
625 |
private void updateTable() { |
626 |
|
627 |
String[] colnames = { PluginServices.getText(null, "components"), |
628 |
PluginServices.getText(null, "folders") }; |
629 |
DefaultTableModel model = new DefaultTableModel(colnames, 0); |
630 |
jTableElements.setModel(model); |
631 |
jTableElements.validate(); |
632 |
} |
633 |
|
634 |
/**
|
635 |
* This method creates a JComboBox to insert in the JTable cells
|
636 |
*
|
637 |
* @return
|
638 |
*/
|
639 |
private JComboBox createComboComponents() { |
640 |
|
641 |
/* Combo elements number, plus default element */
|
642 |
int ele = components.size() + 1; |
643 |
|
644 |
Object[] comboele = new Object[ele]; |
645 |
|
646 |
/* Add default element */
|
647 |
comboele[0] = "..."; |
648 |
/* Add other elements */
|
649 |
for (int i = 1; i < ele; i++) { |
650 |
comboele[i] = (String) components.get(i - 1); |
651 |
} |
652 |
JComboBox inCombo = new JComboBox(comboele); |
653 |
inCombo.setEditable(false);
|
654 |
|
655 |
return inCombo;
|
656 |
} |
657 |
|
658 |
/**
|
659 |
* This method creates a JComboBox to insert in the JTable cells
|
660 |
*
|
661 |
* @return
|
662 |
*/
|
663 |
private JComboBox createComboFolders(List names) { |
664 |
|
665 |
/* Combo elements number, plus default element */
|
666 |
int fNames = names.size() + 1; |
667 |
|
668 |
Object[] comboele = new Object[fNames]; |
669 |
|
670 |
/* Add default element */
|
671 |
comboele[0] = "..."; |
672 |
/* Add other elements */
|
673 |
for (int i = 1; i < fNames; i++) { |
674 |
comboele[i] = (String) names.get(i-1); |
675 |
} |
676 |
JComboBox inCombo = new JComboBox(comboele); |
677 |
inCombo.setEditable(false);
|
678 |
|
679 |
return inCombo;
|
680 |
} |
681 |
|
682 |
/**
|
683 |
*
|
684 |
* @return
|
685 |
*/
|
686 |
private String getLayerEntity() { |
687 |
FLyrVect lyr = getSelectedLayer(); |
688 |
XMLEntity xml = null;
|
689 |
String entity = ""; |
690 |
try {
|
691 |
xml = lyr.getXMLEntity(); |
692 |
entity = xml.toString(); |
693 |
} catch (XMLException e) {
|
694 |
log.error("Getting the XMLEntity of the selected layer", e);
|
695 |
} |
696 |
return "<![CDATA[" + entity + "]]>"; |
697 |
} |
698 |
|
699 |
/**
|
700 |
*
|
701 |
* @return
|
702 |
*/
|
703 |
private List<Component> getRelationsFolderComponent() { |
704 |
|
705 |
List<Component> relations = new ArrayList<Component>(); |
706 |
TableModel model = jTableElements.getModel();
|
707 |
FLyrVect lyr = getSelectedLayer(); |
708 |
List<String> foldernames = null; |
709 |
FeatureStore store = null;
|
710 |
FeatureType type = null;
|
711 |
|
712 |
try {
|
713 |
store = lyr.getFeatureStore(); |
714 |
type = store.getDefaultFeatureType(); |
715 |
for (int i = 0; i < type.size(); i++) { |
716 |
foldernames.add(type.getAttributeDescriptor(i).getName()); |
717 |
} |
718 |
} catch (ReadException e) {
|
719 |
log.error("Getting names of folders of selected layer", e);
|
720 |
} catch (DataException e) {
|
721 |
log.error("Getting names of folders of selected layer", e);
|
722 |
} |
723 |
|
724 |
for (int i = 0; i < foldernames.size(); i++) { |
725 |
|
726 |
String key = (String) model.getValueAt(i, 0); |
727 |
|
728 |
if (key != null && key.trim().compareTo("...") != 0) { |
729 |
String value = (String) model.getValueAt(i, 1); |
730 |
if (value != null && value.trim().compareTo("...") != 0) { |
731 |
relations.add(new Component(key.trim(), value.trim())); |
732 |
} |
733 |
} |
734 |
} |
735 |
return relations;
|
736 |
} |
737 |
|
738 |
/**
|
739 |
*
|
740 |
* @return
|
741 |
*/
|
742 |
private FLyrVect getSelectedLayer() {
|
743 |
int posCapa = (int) jComboLayers.getSelectedIndex(); |
744 |
return lyrs.get(posCapa);
|
745 |
} |
746 |
|
747 |
} |