Revision 37491
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/MapContextManager.java | ||
---|---|---|
40 | 40 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorLegend; |
41 | 41 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
42 | 42 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
43 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
|
43 | 44 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
44 | 45 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
45 | 46 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
... | ... | |
351 | 352 |
* the legend or <code>null</code>. |
352 | 353 |
*/ |
353 | 354 |
ILegend getLegend(DataStore dataStore); |
355 |
|
|
356 |
/** |
|
357 |
* It returns the labeling strategy associated with a {@link DataStore}. |
|
358 |
* If the labeling strategy doesn't exist it returns <code>null</code>. |
|
359 |
* @param dataStore |
|
360 |
* the store that could have a labeling strategy. |
|
361 |
* @return |
|
362 |
* the labeling strategy or <code>null</code>. |
|
363 |
*/ |
|
364 |
ILabelingStrategy getLabelingStrategy(DataStore dataStore); |
|
354 | 365 |
|
355 | 366 |
|
356 | 367 |
// TODO: |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/layers/vectorial/FLyrVect.java | ||
---|---|---|
74 | 74 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
75 | 75 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
76 | 76 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
77 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
|
77 | 78 |
import org.gvsig.fmap.mapcontext.ViewPort; |
78 | 79 |
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException; |
79 | 80 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
... | ... | |
99 | 100 |
import org.gvsig.tools.ToolsLocator; |
100 | 101 |
import org.gvsig.tools.dynobject.DynObjectSet; |
101 | 102 |
import org.gvsig.tools.dynobject.DynStruct; |
102 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
|
103 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
|
104 | 103 |
import org.gvsig.tools.exception.BaseException; |
105 | 104 |
import org.gvsig.tools.locator.LocatorException; |
106 | 105 |
import org.gvsig.tools.observer.Observable; |
... | ... | |
280 | 279 |
|
281 | 280 |
featureStore = (FeatureStore) dataStore; |
282 | 281 |
|
282 |
MapContextManager mapContextManager = |
|
283 |
MapContextLocator.getMapContextManager(); |
|
284 |
|
|
285 |
//Set the legend |
|
283 | 286 |
IVectorLegend legend = |
284 |
(IVectorLegend) MapContextLocator.getMapContextManager().getLegend(dataStore);
|
|
287 |
(IVectorLegend)mapContextManager.getLegend(dataStore);
|
|
285 | 288 |
|
286 | 289 |
if (legend == null) { |
287 | 290 |
throw new LegendLayerException(this.getName()); |
... | ... | |
289 | 292 |
|
290 | 293 |
this.setLegend(legend); |
291 | 294 |
|
292 |
ILabelingStrategy labeler = null; |
|
293 |
try { |
|
294 |
labeler = |
|
295 |
(ILabelingStrategy) dataStore.invokeDynMethod("getLabeling", |
|
296 |
null); |
|
297 |
} catch (DynMethodNotSupportedException e1) { |
|
298 |
labeler = null; |
|
299 |
} catch (DynMethodException e1) { |
|
300 |
logger.error("Can't load the specific lebeling strategy provided for the layer {}.", |
|
301 |
this.getName(), |
|
302 |
e1); |
|
303 |
} |
|
295 |
//Set the labeling strategy |
|
296 |
ILabelingStrategy labeler = |
|
297 |
(ILabelingStrategy) mapContextManager.getLabelingStrategy(dataStore); |
|
304 | 298 |
|
305 | 299 |
if (labeler != null) { |
306 | 300 |
labeler.setLayer(this); |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java | ||
---|---|---|
31 | 31 |
import java.io.File; |
32 | 32 |
import java.io.FileFilter; |
33 | 33 |
import java.io.FileInputStream; |
34 |
import java.io.FileNotFoundException; |
|
35 |
import java.io.IOException; |
|
34 | 36 |
import java.lang.reflect.Method; |
35 |
import java.security.acl.LastOwnerException; |
|
36 | 37 |
import java.util.Collections; |
37 | 38 |
import java.util.HashMap; |
38 | 39 |
import java.util.Map; |
... | ... | |
62 | 63 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
63 | 64 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendReader; |
64 | 65 |
import org.gvsig.fmap.mapcontext.rendering.legend.driver.ILegendWriter; |
66 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
|
65 | 67 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
66 | 68 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
67 | 69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
... | ... | |
72 | 74 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
73 | 75 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
74 | 76 |
import org.gvsig.tools.persistence.PersistenceManager; |
75 |
import org.gvsig.tools.persistence.PersistentState; |
|
76 | 77 |
|
77 | 78 |
/** |
78 | 79 |
* Default implementation of the {@link MapContextManager}. |
... | ... | |
462 | 463 |
public ILegend getLegend(DataStore dataStore) { |
463 | 464 |
ILegend legend = null; |
464 | 465 |
|
465 |
//Loading the legend from a store based on file |
|
466 |
DataServerExplorer dataServerExplorer = null; |
|
467 |
try { |
|
468 |
// This access by reflection is done because the libFMap_dalfile project |
|
469 |
// has to be divided in several projects. The commented code is the fine |
|
470 |
// code whereas the used code has to be deleted. |
|
471 |
// |
|
472 |
// if (dataStore.getExplorer() instanceof FilesystemServerExplorer){ |
|
473 |
// File file = ((FilesystemServerExplorer)dataStore.getExplorer()).getResourcePath(dataStore, "gvl"); |
|
474 |
// if ((file != null) && (file.exists())){ |
|
475 |
// PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
476 |
// PersistentState persistentState = persistenceManager.loadState(new FileInputStream(file)); |
|
477 |
// legend = (ILegend)persistenceManager.create(persistentState); |
|
478 |
// } |
|
479 |
// } |
|
480 |
dataServerExplorer = dataStore.getExplorer(); |
|
481 |
Class[] args = new Class[2]; |
|
482 |
args[0] = DataStore.class; |
|
483 |
args[1] = String.class; |
|
484 |
Method method = dataStore.getExplorer().getClass().getMethod("getResourcePath", args); |
|
485 |
if (method != null){ |
|
486 |
Object[] params = new Object[2]; |
|
487 |
params[0] = dataStore; |
|
488 |
params[1] = SymbolManager.LEGEND_FILE_EXTENSION.substring(1); |
|
489 |
File file = (File)method.invoke(dataServerExplorer, params); |
|
490 |
if ((file != null) && (file.exists())){ |
|
491 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
492 |
FileInputStream is = new FileInputStream(file); |
|
493 |
legend = (ILegend) persistenceManager.getObject(is); |
|
494 |
is.close(); |
|
495 |
} |
|
496 |
} |
|
497 |
|
|
498 |
} catch (Exception e) { |
|
499 |
LOG.debug( |
|
500 |
"Can't load the specific legend provided by the explorer " |
|
501 |
+ dataServerExplorer, e); |
|
502 |
} |
|
503 |
|
|
466 |
File file = getResourcePathByReflection(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1)); |
|
467 |
try{ |
|
468 |
if ((file != null) && (file.exists())){ |
|
469 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
470 |
FileInputStream is = new FileInputStream(file); |
|
471 |
legend = (ILegend) persistenceManager.getObject(is); |
|
472 |
is.close(); |
|
473 |
} |
|
474 |
} catch (FileNotFoundException e){ |
|
475 |
LOG.error("Legend not found", e); |
|
476 |
} catch (IOException e) { |
|
477 |
LOG.error("Error reading the legend", e); |
|
478 |
} |
|
479 |
|
|
504 | 480 |
//If the legend is null, next option is to check if the store has the getLegend method |
505 | 481 |
if (legend == null){ |
506 | 482 |
try { |
... | ... | |
532 | 508 |
return legend; |
533 | 509 |
} |
534 | 510 |
|
511 |
public ILabelingStrategy getLabelingStrategy(DataStore dataStore) { |
|
512 |
ILabelingStrategy labelingStrategy = null; |
|
513 |
|
|
514 |
File file = getResourcePathByReflection(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1)); |
|
515 |
try{ |
|
516 |
if ((file != null) && (file.exists())){ |
|
517 |
PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager(); |
|
518 |
FileInputStream is = new FileInputStream(file); |
|
519 |
labelingStrategy = (ILabelingStrategy) persistenceManager.getObject(is); |
|
520 |
is.close(); |
|
521 |
} |
|
522 |
} catch (FileNotFoundException e){ |
|
523 |
LOG.error("Label strategy not found", e); |
|
524 |
} catch (IOException e) { |
|
525 |
LOG.error("Error reading the labeling strategy", e); |
|
526 |
} |
|
527 |
|
|
528 |
//If the legend is null, next option is to check if the store has the getLegend method |
|
529 |
if (labelingStrategy == null){ |
|
530 |
try { |
|
531 |
labelingStrategy = |
|
532 |
(ILabelingStrategy) dataStore.invokeDynMethod("getLabeling", |
|
533 |
null); |
|
534 |
} catch (DynMethodNotSupportedException e1) { |
|
535 |
labelingStrategy = null; |
|
536 |
} catch (DynMethodException e1) { |
|
537 |
LOG.error("Can't load the specific lebeling strategy provided for the datastore {}.", |
|
538 |
dataStore.getName(), |
|
539 |
e1); |
|
540 |
} |
|
541 |
} |
|
542 |
|
|
543 |
return labelingStrategy; |
|
544 |
} |
|
545 |
|
|
546 |
private File getResourcePathByReflection(DataStore dataStore, String resource){ |
|
547 |
//Loading the file from a store based on file |
|
548 |
DataServerExplorer dataServerExplorer = null; |
|
549 |
try { |
|
550 |
dataServerExplorer = dataStore.getExplorer(); |
|
551 |
Class[] args = new Class[2]; |
|
552 |
args[0] = DataStore.class; |
|
553 |
args[1] = String.class; |
|
554 |
Method method = dataStore.getExplorer().getClass().getMethod("getResourcePath", args); |
|
555 |
if (method != null){ |
|
556 |
Object[] params = new Object[2]; |
|
557 |
params[0] = dataStore; |
|
558 |
params[1] = resource; |
|
559 |
return (File)method.invoke(dataServerExplorer, params); |
|
560 |
} |
|
561 |
} catch (Exception e) { |
|
562 |
LOG.debug( |
|
563 |
"Can't load the specific legend provided by the explorer " |
|
564 |
+ dataServerExplorer, e); |
|
565 |
} |
|
566 |
return null; |
|
567 |
} |
|
535 | 568 |
} |
branches/v2_0_0_prep/libraries/libFMap_mapcontext/src/org/gvsig/fmap/mapcontext/rendering/symbols/SymbolManager.java | ||
---|---|---|
43 | 43 |
public interface SymbolManager { |
44 | 44 |
|
45 | 45 |
public static final String LEGEND_FILE_EXTENSION = ".gvsleg"; |
46 |
public static final String LABELINGSTRATEGY_FILE_EXTENSION = ".gvslab"; |
|
46 | 47 |
|
47 | 48 |
/** |
48 | 49 |
* Loads the symbols persisted into a folder. It loads the symbols through |
Also available in: Unified diff