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