Statistics
| Revision:

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

History | View | Annotate | Download (5.47 KB)

1 1222 fernando
/* 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 21530 vcaballero
import org.gvsig.fmap.geom.primitive.DefaultEnvelope;
46
import org.gvsig.fmap.geom.primitive.Envelope;
47
48 7304 caballero
import com.iver.utiles.XMLEntity;
49 1222 fernando
50 7304 caballero
51 1222 fernando
/**
52
 * DOCUMENT ME!
53
 *
54
 * @author Fernando Gonz?lez Cort?s
55
 */
56
public class ProjectExtent {
57
    private Rectangle2D extent = new Rectangle2D.Double();
58
    private String description;
59
60
    /**
61
     * DOCUMENT ME!
62
     *
63
     * @return
64
     */
65
    public String getDescription() {
66
        return description;
67
    }
68
69
    /**
70
     * DOCUMENT ME!
71
     *
72
     * @return
73
     */
74 21530 vcaballero
    public Envelope getExtent() {
75
        return new DefaultEnvelope(2,new double[]{extent.getX(),extent.getY()},new double[]{extent.getMaxX(),extent.getMaxY()});
76 1222 fernando
    }
77
78
    /**
79
     * DOCUMENT ME!
80
     *
81
     * @param string
82
     */
83
    public void setDescription(String string) {
84
        description = string;
85
    }
86
87
    /**
88
     * DOCUMENT ME!
89
     *
90
     * @param rectangle2D
91
     */
92
    public void setExtent(Rectangle2D rectangle2D) {
93
        extent = rectangle2D;
94
    }
95
96
    /**
97
     * DOCUMENT ME!
98
     *
99
     * @return DOCUMENT ME!
100
     */
101
    public String getEncuadre() {
102
        return extent.getMinX() + "," + extent.getMinY() + "," +
103
        extent.getWidth() + "," + extent.getHeight();
104
    }
105
106
    /**
107
     * DOCUMENT ME!
108
     *
109
     * @param encuadre DOCUMENT ME!
110
     */
111
    public void setEncuadre(String encuadre) {
112
        String[] coords = encuadre.split(",");
113
        extent = new Rectangle2D.Double(new Double(coords[0]).doubleValue(),
114
                new Double(coords[1]).doubleValue(),
115
                new Double(coords[2]).doubleValue(),
116
                new Double(coords[3]).doubleValue());
117
    }
118
119
    /**
120
     * @see java.lang.Object#toString()
121
     */
122
    public String toString() {
123
        return description;
124
    }
125
126
    /**
127
     * DOCUMENT ME!
128
     *
129
     * @return DOCUMENT ME!
130
     */
131
    public XMLEntity getXMLEntity() {
132
        XMLEntity xml = new XMLEntity();
133
        xml.putProperty("description", description);
134
        xml.putProperty("extentX", extent.getX());
135
        xml.putProperty("extentY", extent.getY());
136
        xml.putProperty("extentW", extent.getWidth());
137
        xml.putProperty("extentH", extent.getHeight());
138
139
        return xml;
140
    }
141
142 21530 vcaballero
     /**
143 1222 fernando
     * DOCUMENT ME!
144
     *
145
     * @param xml DOCUMENT ME!
146
     *
147
     * @return DOCUMENT ME!
148
     */
149
    public static ProjectExtent createFromXML(XMLEntity xml) {
150
        ProjectExtent pe = new ProjectExtent();
151
        pe.description = xml.getStringProperty("description");
152
        pe.extent.setRect(xml.getDoubleProperty("extentX"),
153
            xml.getDoubleProperty("extentY"), xml.getDoubleProperty("extentW"),
154
            xml.getDoubleProperty("extentH"));
155
156
        return pe;
157
    }
158 6888 jaume
159
//        public int computeSignature() {
160
//                int result = 17;
161
//
162
//                Class clazz = getClass();
163
//                Field[] fields = clazz.getDeclaredFields();
164
//                for (int i = 0; i < fields.length; i++) {
165
//                        try {
166
//                                String type = fields[i].getType().getName();
167
//                                if (type.equals("boolean")) {
168
//                                        result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
169
//                                } else if (type.equals("java.lang.String")) {
170
//                                        Object v = fields[i].get(this);
171
//                                        if (v == null) {
172
//                                                result += 37;
173
//                                                continue;
174
//                                        }
175
//                                        char[] chars = ((String) v).toCharArray();
176
//                                        for (int j = 0; j < chars.length; j++) {
177
//                                                result += 37 + (int) chars[i];
178
//                                        }
179
//                                } else if (type.equals("byte")) {
180
//                                        result += 37 + (int) fields[i].getByte(this);
181
//                                } else if (type.equals("char")) {
182
//                                        result += 37 + (int) fields[i].getChar(this);
183
//                                } else if (type.equals("short")) {
184
//                                        result += 37 + (int) fields[i].getShort(this);
185
//                                } else if (type.equals("int")) {
186
//                                        result += 37 + fields[i].getInt(this);
187
//                                } else if (type.equals("long")) {
188
//                                        long f = fields[i].getLong(this) ;
189
//                                        result += 37 + (f ^ (f >>> 32));
190
//                                } else if (type.equals("float")) {
191
//                                        result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
192
//                                } else if (type.equals("double")) {
193
//                                        long f = Double.doubleToLongBits(fields[i].getDouble(this));
194
//                                        result += 37 + (f ^ (f >>> 32));
195
//                                } else {
196
//                                        Object obj = fields[i].get(this);
197
//                                        result += 37 + ((obj != null)? obj.hashCode() : 0);
198
//                                }
199
//                        } catch (Exception e) { e.printStackTrace(); }
200
//
201
//                }
202
//                return result;
203
//        }
204 1222 fernando
}