Revision 21049 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/GeometryManager.java
GeometryManager.java | ||
---|---|---|
89 | 89 |
|
90 | 90 |
/** GeometryType index counter. Each time a new geometry type is registered it is assigned this counter's value as index and after that |
91 | 91 |
* it is incremented by 1 */ |
92 |
private int geomTypeIndex = 100; |
|
92 |
private int geomTypeIndex = 10000;
|
|
93 | 93 |
|
94 | 94 |
/** |
95 |
* Geometry Factory |
|
96 |
*/ |
|
97 |
private GeometryFactory factory = new GeometryFactory(); |
|
98 |
|
|
99 |
/** |
|
95 | 100 |
* Singleton's private constructor |
96 | 101 |
*/ |
97 | 102 |
private GeometryManager() { |
... | ... | |
104 | 109 |
public static GeometryManager getInstance() { |
105 | 110 |
if (instance == null) { |
106 | 111 |
instance = new GeometryManager(); |
112 |
instance.registerGeometryFactory(new GeometryFactory()); |
|
107 | 113 |
} |
108 | 114 |
return instance; |
109 | 115 |
} |
110 | 116 |
|
111 | 117 |
/** |
118 |
* Registers a GeometryFactory that will be used instead of the default one. |
|
119 |
* @param factory |
|
120 |
*/ |
|
121 |
public void registerGeometryFactory(GeometryFactory factory) { |
|
122 |
this.factory = factory; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Returns the current geometry factory |
|
127 |
* @return |
|
128 |
*/ |
|
129 |
public GeometryFactory getGeometryFactory() { |
|
130 |
return factory; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
112 | 134 |
* Registers the unique name of one operation. If it already exists then this method does nothing but returning |
113 | 135 |
* the name's corresponding index. |
114 | 136 |
* @param geomOpName Name used to register the geometry operation |
... | ... | |
280 | 302 |
* associated GeometryType instance. If the class is already registered |
281 | 303 |
* then this method does nothing but returning the associated GeometryType.<br> |
282 | 304 |
* |
305 |
* How to register a new geometry type: |
|
306 |
* <pre> |
|
307 |
* |
|
308 |
* public class MyGeom3D implements Solid { |
|
309 |
* private static final GeometryType geomType = GeometryManager.getInstance() |
|
310 |
* .registerGeometryType(MyGeom3D.class, "MyGeom3D"); |
|
311 |
* |
|
312 |
* public static final int GEOM_TYPE = geomType.getType(); |
|
313 |
* ... |
|
314 |
* public int getType() { |
|
315 |
* return GEOM_TYPE; |
|
316 |
* } |
|
317 |
* } |
|
318 |
* </pre> |
|
319 |
* |
|
283 | 320 |
* @param geomClass |
284 | 321 |
* Geometry subclass. It must not be null and must implement Geometry, otherwise an exception |
285 | 322 |
* is raised. |
... | ... | |
320 | 357 |
* associated GeometryType instance. If the class is already registered |
321 | 358 |
* then this method does nothing but returning the associated GeometryType.<br> |
322 | 359 |
* |
360 |
* In this case the symbolic name will be the geometry's simple class name |
|
361 |
* |
|
362 |
* How to register a new geometry type: |
|
363 |
* <pre> |
|
364 |
* |
|
365 |
* public class MyGeom3D implements Solid { |
|
366 |
* private static final GeometryType geomType = GeometryManager.getInstance() |
|
367 |
* .registerGeometryType(MyGeom3D.class); |
|
368 |
* |
|
369 |
* public static final int GEOM_TYPE = geomType.getType(); |
|
370 |
* ... |
|
371 |
* public int getType() { |
|
372 |
* return GEOM_TYPE; |
|
373 |
* } |
|
374 |
* } |
|
375 |
* </pre> |
|
376 |
* |
|
323 | 377 |
* @param geomClass |
324 | 378 |
* Geometry implementation class. It must not be null and must implement Geometry, |
325 | 379 |
* otherwise an exception is thrown. |
326 |
* @param name |
|
327 |
* Symbolic name for the geometry type, it can be null. If it is null then the symbolic name |
|
328 |
* will be the simple class name. |
|
329 |
* @return Instancia de GeometryType asociada a la clase de geometr?a |
|
330 |
* geomClass |
|
380 |
* @return Instance of GeometryType associated to the Geometry implementation class |
|
331 | 381 |
* @throws IllegalArgumentException |
332 | 382 |
* If geomClass is null or does not implement Geometry |
333 | 383 |
*/ |
... | ... | |
339 | 389 |
* class. |
340 | 390 |
* |
341 | 391 |
* @param geomClass |
342 |
* @return Instance of GeometryType associated to geomClass
|
|
392 |
* @return Instance of GeometryType associated to the Geometry implementation class
|
|
343 | 393 |
*/ |
344 | 394 |
public GeometryType getGeometryType(Class geomClass) { |
345 | 395 |
return (GeometryType) geometryTypes.get(geomClass.getName()); |
... | ... | |
363 | 413 |
* |
364 | 414 |
* @param geomClass |
365 | 415 |
* @param index |
366 |
* @return |
|
416 |
* @return Geometry operation
|
|
367 | 417 |
*/ |
368 | 418 |
public GeometryOperation getGeometryOperation(Class geomClass, int index) { |
369 | 419 |
GeometryType geomType = getGeometryType(geomClass); |
Also available in: Unified diff