Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectExtent.java @ 38063

History | View | Annotate | Download (5.76 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 7304 caballero
import com.iver.utiles.XMLEntity;
46 1222 fernando
47 7304 caballero
48 1222 fernando
/**
49
 * DOCUMENT ME!
50
 *
51
 * @author Fernando Gonz?lez Cort?s
52
 */
53
public class ProjectExtent {
54
    private Rectangle2D extent = new Rectangle2D.Double();
55
    private String description;
56
57
    /**
58
     * DOCUMENT ME!
59
     *
60
     * @return
61
     */
62
    public String getDescription() {
63
        return description;
64
    }
65
66
    /**
67
     * DOCUMENT ME!
68
     *
69
     * @return
70
     */
71
    public Rectangle2D getExtent() {
72
        return extent;
73
    }
74
75
    /**
76
     * DOCUMENT ME!
77
     *
78
     * @param string
79
     */
80
    public void setDescription(String string) {
81
        description = string;
82
    }
83
84
    /**
85
     * DOCUMENT ME!
86
     *
87
     * @param rectangle2D
88
     */
89
    public void setExtent(Rectangle2D rectangle2D) {
90
        extent = rectangle2D;
91
    }
92
93
    /**
94
     * DOCUMENT ME!
95
     *
96
     * @return DOCUMENT ME!
97
     */
98
    public String getEncuadre() {
99
        return extent.getMinX() + "," + extent.getMinY() + "," +
100
        extent.getWidth() + "," + extent.getHeight();
101
    }
102
103
    /**
104
     * DOCUMENT ME!
105
     *
106
     * @param encuadre DOCUMENT ME!
107
     */
108
    public void setEncuadre(String encuadre) {
109
        String[] coords = encuadre.split(",");
110
        extent = new Rectangle2D.Double(new Double(coords[0]).doubleValue(),
111
                new Double(coords[1]).doubleValue(),
112
                new Double(coords[2]).doubleValue(),
113
                new Double(coords[3]).doubleValue());
114
    }
115
116
    /**
117
     * @see java.lang.Object#toString()
118
     */
119
    public String toString() {
120
        return description;
121
    }
122
123
    /**
124
     * DOCUMENT ME!
125
     *
126
     * @return DOCUMENT ME!
127
     */
128
    public XMLEntity getXMLEntity() {
129
        XMLEntity xml = new XMLEntity();
130
        xml.putProperty("description", description);
131
        xml.putProperty("extentX", extent.getX());
132
        xml.putProperty("extentY", extent.getY());
133
        xml.putProperty("extentW", extent.getWidth());
134
        xml.putProperty("extentH", extent.getHeight());
135
136
        return xml;
137
    }
138
139
    /**
140
     * DOCUMENT ME!
141
     *
142
     * @param xml DOCUMENT ME!
143
     *
144
     * @return DOCUMENT ME!
145
     */
146 2183 fernando
    public static ProjectExtent createFromXML03(XMLEntity xml) {
147
        ProjectExtent pe = new ProjectExtent();
148
        pe.description = xml.getStringProperty("description");
149
        pe.extent.setRect(xml.getDoubleProperty("extentX"),
150
            xml.getDoubleProperty("extentY"), xml.getDoubleProperty("extentW"),
151
            xml.getDoubleProperty("extentH"));
152
153
        return pe;
154
    }
155
156
    /**
157
     * DOCUMENT ME!
158
     *
159
     * @param xml DOCUMENT ME!
160
     *
161
     * @return DOCUMENT ME!
162
     */
163 1222 fernando
    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 6888 jaume
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 1222 fernando
}