Revision 44831 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 | ||
---|---|---|
37 | 37 |
import java.util.Map; |
38 | 38 |
import org.apache.commons.io.IOUtils; |
39 | 39 |
import org.apache.commons.lang3.StringUtils; |
40 |
import org.cresques.cts.ICoordTrans; |
|
40 | 41 |
|
41 | 42 |
import org.cresques.cts.IProjection; |
42 | 43 |
import org.gvsig.fmap.crs.CRSFactory; |
43 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
44 |
import org.gvsig.fmap.dal.DALLocator; |
|
45 |
import org.gvsig.fmap.dal.DataManager; |
|
44 | 46 |
import org.gvsig.fmap.dal.DataStore; |
45 | 47 |
import org.gvsig.fmap.dal.DataStoreParameters; |
48 |
import org.gvsig.fmap.dal.DataStoreProviderFactory; |
|
46 | 49 |
import org.gvsig.fmap.dal.exception.DataException; |
47 | 50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
48 | 51 |
import org.gvsig.fmap.dal.feature.FeatureType; |
52 |
import org.gvsig.fmap.dal.raster.BandDescriptor; |
|
53 |
import org.gvsig.fmap.dal.raster.RasterStore; |
|
49 | 54 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 | 55 |
import org.gvsig.fmap.mapcontext.MapContextDrawer; |
51 | 56 |
import org.gvsig.fmap.mapcontext.MapContextException; |
... | ... | |
53 | 58 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
54 | 59 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
55 | 60 |
import org.gvsig.fmap.mapcontext.ViewPort; |
61 |
import org.gvsig.fmap.mapcontext.exceptions.CantRetrieveLayerByStoreException; |
|
56 | 62 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
57 | 63 |
import org.gvsig.fmap.mapcontext.layers.DefaultLayerInformationBuilder; |
58 | 64 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
59 |
import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
|
60 | 65 |
import org.gvsig.fmap.mapcontext.layers.LayerInformationBuilder; |
66 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
|
61 | 67 |
import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
62 | 68 |
import org.gvsig.fmap.mapcontext.layers.vectorial.impl.DefaultGraphicLayer; |
63 | 69 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
... | ... | |
72 | 78 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolException; |
73 | 79 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
74 | 80 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
81 |
import org.gvsig.raster.lib.legend.api.RasterLegend; |
|
82 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
|
83 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
|
84 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
|
75 | 85 |
import org.gvsig.tools.ToolsLocator; |
86 |
import org.gvsig.tools.dynobject.DynObject; |
|
76 | 87 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
77 | 88 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
89 |
import org.gvsig.tools.folders.FoldersManager; |
|
78 | 90 |
import org.gvsig.tools.observer.Notification; |
79 | 91 |
import org.gvsig.tools.observer.ObservableHelper; |
80 | 92 |
import org.gvsig.tools.observer.Observer; |
... | ... | |
87 | 99 |
/** |
88 | 100 |
* Default implementation of the {@link MapContextManager}. |
89 | 101 |
* |
90 |
* @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a> |
|
91 | 102 |
*/ |
103 |
@SuppressWarnings("UseSpecificCatch") |
|
92 | 104 |
public class DefaultMapContextManager implements MapContextManager { |
93 | 105 |
|
94 | 106 |
private static final Logger LOGGER = LoggerFactory |
... | ... | |
96 | 108 |
|
97 | 109 |
private Class drawerClazz = DefaultMapContextDrawer.class; |
98 | 110 |
|
99 |
private final Map legends = new HashMap(); |
|
111 |
private final Map<String,Class<ILegend>> legends = new HashMap();
|
|
100 | 112 |
|
101 | 113 |
private final Map<String, Class<ILegendReader>> legendReaders = new LinkedHashMap<>(); |
102 | 114 |
|
103 | 115 |
private final Map<String, Map<Class<ILegend>,Class<ILegendWriter>>> legendWriters = new LinkedHashMap<>(); |
116 |
|
|
117 |
private final Map<Class<? extends DataStore>,Class<? extends FLayer>> layerClassFromStoreClass = new HashMap<>(); |
|
104 | 118 |
|
119 |
private final Map<String,String> iconLayers = new HashMap(); // (Map<String storeProviderName, String iconName>) |
|
120 |
|
|
105 | 121 |
private String defaultVectorLegend; |
106 | 122 |
|
107 | 123 |
private final ObservableHelper observableHelper = new ObservableHelper(); |
108 | 124 |
|
109 | 125 |
private File colorTableLibraryFolder = null; |
126 |
private String defaultRasterLegend; |
|
110 | 127 |
|
128 |
@Override |
|
111 | 129 |
public MapContext createMapContext() { |
112 | 130 |
MapContext mapcontext = new MapContext(new ViewPort()); |
113 | 131 |
return (MapContext) notifyObservers(CREATE_MAPCONTEXT, mapcontext).getValue(); |
114 | 132 |
} |
115 | 133 |
|
134 |
@Override |
|
116 | 135 |
public SymbolManager getSymbolManager() { |
117 | 136 |
return MapContextLocator.getSymbolManager(); |
118 | 137 |
} |
... | ... | |
121 | 140 |
return getSymbolManager().getSymbolPreferences(); |
122 | 141 |
} |
123 | 142 |
|
143 |
@Override |
|
124 | 144 |
public String getSymbolLibraryPath() { |
125 | 145 |
return getSymbolPreferences().getSymbolLibraryPath(); |
126 | 146 |
} |
127 | 147 |
|
148 |
@Override |
|
128 | 149 |
public void setSymbolLibraryPath(String symbolLibraryPath) { |
129 | 150 |
getSymbolPreferences().setSymbolLibraryPath(symbolLibraryPath); |
130 | 151 |
} |
131 | 152 |
|
153 |
@Override |
|
132 | 154 |
public void resetSymbolLibraryPath() { |
133 | 155 |
getSymbolPreferences().resetSymbolLibraryPath(); |
134 | 156 |
} |
135 | 157 |
|
158 |
@Override |
|
136 | 159 |
public Color getDefaultSymbolColor() { |
137 | 160 |
return getSymbolPreferences().getDefaultSymbolColor(); |
138 | 161 |
} |
139 | 162 |
|
163 |
@Override |
|
140 | 164 |
public Color getDefaultSymbolFillColor() { |
141 | 165 |
return getSymbolPreferences().getDefaultSymbolFillColor(); |
142 | 166 |
} |
143 | 167 |
|
168 |
@Override |
|
144 | 169 |
public Font getDefaultSymbolFont() { |
145 | 170 |
return getSymbolPreferences().getDefaultSymbolFont(); |
146 | 171 |
} |
... | ... | |
149 | 174 |
return getSymbolPreferences().getSymbolFileExtension(); |
150 | 175 |
} |
151 | 176 |
|
177 |
@Override |
|
152 | 178 |
public boolean isDefaultSymbolFillColorAleatory() { |
153 | 179 |
return getSymbolPreferences().isDefaultSymbolFillColorAleatory(); |
154 | 180 |
} |
155 | 181 |
|
182 |
@Override |
|
156 | 183 |
public void resetDefaultSymbolColor() { |
157 | 184 |
getSymbolPreferences().resetDefaultSymbolColor(); |
158 | 185 |
} |
159 | 186 |
|
187 |
@Override |
|
160 | 188 |
public void resetDefaultSymbolFillColor() { |
161 | 189 |
getSymbolPreferences().resetDefaultSymbolFillColor(); |
162 | 190 |
} |
163 | 191 |
|
192 |
@Override |
|
164 | 193 |
public void resetDefaultSymbolFillColorAleatory() { |
165 | 194 |
getSymbolPreferences().resetDefaultSymbolFillColorAleatory(); |
166 | 195 |
} |
167 | 196 |
|
197 |
@Override |
|
168 | 198 |
public void resetDefaultSymbolFont() { |
169 | 199 |
getSymbolPreferences().resetDefaultSymbolFont(); |
170 | 200 |
} |
171 | 201 |
|
202 |
@Override |
|
172 | 203 |
public void setDefaultSymbolColor(Color defaultSymbolColor) { |
173 | 204 |
getSymbolPreferences().setDefaultSymbolColor(defaultSymbolColor); |
174 | 205 |
} |
175 | 206 |
|
207 |
@Override |
|
176 | 208 |
public void setDefaultSymbolFillColor(Color defaultSymbolFillColor) { |
177 | 209 |
getSymbolPreferences().setDefaultSymbolFillColor(defaultSymbolFillColor); |
178 | 210 |
} |
179 | 211 |
|
212 |
@Override |
|
180 | 213 |
public void setDefaultSymbolFillColorAleatory( |
181 | 214 |
boolean defaultSymbolFillColorAleatory) { |
182 | 215 |
getSymbolPreferences().setDefaultSymbolFillColorAleatory( |
183 | 216 |
defaultSymbolFillColorAleatory); |
184 | 217 |
} |
185 | 218 |
|
219 |
@Override |
|
186 | 220 |
public void setDefaultSymbolFont(Font defaultSymbolFont) { |
187 | 221 |
getSymbolPreferences().setDefaultSymbolFont(defaultSymbolFont); |
188 | 222 |
} |
... | ... | |
191 | 225 |
getSymbolPreferences().setSymbolFileExtension(extension); |
192 | 226 |
} |
193 | 227 |
|
228 |
@Override |
|
194 | 229 |
public int getDefaultCartographicSupportMeasureUnit() { |
195 | 230 |
return getSymbolPreferences().getDefaultCartographicSupportMeasureUnit(); |
196 | 231 |
} |
197 | 232 |
|
233 |
@Override |
|
198 | 234 |
public void setDefaultCartographicSupportMeasureUnit( |
199 | 235 |
int defaultCartographicSupportMeasureUnit) { |
200 | 236 |
getSymbolPreferences().setDefaultCartographicSupportMeasureUnit( |
201 | 237 |
defaultCartographicSupportMeasureUnit); |
202 | 238 |
} |
203 | 239 |
|
240 |
@Override |
|
204 | 241 |
public int getDefaultCartographicSupportReferenceSystem() { |
205 | 242 |
return getSymbolPreferences().getDefaultCartographicSupportReferenceSystem(); |
206 | 243 |
} |
207 | 244 |
|
245 |
@Override |
|
208 | 246 |
public void setDefaultCartographicSupportReferenceSystem( |
209 | 247 |
int defaultCartographicSupportReferenceSystem) { |
210 | 248 |
getSymbolPreferences().setDefaultCartographicSupportReferenceSystem( |
211 | 249 |
defaultCartographicSupportReferenceSystem); |
212 | 250 |
} |
213 | 251 |
|
252 |
@Override |
|
214 | 253 |
public MapContextDrawer createMapContextDrawerInstance(Class drawerClazz) |
215 | 254 |
throws MapContextException { |
216 | 255 |
return createMapContextDrawerInstance(drawerClazz, "NONE"); |
217 | 256 |
} |
218 | 257 |
|
258 |
@Override |
|
219 | 259 |
public MapContextDrawer createDefaultMapContextDrawerInstance() |
220 | 260 |
throws MapContextException { |
221 | 261 |
|
... | ... | |
234 | 274 |
} |
235 | 275 |
} |
236 | 276 |
|
277 |
@Override |
|
237 | 278 |
public void setDefaultMapContextDrawer(Class drawerClazz) |
238 | 279 |
throws MapContextException { |
239 | 280 |
|
... | ... | |
242 | 283 |
notifyObservers(SET_MAPCONTEXT_DRAWER, drawerClazz); |
243 | 284 |
} |
244 | 285 |
|
286 |
@Override |
|
245 | 287 |
public void validateMapContextDrawer(Class drawerClazz) |
246 | 288 |
throws MapContextException { |
247 | 289 |
if (!MapContextDrawer.class.isAssignableFrom(drawerClazz)) { |
... | ... | |
250 | 292 |
} |
251 | 293 |
} |
252 | 294 |
|
295 |
@Override |
|
253 | 296 |
public GraphicLayer createGraphicsLayer(IProjection projection) { |
254 | 297 |
DefaultGraphicLayer layer = new DefaultGraphicLayer(); |
255 | 298 |
try { |
... | ... | |
261 | 304 |
return (GraphicLayer) notifyObservers(CREATE_GRAPHICS_LAYER, layer).getValue(); |
262 | 305 |
} |
263 | 306 |
|
307 |
@Override |
|
264 | 308 |
public String getDefaultVectorLegend() { |
265 | 309 |
return defaultVectorLegend; |
266 | 310 |
} |
267 | 311 |
|
312 |
@Override |
|
268 | 313 |
public void setDefaultVectorLegend(String defaultVectorLegend) { |
269 | 314 |
this.defaultVectorLegend = defaultVectorLegend; |
270 | 315 |
} |
271 | 316 |
|
317 |
@Override |
|
318 |
public String getDefaultRasterLegend() { |
|
319 |
return defaultRasterLegend; |
|
320 |
} |
|
321 |
|
|
322 |
@Override |
|
323 |
public void setDefaultRasterLegend(String defaultRasterLegend) { |
|
324 |
this.defaultRasterLegend = defaultRasterLegend; |
|
325 |
} |
|
326 |
|
|
327 |
@Override |
|
272 | 328 |
public void registerLegend(String legendName, Class legendClass) |
273 | 329 |
throws MapContextRuntimeException { |
274 | 330 |
|
... | ... | |
281 | 337 |
notifyObservers(REGISTER_LEGEND, legendName, legendClass); |
282 | 338 |
} |
283 | 339 |
|
340 |
@Override |
|
284 | 341 |
public ILegend createLegend(String legendName) |
285 | 342 |
throws MapContextRuntimeException { |
286 | 343 |
Class legendClass = (Class) legends.get(legendName); |
... | ... | |
289 | 346 |
try { |
290 | 347 |
ILegend legend = (ILegend) legendClass.newInstance(); |
291 | 348 |
return (ILegend) notifyObservers(CREATE_LEGEND, legend).getValue(); |
292 |
} catch (InstantiationException e) { |
|
349 |
} catch (InstantiationException | IllegalAccessException e) {
|
|
293 | 350 |
throw new RegisteredClassInstantiationException(ILegend.class, |
294 | 351 |
legendClass, legendName, e); |
295 |
} catch (IllegalAccessException e) { |
|
296 |
throw new RegisteredClassInstantiationException(ILegend.class, |
|
297 |
legendClass, legendName, e); |
|
298 | 352 |
} |
299 | 353 |
} |
300 | 354 |
return null; |
301 | 355 |
} |
302 | 356 |
|
357 |
@Override |
|
303 | 358 |
public IVectorLegend createDefaultVectorLegend(int shapeType) |
304 | 359 |
throws MapContextRuntimeException { |
305 | 360 |
try { |
... | ... | |
323 | 378 |
} |
324 | 379 |
} |
325 | 380 |
|
381 |
@Override |
|
382 |
public RasterLegend createDefaultRasterLegend(List<BandDescriptor> bands) |
|
383 |
throws MapContextRuntimeException { |
|
384 |
try { |
|
385 |
// Create legend |
|
386 |
RasterLegend legend = (RasterLegend) createLegend(getDefaultRasterLegend()); |
|
387 |
if (legend == null) { |
|
388 |
return null; |
|
389 |
} |
|
390 |
ColorInterpretation colorInterpretation; |
|
391 |
RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager(); |
|
392 |
switch (bands.size()) { |
|
393 |
case 3: |
|
394 |
colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.RGB); |
|
395 |
break; |
|
396 |
case 4: |
|
397 |
colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.ARGB); |
|
398 |
break; |
|
399 |
default: |
|
400 |
String[] colorBands = new String[bands.size()]; |
|
401 |
colorBands[0] = ColorInterpretation.GRAY_BAND; |
|
402 |
for (int i = 1; i < colorBands.length; i++) { |
|
403 |
colorBands[i] = ColorInterpretation.UNDEFINED_BAND; |
|
404 |
} colorInterpretation = legendManager.createColorInterpretation(colorBands); |
|
405 |
break; |
|
406 |
} |
|
407 |
legend.setColorInterpretation(colorInterpretation); |
|
408 |
legend.addLinearStretchEnhancementOperationIfNeeded(colorInterpretation, bands, 0); |
|
409 |
return legend; |
|
410 |
} catch (Exception e) { |
|
411 |
throw new MapContextRuntimeException(e); |
|
412 |
} |
|
413 |
} |
|
414 |
|
|
326 | 415 |
// ============================================================= |
327 | 416 |
// Legend reading/writing |
328 | 417 |
|
... | ... | |
455 | 544 |
throws Exception { |
456 | 545 |
|
457 | 546 |
Iterator kiter = clsToWtr.keySet().iterator(); |
458 |
Object oitem = null;
|
|
459 |
Class citem = null;
|
|
547 |
Object oitem; |
|
548 |
Class<ILegendWriter> citem;
|
|
460 | 549 |
while (kiter.hasNext()) { |
461 | 550 |
oitem = kiter.next(); |
462 | 551 |
if (oitem instanceof Class) { |
... | ... | |
465 | 554 |
/* |
466 | 555 |
* Found superclass/superinterface |
467 | 556 |
*/ |
468 |
citem = (Class) clsToWtr.get(oitem);
|
|
557 |
citem = clsToWtr.get(oitem); |
|
469 | 558 |
return (ILegendWriter) citem.newInstance(); |
470 | 559 |
} |
471 | 560 |
} |
... | ... | |
478 | 567 |
|
479 | 568 |
// ============================================================= |
480 | 569 |
|
570 |
@Override |
|
481 | 571 |
public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
482 | 572 |
throws MapContextRuntimeException { |
483 | 573 |
IMultiLayerSymbol symbol = getSymbolManager().createMultiLayerSymbol(shapeType); |
484 | 574 |
return (IMultiLayerSymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue(); |
485 | 575 |
} |
486 | 576 |
|
577 |
@Override |
|
487 | 578 |
public IMultiLayerSymbol createMultiLayerSymbol(String symbolName) |
488 | 579 |
throws MapContextRuntimeException { |
489 | 580 |
IMultiLayerSymbol symbol = getSymbolManager().createMultiLayerSymbol(symbolName); |
490 | 581 |
return (IMultiLayerSymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue(); |
491 | 582 |
} |
492 | 583 |
|
584 |
@Override |
|
493 | 585 |
public ISymbol createSymbol(int shapeType, Color color) |
494 | 586 |
throws MapContextRuntimeException { |
495 | 587 |
ISymbol symbol = getSymbolManager().createSymbol(shapeType, color); |
496 | 588 |
return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue(); |
497 | 589 |
} |
498 | 590 |
|
591 |
@Override |
|
499 | 592 |
public ISymbol createSymbol(int shapeType) |
500 | 593 |
throws MapContextRuntimeException { |
501 | 594 |
ISymbol symbol = getSymbolManager().createSymbol(shapeType); |
502 | 595 |
return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue(); |
503 | 596 |
} |
504 | 597 |
|
598 |
@Override |
|
505 | 599 |
public ISymbol createSymbol(String symbolName, Color color) |
506 | 600 |
throws MapContextRuntimeException { |
507 | 601 |
ISymbol symbol = getSymbolManager().createSymbol(symbolName, color); |
508 | 602 |
return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue(); |
509 | 603 |
} |
510 | 604 |
|
605 |
@Override |
|
511 | 606 |
public ISymbol createSymbol(String symbolName) |
512 | 607 |
throws MapContextRuntimeException { |
513 | 608 |
ISymbol symbol = getSymbolManager().createSymbol(symbolName); |
514 | 609 |
return (ISymbol) notifyObservers(CREATE_SYMBOL, symbol).getValue(); |
515 | 610 |
} |
516 | 611 |
|
612 |
@Override |
|
517 | 613 |
public IWarningSymbol getWarningSymbol(String message, String symbolDesc, |
518 | 614 |
int symbolDrawExceptionType) throws MapContextRuntimeException { |
519 | 615 |
return getSymbolManager().getWarningSymbol(message, symbolDesc, |
... | ... | |
531 | 627 |
return (ISymbol[]) notifyObservers(LOAD_SYMBOLS, symbols).getValue(); |
532 | 628 |
} |
533 | 629 |
|
630 |
@Override |
|
534 | 631 |
public void registerMultiLayerSymbol(String symbolName, Class symbolClass) |
535 | 632 |
throws MapContextRuntimeException { |
536 | 633 |
getSymbolManager().registerMultiLayerSymbol(symbolName, symbolClass); |
537 | 634 |
notifyObservers(REGISTER_MULTILAYER_SYMBOL, symbolName, symbolClass); |
538 | 635 |
} |
539 | 636 |
|
637 |
@Override |
|
540 | 638 |
public void registerMultiLayerSymbol(String symbolName, int[] shapeTypes, |
541 | 639 |
Class symbolClass) throws MapContextRuntimeException { |
542 | 640 |
getSymbolManager().registerMultiLayerSymbol(symbolName, shapeTypes, |
... | ... | |
544 | 642 |
notifyObservers(REGISTER_MULTILAYER_SYMBOL, symbolName, symbolClass, shapeTypes); |
545 | 643 |
} |
546 | 644 |
|
645 |
@Override |
|
547 | 646 |
public void registerSymbol(String symbolName, Class symbolClass) |
548 | 647 |
throws MapContextRuntimeException { |
549 | 648 |
getSymbolManager().registerSymbol(symbolName, symbolClass); |
550 | 649 |
notifyObservers(REGISTER_SYMBOL, symbolName, symbolClass); |
551 | 650 |
} |
552 | 651 |
|
652 |
@Override |
|
553 | 653 |
public void registerSymbol(String symbolName, int[] shapeTypes, |
554 | 654 |
Class symbolClass) throws MapContextException { |
555 | 655 |
getSymbolManager().registerSymbol(symbolName, shapeTypes, symbolClass); |
... | ... | |
566 | 666 |
getSymbolManager().saveSymbol(symbol, fileName, folder); |
567 | 667 |
} |
568 | 668 |
|
569 |
public FLayer createLayer(String layerName, DataStoreParameters parameters) |
|
669 |
@Override |
|
670 |
public boolean registerLayer( |
|
671 |
Class<? extends DataStore> dataStoreClass, |
|
672 |
Class<? extends FLayer> layerClass) |
|
673 |
{ |
|
674 |
this.layerClassFromStoreClass.put(dataStoreClass, layerClass); |
|
675 |
return true; |
|
676 |
} |
|
677 |
|
|
678 |
private Class<? extends FLayer> getLayerClassFromDataStoreClass( |
|
679 |
Class<? extends DataStore> dataStoreClass) { |
|
680 |
Class<? extends FLayer> layerClass = this.layerClassFromStoreClass.get(dataStoreClass); |
|
681 |
if( layerClass!=null ) { |
|
682 |
return layerClass; |
|
683 |
} |
|
684 |
for (Map.Entry<Class<? extends DataStore>, Class<? extends FLayer>> entry : layerClassFromStoreClass.entrySet()) { |
|
685 |
Class<? extends DataStore> currentDataStoreClass = entry.getKey(); |
|
686 |
layerClass = entry.getValue(); |
|
687 |
if( currentDataStoreClass.isAssignableFrom(dataStoreClass) ) { |
|
688 |
return layerClass; |
|
689 |
} |
|
690 |
} |
|
691 |
return null; |
|
692 |
} |
|
693 |
|
|
694 |
@Override |
|
695 |
public FLayer createLayer(String layerName, DataStoreParameters dataParameters) |
|
570 | 696 |
throws LoadLayerException { |
571 |
FLayer layer = LayerFactory.getInstance().createLayer(layerName, parameters); |
|
572 |
return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue(); |
|
697 |
try { |
|
698 |
DataManager dataManager = DALLocator.getDataManager(); |
|
699 |
DataStore dataStore = dataManager.openStore( |
|
700 |
dataParameters.getDataStoreName(), |
|
701 |
dataParameters |
|
702 |
); |
|
703 |
return this.createLayer(layerName, dataStore, null); |
|
704 |
} catch (Exception e) { |
|
705 |
throw new LoadLayerException(layerName, e); |
|
706 |
} |
|
573 | 707 |
} |
574 | 708 |
|
575 |
public FLayer createLayer(String layerName, DataStore store) |
|
709 |
@Override |
|
710 |
public FLayer createLayer(String layerName, DataStore dataStore) |
|
576 | 711 |
throws LoadLayerException { |
577 |
FLayer layer = LayerFactory.getInstance().createLayer(layerName, store); |
|
578 |
return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue(); |
|
712 |
return this.createLayer(layerName, dataStore, null); |
|
579 | 713 |
} |
580 | 714 |
|
715 |
|
|
581 | 716 |
@Override |
717 |
public FLayer createLayer(String layerName, CreateLayerParameters parameters) throws LoadLayerException { |
|
718 |
try { |
|
719 |
DataManager dataManager = DALLocator.getDataManager(); |
|
720 |
DataStoreParameters dataParameters = parameters.getDataParameters(); |
|
721 |
DataStore dataStore = dataManager.openStore( |
|
722 |
dataParameters.getDataStoreName(), |
|
723 |
dataParameters |
|
724 |
); |
|
725 |
return this.createLayer(layerName, dataStore, parameters); |
|
726 |
} catch (Exception e) { |
|
727 |
throw new LoadLayerException(layerName, e); |
|
728 |
} |
|
729 |
} |
|
730 |
|
|
731 |
@Override |
|
732 |
public FLayer createLayer(String layerName, DataStore dataStore, CreateLayerParameters parameters) throws LoadLayerException { |
|
733 |
try { |
|
734 |
boolean useCache = false; |
|
735 |
ICoordTrans coordTrans = null; |
|
736 |
IProjection projection = (IProjection) dataStore.getDynValue(FeatureStore.METADATA_CRS); |
|
737 |
|
|
738 |
if( parameters!=null ) { |
|
739 |
if( parameters.getDataParameters()!=dataStore.getParameters() ) { |
|
740 |
throw new IllegalArgumentException("The dataStore parameters are not the same of the store pased to create layer."); |
|
741 |
} |
|
742 |
useCache = parameters.useCache(); |
|
743 |
|
|
744 |
coordTrans = parameters.getCoordTrans(); |
|
745 |
// TODO: Aqui comprobacion de que si hay transformacion es adecuada |
|
746 |
// para la proyeccion del store. |
|
747 |
} |
|
748 |
|
|
749 |
if( useCache ) { |
|
750 |
DataStoreProviderFactory factory = dataStore.getProviderFactory(); |
|
751 |
if( factory.isTiledSupported() != DataStoreProviderFactory.NO ) { |
|
752 |
if( !factory.getClass().getSimpleName().equals("TileProviderFactory")) { |
|
753 |
DataManager dataManager = DALLocator.getDataManager(); |
|
754 |
DynObject tileParameters = dataManager.createStoreParameters("TileCache"); |
|
755 |
File cacheFolder; |
|
756 |
FoldersManager folderManager = ToolsLocator.getFoldersManager(); |
|
757 |
File applicationHome = folderManager.get("ApplicationHome"); |
|
758 |
if( applicationHome==null ) { |
|
759 |
cacheFolder = folderManager.getTemporaryFile("gvsig_rcache"); |
|
760 |
} else { |
|
761 |
cacheFolder = new File(applicationHome, "gvsig_rcache"); |
|
762 |
} |
|
763 |
if (tileParameters.getDynClass().getDynField("rootFolder") != null) { |
|
764 |
tileParameters.setDynValue("rootFolder", cacheFolder); |
|
765 |
} |
|
766 |
try { |
|
767 |
dataStore.useCache("TileCache", tileParameters); |
|
768 |
} catch (DataException e) { |
|
769 |
LOGGER.warn("Can't cache the layer.", e); |
|
770 |
} |
|
771 |
} |
|
772 |
} |
|
773 |
} |
|
774 |
|
|
775 |
Class<? extends FLayer> layerClass = this.getLayerClassFromDataStoreClass(dataStore.getClass()); |
|
776 |
if (layerClass == null) { |
|
777 |
throw new CantRetrieveLayerByStoreException(layerName, dataStore.getName()); |
|
778 |
} |
|
779 |
FLayer layer; |
|
780 |
try { |
|
781 |
layer = (FLayer) layerClass.newInstance(); |
|
782 |
} catch (InstantiationException | IllegalAccessException e) { |
|
783 |
throw new LoadLayerException(layerName, e); |
|
784 |
} |
|
785 |
|
|
786 |
layer.setName(layerName); |
|
787 |
((SingleLayer) layer).setDataStore(dataStore); |
|
788 |
if (projection != null) { |
|
789 |
layer.setProjection(projection); |
|
790 |
if( coordTrans != null ) { |
|
791 |
layer.setCoordTrans(coordTrans); |
|
792 |
} |
|
793 |
} |
|
794 |
layer.load(); |
|
795 |
return (FLayer) notifyObservers(CREATE_LAYER, layer).getValue(); |
|
796 |
} catch (Exception e) { |
|
797 |
throw new LoadLayerException(layerName, e); |
|
798 |
} |
|
799 |
} |
|
800 |
|
|
801 |
@Override |
|
582 | 802 |
public ILegend getLegend(DataStore dataStore) { |
583 | 803 |
ILegend legend = null; |
584 | 804 |
ResourcesStorage resourcesStorage = dataStore.getResourcesStorage(); |
... | ... | |
600 | 820 |
//If the legend is null, next option is to check if the store has the getLegend method |
601 | 821 |
if (legend == null) { |
602 | 822 |
try { |
603 |
legend = (IVectorLegend) dataStore.invokeDynMethod("getLegend", null);
|
|
823 |
legend = (ILegend) dataStore.invokeDynMethod("getLegend", null); |
|
604 | 824 |
} catch (DynMethodNotSupportedException e) { |
605 | 825 |
LOGGER.debug("This store {} does not provide a legend.", |
606 | 826 |
dataStore.getName()); |
607 | 827 |
} catch (DynMethodException e) { |
608 |
LOGGER.error(
|
|
828 |
LOGGER.warn(
|
|
609 | 829 |
"Can't load the specific legend provided for the store {}.", |
610 | 830 |
dataStore.getName(), e); |
611 | 831 |
} |
... | ... | |
613 | 833 |
|
614 | 834 |
//If legend is null, last step is just try to create the legend by default |
615 | 835 |
if (legend == null) { |
616 |
FeatureType featureType; |
|
617 |
try { |
|
618 |
featureType = (((FeatureStore) dataStore).getDefaultFeatureType()); |
|
619 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
620 |
if (indexGeom < 0) { |
|
621 |
throw new IllegalArgumentException("The layer don't has a geometry column."); |
|
836 |
if( dataStore instanceof FeatureStore ) { |
|
837 |
FeatureType featureType; |
|
838 |
try { |
|
839 |
featureType = (((FeatureStore) dataStore).getDefaultFeatureType()); |
|
840 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
841 |
if (indexGeom < 0) { |
|
842 |
throw new IllegalArgumentException("The layer don't has a geometry column."); |
|
843 |
} |
|
844 |
int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
845 |
legend = createDefaultVectorLegend(typeShape); |
|
846 |
} catch (DataException e) { |
|
847 |
LOGGER.warn("Error getting the default feature type", e); |
|
622 | 848 |
} |
623 |
int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
624 |
legend = createDefaultVectorLegend(typeShape); |
|
625 |
} catch (DataException e) { |
|
626 |
LOGGER.error("Error getting the default feature type", e); |
|
849 |
|
|
850 |
} else if( dataStore instanceof RasterStore ) { |
|
851 |
RasterStore rasterStore = (RasterStore) dataStore; |
|
852 |
List<BandDescriptor> bands = rasterStore.getBandDescriptors(); |
|
853 |
legend = createDefaultRasterLegend(bands); |
|
627 | 854 |
} |
628 | 855 |
} |
629 | 856 |
|
857 |
if( legend instanceof RasterLegend ) { |
|
858 |
RasterLegend rasterLegend = (RasterLegend) legend; |
|
859 |
RasterStore rasterStore = (RasterStore) dataStore; |
|
860 |
ColorInterpretation colorInterpretation = rasterLegend.getColorInterpretation(); |
|
861 |
if (colorInterpretation.isPalette()) { |
|
862 |
rasterLegend.addColorTableOperation(colorInterpretation, 0); |
|
863 |
} else { |
|
864 |
rasterLegend.addLinearStretchEnhancementOperationIfNeeded( |
|
865 |
colorInterpretation, |
|
866 |
rasterStore.getBandDescriptors(), |
|
867 |
0); |
|
868 |
} |
|
869 |
if (colorInterpretation.hasAnyHSLBand()) { |
|
870 |
rasterLegend.addHSLToRGBOperation(colorInterpretation); |
|
871 |
} else if (colorInterpretation.hasAnyCMYKBand()) { |
|
872 |
rasterLegend.addCMYKToRGBOperation(colorInterpretation); |
|
873 |
} else if (colorInterpretation.hasAnyYCBCRBand()) { |
|
874 |
//TODO: Not implemented yet, meanwhile do nothing |
|
875 |
// legend.addYCBCRToRGBOperation(colorInterpretation); |
|
876 |
} |
|
877 |
} |
|
630 | 878 |
return legend; |
631 | 879 |
} |
632 | 880 |
|
... | ... | |
677 | 925 |
} |
678 | 926 |
Object value = method.invoke(instance, params); |
679 | 927 |
return value; |
680 |
} catch (NoSuchMethodException ex) {
|
|
928 |
} catch (Exception ex) { |
|
681 | 929 |
return null; |
682 |
} catch (SecurityException ex) { |
|
683 |
return null; |
|
684 |
} catch (IllegalAccessException ex) { |
|
685 |
return null; |
|
686 |
} catch (IllegalArgumentException ex) { |
|
687 |
return null; |
|
688 |
} catch (InvocationTargetException ex) { |
|
689 |
return null; |
|
690 | 930 |
} |
691 | 931 |
} |
692 | 932 |
|
693 |
private Map iconLayers = new HashMap(); // (Map<String storeProviderName, String iconName>) |
|
694 |
|
|
933 |
@Override |
|
695 | 934 |
public void registerIconLayer(String storeProviderName, String iconName) { |
696 | 935 |
if (storeProviderName == null || iconName == null) { |
697 | 936 |
LOGGER.info("registerIconLayer, storeProviderName or iconName are null"); |
... | ... | |
732 | 971 |
/* (non-Javadoc) |
733 | 972 |
* @see org.gvsig.fmap.mapcontext.MapContextManager#getDefaultCRS() |
734 | 973 |
*/ |
974 |
@Override |
|
735 | 975 |
public IProjection getDefaultCRS() { |
736 | 976 |
IProjection crs = CRSFactory.getCRS("EPSG:4326"); |
737 | 977 |
return (IProjection) notifyObservers(GET_DEFAULT_CRS, crs).getValue(); |
... | ... | |
745 | 985 |
return this.observableHelper.notifyObservers(this, LOAD_LAYER, layer); |
746 | 986 |
} |
747 | 987 |
|
988 |
@Override |
|
748 | 989 |
public void addObserver(Observer o) { |
749 | 990 |
this.observableHelper.addObserver(o); |
750 | 991 |
} |
751 | 992 |
|
993 |
@Override |
|
752 | 994 |
public void deleteObserver(Observer o) { |
753 | 995 |
this.observableHelper.deleteObserver(o); |
754 | 996 |
} |
755 | 997 |
|
998 |
@Override |
|
756 | 999 |
public void deleteObservers() { |
757 | 1000 |
this.observableHelper.deleteObservers(); |
758 | 1001 |
} |
... | ... | |
769 | 1012 |
return this.observableHelper.notifyObservers(this, type, value1, value2, value3); |
770 | 1013 |
} |
771 | 1014 |
|
1015 |
@Override |
|
772 | 1016 |
public File getColorTableLibraryFolder() { |
773 | 1017 |
if (this.colorTableLibraryFolder == null) { |
774 | 1018 |
// Provide a default value to the location for the color |
... | ... | |
783 | 1027 |
return this.colorTableLibraryFolder; |
784 | 1028 |
} |
785 | 1029 |
|
1030 |
@Override |
|
786 | 1031 |
public void setColorTableLibraryFolder(File colorTableLibraryFolder) { |
787 | 1032 |
this.colorTableLibraryFolder = colorTableLibraryFolder; |
788 | 1033 |
} |
Also available in: Unified diff