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