svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / gvsig / fmap / crs / persistence / CoordTransPersistenceFactory.java @ 40559
History | View | Annotate | Download (3.15 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40455 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40455 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40455 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * 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 | *
|
||
16 | * 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 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40455 | jjdelcerro | */
|
24 | package org.gvsig.fmap.crs.persistence; |
||
25 | |||
26 | import org.cresques.DataTypes; |
||
27 | import org.cresques.cts.ICoordTrans; |
||
28 | import org.cresques.cts.IProjection; |
||
29 | |||
30 | import org.gvsig.tools.dynobject.DynStruct; |
||
31 | import org.gvsig.tools.persistence.AbstractSinglePersistenceFactory; |
||
32 | import org.gvsig.tools.persistence.PersistentState; |
||
33 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
34 | |||
35 | |||
36 | /**
|
||
37 | * @author gvSIG Team
|
||
38 | * @version $Id$
|
||
39 | *
|
||
40 | */
|
||
41 | public class CoordTransPersistenceFactory extends AbstractSinglePersistenceFactory { |
||
42 | |||
43 | private static final String FIELD_SOURCE_PROJECTION = "source"; |
||
44 | private static final String DESCRIPTION_SOURCE_PROJECTION = "Source projection"; |
||
45 | |||
46 | private static final String FIELD_DESTINATION_PROJECTION = "destination"; |
||
47 | private static final String DESCRIPTION_DESTINATION_PROJECTION = "Destination Projection"; |
||
48 | |||
49 | private static final String DYNCLASS_NAME = "CoordTrans"; |
||
50 | private static final String DYNCLASS_DESCRIPTION = "Coordinates Transformation"; |
||
51 | |||
52 | /**
|
||
53 | * Creates a new {@link CoordTransPersistenceFactory}.
|
||
54 | */
|
||
55 | public CoordTransPersistenceFactory() {
|
||
56 | super(ICoordTrans.class, DYNCLASS_NAME, DYNCLASS_DESCRIPTION, null, null); |
||
57 | |||
58 | DynStruct definition = this.getDefinition();
|
||
59 | |||
60 | definition.addDynField(FIELD_SOURCE_PROJECTION).setDescription( |
||
61 | DESCRIPTION_SOURCE_PROJECTION).setMandatory(true).setType(
|
||
62 | DataTypes.CRS); |
||
63 | |||
64 | definition.addDynField(FIELD_DESTINATION_PROJECTION).setDescription( |
||
65 | DESCRIPTION_DESTINATION_PROJECTION).setMandatory(true).setType(
|
||
66 | DataTypes.CRS); |
||
67 | } |
||
68 | |||
69 | public Object createFromState(PersistentState state) |
||
70 | throws PersistenceException {
|
||
71 | IProjection sourceProjection = (IProjection)state.get(FIELD_SOURCE_PROJECTION); |
||
72 | IProjection destinationProjection = (IProjection)state.get(FIELD_DESTINATION_PROJECTION); |
||
73 | return sourceProjection.getCT(destinationProjection);
|
||
74 | } |
||
75 | |||
76 | public void saveToState(PersistentState state, Object obj) |
||
77 | throws PersistenceException {
|
||
78 | state.set(FIELD_SOURCE_PROJECTION, ((ICoordTrans) obj).getPOrig()); |
||
79 | state.set(FIELD_DESTINATION_PROJECTION, ((ICoordTrans) obj).getPDest()); |
||
80 | } |
||
81 | } |