Revision 42352 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/rendering/symbols/impl/DefaultSymbolManager.java
DefaultSymbolManager.java | ||
---|---|---|
44 | 44 |
import java.util.Collections; |
45 | 45 |
import java.util.Comparator; |
46 | 46 |
import java.util.HashMap; |
47 |
import java.util.Iterator; |
|
47 | 48 |
import java.util.List; |
48 | 49 |
import java.util.Map; |
49 | 50 |
import java.util.Random; |
51 |
|
|
50 | 52 |
import org.apache.commons.io.FileUtils; |
51 | 53 |
import org.apache.commons.io.FilenameUtils; |
52 | 54 |
import org.apache.commons.io.filefilter.FileFilterUtils; |
53 | 55 |
import org.apache.commons.lang3.StringUtils; |
56 |
import org.slf4j.Logger; |
|
57 |
import org.slf4j.LoggerFactory; |
|
58 |
|
|
59 |
import org.gvsig.fmap.geom.Geometry; |
|
60 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
61 |
import org.gvsig.fmap.geom.GeometryManager; |
|
62 |
import org.gvsig.fmap.geom.type.GeometryType; |
|
63 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
|
64 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
|
54 | 65 |
import org.gvsig.fmap.mapcontext.MapContextRuntimeException; |
55 | 66 |
import org.gvsig.fmap.mapcontext.impl.InvalidRegisteredClassException; |
56 | 67 |
import org.gvsig.fmap.mapcontext.impl.RegisteredClassInstantiationException; |
... | ... | |
72 | 83 |
import org.gvsig.tools.task.TaskStatusManager; |
73 | 84 |
import org.gvsig.tools.visitor.VisitCanceledException; |
74 | 85 |
import org.gvsig.tools.visitor.Visitor; |
75 |
import org.slf4j.Logger; |
|
76 |
import org.slf4j.LoggerFactory; |
|
77 | 86 |
|
78 | 87 |
/** |
79 | 88 |
* Default {@link SymbolManager} implementation. |
... | ... | |
350 | 359 |
|
351 | 360 |
public ISymbol createSymbol(int shapeType) |
352 | 361 |
throws MapContextRuntimeException { |
353 |
String symbolName |
|
354 |
= (String) symbolsByShapeType.get(new Integer(shapeType)); |
|
362 |
String symbolName = getSymbolName(symbolsByShapeType, shapeType); |
|
355 | 363 |
|
356 | 364 |
return symbolName == null ? null : createSymbol(symbolName); |
357 | 365 |
} |
... | ... | |
369 | 377 |
|
370 | 378 |
public ISymbol createSymbol(int shapeType, Color color) |
371 | 379 |
throws MapContextRuntimeException { |
372 |
String symbolName |
|
373 |
= (String) symbolsByShapeType.get(new Integer(shapeType)); |
|
380 |
String symbolName = getSymbolName(symbolsByShapeType, shapeType); |
|
374 | 381 |
|
375 | 382 |
return symbolName == null ? null : createSymbol(symbolName, color); |
376 | 383 |
} |
... | ... | |
384 | 391 |
|
385 | 392 |
public IMultiLayerSymbol createMultiLayerSymbol(int shapeType) |
386 | 393 |
throws MapContextRuntimeException { |
387 |
String symbolName |
|
388 |
= (String) multiLineSymbolsByShapeType.get(new Integer(shapeType)); |
|
394 |
String symbolName = getSymbolName(multiLineSymbolsByShapeType, shapeType); |
|
389 | 395 |
|
390 | 396 |
return symbolName == null ? null : createMultiLayerSymbol(symbolName); |
391 | 397 |
} |
392 | 398 |
|
399 |
/** |
|
400 |
* @param shapeType |
|
401 |
* @return |
|
402 |
*/ |
|
403 |
private String getSymbolName(Map symbols, int shapeType) { |
|
404 |
String symbolName |
|
405 |
= (String) symbols.get(new Integer(shapeType)); |
|
406 |
if (symbolName == null) { |
|
407 |
GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
408 |
GeometryType shapeGeometryType; |
|
409 |
try { |
|
410 |
shapeGeometryType = geomManager.getGeometryType(shapeType, Geometry.SUBTYPES.UNKNOWN); |
|
411 |
Iterator it = symbols.keySet().iterator(); |
|
412 |
while (it.hasNext()) { |
|
413 |
Integer geomType = (Integer) it.next(); |
|
414 |
GeometryType geomGeometryType = |
|
415 |
geomManager.getGeometryType(geomType.intValue(), Geometry.SUBTYPES.UNKNOWN); |
|
416 |
if (shapeGeometryType.isSubTypeOf(geomGeometryType)) { |
|
417 |
symbolName = (String) symbols.get(geomType); |
|
418 |
break; |
|
419 |
} |
|
420 |
} |
|
421 |
} catch (GeometryTypeNotSupportedException e) { |
|
422 |
// do nothing |
|
423 |
} catch (GeometryTypeNotValidException e) { |
|
424 |
// do nothing |
|
425 |
} |
|
426 |
} |
|
427 |
return symbolName; |
|
428 |
} |
|
429 |
|
|
393 | 430 |
public void registerSymbol(String symbolName, Class symbolClass) |
394 | 431 |
throws MapContextRuntimeException { |
395 | 432 |
if (symbolClass == null || !ISymbol.class.isAssignableFrom(symbolClass)) { |
... | ... | |
578 | 615 |
// ...else resp remains the same |
579 | 616 |
} |
580 | 617 |
|
581 |
// finally add some dark noise
|
|
618 |
// finally add some dark noise |
|
582 | 619 |
resp = addDarkNoise(resp); |
583 | 620 |
return resp; |
584 | 621 |
} |
Also available in: Unified diff