root / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / extension / GeocodingController.java @ 32090
History | View | Annotate | Download (20.5 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. main developer
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.geocoding.extension; |
29 |
|
30 |
import java.awt.Color; |
31 |
import java.io.BufferedReader; |
32 |
import java.io.File; |
33 |
import java.io.FileReader; |
34 |
import java.io.IOException; |
35 |
import java.util.ArrayList; |
36 |
import java.util.List; |
37 |
import java.util.Locale; |
38 |
import java.util.Set; |
39 |
|
40 |
import javax.swing.DefaultComboBoxModel; |
41 |
import javax.swing.JFileChooser; |
42 |
import javax.swing.JOptionPane; |
43 |
import javax.swing.JTable; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
47 |
import org.gvsig.app.project.Project; |
48 |
import org.gvsig.app.project.documents.Document; |
49 |
import org.gvsig.app.project.documents.gui.ProjectWindow; |
50 |
import org.gvsig.app.project.documents.table.TableDocument; |
51 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
52 |
import org.gvsig.app.project.documents.view.gui.IView; |
53 |
import org.gvsig.fmap.dal.exception.DataException; |
54 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
55 |
import org.gvsig.fmap.geom.Geometry; |
56 |
import org.gvsig.fmap.geom.primitive.Envelope; |
57 |
import org.gvsig.fmap.geom.primitive.Point; |
58 |
import org.gvsig.fmap.geom.primitive.impl.Envelope2D; |
59 |
import org.gvsig.fmap.geom.primitive.impl.Point2D; |
60 |
import org.gvsig.fmap.mapcontext.MapContext; |
61 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
62 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
63 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
64 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
65 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
66 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
67 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
68 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
70 |
import org.gvsig.fmap.mapcontrol.MapControl; |
71 |
import org.gvsig.geocoding.address.Literal; |
72 |
import org.gvsig.geocoding.gui.GeocodingModel; |
73 |
import org.gvsig.geocoding.gui.GeocodingPanel; |
74 |
import org.gvsig.geocoding.gui.IGeocodingModel; |
75 |
import org.gvsig.geocoding.gui.address.AbstractAddressPanel; |
76 |
import org.gvsig.geocoding.gui.address.AddressComposedPanel; |
77 |
import org.gvsig.geocoding.gui.address.AddressRangePanel; |
78 |
import org.gvsig.geocoding.gui.address.AddressSimpleCentroidPanel; |
79 |
import org.gvsig.geocoding.gui.newpattern.NewPatternPanel; |
80 |
import org.gvsig.geocoding.gui.relation.RelatePanel; |
81 |
import org.gvsig.geocoding.gui.results.ResultsPanel; |
82 |
import org.gvsig.geocoding.pattern.GeocodingPattern; |
83 |
import org.gvsig.geocoding.pattern.GeocodingSettings; |
84 |
import org.gvsig.geocoding.result.GeocodingResult; |
85 |
import org.gvsig.geocoding.styles.AbstractGeocodingStyle; |
86 |
import org.gvsig.geocoding.styles.impl.AbstractRange; |
87 |
import org.gvsig.geocoding.styles.impl.Composed; |
88 |
import org.gvsig.geocoding.styles.impl.SimpleCentroid; |
89 |
import org.gvsig.geocoding.tasks.GeocodingTask; |
90 |
import org.gvsig.geocoding.tasks.IndexingTask; |
91 |
import org.gvsig.geocoding.utils.GeocodingExtTags; |
92 |
import org.gvsig.geocoding.utils.GeocodingUtils; |
93 |
import org.gvsig.geocoding.utils.PatternLoaderThread; |
94 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol; |
95 |
import org.gvsig.utils.GenericFileFilter; |
96 |
import org.gvsig.utils.XMLEntity; |
97 |
import org.slf4j.Logger; |
98 |
import org.slf4j.LoggerFactory; |
99 |
|
100 |
/**
|
101 |
* Controller of the geocoding extension and all yours panels
|
102 |
*
|
103 |
* @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
|
104 |
* @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
|
105 |
*/
|
106 |
public class GeocodingController { |
107 |
|
108 |
private static final Logger log = LoggerFactory |
109 |
.getLogger(GeocodingController.class); |
110 |
|
111 |
private volatile static GeocodingController instance; |
112 |
|
113 |
public static final String ROW = PluginServices.getText(null, "row") |
114 |
+ " : ";
|
115 |
|
116 |
private IGeocodingModel gmodel = null; |
117 |
private GeocodingPanel gpanel = null; |
118 |
private RelatePanel relpanel = null; |
119 |
private ResultsPanel respanel = null; |
120 |
|
121 |
/**
|
122 |
* Controller Constructor
|
123 |
*/
|
124 |
private GeocodingController() {
|
125 |
// Build geocoding model
|
126 |
this.gmodel = new GeocodingModel(); |
127 |
// Create all extensions panel
|
128 |
this.gpanel = new GeocodingPanel(this); |
129 |
this.relpanel = new RelatePanel(this); |
130 |
this.respanel = new ResultsPanel(this); |
131 |
|
132 |
} |
133 |
|
134 |
/**
|
135 |
*
|
136 |
* @return
|
137 |
*/
|
138 |
public static GeocodingController getInstance() { |
139 |
if (instance == null) { |
140 |
synchronized (GeocodingController.class) {
|
141 |
if (instance == null) { |
142 |
instance = new GeocodingController();
|
143 |
} |
144 |
} |
145 |
} |
146 |
return instance;
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Run the geocoding process in background
|
151 |
*/
|
152 |
public void geocoding() { |
153 |
PluginServices.cancelableBackgroundExecution(new GeocodingTask(this)); |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Run the indexing process in background
|
158 |
*/
|
159 |
public void indexing() { |
160 |
PluginServices.cancelableBackgroundExecution(new IndexingTask(this)); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* This method loads a Pattern from XML file
|
165 |
*
|
166 |
* @return true if the load is succesfully
|
167 |
*/
|
168 |
public boolean loadPatternFromXML() { |
169 |
boolean ok = true; |
170 |
File thefile = null; |
171 |
JFileChooser jfc = null; |
172 |
/* Show the FileChooser to select a pattern file */
|
173 |
try {
|
174 |
jfc = new JFileChooser(); |
175 |
jfc.setDialogTitle(PluginServices.getText(this,
|
176 |
"load_geoco_pattern"));
|
177 |
String[] extensions = { "xml" }; |
178 |
jfc.setCurrentDirectory(new File("")); |
179 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
180 |
PluginServices.getText(this, "pattern_geoco_file"))); |
181 |
int returnval = jfc
|
182 |
.showOpenDialog((java.awt.Component) PluginServices |
183 |
.getMainFrame()); |
184 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
185 |
thefile = jfc.getSelectedFile(); |
186 |
log.debug("geocoding pattern file opened: " + thefile);
|
187 |
} else {
|
188 |
return false; |
189 |
} |
190 |
} catch (Exception e) { |
191 |
String mes = PluginServices.getText(this, "geocoerrorloadingfile"); |
192 |
String tit = PluginServices.getText(this, "geocoding"); |
193 |
JOptionPane.showMessageDialog(null, mes, tit, |
194 |
JOptionPane.ERROR_MESSAGE);
|
195 |
log.error("Error loading pattern file", e);
|
196 |
} |
197 |
/* Parse the xml file */
|
198 |
PatternLoaderThread load = new PatternLoaderThread(thefile);
|
199 |
load.run(); |
200 |
ok = load.isOk(); |
201 |
if (ok) {
|
202 |
this.gmodel.setPatternFile(load.getFile());
|
203 |
this.gmodel.setPattern(load.getPattern());
|
204 |
} |
205 |
return ok;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* This method gets the list with the address components that the user has
|
210 |
* defined in the Geocoding Preferences
|
211 |
*
|
212 |
* @return
|
213 |
*/
|
214 |
public List<String> getListAddressComponents() { |
215 |
|
216 |
List<String> components = new ArrayList<String>(); |
217 |
PluginServices ps = PluginServices.getPluginServices(this);
|
218 |
XMLEntity xml = ps.getPersistentXML(); |
219 |
|
220 |
String tag = GeocodingExtTags.GEOCODINGELEMENTS + "_" + getLanguage(); |
221 |
if (xml.contains(tag)) {
|
222 |
|
223 |
String nam = String.valueOf(xml.getStringProperty(tag)); |
224 |
File persistenceFile = new File(nam); |
225 |
String str = ""; |
226 |
|
227 |
try {
|
228 |
BufferedReader br = new BufferedReader(new FileReader( |
229 |
persistenceFile)); |
230 |
while ((str = br.readLine()) != null) { |
231 |
components.add(str); |
232 |
} |
233 |
} catch (IOException e) { |
234 |
log.error("Reading the geocoding elements file", e);
|
235 |
} |
236 |
} |
237 |
return components;
|
238 |
} |
239 |
|
240 |
/**
|
241 |
* This method gets the application language
|
242 |
*
|
243 |
* @return
|
244 |
*/
|
245 |
private String getLanguage() { |
246 |
|
247 |
ArrayList<Locale> myLocs = org.gvsig.i18n.Messages |
248 |
.getPreferredLocales(); |
249 |
Locale myLoc = myLocs.size() == 0 ? Locale.ENGLISH : myLocs.get(0); |
250 |
|
251 |
/*
|
252 |
* TODO review and test with differente language codes, included Spanish
|
253 |
* languages
|
254 |
*/
|
255 |
String lang = myLoc.getLanguage().toLowerCase();
|
256 |
|
257 |
return lang;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* This method saves the Geocoding Pattern
|
262 |
*
|
263 |
* @return
|
264 |
*/
|
265 |
public boolean savePattern() { |
266 |
|
267 |
boolean savedOK = false; |
268 |
|
269 |
JFileChooser jfc = new JFileChooser(); |
270 |
jfc.setDialogTitle(PluginServices.getText(this, "save_geoco_pattern")); |
271 |
String[] extensions = { "xml" }; |
272 |
jfc.addChoosableFileFilter(new GenericFileFilter(extensions,
|
273 |
PluginServices.getText(this, "pattern_geoco_file"))); |
274 |
int returnval = jfc.showSaveDialog((java.awt.Component) PluginServices
|
275 |
.getMainFrame()); |
276 |
|
277 |
if (returnval == JFileChooser.APPROVE_OPTION) { |
278 |
|
279 |
File file = jfc.getSelectedFile();
|
280 |
log.debug("file created: " + file);
|
281 |
if (file != null) { |
282 |
file = GeocodingUtils.addXMLSuffix(file); |
283 |
GeocodingPattern pat = this.getGmodel().getPattern();
|
284 |
pat.setPatternName(file.getName()); |
285 |
try {
|
286 |
pat.saveToXML(file); |
287 |
savedOK = true;
|
288 |
log.debug("pattern saved: " + file);
|
289 |
this.gmodel.setPatternFile(file);
|
290 |
} catch (Exception e) { |
291 |
log.error("Serializing the pattern", e);
|
292 |
String mes = PluginServices.getText(this, |
293 |
"geocorrorsavingfile");
|
294 |
String tit = PluginServices.getText(this, "geocoding"); |
295 |
JOptionPane.showMessageDialog(null, mes, tit, |
296 |
JOptionPane.ERROR_MESSAGE);
|
297 |
} |
298 |
} |
299 |
} |
300 |
return savedOK;
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* This method launches the New Pattern Panel
|
305 |
*
|
306 |
* @param pat
|
307 |
*/
|
308 |
public void launchNewPatternPanel(GeocodingPattern pat) { |
309 |
|
310 |
List<FLyrVect> lyrs = this.getListgvSIGVectLayers(); |
311 |
if (lyrs.size() > 0) { |
312 |
/* Launch the new pattern panel */
|
313 |
NewPatternPanel ppanel = new NewPatternPanel(this, pat); |
314 |
PluginServices.getMDIManager().addWindow(ppanel); |
315 |
ppanel.setVisible(true);
|
316 |
} else {
|
317 |
// show warning message
|
318 |
String title = PluginServices.getText(null, "geocoding"); |
319 |
|
320 |
String message = PluginServices.getText(null, "nolayers"); |
321 |
JOptionPane.showMessageDialog(null, message, title, |
322 |
JOptionPane.WARNING_MESSAGE);
|
323 |
} |
324 |
} |
325 |
|
326 |
/**
|
327 |
* This method updates the GeocodingPanel after save
|
328 |
*/
|
329 |
public void updateGeocoGUI() { |
330 |
// pattern path
|
331 |
gpanel.setJTextPatternPath(this.getGmodel().getPatternFile()
|
332 |
.getAbsolutePath()); |
333 |
// settings. Maximum results availables
|
334 |
gpanel.setParamMaxresults(this.getPattern().getSettings()
|
335 |
.getResultsNumber()); |
336 |
// settings. Minimum score
|
337 |
gpanel.setParamScore(this.getPattern().getSettings().getScore());
|
338 |
} |
339 |
|
340 |
/**
|
341 |
* Get the pattern from the geocoding model
|
342 |
*
|
343 |
* @return pattern
|
344 |
*/
|
345 |
public GeocodingPattern getPattern() {
|
346 |
return this.getGmodel().getPattern(); |
347 |
} |
348 |
|
349 |
/**
|
350 |
* Get geocoding model
|
351 |
*
|
352 |
* @return the gmodel
|
353 |
*/
|
354 |
public IGeocodingModel getGmodel() {
|
355 |
return gmodel;
|
356 |
} |
357 |
|
358 |
/**
|
359 |
* Get main geocoding panel
|
360 |
*
|
361 |
* @return the gpanel
|
362 |
*/
|
363 |
public GeocodingPanel getGPanel() {
|
364 |
return gpanel;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
* Get relate geocoding panel
|
369 |
*
|
370 |
* @return the gpanel
|
371 |
*/
|
372 |
public RelatePanel getGRelPanel() {
|
373 |
return relpanel;
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* Get results geocoding panel
|
378 |
*
|
379 |
* @return the gpanel
|
380 |
*/
|
381 |
public ResultsPanel getGResPanel() {
|
382 |
return respanel;
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* Get a list gvSIG Project tables
|
387 |
*
|
388 |
* @return
|
389 |
*/
|
390 |
public DefaultComboBoxModel getModelgvSIGTables() { |
391 |
// get tables loaded in gvSIG project
|
392 |
List<TableDocument> tables = this.getListgvSIGTables(); |
393 |
// Build combo model with list of tables availables
|
394 |
if (tables.size() > 0) { |
395 |
DefaultComboBoxModel comboModel = new DefaultComboBoxModel(); |
396 |
for (int i = 0; i < tables.size(); i++) { |
397 |
TableDocument table = tables.get(i); |
398 |
comboModel.addElement(table); |
399 |
} |
400 |
return comboModel;
|
401 |
} |
402 |
return null; |
403 |
} |
404 |
|
405 |
/**
|
406 |
* Get the address panel from pattern style
|
407 |
*
|
408 |
* @return panel
|
409 |
*/
|
410 |
public AbstractAddressPanel getAddressPanelFromPatternStyle() {
|
411 |
GeocodingPattern pat = this.getPattern();
|
412 |
if (pat != null) { |
413 |
AbstractGeocodingStyle style = pat.getSource().getStyle(); |
414 |
Literal lit = style.getRelationsLiteral(); |
415 |
AbstractAddressPanel aPanel = null;
|
416 |
if (style instanceof SimpleCentroid) { |
417 |
aPanel = new AddressSimpleCentroidPanel(this, lit); |
418 |
} |
419 |
if (style instanceof AbstractRange) { |
420 |
aPanel = new AddressRangePanel(this, lit); |
421 |
} |
422 |
if (style instanceof Composed) { |
423 |
aPanel = new AddressComposedPanel(this, lit); |
424 |
} |
425 |
return aPanel;
|
426 |
} |
427 |
return null; |
428 |
} |
429 |
|
430 |
/**
|
431 |
* get loops number of geocoding process
|
432 |
*
|
433 |
* @return
|
434 |
*/
|
435 |
public long getGeocodingProcessCount() { |
436 |
if (this.getGmodel().isSimple()) { |
437 |
return 1; |
438 |
} else {
|
439 |
long n = 0; |
440 |
try {
|
441 |
n = this.getGmodel().getSelectedTableStore().getFeatureSet()
|
442 |
.getSize(); |
443 |
return n;
|
444 |
} catch (Exception e) { |
445 |
return 0; |
446 |
} |
447 |
} |
448 |
} |
449 |
|
450 |
/**
|
451 |
* get JTable Results
|
452 |
*
|
453 |
* @return
|
454 |
*/
|
455 |
public JTable getJTableResults() { |
456 |
return this.gpanel.getJTableResults(); |
457 |
} |
458 |
|
459 |
/**
|
460 |
* Create initial array with list of selected results elements to export
|
461 |
*
|
462 |
* @param results
|
463 |
* @return
|
464 |
*/
|
465 |
public Integer[] createInitialResultsExportElements( |
466 |
List<Set<GeocodingResult>> results) { |
467 |
int cant = results.size();
|
468 |
Integer[] expElems = new Integer[cant]; |
469 |
int i = 0; |
470 |
for (Set<GeocodingResult> res : results) { |
471 |
if (res.size() > 0) { |
472 |
expElems[i] = 0;
|
473 |
} else {
|
474 |
expElems[i] = -1;
|
475 |
} |
476 |
i++; |
477 |
} |
478 |
return expElems;
|
479 |
} |
480 |
|
481 |
/**
|
482 |
* Get current view in gvSIG
|
483 |
*
|
484 |
* @return view
|
485 |
*/
|
486 |
public IView getCurrentView() {
|
487 |
IWindow[] ws = PluginServices.getMDIManager().getOrderedWindows();
|
488 |
for (int k = 0; k < ws.length; k++) { |
489 |
if (ws[k] instanceof IView) { |
490 |
return (DefaultViewPanel) ws[k];
|
491 |
} |
492 |
} |
493 |
return null; |
494 |
} |
495 |
|
496 |
/**
|
497 |
* Centers the view in a point (x,y)
|
498 |
*
|
499 |
* @param x
|
500 |
* @param y
|
501 |
*
|
502 |
* @throws Exception
|
503 |
*/
|
504 |
public void zoomToPoint(double x, double y) throws Exception { |
505 |
|
506 |
IView view = getCurrentView(); |
507 |
if (view != null) { |
508 |
MapContext mapContext = ((DefaultViewPanel) view).getModel() |
509 |
.getMapContext(); |
510 |
MapControl mapControl = new MapControl();
|
511 |
mapControl.setMapContext(mapContext); |
512 |
|
513 |
Envelope oldExtent = mapControl.getViewPort().getAdjustedEnvelope(); |
514 |
double oldCenterX = oldExtent.getCenter(0); |
515 |
double oldCenterY = oldExtent.getCenter(1); |
516 |
double movX = x - oldCenterX;
|
517 |
double movY = y - oldCenterY;
|
518 |
double minX = oldExtent.getMinimum(0) + movX; |
519 |
double minY = oldExtent.getMinimum(1) + movY; |
520 |
double width = oldExtent.getLength(0); |
521 |
double height = oldExtent.getLength(1); |
522 |
Point pto1 = new Point2D(minX, minY); |
523 |
Point pto2 = new Point2D(minX + width, minY + height); |
524 |
Envelope enve = new Envelope2D(pto1, pto2);
|
525 |
if (enve != null) { |
526 |
mapControl.getViewPort().setEnvelope(enve); |
527 |
} |
528 |
|
529 |
} |
530 |
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* Clear all graphics in view
|
535 |
*/
|
536 |
public void clearGeocodingPoint() { |
537 |
DefaultViewPanel view = (DefaultViewPanel) this.getCurrentView();
|
538 |
if (view != null) { |
539 |
MapContext mapContext = view.getModel().getMapContext(); |
540 |
MapControl mapControl = new MapControl();
|
541 |
mapControl.setMapContext(mapContext); |
542 |
|
543 |
GraphicLayer grphclyr = mapContext.getGraphicsLayer(); |
544 |
if (grphclyr != null) { |
545 |
FeatureSet set = null;
|
546 |
try {
|
547 |
set = (FeatureSet) grphclyr.getDataStore().getDataSet(); |
548 |
if (set != null && !set.isEmpty()) { |
549 |
grphclyr.clearAllGraphics(); |
550 |
} |
551 |
} catch (DataException e) {
|
552 |
log.warn("GraphicLayer hasn't features", e);
|
553 |
} |
554 |
} |
555 |
|
556 |
mapControl.drawGraphics(); |
557 |
view.repaint(); |
558 |
view.repaintMap(); |
559 |
} |
560 |
} |
561 |
|
562 |
/**
|
563 |
* This method gets the FLyrVect list of the View
|
564 |
*
|
565 |
* @return
|
566 |
*/
|
567 |
public List<FLyrVect> getListgvSIGVectLayers() { |
568 |
|
569 |
List<FLyrVect> layers = new ArrayList<FLyrVect>(); |
570 |
|
571 |
IView view = this.getCurrentView();
|
572 |
|
573 |
if (view != null) { |
574 |
/* Get the layers of the view */
|
575 |
MapControl mapControl = view.getMapControl(); |
576 |
FLayers lyrs = mapControl.getMapContext().getLayers(); |
577 |
if (lyrs.getLayersCount() > 0) { |
578 |
/* Get the layers (FLyrVect) of the view */
|
579 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
580 |
FLayer lyr = lyrs.getLayer(i); |
581 |
if (lyr instanceof FLyrVect) { |
582 |
layers.add((FLyrVect) lyr); |
583 |
} |
584 |
} |
585 |
} |
586 |
} |
587 |
return layers;
|
588 |
} |
589 |
|
590 |
/**
|
591 |
* Get a tables list of gvSIG project
|
592 |
*
|
593 |
* @return
|
594 |
*/
|
595 |
public List<TableDocument> getListgvSIGTables() { |
596 |
|
597 |
List<TableDocument> tables = new ArrayList<TableDocument>(); |
598 |
|
599 |
IWindow[] wins = PluginServices.getMDIManager().getAllWindows();
|
600 |
ProjectWindow projWindow = null;
|
601 |
for (int i = 0; i < wins.length; i++) { |
602 |
if (wins[i] instanceof ProjectWindow) { |
603 |
projWindow = (ProjectWindow) wins[i]; |
604 |
break;
|
605 |
} |
606 |
} |
607 |
if (projWindow != null) { |
608 |
Project p = (Project) projWindow.getWindowModel(); |
609 |
List<Document> documents = p.getDocuments(); |
610 |
for (Document docu : documents) { |
611 |
if (docu instanceof TableDocument) { |
612 |
tables.add((TableDocument) docu); |
613 |
} |
614 |
} |
615 |
} |
616 |
return tables;
|
617 |
} |
618 |
|
619 |
/**
|
620 |
* Draw point in the results position with identifier label
|
621 |
*
|
622 |
* @param result
|
623 |
* @param max
|
624 |
* @param score
|
625 |
* @throws LegendLayerException
|
626 |
*/
|
627 |
public void showResultsPositionsOnView(Set<GeocodingResult> result) |
628 |
throws LegendLayerException {
|
629 |
|
630 |
GeocodingSettings sett = this.getPattern().getSettings();
|
631 |
int max = sett.getResultsNumber();
|
632 |
double score = sett.getScore();
|
633 |
|
634 |
DefaultViewPanel vista = (DefaultViewPanel) this.getCurrentView();
|
635 |
MapContext mapContext = vista.getModel().getMapContext(); |
636 |
MapControl mapControl = new MapControl();
|
637 |
mapControl.setMapContext(mapContext); |
638 |
GraphicLayer grphclyr = mapControl.getMapContext().getGraphicsLayer(); |
639 |
long siz = 0; |
640 |
try {
|
641 |
siz = ((FeatureSet) grphclyr.getDataStore().getDataSet()).getSize(); |
642 |
} catch (DataException e) {
|
643 |
e.printStackTrace(); |
644 |
} |
645 |
if (siz > 0) { |
646 |
grphclyr.clearAllGraphics(); |
647 |
} |
648 |
|
649 |
int i = 1; |
650 |
for (GeocodingResult res : result) {
|
651 |
if (res.getScore() >= score && i <= max) {
|
652 |
IVectorialUniqueValueLegend legend = buildPointLegend(); |
653 |
grphclyr.setLegend(legend); |
654 |
|
655 |
// SimpleTextSymbol symbolText = new SimpleTextSymbol();
|
656 |
// symbolText.setFont(new Font("Verdana", Font.BOLD, 12));
|
657 |
// symbolText.setTextColor(Color.BLACK);
|
658 |
// symbolText.setText(Integer.toString(i));
|
659 |
// idSymbol = grphclyr.addSymbol(symbolText);
|
660 |
// grphclyr.addGraphic(geom, idSymbol);
|
661 |
} |
662 |
i++; |
663 |
} |
664 |
mapControl.drawGraphics(); |
665 |
} |
666 |
|
667 |
public void drawPositionsOnView(Geometry geom) { |
668 |
|
669 |
DefaultViewPanel vista = (DefaultViewPanel) this.getCurrentView();
|
670 |
MapContext mapContext = vista.getModel().getMapContext(); |
671 |
MapControl mapControl = new MapControl();
|
672 |
mapControl.setMapContext(mapContext); |
673 |
GraphicLayer grphclyr = mapControl.getMapContext().getGraphicsLayer(); |
674 |
grphclyr.clearAllGraphics(); |
675 |
|
676 |
SimpleMarkerSymbol symbol = new SimpleMarkerSymbol();
|
677 |
symbol.setStyle(SimpleMarkerSymbol.CIRCLE_STYLE); |
678 |
symbol.setSize(4);
|
679 |
symbol.setColor(Color.RED);
|
680 |
|
681 |
int idSymbol = grphclyr.addSymbol(symbol);
|
682 |
grphclyr.addGraphic(geom, idSymbol); |
683 |
mapControl.drawGraphics(); |
684 |
} |
685 |
|
686 |
/**
|
687 |
* Get selected FLyrVect in view
|
688 |
*
|
689 |
* @return
|
690 |
*/
|
691 |
public FLyrVect getSelectedFLyrVect() {
|
692 |
IView view = this.getCurrentView();
|
693 |
|
694 |
if (view != null) { |
695 |
/* Get the layers of the view */
|
696 |
MapControl mapControl = view.getMapControl(); |
697 |
FLayers lyrs = mapControl.getMapContext().getLayers(); |
698 |
if (lyrs.getActives().length > 0) { |
699 |
return (FLyrVect) lyrs.getLayer(0); |
700 |
} else {
|
701 |
return null; |
702 |
} |
703 |
} |
704 |
return null; |
705 |
} |
706 |
|
707 |
/**
|
708 |
*
|
709 |
* @return
|
710 |
*/
|
711 |
private IVectorialUniqueValueLegend buildPointLegend() {
|
712 |
|
713 |
MapContextManager mapContextManager = MapContextLocator |
714 |
.getMapContextManager(); |
715 |
|
716 |
IVectorialUniqueValueLegend legend = (IVectorialUniqueValueLegend) mapContextManager |
717 |
.createLegend(IVectorialUniqueValueLegend.LEGEND_NAME); |
718 |
legend.setShapeType(Geometry.TYPES.POINT); |
719 |
|
720 |
ISymbol symbol = mapContextManager.getSymbolManager().createSymbol( |
721 |
Geometry.TYPES.POINT, Color.RED);
|
722 |
|
723 |
((SimpleMarkerSymbol) symbol).setStyle(SimpleMarkerSymbol.CIRCLE_STYLE); |
724 |
((SimpleMarkerSymbol) symbol).setSize(4);
|
725 |
|
726 |
legend.setDefaultSymbol(symbol); |
727 |
|
728 |
return legend;
|
729 |
} |
730 |
|
731 |
} |