svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / impl / DefaultMapContextManager.java @ 33615
History | View | Annotate | Download (17.9 KB)
1 | 28882 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | 31544 | cordinyana | * of the Valencian Government (CIT)
|
5 | 30183 | jmvivo | *
|
6 | 28882 | cordinyana | * 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 | 30183 | jmvivo | *
|
11 | 28882 | cordinyana | * 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 | 30183 | jmvivo | *
|
16 | 28882 | cordinyana | * 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 | 30183 | jmvivo | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 28882 | cordinyana | * MA 02110-1301, USA.
|
20 | 30183 | jmvivo | *
|
21 | 28882 | cordinyana | */
|
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 {DiSiD Technologies} {Create Manager to register MapContextDrawer implementation}
|
||
26 | */
|
||
27 | package org.gvsig.fmap.mapcontext.impl; |
||
28 | |||
29 | 30011 | cordinyana | import java.awt.Color; |
30 | import java.awt.Font; |
||
31 | import java.io.File; |
||
32 | 30892 | cordinyana | import java.io.FileFilter; |
33 | 33339 | jpiera | import java.io.FileInputStream; |
34 | import java.lang.reflect.Method; |
||
35 | 30011 | cordinyana | import java.util.Collections; |
36 | import java.util.HashMap; |
||
37 | import java.util.Map; |
||
38 | import java.util.Random; |
||
39 | |||
40 | 30748 | jpiera | import org.cresques.cts.IProjection; |
41 | 33615 | cordinyana | import org.slf4j.Logger; |
42 | import org.slf4j.LoggerFactory; |
||
43 | |||
44 | 33339 | jpiera | import org.gvsig.fmap.dal.DataServerExplorer; |
45 | 32923 | jjdelcerro | import org.gvsig.fmap.dal.DataStore; |
46 | import org.gvsig.fmap.dal.DataStoreParameters; |
||
47 | 33339 | jpiera | import org.gvsig.fmap.dal.exception.DataException; |
48 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
49 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
50 | 28882 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextDrawer; |
51 | import org.gvsig.fmap.mapcontext.MapContextException; |
||
52 | 30892 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextLocator; |
53 | 28882 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextManager; |
54 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
55 | 32923 | jjdelcerro | import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
56 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
57 | import org.gvsig.fmap.mapcontext.layers.LayerFactory; |
||
58 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.layers.vectorial.GraphicLayer; |
59 | 30183 | jmvivo | import org.gvsig.fmap.mapcontext.layers.vectorial.impl.DefaultGraphicLayer; |
60 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
61 | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
||
62 | 31631 | jpiera | import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
63 | 30011 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
64 | import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
||
65 | import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
||
66 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
67 | import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
||
68 | 30892 | cordinyana | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolException; |
69 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
||
70 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
||
71 | 33339 | jpiera | import org.gvsig.tools.ToolsLocator; |
72 | import org.gvsig.tools.dynobject.exception.DynMethodException; |
||
73 | import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
||
74 | import org.gvsig.tools.persistence.PersistenceManager; |
||
75 | import org.gvsig.tools.persistence.PersistentState; |
||
76 | 28882 | cordinyana | |
77 | /**
|
||
78 | * Default implementation of the {@link MapContextManager}.
|
||
79 | 30183 | jmvivo | *
|
80 | 28882 | cordinyana | * @author <a href="mailto:cordinyana@gvsig.org">C?sar Ordi?ana</a>
|
81 | */
|
||
82 | public class DefaultMapContextManager implements MapContextManager { |
||
83 | 33339 | jpiera | |
84 | 33615 | cordinyana | private static final Logger LOG = LoggerFactory |
85 | .getLogger(DefaultMapContextManager.class); |
||
86 | |||
87 | 30011 | cordinyana | private Class drawerClazz = DefaultMapContextDrawer.class; |
88 | 28882 | cordinyana | |
89 | 30011 | cordinyana | private Map legends = Collections.synchronizedMap(new HashMap()); |
90 | 28882 | cordinyana | |
91 | 30011 | cordinyana | private Map legendReaders = Collections.synchronizedMap(new HashMap()); |
92 | 28882 | cordinyana | |
93 | 30011 | cordinyana | private Map legendWriters = Collections.synchronizedMap(new HashMap()); |
94 | 28882 | cordinyana | |
95 | 30011 | cordinyana | private String defaultVectorLegend; |
96 | |||
97 | 30892 | cordinyana | public SymbolManager getSymbolManager() {
|
98 | return MapContextLocator.getSymbolManager();
|
||
99 | } |
||
100 | 30011 | cordinyana | |
101 | 30892 | cordinyana | private SymbolPreferences getSymbolPreferences() {
|
102 | return getSymbolManager().getSymbolPreferences();
|
||
103 | 30011 | cordinyana | } |
104 | |||
105 | public String getSymbolLibraryPath() { |
||
106 | 30892 | cordinyana | return getSymbolPreferences().getSymbolLibraryPath();
|
107 | 30011 | cordinyana | } |
108 | |||
109 | public void setSymbolLibraryPath(String symbolLibraryPath) { |
||
110 | 30892 | cordinyana | getSymbolPreferences().setSymbolLibraryPath(symbolLibraryPath); |
111 | 30011 | cordinyana | } |
112 | |||
113 | public void resetSymbolLibraryPath() { |
||
114 | 30892 | cordinyana | getSymbolPreferences().resetSymbolLibraryPath(); |
115 | 30011 | cordinyana | } |
116 | |||
117 | public Color getDefaultSymbolColor() { |
||
118 | 30892 | cordinyana | return getSymbolPreferences().getDefaultSymbolColor();
|
119 | 30011 | cordinyana | } |
120 | |||
121 | 30892 | cordinyana | public Color getDefaultSymbolFillColor() { |
122 | return getSymbolPreferences().getDefaultSymbolFillColor();
|
||
123 | 30011 | cordinyana | } |
124 | |||
125 | 30892 | cordinyana | public Font getDefaultSymbolFont() { |
126 | return getSymbolPreferences().getDefaultSymbolFont();
|
||
127 | 30011 | cordinyana | } |
128 | |||
129 | 30892 | cordinyana | public String getSymbolFileExtension() { |
130 | return getSymbolPreferences().getSymbolFileExtension();
|
||
131 | 30011 | cordinyana | } |
132 | |||
133 | 30892 | cordinyana | public boolean isDefaultSymbolFillColorAleatory() { |
134 | return getSymbolPreferences().isDefaultSymbolFillColorAleatory();
|
||
135 | 30011 | cordinyana | } |
136 | |||
137 | 30892 | cordinyana | public void resetDefaultSymbolColor() { |
138 | getSymbolPreferences().resetDefaultSymbolColor(); |
||
139 | } |
||
140 | |||
141 | 30011 | cordinyana | public void resetDefaultSymbolFillColor() { |
142 | 30892 | cordinyana | getSymbolPreferences().resetDefaultSymbolFillColor(); |
143 | 30011 | cordinyana | } |
144 | |||
145 | 30892 | cordinyana | public void resetDefaultSymbolFillColorAleatory() { |
146 | getSymbolPreferences().resetDefaultSymbolFillColorAleatory(); |
||
147 | 30011 | cordinyana | } |
148 | |||
149 | 30892 | cordinyana | public void resetDefaultSymbolFont() { |
150 | getSymbolPreferences().resetDefaultSymbolFont(); |
||
151 | 30011 | cordinyana | } |
152 | 30183 | jmvivo | |
153 | 30892 | cordinyana | public void setDefaultSymbolColor(Color defaultSymbolColor) { |
154 | getSymbolPreferences().setDefaultSymbolColor(defaultSymbolColor); |
||
155 | 30011 | cordinyana | } |
156 | |||
157 | 30892 | cordinyana | public void setDefaultSymbolFillColor(Color defaultSymbolFillColor) { |
158 | getSymbolPreferences().setDefaultSymbolFillColor(defaultSymbolFillColor); |
||
159 | 30011 | cordinyana | } |
160 | |||
161 | 30892 | cordinyana | public void setDefaultSymbolFillColorAleatory( |
162 | boolean defaultSymbolFillColorAleatory) {
|
||
163 | getSymbolPreferences().setDefaultSymbolFillColorAleatory( |
||
164 | defaultSymbolFillColorAleatory); |
||
165 | } |
||
166 | |||
167 | 30011 | cordinyana | public void setDefaultSymbolFont(Font defaultSymbolFont) { |
168 | 30892 | cordinyana | getSymbolPreferences().setDefaultSymbolFont(defaultSymbolFont); |
169 | 30011 | cordinyana | } |
170 | 30183 | jmvivo | |
171 | 30892 | cordinyana | public void setSymbolFileExtension(String extension) { |
172 | getSymbolPreferences().setSymbolFileExtension(extension); |
||
173 | 30011 | cordinyana | } |
174 | |||
175 | public int getDefaultCartographicSupportMeasureUnit() { |
||
176 | 30892 | cordinyana | return getSymbolPreferences().getDefaultCartographicSupportMeasureUnit();
|
177 | 30011 | cordinyana | } |
178 | |||
179 | public void setDefaultCartographicSupportMeasureUnit( |
||
180 | int defaultCartographicSupportMeasureUnit) {
|
||
181 | 30892 | cordinyana | getSymbolPreferences().setDefaultCartographicSupportMeasureUnit( |
182 | defaultCartographicSupportMeasureUnit); |
||
183 | 30011 | cordinyana | } |
184 | |||
185 | public int getDefaultCartographicSupportReferenceSystem() { |
||
186 | 30892 | cordinyana | return getSymbolPreferences().getDefaultCartographicSupportReferenceSystem();
|
187 | 30011 | cordinyana | } |
188 | |||
189 | public void setDefaultCartographicSupportReferenceSystem( |
||
190 | int defaultCartographicSupportReferenceSystem) {
|
||
191 | 30892 | cordinyana | getSymbolPreferences().setDefaultCartographicSupportReferenceSystem( |
192 | defaultCartographicSupportReferenceSystem); |
||
193 | 30011 | cordinyana | } |
194 | |||
195 | public MapContextDrawer createMapContextDrawerInstance(Class drawerClazz) |
||
196 | 33339 | jpiera | throws MapContextException {
|
197 | 30011 | cordinyana | return createMapContextDrawerInstance(drawerClazz, "NONE"); |
198 | } |
||
199 | |||
200 | public MapContextDrawer createDefaultMapContextDrawerInstance()
|
||
201 | 33339 | jpiera | throws MapContextException {
|
202 | 30011 | cordinyana | |
203 | return createMapContextDrawerInstance(drawerClazz, "default"); |
||
204 | } |
||
205 | |||
206 | private MapContextDrawer createMapContextDrawerInstance(Class drawerClazz, |
||
207 | String name) throws RegisteredClassInstantiationException { |
||
208 | try {
|
||
209 | return (MapContextDrawer) drawerClazz.newInstance();
|
||
210 | } catch (Exception ex) { |
||
211 | throw new RegisteredClassInstantiationException( |
||
212 | MapContextDrawer.class, drawerClazz, name, ex); |
||
213 | } |
||
214 | } |
||
215 | |||
216 | public void setDefaultMapContextDrawer(Class drawerClazz) |
||
217 | 33339 | jpiera | throws MapContextException {
|
218 | 30011 | cordinyana | |
219 | validateMapContextDrawer(drawerClazz); |
||
220 | this.drawerClazz = drawerClazz;
|
||
221 | } |
||
222 | |||
223 | public void validateMapContextDrawer(Class drawerClazz) |
||
224 | 33339 | jpiera | throws MapContextException {
|
225 | 30011 | cordinyana | if (!MapContextDrawer.class.isAssignableFrom(drawerClazz)) {
|
226 | throw new InvalidRegisteredClassException(MapContextDrawer.class, |
||
227 | drawerClazz, "UNKNOWN");
|
||
228 | } |
||
229 | } |
||
230 | |||
231 | 30748 | jpiera | public GraphicLayer createGraphicsLayer(IProjection projection) {
|
232 | DefaultGraphicLayer layer = new DefaultGraphicLayer();
|
||
233 | try {
|
||
234 | layer.initialize(projection); |
||
235 | 31631 | jpiera | layer.setLegend((IVectorLegend)createLegend(IVectorialUniqueValueLegend.LEGEND_NAME)); |
236 | 30748 | jpiera | } catch (Exception e) { |
237 | 33030 | jjdelcerro | LOG.error("Error initializing the graphics layer", e);
|
238 | 30748 | jpiera | } |
239 | return layer;
|
||
240 | 30011 | cordinyana | } |
241 | |||
242 | public String getDefaultVectorLegend() { |
||
243 | return defaultVectorLegend;
|
||
244 | } |
||
245 | |||
246 | public void setDefaultVectorLegend(String defaultVectorLegend) { |
||
247 | this.defaultVectorLegend = defaultVectorLegend;
|
||
248 | } |
||
249 | |||
250 | public void registerLegend(String legendName, Class legendClass) |
||
251 | 33339 | jpiera | throws MapContextRuntimeException {
|
252 | 30011 | cordinyana | |
253 | if (legendClass == null || !ILegend.class.isAssignableFrom(legendClass)) { |
||
254 | throw new InvalidRegisteredClassException(ILegend.class, |
||
255 | legendClass, legendName); |
||
256 | } |
||
257 | |||
258 | legends.put(legendName, legendClass); |
||
259 | } |
||
260 | |||
261 | public ILegend createLegend(String legendName) |
||
262 | 33339 | jpiera | throws MapContextRuntimeException {
|
263 | 30011 | cordinyana | Class legendClass = (Class) legends.get(legendName); |
264 | |||
265 | if (legendClass != null) { |
||
266 | try {
|
||
267 | return (ILegend) legendClass.newInstance();
|
||
268 | } catch (InstantiationException e) { |
||
269 | throw new RegisteredClassInstantiationException(ILegend.class, |
||
270 | legendClass, legendName, e); |
||
271 | } catch (IllegalAccessException e) { |
||
272 | throw new RegisteredClassInstantiationException(ILegend.class, |
||
273 | legendClass, legendName, e); |
||
274 | } |
||
275 | } |
||
276 | return null; |
||
277 | } |
||
278 | |||
279 | public IVectorLegend createDefaultVectorLegend(int shapeType) |
||
280 | 33339 | jpiera | throws MapContextRuntimeException {
|
281 | 33030 | jjdelcerro | try {
|
282 | Random rand = new Random(); |
||
283 | 33339 | jpiera | |
284 | 33030 | jjdelcerro | int numreg = rand.nextInt(255 / 2); |
285 | double div = (1 - rand.nextDouble() * 0.66) * 0.9; |
||
286 | Color randomColor = new Color(((int) (255 * div + (numreg * rand |
||
287 | .nextDouble()))) % 255, ((int) (255 * div + (numreg * rand |
||
288 | 33339 | jpiera | .nextDouble()))) % 255, ((int) (255 * div + (numreg * rand |
289 | .nextDouble()))) % 255);
|
||
290 | 33030 | jjdelcerro | IVectorLegend legend = (IVectorLegend) createLegend(getDefaultVectorLegend()); |
291 | if( legend == null ) { |
||
292 | return null; |
||
293 | } |
||
294 | ISymbol defaultSymbol = |
||
295 | 33339 | jpiera | getSymbolManager().createSymbol(shapeType, randomColor); |
296 | 33030 | jjdelcerro | legend.setDefaultSymbol(defaultSymbol); |
297 | return legend;
|
||
298 | } catch(Exception e) { |
||
299 | throw new MapContextRuntimeException(e); |
||
300 | } |
||
301 | 30011 | cordinyana | } |
302 | |||
303 | public void registerLegendReader(String format, Class readerClass) |
||
304 | 33339 | jpiera | throws MapContextRuntimeException {
|
305 | 30011 | cordinyana | if (readerClass == null |
306 | || !ILegendReader.class.isAssignableFrom(readerClass)) { |
||
307 | throw new InvalidRegisteredClassException(ILegendReader.class, |
||
308 | readerClass, format); |
||
309 | } |
||
310 | |||
311 | legendReaders.put(format, readerClass); |
||
312 | } |
||
313 | |||
314 | public ILegendReader createLegendReader(String format) |
||
315 | 33339 | jpiera | throws MapContextRuntimeException {
|
316 | 30011 | cordinyana | Class legendReaderClazz = (Class) legendReaders.get(format); |
317 | |||
318 | if (legendReaderClazz != null) { |
||
319 | try {
|
||
320 | return (ILegendReader) legendReaderClazz.newInstance();
|
||
321 | } catch (InstantiationException e) { |
||
322 | throw new RegisteredClassInstantiationException( |
||
323 | ILegendReader.class, legendReaderClazz, format, e); |
||
324 | } catch (IllegalAccessException e) { |
||
325 | throw new RegisteredClassInstantiationException( |
||
326 | ILegendReader.class, legendReaderClazz, format, e); |
||
327 | } |
||
328 | } |
||
329 | return null; |
||
330 | } |
||
331 | |||
332 | public void registerLegendWriter(String legendName, String format, |
||
333 | Class writerClass) throws MapContextRuntimeException { |
||
334 | if (writerClass == null |
||
335 | || !ILegendWriter.class.isAssignableFrom(writerClass)) { |
||
336 | throw new InvalidRegisteredClassException(ILegendWriter.class, |
||
337 | writerClass, format.concat("-").concat(legendName));
|
||
338 | } |
||
339 | |||
340 | Map legendFormatWriters = (Map) legendWriters.get(format); |
||
341 | |||
342 | synchronized (legendWriters) {
|
||
343 | if (legendFormatWriters == null) { |
||
344 | legendFormatWriters = Collections
|
||
345 | 33339 | jpiera | .synchronizedMap(new HashMap()); |
346 | 30011 | cordinyana | legendWriters.put(format, legendFormatWriters); |
347 | } |
||
348 | } |
||
349 | |||
350 | legendFormatWriters.put(legendName, writerClass); |
||
351 | } |
||
352 | |||
353 | public ILegendWriter createLegendWriter(String legendName, String format) |
||
354 | 33339 | jpiera | throws MapContextRuntimeException {
|
355 | 30011 | cordinyana | Map legendFormatWriters = getLegendWritersForFormat(format);
|
356 | |||
357 | if (legendFormatWriters != null) { |
||
358 | Class legendWriterClazz = (Class) legendFormatWriters |
||
359 | 33339 | jpiera | .get(legendName); |
360 | 30011 | cordinyana | |
361 | if (legendWriterClazz != null) { |
||
362 | try {
|
||
363 | return (ILegendWriter) legendWriterClazz.newInstance();
|
||
364 | } catch (InstantiationException e) { |
||
365 | throw new RegisteredClassInstantiationException( |
||
366 | ILegendWriter.class, legendWriterClazz, format |
||
367 | 33339 | jpiera | .concat("-").concat(legendName), e);
|
368 | 30011 | cordinyana | } catch (IllegalAccessException e) { |
369 | throw new RegisteredClassInstantiationException( |
||
370 | ILegendWriter.class, legendWriterClazz, format |
||
371 | 33339 | jpiera | .concat("-").concat(legendName), e);
|
372 | 30011 | cordinyana | } |
373 | } |
||
374 | } |
||
375 | return null; |
||
376 | } |
||
377 | |||
378 | private Map getLegendWritersForFormat(String format) { |
||
379 | return (Map) legendWriters.get(format); |
||
380 | } |
||
381 | |||
382 | 30892 | cordinyana | public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
383 | 33339 | jpiera | throws MapContextRuntimeException {
|
384 | 30892 | cordinyana | return getSymbolManager().createMultiLayerSymbol(shapeType);
|
385 | 30011 | cordinyana | } |
386 | |||
387 | 30892 | cordinyana | public IMultiLayerSymbol createMultiLayerSymbol(String symbolName) |
388 | 33339 | jpiera | throws MapContextRuntimeException {
|
389 | 30892 | cordinyana | return getSymbolManager().createMultiLayerSymbol(symbolName);
|
390 | 30011 | cordinyana | } |
391 | |||
392 | 30892 | cordinyana | public ISymbol createSymbol(int shapeType, Color color) |
393 | 33339 | jpiera | throws MapContextRuntimeException {
|
394 | 30892 | cordinyana | return getSymbolManager().createSymbol(shapeType, color);
|
395 | 30011 | cordinyana | } |
396 | |||
397 | 30892 | cordinyana | public ISymbol createSymbol(int shapeType) |
398 | 33339 | jpiera | throws MapContextRuntimeException {
|
399 | 30892 | cordinyana | return getSymbolManager().createSymbol(shapeType);
|
400 | 30011 | cordinyana | } |
401 | |||
402 | 30892 | cordinyana | public ISymbol createSymbol(String symbolName, Color color) |
403 | 33339 | jpiera | throws MapContextRuntimeException {
|
404 | 30892 | cordinyana | return getSymbolManager().createSymbol(symbolName, color);
|
405 | 30011 | cordinyana | } |
406 | |||
407 | 30892 | cordinyana | public ISymbol createSymbol(String symbolName) |
408 | 33339 | jpiera | throws MapContextRuntimeException {
|
409 | 30892 | cordinyana | return getSymbolManager().createSymbol(symbolName);
|
410 | } |
||
411 | 30011 | cordinyana | |
412 | 30892 | cordinyana | public IWarningSymbol getWarningSymbol(String message, String symbolDesc, |
413 | int symbolDrawExceptionType) throws MapContextRuntimeException { |
||
414 | return getSymbolManager().getWarningSymbol(message, symbolDesc,
|
||
415 | symbolDrawExceptionType); |
||
416 | 30011 | cordinyana | } |
417 | |||
418 | 30892 | cordinyana | public ISymbol[] loadSymbols(File folder, FileFilter filter) |
419 | 33339 | jpiera | throws SymbolException {
|
420 | 30892 | cordinyana | return getSymbolManager().loadSymbols(folder, filter);
|
421 | 30011 | cordinyana | } |
422 | |||
423 | 30892 | cordinyana | public ISymbol[] loadSymbols(File folder) throws SymbolException { |
424 | return getSymbolManager().loadSymbols(folder);
|
||
425 | 30011 | cordinyana | } |
426 | |||
427 | public void registerMultiLayerSymbol(String symbolName, Class symbolClass) |
||
428 | 33339 | jpiera | throws MapContextRuntimeException {
|
429 | 30892 | cordinyana | getSymbolManager().registerMultiLayerSymbol(symbolName, symbolClass); |
430 | 30011 | cordinyana | } |
431 | |||
432 | public void registerMultiLayerSymbol(String symbolName, int[] shapeTypes, |
||
433 | Class symbolClass) throws MapContextRuntimeException { |
||
434 | 30892 | cordinyana | getSymbolManager().registerMultiLayerSymbol(symbolName, shapeTypes, |
435 | symbolClass); |
||
436 | 30011 | cordinyana | } |
437 | |||
438 | 30892 | cordinyana | public void registerSymbol(String symbolName, Class symbolClass) |
439 | 33339 | jpiera | throws MapContextRuntimeException {
|
440 | 30892 | cordinyana | getSymbolManager().registerSymbol(symbolName, symbolClass); |
441 | } |
||
442 | 30011 | cordinyana | |
443 | 30892 | cordinyana | public void registerSymbol(String symbolName, int[] shapeTypes, |
444 | Class symbolClass) throws MapContextException { |
||
445 | getSymbolManager().registerSymbol(symbolName, shapeTypes, symbolClass); |
||
446 | } |
||
447 | 30011 | cordinyana | |
448 | 30892 | cordinyana | public void saveSymbol(ISymbol symbol, String fileName, File folder, |
449 | boolean overwrite) throws SymbolException { |
||
450 | getSymbolManager().saveSymbol(symbol, fileName, folder, overwrite); |
||
451 | 30011 | cordinyana | } |
452 | |||
453 | 30892 | cordinyana | public void saveSymbol(ISymbol symbol, String fileName, File folder) |
454 | 33339 | jpiera | throws SymbolException {
|
455 | 30892 | cordinyana | getSymbolManager().saveSymbol(symbol, fileName, folder); |
456 | 30011 | cordinyana | } |
457 | 32923 | jjdelcerro | |
458 | public FLayer createLayer(String layerName, DataStoreParameters parameters) |
||
459 | 33339 | jpiera | throws LoadLayerException {
|
460 | 32923 | jjdelcerro | return LayerFactory.getInstance().createLayer(layerName, parameters);
|
461 | } |
||
462 | |||
463 | public FLayer createLayer(String layerName, DataStore store) |
||
464 | 33339 | jpiera | throws LoadLayerException {
|
465 | 32923 | jjdelcerro | return LayerFactory.getInstance().createLayer(layerName, store);
|
466 | } |
||
467 | 33339 | jpiera | |
468 | public ILegend getLegend(DataStore dataStore) {
|
||
469 | ILegend legend = null;
|
||
470 | |||
471 | //Loading the legend from a store based on file
|
||
472 | try {
|
||
473 | // This access by reflection is done because the libFMap_dalfile project
|
||
474 | // has to be divided in several projects. The commented code is the fine
|
||
475 | // code whereas the used code has to be deleted.
|
||
476 | //
|
||
477 | // if (dataStore.getExplorer() instanceof FilesystemServerExplorer){
|
||
478 | // File file = ((FilesystemServerExplorer)dataStore.getExplorer()).getResourcePath(dataStore, "gvl");
|
||
479 | // if ((file != null) && (file.exists())){
|
||
480 | // PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
|
||
481 | // PersistentState persistentState = persistenceManager.loadState(new FileInputStream(file));
|
||
482 | // legend = (ILegend)persistenceManager.create(persistentState);
|
||
483 | // }
|
||
484 | // }
|
||
485 | DataServerExplorer dataServerExplorer = dataStore.getExplorer(); |
||
486 | Class[] args = new Class[2]; |
||
487 | args[0] = DataStore.class;
|
||
488 | args[1] = String.class; |
||
489 | Method method = dataStore.getExplorer().getClass().getMethod("getResourcePath", args); |
||
490 | if (method != null){ |
||
491 | Object[] params = new Object[2]; |
||
492 | params[0] = dataStore;
|
||
493 | params[1] = "gvl"; |
||
494 | File file = (File)method.invoke(dataServerExplorer, params); |
||
495 | if ((file != null) && (file.exists())){ |
||
496 | PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
||
497 | PersistentState persistentState = persistenceManager.loadState(new FileInputStream(file)); |
||
498 | legend = (ILegend)persistenceManager.create(persistentState); |
||
499 | } |
||
500 | } |
||
501 | |||
502 | } catch (Exception e) { |
||
503 | LOG.error("Error creating the legend the explorer", e);
|
||
504 | } |
||
505 | |||
506 | //If the legend is null, next option is to check if the store has the getLegend method
|
||
507 | if (legend == null){ |
||
508 | try {
|
||
509 | legend = (IVectorLegend) dataStore.invokeDynMethod( |
||
510 | "getLegend", null); |
||
511 | } catch (DynMethodNotSupportedException e) {
|
||
512 | // Do nothing
|
||
513 | } catch (DynMethodException e) {
|
||
514 | LOG.error("Can't load the specific legend provided for the store {}.", dataStore.getName(), e);
|
||
515 | } |
||
516 | } |
||
517 | |||
518 | //If legend is null, last step is just try to create the legend by default
|
||
519 | if( legend == null ) { |
||
520 | FeatureType featureType; |
||
521 | try {
|
||
522 | featureType = (((FeatureStore)dataStore).getDefaultFeatureType()); |
||
523 | int indexGeom = featureType.getDefaultGeometryAttributeIndex();
|
||
524 | int typeShape = featureType.getAttributeDescriptor(indexGeom).getGeometryType();
|
||
525 | legend = MapContextLocator.getMapContextManager().createDefaultVectorLegend(typeShape); |
||
526 | } catch (DataException e) {
|
||
527 | LOG.error("Error getting the default feature type", e);
|
||
528 | } |
||
529 | } |
||
530 | |||
531 | return legend;
|
||
532 | } |
||
533 | |||
534 | 28882 | cordinyana | } |