Revision 33420 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/layout/geometryadapters/GeometryAdapter.java
GeometryAdapter.java | ||
---|---|---|
45 | 45 |
import java.awt.geom.Point2D; |
46 | 46 |
import java.awt.geom.Rectangle2D; |
47 | 47 |
import java.util.ArrayList; |
48 |
import java.util.Collections; |
|
49 |
import java.util.List; |
|
48 | 50 |
|
49 | 51 |
import org.gvsig.compat.print.PrintAttributes; |
50 | 52 |
import org.gvsig.fmap.geom.Geometry; |
51 | 53 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
52 | 54 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
55 |
import org.gvsig.tools.ToolsLocator; |
|
56 |
import org.gvsig.tools.dynobject.DynStruct; |
|
57 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
58 |
import org.gvsig.tools.persistence.Persistent; |
|
59 |
import org.gvsig.tools.persistence.PersistentState; |
|
60 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
53 | 61 |
import org.gvsig.utils.XMLEntity; |
54 | 62 |
|
55 | 63 |
|
... | ... | |
60 | 68 |
* |
61 | 69 |
* @author Vicente Caballero Navarro |
62 | 70 |
*/ |
63 |
public abstract class GeometryAdapter { |
|
64 |
private ArrayList points = new ArrayList(); |
|
71 |
public abstract class GeometryAdapter implements Persistent { |
|
72 |
public static final String PERSISTENCE_DEFINITION_NAME = "GeometryAdapter"; |
|
73 |
|
|
74 |
private static final String POINTS_FIELD = "points"; |
|
75 |
|
|
76 |
private List points = new ArrayList(); |
|
65 | 77 |
private GeneralPathX shape; |
66 | 78 |
|
67 | 79 |
/** |
... | ... | |
285 | 297 |
} catch (InstantiationException e) { |
286 | 298 |
} catch (IllegalAccessException e) { |
287 | 299 |
} |
288 |
cloneAdapter.points=(ArrayList)this.points.clone();
|
|
289 |
cloneAdapter.shape=(GeneralPathX)this.shape.clone();
|
|
300 |
Collections.copy(cloneAdapter.points, this.points);
|
|
301 |
cloneAdapter.shape = (GeneralPathX)this.shape.clone();
|
|
290 | 302 |
return cloneAdapter; |
291 | 303 |
} |
292 | 304 |
public Rectangle2D getBounds2D(){ |
... | ... | |
311 | 323 |
} |
312 | 324 |
return r; |
313 | 325 |
} |
326 |
|
|
327 |
public static void registerPersistent() { |
|
328 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
329 |
if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) { |
|
330 |
DynStruct definition = manager.addDefinition( |
|
331 |
GeometryAdapter.class, |
|
332 |
PERSISTENCE_DEFINITION_NAME, |
|
333 |
"GeometryAdapter persistence definition", |
|
334 |
null, |
|
335 |
null |
|
336 |
); |
|
337 |
|
|
338 |
definition.addDynFieldList(POINTS_FIELD).setClassOfItems(Point2D.class).setMandatory(true); |
|
339 |
} |
|
340 |
} |
|
341 |
|
|
342 |
|
|
343 |
public void loadFromState(PersistentState state) |
|
344 |
throws PersistenceException { |
|
345 |
points = state.getList(POINTS_FIELD); |
|
346 |
} |
|
347 |
|
|
348 |
|
|
349 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
350 |
state.set(POINTS_FIELD, points); |
|
351 |
} |
|
314 | 352 |
} |
Also available in: Unified diff