Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectExtent.java @ 28304

History | View | Annotate | Download (6.04 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.project;
42

    
43
import java.awt.geom.Rectangle2D;
44

    
45
import org.gvsig.fmap.geom.GeometryLocator;
46
import org.gvsig.fmap.geom.GeometryManager;
47
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
48
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
49
import org.gvsig.fmap.geom.primitive.Envelope;
50
import org.gvsig.fmap.geom.util.UtilFunctions;
51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
53

    
54
import com.iver.cit.gvsig.gui.styling.SymbolSelector;
55
import com.iver.utiles.XMLEntity;
56

    
57

    
58
/**
59
 * DOCUMENT ME!
60
 *
61
 * @author Fernando Gonz?lez Cort?s
62
 */
63
public class ProjectExtent {
64
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
65
        private static final Logger logger = LoggerFactory.getLogger(ProjectExtent.class);
66
        private Rectangle2D extent = new Rectangle2D.Double();
67
    private String description;
68

    
69
    /**
70
     * DOCUMENT ME!
71
     *
72
     * @return
73
     */
74
    public String getDescription() {
75
        return description;
76
    }
77

    
78
    /**
79
     * DOCUMENT ME!
80
     *
81
     * @return
82
     */
83
    public Envelope getExtent() {
84
        try {
85
                        return geomManager.createEnvelope(extent.getX(),extent.getY(),extent.getMaxX(),extent.getMaxY(), SUBTYPES.GEOM2D);
86
                } catch (CreateEnvelopeException e) {
87
                        logger.error("Error creating the envelope", e);
88
                }
89
                return null;
90
    }
91

    
92
    /**
93
     * DOCUMENT ME!
94
     *
95
     * @param string
96
     */
97
    public void setDescription(String string) {
98
        description = string;
99
    }
100

    
101
    /**
102
     * DOCUMENT ME!
103
     *
104
     * @param rectangle2D
105
     */
106
    public void setExtent(Rectangle2D rectangle2D) {
107
        extent = rectangle2D;
108
    }
109

    
110
    /**
111
     * DOCUMENT ME!
112
     *
113
     * @return DOCUMENT ME!
114
     */
115
    public String getEncuadre() {
116
        return extent.getMinX() + "," + extent.getMinY() + "," +
117
        extent.getWidth() + "," + extent.getHeight();
118
    }
119

    
120
    /**
121
     * DOCUMENT ME!
122
     *
123
     * @param encuadre DOCUMENT ME!
124
     */
125
    public void setEncuadre(String encuadre) {
126
        String[] coords = encuadre.split(",");
127
        extent = new Rectangle2D.Double(new Double(coords[0]).doubleValue(),
128
                new Double(coords[1]).doubleValue(),
129
                new Double(coords[2]).doubleValue(),
130
                new Double(coords[3]).doubleValue());
131
    }
132

    
133
    /**
134
     * @see java.lang.Object#toString()
135
     */
136
    public String toString() {
137
        return description;
138
    }
139

    
140
    /**
141
     * DOCUMENT ME!
142
     *
143
     * @return DOCUMENT ME!
144
     */
145
    public XMLEntity getXMLEntity() {
146
        XMLEntity xml = new XMLEntity();
147
        xml.putProperty("description", description);
148
        xml.putProperty("extentX", extent.getX());
149
        xml.putProperty("extentY", extent.getY());
150
        xml.putProperty("extentW", extent.getWidth());
151
        xml.putProperty("extentH", extent.getHeight());
152

    
153
        return xml;
154
    }
155

    
156
     /**
157
     * DOCUMENT ME!
158
     *
159
     * @param xml DOCUMENT ME!
160
     *
161
     * @return DOCUMENT ME!
162
     */
163
    public static ProjectExtent createFromXML(XMLEntity xml) {
164
        ProjectExtent pe = new ProjectExtent();
165
        pe.description = xml.getStringProperty("description");
166
        pe.extent.setRect(xml.getDoubleProperty("extentX"),
167
            xml.getDoubleProperty("extentY"), xml.getDoubleProperty("extentW"),
168
            xml.getDoubleProperty("extentH"));
169

    
170
        return pe;
171
    }
172

    
173
//        public int computeSignature() {
174
//                int result = 17;
175
//
176
//                Class clazz = getClass();
177
//                Field[] fields = clazz.getDeclaredFields();
178
//                for (int i = 0; i < fields.length; i++) {
179
//                        try {
180
//                                String type = fields[i].getType().getName();
181
//                                if (type.equals("boolean")) {
182
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
183
//                                } else if (type.equals("java.lang.String")) {
184
//                                        Object v = fields[i].get(this);
185
//                                        if (v == null) {
186
//                                                result += 37;
187
//                                                continue;
188
//                                        }
189
//                                        char[] chars = ((String) v).toCharArray();
190
//                                        for (int j = 0; j < chars.length; j++) {
191
//                                                result += 37 + (int) chars[i];
192
//                                        }
193
//                                } else if (type.equals("byte")) {
194
//                                        result += 37 + (int) fields[i].getByte(this);
195
//                                } else if (type.equals("char")) {
196
//                                        result += 37 + (int) fields[i].getChar(this);
197
//                                } else if (type.equals("short")) {
198
//                                        result += 37 + (int) fields[i].getShort(this);
199
//                                } else if (type.equals("int")) {
200
//                                        result += 37 + fields[i].getInt(this);
201
//                                } else if (type.equals("long")) {
202
//                                        long f = fields[i].getLong(this) ;
203
//                                        result += 37 + (f ^ (f >>> 32));
204
//                                } else if (type.equals("float")) {
205
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
206
//                                } else if (type.equals("double")) {
207
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
208
//                                        result += 37 + (f ^ (f >>> 32));
209
//                                } else {
210
//                                        Object obj = fields[i].get(this);
211
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
212
//                                }
213
//                        } catch (Exception e) { e.printStackTrace(); }
214
//
215
//                }
216
//                return result;
217
//        }
218
}