Revision 41302 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
DefaultMapContextManager.java | ||
---|---|---|
74 | 74 |
import org.gvsig.tools.ToolsLocator; |
75 | 75 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
76 | 76 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
77 |
import org.gvsig.tools.observer.Notification; |
|
78 |
import org.gvsig.tools.observer.ObservableHelper; |
|
79 |
import org.gvsig.tools.observer.Observer; |
|
77 | 80 |
import org.gvsig.tools.persistence.PersistenceManager; |
78 | 81 |
import org.slf4j.Logger; |
79 | 82 |
import org.slf4j.LoggerFactory; |
... | ... | |
98 | 101 |
|
99 | 102 |
private String defaultVectorLegend; |
100 | 103 |
|
104 |
private ObservableHelper observableHelper = new ObservableHelper(); |
|
105 |
|
|
101 | 106 |
public MapContext createMapContext() { |
102 |
return new MapContext(new ViewPort()); |
|
107 |
MapContext mapcontext = new MapContext(new ViewPort()); |
|
108 |
return (MapContext) notifyObservers(CREATE_MAPCONTEXT, mapcontext).getValue(); |
|
103 | 109 |
} |
104 | 110 |
|
105 | 111 |
public SymbolManager getSymbolManager() { |
... | ... | |
214 | 220 |
private MapContextDrawer createMapContextDrawerInstance(Class drawerClazz, |
215 | 221 |
String name) throws RegisteredClassInstantiationException { |
216 | 222 |
try { |
217 |
return (MapContextDrawer) drawerClazz.newInstance(); |
|
223 |
MapContextDrawer drawer = (MapContextDrawer) drawerClazz.newInstance(); |
|
224 |
notifyObservers( CREATE_MAPCONTEXT_DRAWER, drawer); |
|
225 |
return drawer; |
|
218 | 226 |
} catch (Exception ex) { |
219 | 227 |
throw new RegisteredClassInstantiationException( |
220 | 228 |
MapContextDrawer.class, drawerClazz, name, ex); |
... | ... | |
226 | 234 |
|
227 | 235 |
validateMapContextDrawer(drawerClazz); |
228 | 236 |
this.drawerClazz = drawerClazz; |
237 |
notifyObservers( SET_MAPCONTEXT_DRAWER, drawerClazz); |
|
229 | 238 |
} |
230 | 239 |
|
231 | 240 |
public void validateMapContextDrawer(Class drawerClazz) |
... | ... | |
244 | 253 |
} catch (Exception e) { |
245 | 254 |
logger.error("Error initializing the graphics layer", e); |
246 | 255 |
} |
247 |
return layer;
|
|
256 |
return (GraphicLayer) notifyObservers( CREATE_GRAPHICS_LAYER, layer).getValue();
|
|
248 | 257 |
} |
249 | 258 |
|
250 | 259 |
public String getDefaultVectorLegend() { |
... | ... | |
264 | 273 |
} |
265 | 274 |
|
266 | 275 |
legends.put(legendName, legendClass); |
276 |
notifyObservers( REGISTER_LEGEND, legendName, legendClass); |
|
267 | 277 |
} |
268 | 278 |
|
269 | 279 |
public ILegend createLegend(String legendName) |
... | ... | |
272 | 282 |
|
273 | 283 |
if (legendClass != null) { |
274 | 284 |
try { |
275 |
return (ILegend) legendClass.newInstance(); |
|
285 |
ILegend legend = (ILegend) legendClass.newInstance(); |
|
286 |
return (ILegend) notifyObservers( CREATE_LEGEND, legend).getValue(); |
|
276 | 287 |
} catch (InstantiationException e) { |
277 | 288 |
throw new RegisteredClassInstantiationException(ILegend.class, |
278 | 289 |
legendClass, legendName, e); |
... | ... | |
319 | 330 |
} |
320 | 331 |
|
321 | 332 |
legendReaders.put(format, readerClass); |
333 |
notifyObservers( REGISTER_LEGEND_READER, format, readerClass); |
|
322 | 334 |
} |
323 | 335 |
|
324 | 336 |
|
... | ... | |
328 | 340 |
|
329 | 341 |
if (legendReaderClazz != null) { |
330 | 342 |
try { |
331 |
return (ILegendReader) legendReaderClazz.newInstance(); |
|
343 |
ILegendReader reader = (ILegendReader) legendReaderClazz.newInstance(); |
|
344 |
return (ILegendReader) notifyObservers( CREATE_LEGEND_READER, reader).getValue(); |
|
332 | 345 |
} catch (InstantiationException e) { |
333 | 346 |
throw new RegisteredClassInstantiationException( |
334 | 347 |
ILegendReader.class, legendReaderClazz, format, e); |
... | ... | |
362 | 375 |
} |
363 | 376 |
} |
364 | 377 |
legendFormatWriters.put(legendClass, writerClass); |
378 |
notifyObservers( REGISTER_LEGEND_WRITER, format, writerClass); |
|
365 | 379 |
} |
366 | 380 |
|
367 | 381 |
public ILegendWriter createLegendWriter(Class legendClass, String format) |
... | ... | |
382 | 396 |
* Found exact match |
383 | 397 |
*/ |
384 | 398 |
try { |
385 |
return (ILegendWriter) legendWriterClazz.newInstance(); |
|
399 |
ILegendWriter writer = (ILegendWriter) legendWriterClazz.newInstance(); |
|
400 |
return (ILegendWriter) notifyObservers( CREATE_LEGEND_READER, writer).getValue(); |
|
386 | 401 |
} catch (InstantiationException e) { |
387 | 402 |
throw new RegisteredClassInstantiationException( |
388 | 403 |
ILegendWriter.class, legendWriterClazz, format |
... | ... | |
463 | 478 |
|
464 | 479 |
public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
465 | 480 |
throws MapContextRuntimeException { |
466 |
return getSymbolManager().createMultiLayerSymbol(shapeType); |
|
481 |
IMultiLayerSymbol symbol = getSymbolManager().createMultiLayerSymbol(shapeType); |
|
482 |
return (IMultiLayerSymbol) notifyObservers( CREATE_SYMBOL, symbol).getValue(); |
|
467 | 483 |
} |
468 | 484 |
|
469 | 485 |
public IMultiLayerSymbol createMultiLayerSymbol(String symbolName) |
470 | 486 |
throws MapContextRuntimeException { |
471 |
return getSymbolManager().createMultiLayerSymbol(symbolName); |
|
487 |
IMultiLayerSymbol symbol = getSymbolManager().createMultiLayerSymbol(symbolName); |
|
488 |
return (IMultiLayerSymbol) notifyObservers( CREATE_SYMBOL, symbol).getValue(); |
|
472 | 489 |
} |
473 | 490 |
|
474 | 491 |
public ISymbol createSymbol(int shapeType, Color color) |
475 | 492 |
throws MapContextRuntimeException { |
476 |
return getSymbolManager().createSymbol(shapeType, color); |
|
493 |
ISymbol symbol = getSymbolManager().createSymbol(shapeType, color); |
|
494 |
return (ISymbol) notifyObservers( CREATE_SYMBOL, symbol).getValue(); |
|
477 | 495 |
} |
478 | 496 |
|
479 | 497 |
public ISymbol createSymbol(int shapeType) |
480 | 498 |
throws MapContextRuntimeException { |
481 |
return getSymbolManager().createSymbol(shapeType); |
|
499 |
ISymbol symbol = getSymbolManager().createSymbol(shapeType); |
|
500 |
return (ISymbol) notifyObservers( CREATE_SYMBOL, symbol).getValue(); |
|
482 | 501 |
} |
483 | 502 |
|
484 | 503 |
public ISymbol createSymbol(String symbolName, Color color) |
485 | 504 |
throws MapContextRuntimeException { |
486 |
return getSymbolManager().createSymbol(symbolName, color); |
|
505 |
ISymbol symbol = getSymbolManager().createSymbol(symbolName, color); |
|
506 |
return (ISymbol) notifyObservers( CREATE_SYMBOL, symbol).getValue(); |
|
487 | 507 |
} |
488 | 508 |
|
489 | 509 |
public ISymbol createSymbol(String symbolName) |
490 | 510 |
throws MapContextRuntimeException { |
491 |
return getSymbolManager().createSymbol(symbolName); |
|
511 |
ISymbol symbol = getSymbolManager().createSymbol(symbolName); |
|
512 |
return (ISymbol) notifyObservers( CREATE_SYMBOL, symbol).getValue(); |
|
492 | 513 |
} |
493 | 514 |
|
494 | 515 |
public IWarningSymbol getWarningSymbol(String message, String symbolDesc, |
... | ... | |
499 | 520 |
|
500 | 521 |
public ISymbol[] loadSymbols(File folder, FileFilter filter) |
501 | 522 |
throws SymbolException { |
502 |
return getSymbolManager().loadSymbols(folder, filter); |
|
523 |
ISymbol[] symbols = getSymbolManager().loadSymbols(folder, filter); |
|
524 |
return (ISymbol[]) notifyObservers( LOAD_SYMBOLS, symbols).getValue(); |
|
503 | 525 |
} |
504 | 526 |
|
505 | 527 |
public ISymbol[] loadSymbols(File folder) throws SymbolException { |
506 |
return getSymbolManager().loadSymbols(folder); |
|
528 |
ISymbol[] symbols = getSymbolManager().loadSymbols(folder); |
|
529 |
return (ISymbol[]) notifyObservers( LOAD_SYMBOLS, symbols).getValue(); |
|
507 | 530 |
} |
508 | 531 |
|
509 | 532 |
public void registerMultiLayerSymbol(String symbolName, Class symbolClass) |
510 | 533 |
throws MapContextRuntimeException { |
511 | 534 |
getSymbolManager().registerMultiLayerSymbol(symbolName, symbolClass); |
535 |
notifyObservers( REGISTER_MULTILAYER_SYMBOL, symbolName, symbolClass); |
|
512 | 536 |
} |
513 | 537 |
|
514 | 538 |
public void registerMultiLayerSymbol(String symbolName, int[] shapeTypes, |
515 | 539 |
Class symbolClass) throws MapContextRuntimeException { |
516 | 540 |
getSymbolManager().registerMultiLayerSymbol(symbolName, shapeTypes, |
517 | 541 |
symbolClass); |
542 |
notifyObservers( REGISTER_MULTILAYER_SYMBOL, symbolName, symbolClass, shapeTypes); |
|
518 | 543 |
} |
519 | 544 |
|
520 | 545 |
public void registerSymbol(String symbolName, Class symbolClass) |
521 | 546 |
throws MapContextRuntimeException { |
522 | 547 |
getSymbolManager().registerSymbol(symbolName, symbolClass); |
548 |
notifyObservers( REGISTER_SYMBOL, symbolName, symbolClass); |
|
523 | 549 |
} |
524 | 550 |
|
525 | 551 |
public void registerSymbol(String symbolName, int[] shapeTypes, |
526 | 552 |
Class symbolClass) throws MapContextException { |
527 | 553 |
getSymbolManager().registerSymbol(symbolName, shapeTypes, symbolClass); |
554 |
notifyObservers( REGISTER_SYMBOL, symbolName, symbolClass, shapeTypes); |
|
528 | 555 |
} |
529 | 556 |
|
530 | 557 |
public void saveSymbol(ISymbol symbol, String fileName, File folder, |
... | ... | |
539 | 566 |
|
540 | 567 |
public FLayer createLayer(String layerName, DataStoreParameters parameters) |
541 | 568 |
throws LoadLayerException { |
542 |
return LayerFactory.getInstance().createLayer(layerName, parameters); |
|
569 |
FLayer layer = LayerFactory.getInstance().createLayer(layerName, parameters); |
|
570 |
return (FLayer) notifyObservers( CREATE_LAYER, layer).getValue(); |
|
543 | 571 |
} |
544 | 572 |
|
545 | 573 |
public FLayer createLayer(String layerName, DataStore store) |
546 | 574 |
throws LoadLayerException { |
547 |
return LayerFactory.getInstance().createLayer(layerName, store); |
|
575 |
FLayer layer = LayerFactory.getInstance().createLayer(layerName, store); |
|
576 |
return (FLayer) notifyObservers( CREATE_LAYER, layer).getValue(); |
|
548 | 577 |
} |
549 | 578 |
|
550 |
public ILegend getLegend(DataStore dataStore) {
|
|
579 |
public ILegend getLegend(DataStore dataStore) {
|
|
551 | 580 |
ILegend legend = null; |
552 | 581 |
|
553 | 582 |
File file = getResourcePath(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1)); |
554 | 583 |
try { |
555 |
if ((file != null) && (file.exists())) {
|
|
584 |
if ( (file != null) && (file.exists()) ) {
|
|
556 | 585 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
557 | 586 |
FileInputStream is = new FileInputStream(file); |
558 | 587 |
legend = (ILegend) persistenceManager.getObject(is); |
... | ... | |
565 | 594 |
} |
566 | 595 |
|
567 | 596 |
//If the legend is null, next option is to check if the store has the getLegend method |
568 |
if (legend == null) {
|
|
597 |
if ( legend == null ) {
|
|
569 | 598 |
try { |
570 | 599 |
legend = (IVectorLegend) dataStore.invokeDynMethod("getLegend", null); |
571 | 600 |
} catch (DynMethodNotSupportedException e) { |
... | ... | |
579 | 608 |
} |
580 | 609 |
|
581 | 610 |
//If legend is null, last step is just try to create the legend by default |
582 |
if (legend == null) {
|
|
611 |
if ( legend == null ) {
|
|
583 | 612 |
FeatureType featureType; |
584 | 613 |
try { |
585 | 614 |
featureType = (((FeatureStore) dataStore).getDefaultFeatureType()); |
... | ... | |
681 | 710 |
logger.info("registerIconLayer, storeProviderName or iconName are null"); |
682 | 711 |
return; |
683 | 712 |
} |
684 |
if( storeProviderName.trim().length()==0 || iconName.trim().length()==0 ) { |
|
713 |
String storeName = storeProviderName.trim().toLowerCase(); |
|
714 |
if( storeName.length()==0 || iconName.trim().length()==0 ) { |
|
685 | 715 |
logger.info("registerIconLayer, invalid storeProviderName or iconName"); |
686 | 716 |
return; |
687 | 717 |
} |
688 |
iconLayers.put(storeProviderName.trim().toLowerCase(), iconName); |
|
718 |
iconLayers.put(storeName, iconName); |
|
719 |
notifyObservers( REGISTER_ICON_LAYER, storeName, iconName); |
|
689 | 720 |
} |
690 | 721 |
|
691 | 722 |
public String getIconLayer(DataStore store) { |
... | ... | |
700 | 731 |
* @see org.gvsig.fmap.mapcontext.MapContextManager#getDefaultCRS() |
701 | 732 |
*/ |
702 | 733 |
public IProjection getDefaultCRS() { |
703 |
return CRSFactory.getCRS("EPSG:4326"); |
|
734 |
IProjection crs = CRSFactory.getCRS("EPSG:4326"); |
|
735 |
return (IProjection) notifyObservers( GET_DEFAULT_CRS, crs).getValue(); |
|
704 | 736 |
} |
705 | 737 |
|
738 |
public Notification notifyLoadMapContext(MapContext mapContext) { |
|
739 |
return this.observableHelper.notifyObservers(this, LOAD_MAPCONTEXT, mapContext); |
|
740 |
} |
|
741 |
|
|
742 |
public Notification notifyLoadLayer(FLayer layer) { |
|
743 |
return this.observableHelper.notifyObservers(this, LOAD_LAYER, layer); |
|
744 |
} |
|
745 |
|
|
746 |
public void addObserver(Observer o) { |
|
747 |
this.observableHelper.addObserver(o); |
|
748 |
} |
|
749 |
|
|
750 |
public void deleteObserver(Observer o) { |
|
751 |
this.observableHelper.deleteObserver(o); |
|
752 |
} |
|
753 |
|
|
754 |
public void deleteObservers() { |
|
755 |
this.observableHelper.deleteObservers(); |
|
756 |
} |
|
757 |
|
|
758 |
protected Notification notifyObservers(String type, Object value) { |
|
759 |
return this.observableHelper.notifyObservers(this, type, value); |
|
760 |
} |
|
761 |
|
|
762 |
protected Notification notifyObservers(String type, Object value1, Object value2) { |
|
763 |
return this.observableHelper.notifyObservers(this, type, value1, value2); |
|
764 |
} |
|
765 |
|
|
766 |
protected Notification notifyObservers(String type, Object value1, Object value2, Object value3) { |
|
767 |
return this.observableHelper.notifyObservers(this, type, value1, value2, value3); |
|
768 |
} |
|
706 | 769 |
} |
Also available in: Unified diff