root / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / gui / GeocodingPanel.java @ 27464
History | View | Annotate | Download (30.6 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 |
package org.gvsig.geocoding.gui; |
28 |
|
29 |
import java.awt.Dimension; |
30 |
import java.awt.GridBagConstraints; |
31 |
import java.awt.event.MouseAdapter; |
32 |
import java.awt.event.MouseEvent; |
33 |
import java.awt.event.MouseListener; |
34 |
import java.io.File; |
35 |
import java.util.ArrayList; |
36 |
import java.util.List; |
37 |
import java.util.Set; |
38 |
|
39 |
import javax.swing.ButtonGroup; |
40 |
import javax.swing.DefaultComboBoxModel; |
41 |
import javax.swing.ImageIcon; |
42 |
import javax.swing.JButton; |
43 |
import javax.swing.JComboBox; |
44 |
import javax.swing.JLabel; |
45 |
import javax.swing.JPanel; |
46 |
import javax.swing.JRadioButton; |
47 |
import javax.swing.JScrollPane; |
48 |
import javax.swing.JTable; |
49 |
import javax.swing.JTextField; |
50 |
import javax.swing.ListSelectionModel; |
51 |
import javax.swing.SwingConstants; |
52 |
import javax.swing.table.JTableHeader; |
53 |
import javax.swing.table.TableColumn; |
54 |
|
55 |
import org.gvsig.fmap.dal.exception.DataException; |
56 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
57 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
58 |
import org.gvsig.fmap.geom.primitive.Point2D; |
59 |
import org.gvsig.geocoding.extension.GeocoController; |
60 |
import org.gvsig.geocoding.gui.address.AbstractAddressPanel; |
61 |
import org.gvsig.geocoding.gui.settings.SettingsPanel; |
62 |
import org.gvsig.geocoding.result.GeocodingResult; |
63 |
import org.gvsig.geocoding.utils.GeocoUtils; |
64 |
import org.gvsig.project.document.table.FeatureTableDocument; |
65 |
import org.slf4j.Logger; |
66 |
import org.slf4j.LoggerFactory; |
67 |
|
68 |
import com.iver.andami.PluginServices; |
69 |
import com.iver.andami.ui.mdiManager.IWindow; |
70 |
import com.iver.andami.ui.mdiManager.SingletonWindow; |
71 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
72 |
|
73 |
/**
|
74 |
* Main panel
|
75 |
*
|
76 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
77 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
|
78 |
*/
|
79 |
|
80 |
public class GeocodingPanel extends JPanel implements SingletonWindow, |
81 |
MouseListener {
|
82 |
|
83 |
private static final long serialVersionUID = 1L; |
84 |
private Logger log = LoggerFactory.getLogger(GeocodingPanel.class); |
85 |
private GeocoController control = null; |
86 |
|
87 |
private AbstractAddressPanel aPanel = null; |
88 |
|
89 |
private ButtonGroup groupRadio; |
90 |
private JButton jButExit; |
91 |
private JButton jButLoad; |
92 |
private JButton jButNew; |
93 |
private JButton jButEdit; |
94 |
private JButton jButNext; |
95 |
private JButton jButPrevious; |
96 |
private JButton jButSearch; |
97 |
private JButton jButExport; |
98 |
private JComboBox jComboTable; |
99 |
private JComboBox jComboType; |
100 |
private JLabel jLabPatternPath; |
101 |
private JLabel jLabScore; |
102 |
private JLabel jLabType; |
103 |
private JLabel jLabRow; |
104 |
private JPanel jPanButtons; |
105 |
private JPanel jPanGeocodingType; |
106 |
private JPanel jPanPattern; |
107 |
private JPanel jPanResults; |
108 |
private JPanel jPanResultsButtons; |
109 |
private JPanel jPanSettings; |
110 |
private JPanel jPanSimpleTable; |
111 |
private JPanel jPanTable; |
112 |
private JPanel jPanType; |
113 |
private JRadioButton jRadioSimple; |
114 |
private JRadioButton jRadioTable; |
115 |
private JScrollPane jScrollResults; |
116 |
private JTable jTableResults; |
117 |
private JTextField jTextPatternPath; |
118 |
private SettingsPanel settingsPanel;
|
119 |
|
120 |
/**
|
121 |
* Constructor
|
122 |
*
|
123 |
* @param _control
|
124 |
*/
|
125 |
public GeocodingPanel(GeocoController _control) {
|
126 |
this.control = _control;
|
127 |
this.initComponents();
|
128 |
this.setMesages();
|
129 |
this.setImages();
|
130 |
|
131 |
// pattern null
|
132 |
this.control.getGmodel().setPattern(null); |
133 |
settingsPanel.setMaxResults(10);
|
134 |
settingsPanel.activateComponents(false);
|
135 |
} |
136 |
|
137 |
/**
|
138 |
*
|
139 |
*/
|
140 |
private void setImages() { |
141 |
String baseDir = PluginServices.getPluginServices(this) |
142 |
.getClassLoader().getBaseDir(); |
143 |
|
144 |
jButLoad.setIcon(new ImageIcon(baseDir + File.separator + "images" |
145 |
+ File.separator + "icons16" + File.separator + "open.png")); |
146 |
jButNew.setIcon(new ImageIcon(baseDir + File.separator + "images" |
147 |
+ File.separator + "icons16" + File.separator + "new.png")); |
148 |
|
149 |
jButEdit.setIcon(new ImageIcon(baseDir + File.separator + "images" |
150 |
+ File.separator + "icons16" + File.separator + "edit.png")); |
151 |
|
152 |
jButNext.setIcon(new ImageIcon(baseDir + File.separator + "images" |
153 |
+ File.separator + "icons16" + File.separator + "next.png")); |
154 |
|
155 |
jButPrevious |
156 |
.setIcon(new ImageIcon(baseDir + File.separator + "images" |
157 |
+ File.separator + "icons16" + File.separator |
158 |
+ "previous.png"));
|
159 |
|
160 |
jButSearch.setIcon(new ImageIcon(baseDir + File.separator + "images" |
161 |
+ File.separator + "icons16" + File.separator + "search.png")); |
162 |
|
163 |
jButExit.setIcon(new ImageIcon(baseDir + File.separator + "images" |
164 |
+ File.separator + "icons16" + File.separator + "out.png")); |
165 |
|
166 |
jButExport.setIcon(new ImageIcon(baseDir + File.separator + "images" |
167 |
+ File.separator + "icons16" + File.separator + "up.png")); |
168 |
|
169 |
} |
170 |
|
171 |
/**
|
172 |
*
|
173 |
*/
|
174 |
private void setMesages() { |
175 |
PluginServices ps = PluginServices.getPluginServices(this);
|
176 |
|
177 |
jPanPattern |
178 |
.setBorder(GeocoUtils.getTitledBorder(ps.getText("pattern")));
|
179 |
|
180 |
this.jButLoad.setToolTipText(ps.getText("butloadpattern")); |
181 |
|
182 |
this.jButNew.setToolTipText(ps.getText("butnewpattern")); |
183 |
|
184 |
this.jButEdit.setToolTipText(ps.getText("buteditpattern")); |
185 |
|
186 |
this.jLabPatternPath.setText(ps.getText("patternpath")); |
187 |
|
188 |
jPanGeocodingType.setBorder(GeocoUtils.getTitledBorder(ps |
189 |
.getText("gtype")));
|
190 |
|
191 |
this.jRadioSimple.setText(ps.getText("gsimple")); |
192 |
this.jRadioSimple.setToolTipText(ps.getText("gsimpletip")); |
193 |
|
194 |
this.jRadioTable.setText(ps.getText("gtable")); |
195 |
this.jRadioTable.setToolTipText(ps.getText("gtabletip")); |
196 |
|
197 |
jPanType.setBorder(GeocoUtils.getTitledBorder(ps.getText("atype")));
|
198 |
|
199 |
jPanSettings.setBorder(GeocoUtils.getTitledBorder(ps |
200 |
.getText("settings")));
|
201 |
|
202 |
jPanResults |
203 |
.setBorder(GeocoUtils.getTitledBorder(ps.getText("results")));
|
204 |
|
205 |
this.jButPrevious.setToolTipText(ps.getText("previoustip")); |
206 |
this.jButNext.setToolTipText(ps.getText("nexttip")); |
207 |
|
208 |
this.jButExit.setText(ps.getText("exit")); |
209 |
this.jButSearch.setText(ps.getText("search")); |
210 |
this.jButExport.setText(ps.getText("export")); |
211 |
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* Components
|
216 |
*/
|
217 |
private void initComponents() { |
218 |
|
219 |
this.setFocusable(true); |
220 |
this.addMouseListener(this); |
221 |
|
222 |
java.awt.GridBagConstraints gridBagConstraints; |
223 |
|
224 |
groupRadio = new javax.swing.ButtonGroup();
|
225 |
jPanPattern = new javax.swing.JPanel();
|
226 |
jLabPatternPath = new javax.swing.JLabel();
|
227 |
jTextPatternPath = new javax.swing.JTextField();
|
228 |
jButLoad = new javax.swing.JButton();
|
229 |
jButNew = new javax.swing.JButton();
|
230 |
jButEdit = new javax.swing.JButton();
|
231 |
jPanGeocodingType = new javax.swing.JPanel();
|
232 |
jPanSimpleTable = new javax.swing.JPanel();
|
233 |
jRadioSimple = new javax.swing.JRadioButton();
|
234 |
jPanTable = new javax.swing.JPanel();
|
235 |
jComboTable = new javax.swing.JComboBox();
|
236 |
jRadioTable = new javax.swing.JRadioButton();
|
237 |
jPanType = new javax.swing.JPanel();
|
238 |
jComboType = new javax.swing.JComboBox();
|
239 |
jLabType = new javax.swing.JLabel();
|
240 |
jLabRow = new javax.swing.JLabel();
|
241 |
jPanSettings = new javax.swing.JPanel();
|
242 |
settingsPanel = new SettingsPanel(control);
|
243 |
jLabScore = new javax.swing.JLabel();
|
244 |
jPanResults = new javax.swing.JPanel();
|
245 |
jScrollResults = new javax.swing.JScrollPane();
|
246 |
jTableResults = new javax.swing.JTable();
|
247 |
jPanResultsButtons = new javax.swing.JPanel();
|
248 |
jButNext = new javax.swing.JButton();
|
249 |
jButPrevious = new javax.swing.JButton();
|
250 |
jPanButtons = new javax.swing.JPanel();
|
251 |
jButExit = new javax.swing.JButton();
|
252 |
jButSearch = new javax.swing.JButton();
|
253 |
jButExport = new javax.swing.JButton();
|
254 |
|
255 |
setLayout(new java.awt.GridBagLayout());
|
256 |
|
257 |
jPanPattern.setBorder(javax.swing.BorderFactory |
258 |
.createTitledBorder("Pattern"));
|
259 |
jPanPattern.setLayout(new java.awt.GridBagLayout());
|
260 |
|
261 |
jLabPatternPath.setText("Name");
|
262 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
263 |
gridBagConstraints.gridx = 0;
|
264 |
gridBagConstraints.gridy = 0;
|
265 |
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 3); |
266 |
jPanPattern.add(jLabPatternPath, gridBagConstraints); |
267 |
|
268 |
jTextPatternPath.setEditable(false);
|
269 |
jTextPatternPath.setToolTipText("Pattern file");
|
270 |
|
271 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
272 |
gridBagConstraints.gridx = 1;
|
273 |
gridBagConstraints.gridy = 0;
|
274 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
275 |
gridBagConstraints.weightx = 1.0;
|
276 |
jPanPattern.add(jTextPatternPath, gridBagConstraints); |
277 |
|
278 |
jButLoad.setText("");
|
279 |
jButLoad.setToolTipText("Load pattern");
|
280 |
jButLoad.setMaximumSize(new java.awt.Dimension(35, 25)); |
281 |
jButLoad.setMinimumSize(new java.awt.Dimension(30, 25)); |
282 |
jButLoad.setPreferredSize(new java.awt.Dimension(30, 25)); |
283 |
jButLoad.addActionListener(new java.awt.event.ActionListener() {
|
284 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
285 |
evLoadPattern(evt); |
286 |
} |
287 |
}); |
288 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
289 |
gridBagConstraints.gridx = 2;
|
290 |
gridBagConstraints.gridy = 0;
|
291 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0); |
292 |
jPanPattern.add(jButLoad, gridBagConstraints); |
293 |
|
294 |
jButNew.setText("");
|
295 |
jButNew.setToolTipText("New");
|
296 |
jButNew.setMaximumSize(new java.awt.Dimension(35, 25)); |
297 |
jButNew.setMinimumSize(new java.awt.Dimension(30, 25)); |
298 |
jButNew.setPreferredSize(new java.awt.Dimension(30, 25)); |
299 |
jButNew.addActionListener(new java.awt.event.ActionListener() {
|
300 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
301 |
evNewPattern(evt); |
302 |
} |
303 |
}); |
304 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
305 |
gridBagConstraints.gridx = 3;
|
306 |
gridBagConstraints.gridy = 0;
|
307 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0); |
308 |
jPanPattern.add(jButNew, gridBagConstraints); |
309 |
|
310 |
jButEdit.setText("");
|
311 |
jButEdit.setToolTipText("Edit");
|
312 |
jButEdit.setMaximumSize(new java.awt.Dimension(35, 25)); |
313 |
jButEdit.setMinimumSize(new java.awt.Dimension(30, 25)); |
314 |
jButEdit.setPreferredSize(new java.awt.Dimension(30, 25)); |
315 |
jButEdit.setEnabled(false);
|
316 |
jButEdit.addActionListener(new java.awt.event.ActionListener() {
|
317 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
318 |
evEditPattern(evt); |
319 |
} |
320 |
}); |
321 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
322 |
gridBagConstraints.gridx = 4;
|
323 |
gridBagConstraints.gridy = 0;
|
324 |
gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 2); |
325 |
jPanPattern.add(jButEdit, gridBagConstraints); |
326 |
|
327 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
328 |
gridBagConstraints.gridx = 0;
|
329 |
gridBagConstraints.gridy = 0;
|
330 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
331 |
gridBagConstraints.weightx = 1.0;
|
332 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
333 |
add(jPanPattern, gridBagConstraints); |
334 |
|
335 |
jPanGeocodingType.setBorder(javax.swing.BorderFactory |
336 |
.createTitledBorder("Geocoding type"));
|
337 |
jPanGeocodingType.setLayout(new java.awt.GridBagLayout());
|
338 |
jPanSimpleTable.setLayout(new java.awt.GridBagLayout());
|
339 |
|
340 |
groupRadio.add(jRadioSimple); |
341 |
jRadioSimple.setSelected(true);
|
342 |
jRadioSimple.setEnabled(false);
|
343 |
jRadioSimple.setText("Simple geocoding");
|
344 |
jRadioSimple.setToolTipText("Simple geocoding");
|
345 |
jRadioSimple.addActionListener(new java.awt.event.ActionListener() {
|
346 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
347 |
evSimpleGeocoding(evt); |
348 |
} |
349 |
}); |
350 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
351 |
gridBagConstraints.gridx = 0;
|
352 |
gridBagConstraints.gridy = 0;
|
353 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
354 |
gridBagConstraints.weightx = 1.0;
|
355 |
gridBagConstraints.insets = new java.awt.Insets(0, 50, 0, 10); |
356 |
jPanSimpleTable.add(jRadioSimple, gridBagConstraints); |
357 |
|
358 |
jPanTable.setLayout(new java.awt.GridBagLayout());
|
359 |
|
360 |
jComboTable.setModel(new javax.swing.DefaultComboBoxModel(
|
361 |
new String[] { "" })); |
362 |
jComboTable.setMinimumSize(new java.awt.Dimension(150, 18)); |
363 |
jComboTable.setPreferredSize(new java.awt.Dimension(200, 22)); |
364 |
|
365 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
366 |
gridBagConstraints.gridx = 1;
|
367 |
gridBagConstraints.gridy = 0;
|
368 |
jComboTable.setEnabled(false);
|
369 |
jComboTable.addActionListener(new java.awt.event.ActionListener() {
|
370 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
371 |
evChangeTable(evt); |
372 |
} |
373 |
}); |
374 |
jPanTable.add(jComboTable, gridBagConstraints); |
375 |
|
376 |
groupRadio.add(jRadioTable); |
377 |
jRadioTable.setText("Table geocoding");
|
378 |
jRadioTable.setEnabled(false);
|
379 |
jRadioTable.setToolTipText("Table geocoding");
|
380 |
jRadioTable.addActionListener(new java.awt.event.ActionListener() {
|
381 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
382 |
evTableGeocoding(evt); |
383 |
} |
384 |
}); |
385 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
386 |
gridBagConstraints.gridx = 0;
|
387 |
gridBagConstraints.gridy = 0;
|
388 |
gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 2); |
389 |
jPanTable.add(jRadioTable, gridBagConstraints); |
390 |
|
391 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
392 |
gridBagConstraints.gridx = 1;
|
393 |
gridBagConstraints.gridy = 0;
|
394 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
395 |
gridBagConstraints.weightx = 1.0;
|
396 |
jPanSimpleTable.add(jPanTable, gridBagConstraints); |
397 |
|
398 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
399 |
gridBagConstraints.gridx = 0;
|
400 |
gridBagConstraints.gridy = 0;
|
401 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
402 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
403 |
jPanGeocodingType.add(jPanSimpleTable, gridBagConstraints); |
404 |
|
405 |
jPanType.setBorder(javax.swing.BorderFactory |
406 |
.createTitledBorder("Search Type"));
|
407 |
jPanType.setLayout(new java.awt.GridBagLayout());
|
408 |
|
409 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
410 |
gridBagConstraints.gridx = 0;
|
411 |
gridBagConstraints.gridy = 1;
|
412 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
413 |
gridBagConstraints.weightx = 1.0;
|
414 |
gridBagConstraints.weighty = 1.0;
|
415 |
gridBagConstraints.insets = new java.awt.Insets(1, 1, 1, 1); |
416 |
jPanGeocodingType.add(jPanType, gridBagConstraints); |
417 |
|
418 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
419 |
gridBagConstraints.gridx = 0;
|
420 |
gridBagConstraints.gridy = 1;
|
421 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
422 |
gridBagConstraints.weightx = 1.0;
|
423 |
gridBagConstraints.weighty = 0.7;
|
424 |
gridBagConstraints.insets = new java.awt.Insets(1, 2, 1, 2); |
425 |
add(jPanGeocodingType, gridBagConstraints); |
426 |
|
427 |
jPanSettings.setBorder(javax.swing.BorderFactory |
428 |
.createTitledBorder("Settings"));
|
429 |
jPanSettings.setLayout(new java.awt.GridBagLayout());
|
430 |
|
431 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
432 |
gridBagConstraints.gridx = 0;
|
433 |
gridBagConstraints.gridy = 0;
|
434 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
435 |
gridBagConstraints.weightx = 1.0;
|
436 |
gridBagConstraints.weighty = 1.0;
|
437 |
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5); |
438 |
jPanSettings.add(settingsPanel, gridBagConstraints); |
439 |
|
440 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
441 |
gridBagConstraints.gridx = 0;
|
442 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
443 |
gridBagConstraints.weightx = 1.0;
|
444 |
gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); |
445 |
jPanGeocodingType.add(jPanSettings, gridBagConstraints); |
446 |
|
447 |
jPanResults.setBorder(javax.swing.BorderFactory |
448 |
.createTitledBorder("Results"));
|
449 |
jPanResults.setLayout(new java.awt.GridBagLayout());
|
450 |
jTableResults.setEnabled(false);
|
451 |
jTableResults.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
452 |
jTableResults.addMouseListener(this);
|
453 |
jTableResults.setModel(new TableResultsModel(control));
|
454 |
// TableColumn col0 = jTableResults.getColumnModel().getColumn(0);
|
455 |
// col0.setPreferredWidth(35);
|
456 |
// col0.setMaxWidth(35);
|
457 |
// TableColumn col1 = jTableResults.getColumnModel().getColumn(1);
|
458 |
// col1.setPreferredWidth(35);
|
459 |
// col1.setMaxWidth(35);
|
460 |
// TableColumn col2 = jTableResults.getColumnModel().getColumn(2);
|
461 |
// col2.setPreferredWidth(35);
|
462 |
// col2.setMaxWidth(35);
|
463 |
jScrollResults.setViewportView(jTableResults); |
464 |
|
465 |
// JTableHeader header = jTableResults.getTableHeader();
|
466 |
//
|
467 |
// header.addMouseListener(new MouseAdapter() {
|
468 |
// public void mouseClicked(MouseEvent e) {
|
469 |
// JTableHeader h = (JTableHeader) e.getSource();
|
470 |
// int nColumn = h.columnAtPoint(e.getPoint());
|
471 |
//
|
472 |
// if (nColumn == 1 || nColumn == 2) {
|
473 |
// ((TableResultsModel) jTableResults.getModel())
|
474 |
// .sort(nColumn);
|
475 |
// jTableResults.validate();
|
476 |
// }
|
477 |
// }
|
478 |
// });
|
479 |
|
480 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
481 |
gridBagConstraints.gridx = 0;
|
482 |
gridBagConstraints.gridy = 0;
|
483 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
484 |
gridBagConstraints.weightx = 1.0;
|
485 |
gridBagConstraints.weighty = 1.0;
|
486 |
jPanResults.add(jScrollResults, gridBagConstraints); |
487 |
|
488 |
jPanResultsButtons.setLayout(new java.awt.GridBagLayout());
|
489 |
|
490 |
jButNext.setText("");
|
491 |
jButNext.setToolTipText("Next register");
|
492 |
jButNext.setEnabled(false);
|
493 |
jButNext.setPreferredSize(new Dimension(35, 25)); |
494 |
jButNext.setMaximumSize(new Dimension(35, 25)); |
495 |
jButNext.addActionListener(new java.awt.event.ActionListener() {
|
496 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
497 |
evNextButton(evt); |
498 |
} |
499 |
}); |
500 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
501 |
gridBagConstraints.gridx = 2;
|
502 |
gridBagConstraints.gridy = 0;
|
503 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; |
504 |
jPanResultsButtons.add(jButNext, gridBagConstraints); |
505 |
|
506 |
jLabRow.setText("");
|
507 |
jLabRow.setEnabled(false);
|
508 |
jLabRow.setHorizontalAlignment(SwingConstants.CENTER);
|
509 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
510 |
gridBagConstraints.gridx = 1;
|
511 |
gridBagConstraints.gridy = 0;
|
512 |
gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5); |
513 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER; |
514 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
515 |
gridBagConstraints.weightx = 1.0;
|
516 |
jPanResultsButtons.add(jLabRow, gridBagConstraints); |
517 |
|
518 |
jButPrevious.setText("");
|
519 |
jButPrevious.setToolTipText("Previous register");
|
520 |
jButPrevious.setEnabled(false);
|
521 |
jButPrevious.setMaximumSize(new Dimension(35, 25)); |
522 |
jButPrevious.setPreferredSize(new Dimension(35, 25)); |
523 |
jButPrevious.addActionListener(new java.awt.event.ActionListener() {
|
524 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
525 |
evPreviousButton(evt); |
526 |
} |
527 |
}); |
528 |
|
529 |
|
530 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
531 |
gridBagConstraints.gridx = 0;
|
532 |
gridBagConstraints.gridy = 0;
|
533 |
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; |
534 |
jPanResultsButtons.add(jButPrevious, gridBagConstraints); |
535 |
|
536 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
537 |
gridBagConstraints.gridx = 0;
|
538 |
gridBagConstraints.gridy = 1;
|
539 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
540 |
gridBagConstraints.weightx = 1.0;
|
541 |
gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0); |
542 |
jPanResults.add(jPanResultsButtons, gridBagConstraints); |
543 |
|
544 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
545 |
gridBagConstraints.gridx = 0;
|
546 |
gridBagConstraints.gridy = 3;
|
547 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
548 |
gridBagConstraints.weightx = 1.0;
|
549 |
gridBagConstraints.weighty = 1.0;
|
550 |
gridBagConstraints.insets = new java.awt.Insets(1, 2, 1, 2); |
551 |
add(jPanResults, gridBagConstraints); |
552 |
|
553 |
jPanButtons.setLayout(new java.awt.GridBagLayout());
|
554 |
|
555 |
jButExit.setText("Exit");
|
556 |
jButExit.setToolTipText("Exit");
|
557 |
jButExit.addActionListener(new java.awt.event.ActionListener() {
|
558 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
559 |
evExit(evt); |
560 |
} |
561 |
}); |
562 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
563 |
gridBagConstraints.gridx = 2;
|
564 |
gridBagConstraints.gridy = 0;
|
565 |
gridBagConstraints.insets = new java.awt.Insets(0, 20, 0, 0); |
566 |
jPanButtons.add(jButExit, gridBagConstraints); |
567 |
|
568 |
jButSearch.setText("Search");
|
569 |
jButSearch.setToolTipText("Search");
|
570 |
jButSearch.setEnabled(false);
|
571 |
jButSearch.addActionListener(new java.awt.event.ActionListener() {
|
572 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
573 |
evSearch(evt); |
574 |
} |
575 |
}); |
576 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
577 |
gridBagConstraints.gridx = 0;
|
578 |
gridBagConstraints.gridy = 0;
|
579 |
jPanButtons.add(jButSearch, gridBagConstraints); |
580 |
|
581 |
jButExport.setText("Export");
|
582 |
jButExport.setToolTipText("Export");
|
583 |
jButExport.addActionListener(new java.awt.event.ActionListener() {
|
584 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
585 |
evExport(evt); |
586 |
} |
587 |
}); |
588 |
jPanButtons.add(jButExport, new java.awt.GridBagConstraints());
|
589 |
|
590 |
gridBagConstraints = new java.awt.GridBagConstraints();
|
591 |
gridBagConstraints.gridx = 0;
|
592 |
gridBagConstraints.gridy = 4;
|
593 |
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
594 |
gridBagConstraints.weightx = 1.0;
|
595 |
gridBagConstraints.insets = new java.awt.Insets(2, 2, 4, 2); |
596 |
add(jPanButtons, gridBagConstraints); |
597 |
} |
598 |
|
599 |
/**
|
600 |
* Load a pattern from file event
|
601 |
*
|
602 |
* @param evt
|
603 |
*/
|
604 |
private void evLoadPattern(java.awt.event.ActionEvent evt) { |
605 |
/* load the pattern */
|
606 |
boolean apto = control.loadPatternXML();
|
607 |
|
608 |
if (apto) {
|
609 |
|
610 |
/* update the url of the pattern in the panel */
|
611 |
if (control.getGmodel().getPatternFile() != null) { |
612 |
jTextPatternPath.setText(control.getGmodel().getPatternFile() |
613 |
.getAbsolutePath()); |
614 |
jButEdit.setEnabled(true);
|
615 |
} |
616 |
/* update the parameters */
|
617 |
settingsPanel.setMaxResults(control.getPattern().getSettings() |
618 |
.getResultsNumber()); |
619 |
settingsPanel.setScore(control.getPattern().getSettings() |
620 |
.getScore()); |
621 |
|
622 |
// enable components
|
623 |
if (control.getPattern() != null) { |
624 |
this.enableComponents();
|
625 |
// insert address panel
|
626 |
insertAddressPanel(); |
627 |
} |
628 |
} |
629 |
} |
630 |
|
631 |
/**
|
632 |
* create new pattern event
|
633 |
*
|
634 |
* @param evt
|
635 |
*/
|
636 |
private void evNewPattern(java.awt.event.ActionEvent evt) { |
637 |
control.launchNewPatternPanel(null);
|
638 |
} |
639 |
|
640 |
/**
|
641 |
* edit current pattern event
|
642 |
*
|
643 |
* @param evt
|
644 |
*/
|
645 |
private void evEditPattern(java.awt.event.ActionEvent evt) { |
646 |
control.launchNewPatternPanel(control.getPattern()); |
647 |
} |
648 |
|
649 |
/**
|
650 |
* Simple geocoding event
|
651 |
*
|
652 |
* @param evt
|
653 |
*/
|
654 |
private void evSimpleGeocoding(java.awt.event.ActionEvent evt) { |
655 |
control.getGmodel().setSimple(true);
|
656 |
activeTableGUIFeatures(false);
|
657 |
jButExport.setEnabled(false);
|
658 |
|
659 |
// insert address panel
|
660 |
insertAddressPanel(); |
661 |
} |
662 |
|
663 |
/**
|
664 |
* Tables availables event
|
665 |
*
|
666 |
* @param evt
|
667 |
*/
|
668 |
private void evTableGeocoding(java.awt.event.ActionEvent evt) { |
669 |
/* Put the tables names availables in the combo */
|
670 |
DefaultComboBoxModel comboModel = control.getModelgvSIGTables();
|
671 |
if (comboModel == null) { |
672 |
comboModel = new DefaultComboBoxModel(); |
673 |
} |
674 |
/* save in the model table geocoding */
|
675 |
jComboTable.setModel(comboModel); |
676 |
/* enable components */
|
677 |
control.getGmodel().setSimple(false);
|
678 |
jComboTable.setEnabled(true);
|
679 |
jButExport.setEnabled(false);
|
680 |
|
681 |
// save descriptor table in the model
|
682 |
List<FeatureAttributeDescriptor> descs = getListOfDescriptorSelectedTable();
|
683 |
control.getGmodel().setListDescriptorSelectedTable(descs); |
684 |
|
685 |
// insert address panel
|
686 |
insertAddressPanel(); |
687 |
|
688 |
} |
689 |
|
690 |
/**
|
691 |
* Table selected event
|
692 |
*
|
693 |
* @param evt
|
694 |
*/
|
695 |
private void evChangeTable(java.awt.event.ActionEvent evt) { |
696 |
|
697 |
// save descriptor table in the model
|
698 |
List<FeatureAttributeDescriptor> descs = getListOfDescriptorSelectedTable();
|
699 |
control.getGmodel().setListDescriptorSelectedTable(descs); |
700 |
|
701 |
// insert address panel
|
702 |
insertAddressPanel(); |
703 |
|
704 |
} |
705 |
|
706 |
/**
|
707 |
* next button
|
708 |
*
|
709 |
* @param evt
|
710 |
*/
|
711 |
private void evNextButton(java.awt.event.ActionEvent evt) { |
712 |
List<Set<GeocodingResult>> results = control.getGmodel() |
713 |
.getAllResults(); |
714 |
int row = control.getGmodel().getNumResultShowed();
|
715 |
int cant = results.size()-2; |
716 |
if (row <= cant) {
|
717 |
Set<GeocodingResult> res = results.get(row + 1); |
718 |
((TableResultsModel) jTableResults.getModel()).setResultSet(res, |
719 |
control.getPattern().getSettings().getResultsNumber(),control.getPattern().getSettings().getScore()); |
720 |
jLabRow.setText(control.ROW + Integer.toString(row + 2)); |
721 |
control.getGmodel().setNumResultShowed(row + 1);
|
722 |
} |
723 |
} |
724 |
|
725 |
/**
|
726 |
* Previous event
|
727 |
*
|
728 |
* @param evt
|
729 |
*/
|
730 |
private void evPreviousButton(java.awt.event.ActionEvent evt) { |
731 |
List<Set<GeocodingResult>> results = control.getGmodel() |
732 |
.getAllResults(); |
733 |
int row = control.getGmodel().getNumResultShowed();
|
734 |
if (row > 0) { |
735 |
Set<GeocodingResult> res = results.get(row-1); |
736 |
((TableResultsModel) jTableResults.getModel()).setResultSet(res, |
737 |
control.getPattern().getSettings().getResultsNumber(),control.getPattern().getSettings().getScore()); |
738 |
jLabRow.setText(control.ROW + Integer.toString(row));
|
739 |
control.getGmodel().setNumResultShowed(row-1);
|
740 |
} |
741 |
} |
742 |
|
743 |
/**
|
744 |
* geocoding search event
|
745 |
*
|
746 |
* @param evt
|
747 |
*/
|
748 |
private void evSearch(java.awt.event.ActionEvent evt) { |
749 |
|
750 |
jTableResults.setModel(new TableResultsModel(control));
|
751 |
jTableResults.validate(); |
752 |
// // GEOCODING PROCESS
|
753 |
control.geocoding(); |
754 |
// // GEOCODING PROCESS
|
755 |
} |
756 |
|
757 |
/**
|
758 |
* export event
|
759 |
*
|
760 |
* @param evt
|
761 |
*/
|
762 |
private void evExport(java.awt.event.ActionEvent evt) { |
763 |
|
764 |
} |
765 |
|
766 |
/**
|
767 |
* exit event. Close the panel
|
768 |
*
|
769 |
* @param evt
|
770 |
*/
|
771 |
private void evExit(java.awt.event.ActionEvent evt) { |
772 |
this.control.getGmodel().setPattern(null); |
773 |
IWindow[] iws = PluginServices.getMDIManager().getAllWindows();
|
774 |
for (int i = 0; i < iws.length; i++) { |
775 |
if (iws[i] instanceof GeocodingPanel) { |
776 |
PluginServices.getMDIManager().closeWindow(iws[i]); |
777 |
} |
778 |
} |
779 |
} |
780 |
|
781 |
/**
|
782 |
* get window info
|
783 |
*/
|
784 |
public WindowInfo getWindowInfo() {
|
785 |
// WindowInfo info = new WindowInfo(WindowInfo.MODALDIALOG
|
786 |
// | WindowInfo.RESIZABLE);
|
787 |
WindowInfo info = new WindowInfo(WindowInfo.RESIZABLE);
|
788 |
|
789 |
info.setMinimumSize(this.getMinimumSize());
|
790 |
info.setWidth(600);
|
791 |
info.setHeight(530);
|
792 |
info.setTitle(PluginServices.getText(this, "geocoding")); |
793 |
|
794 |
return info;
|
795 |
} |
796 |
|
797 |
/**
|
798 |
* get window profile
|
799 |
*/
|
800 |
public Object getWindowProfile() { |
801 |
return null; |
802 |
} |
803 |
|
804 |
/**
|
805 |
* insert changeable address panel
|
806 |
*
|
807 |
* @param pan
|
808 |
*/
|
809 |
public void insertAddressPanel() { |
810 |
|
811 |
// get the panel depending of on the type of geocoding pattern
|
812 |
this.aPanel = control.getAddressPanelFromPattern();
|
813 |
jPanType.removeAll(); |
814 |
|
815 |
GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints(); |
816 |
gridBagConstraints.gridx = 0;
|
817 |
gridBagConstraints.gridy = 0;
|
818 |
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
819 |
gridBagConstraints.weightx = 1.0;
|
820 |
gridBagConstraints.weighty = 1.0;
|
821 |
|
822 |
jPanType.add(this.aPanel, gridBagConstraints);
|
823 |
|
824 |
this.setSize(this.getWidth() + 1, this.getHeight()); |
825 |
jPanType.validate(); |
826 |
jPanResults.validate(); |
827 |
jPanPattern.validate(); |
828 |
this.aPanel.validate();
|
829 |
this.validate();
|
830 |
} |
831 |
|
832 |
/**
|
833 |
* Set maximun results parameter
|
834 |
*
|
835 |
* @param results
|
836 |
*/
|
837 |
public void setParamMaxresults(int results) { |
838 |
settingsPanel.setMaxResults(new Integer(results)); |
839 |
} |
840 |
|
841 |
/**
|
842 |
* Set score parameter
|
843 |
*
|
844 |
* @param score
|
845 |
*/
|
846 |
public void setParamScore(double score) { |
847 |
settingsPanel.setScore(new Double(score)); |
848 |
|
849 |
} |
850 |
|
851 |
/**
|
852 |
* get the path pattern
|
853 |
*
|
854 |
* @return
|
855 |
*/
|
856 |
public String getJTextPatternPath() { |
857 |
return jTextPatternPath.getText();
|
858 |
} |
859 |
|
860 |
/**
|
861 |
* Set path pattern
|
862 |
*
|
863 |
* @param path
|
864 |
*/
|
865 |
public void setJTextPatternPath(String path) { |
866 |
this.jTextPatternPath.setText(path);
|
867 |
jButEdit.setEnabled(true);
|
868 |
} |
869 |
|
870 |
/**
|
871 |
* Enable components when load a pattern or create new pattern
|
872 |
*/
|
873 |
public void enableComponents() { |
874 |
jRadioSimple.setEnabled(true);
|
875 |
if (GeocoUtils.getListgvSIGTables().size() > 0) { |
876 |
jRadioTable.setEnabled(true);
|
877 |
} |
878 |
jLabType.setEnabled(true);
|
879 |
jComboType.setEnabled(true);
|
880 |
jLabScore.setEnabled(true);
|
881 |
jTableResults.setEnabled(true);
|
882 |
jButSearch.setEnabled(true);
|
883 |
settingsPanel.activateComponents(true);
|
884 |
} |
885 |
|
886 |
/**
|
887 |
* Active GUI features related with Massive geocoding from table
|
888 |
*
|
889 |
* @param active
|
890 |
*/
|
891 |
public void activeTableGUIFeatures(boolean active) { |
892 |
jComboTable.setEnabled(active); |
893 |
|
894 |
if (!jRadioSimple.isSelected() && active) {
|
895 |
jButNext.setEnabled(active); |
896 |
jButPrevious.setEnabled(active); |
897 |
jLabRow.setEnabled(active); |
898 |
|
899 |
} else {
|
900 |
jLabRow.setText("");
|
901 |
jButNext.setEnabled(false);
|
902 |
jButPrevious.setEnabled(false);
|
903 |
} |
904 |
} |
905 |
|
906 |
/**
|
907 |
* mouse clicked event
|
908 |
*/
|
909 |
public void mouseClicked(MouseEvent e) { |
910 |
// nothing to do
|
911 |
} |
912 |
|
913 |
/**
|
914 |
* mouse entered event
|
915 |
*/
|
916 |
public void mouseEntered(MouseEvent e) { |
917 |
if (control.getPattern() != null) { |
918 |
List<FeatureTableDocument> tables = GeocoUtils.getListgvSIGTables();
|
919 |
if (tables.size() > 0) { |
920 |
if (control.getPattern() != null) { |
921 |
jRadioTable.setEnabled(true);
|
922 |
} |
923 |
} else {
|
924 |
jRadioTable.setEnabled(false);
|
925 |
} |
926 |
} |
927 |
} |
928 |
|
929 |
/**
|
930 |
* mouse exit event
|
931 |
*/
|
932 |
public void mouseExited(MouseEvent e) { |
933 |
// nothing to do
|
934 |
} |
935 |
|
936 |
/**
|
937 |
* Mouse pressed events
|
938 |
*/
|
939 |
public void mousePressed(MouseEvent e) { |
940 |
// nothing to do
|
941 |
} |
942 |
|
943 |
/**
|
944 |
* Mouse released event
|
945 |
*/
|
946 |
public void mouseReleased(MouseEvent e) { |
947 |
int row = jTableResults.getSelectedRow();
|
948 |
TableResultsModel model = (TableResultsModel)jTableResults.getModel(); |
949 |
Point2D pto = model.getGeometry(row);
|
950 |
try {
|
951 |
GeocoUtils.zoomToPoint(pto.getX(), pto.getY()); |
952 |
} catch (Exception e1) { |
953 |
log.error("Doing zoom to point",e);
|
954 |
} |
955 |
} |
956 |
|
957 |
/**
|
958 |
* get selected table
|
959 |
*
|
960 |
* @return
|
961 |
*/
|
962 |
public FeatureTableDocument getSelectedTable() {
|
963 |
return (FeatureTableDocument) jComboTable.getModel().getSelectedItem();
|
964 |
} |
965 |
|
966 |
/**
|
967 |
* get window model
|
968 |
*/
|
969 |
public Object getWindowModel() { |
970 |
return this.getClass().getCanonicalName(); |
971 |
} |
972 |
|
973 |
/**
|
974 |
* save in the model the list of fields descriptors of the selected table
|
975 |
*/
|
976 |
private List<FeatureAttributeDescriptor> getListOfDescriptorSelectedTable() { |
977 |
List<FeatureAttributeDescriptor> descs = new ArrayList<FeatureAttributeDescriptor>(); |
978 |
FeatureTableDocument table = (FeatureTableDocument) jComboTable |
979 |
.getSelectedItem(); |
980 |
FeatureStore store = (FeatureStore) table.getStore(); |
981 |
control.getGmodel().setSelectedTableStore(store); |
982 |
|
983 |
try {
|
984 |
int nDescs = store.getDefaultFeatureType().size();
|
985 |
for (int i = 0; i < nDescs; i++) { |
986 |
FeatureAttributeDescriptor desc = store.getDefaultFeatureType() |
987 |
.getAttributeDescriptor(i); |
988 |
descs.add(desc); |
989 |
} |
990 |
} catch (DataException e) {
|
991 |
log |
992 |
.error( |
993 |
"Error getting the fields descriptors of the selected table",
|
994 |
e); |
995 |
} |
996 |
return descs;
|
997 |
|
998 |
} |
999 |
|
1000 |
/**
|
1001 |
* get address panel
|
1002 |
*
|
1003 |
* @return
|
1004 |
*/
|
1005 |
public AbstractAddressPanel getAddressPanel() {
|
1006 |
return aPanel;
|
1007 |
} |
1008 |
|
1009 |
/**
|
1010 |
* get table of results
|
1011 |
*
|
1012 |
* @return
|
1013 |
*/
|
1014 |
public JTable getJTableResults() { |
1015 |
return jTableResults;
|
1016 |
} |
1017 |
|
1018 |
/**
|
1019 |
*
|
1020 |
* @param string
|
1021 |
*/
|
1022 |
public void setLabRow(String string) { |
1023 |
jLabRow.setText(string); |
1024 |
|
1025 |
} |
1026 |
|
1027 |
} |