svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / ExtentHistory.java @ 13679
History | View | Annotate | Download (6.88 KB)
1 | 1100 | fjp | /* 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 | 213 | fernando | package com.iver.cit.gvsig.fmap; |
42 | |||
43 | 485 | vcaballero | import com.iver.utiles.XMLEntity; |
44 | |||
45 | 213 | fernando | import java.awt.geom.Rectangle2D; |
46 | |||
47 | 449 | vcaballero | |
48 | 485 | vcaballero | /**
|
49 | 13537 | ppiqueras | * <p>The class <code>ExtentHistory</code> is designed for managing a history of extents.</p>
|
50 | * <p><i>(An extent is a point of a corner and the dimensions of a rectangular area).</i></p>
|
||
51 | * <p><i>Note:</i> The class <code>ExtentHistory</code> only supports <i>get</i> and <i>remove</i> the last extent.</p>
|
||
52 | 485 | vcaballero | *
|
53 | * @author Vicente Caballero Navarro
|
||
54 | */
|
||
55 | 213 | fernando | public class ExtentHistory { |
56 | 13537 | ppiqueras | /**
|
57 | * <p>Maximum number of extents that can store.</p>
|
||
58 | */
|
||
59 | 1034 | vcaballero | private int NUMREC; |
60 | 13537 | ppiqueras | |
61 | /**
|
||
62 | * <p>Array with the extents.</p>
|
||
63 | *
|
||
64 | * @see #hasPrevious()
|
||
65 | * @see #put(Rectangle2D)
|
||
66 | * @see #get()
|
||
67 | * @see #removePrev()
|
||
68 | */
|
||
69 | 1034 | vcaballero | private Rectangle2D[] extents; |
70 | 13537 | ppiqueras | |
71 | /**
|
||
72 | * <p>Number of extents stored.</p>
|
||
73 | *
|
||
74 | * @see #hasPrevious()
|
||
75 | * @see #put(Rectangle2D)
|
||
76 | * @see #get()
|
||
77 | * @see #removePrev()
|
||
78 | */
|
||
79 | 1034 | vcaballero | private int num = 0; |
80 | 213 | fernando | |
81 | 1034 | vcaballero | /**
|
82 | 13537 | ppiqueras | * <p>Creates a new instance of <code>ExtentsHistory</code> with an history of 10 extents.</p>
|
83 | 1034 | vcaballero | */
|
84 | public ExtentHistory() {
|
||
85 | NUMREC = 10;
|
||
86 | 1326 | fernando | extents = new Rectangle2D[NUMREC]; |
87 | 1034 | vcaballero | } |
88 | 213 | fernando | |
89 | 1034 | vcaballero | /**
|
90 | 13537 | ppiqueras | * <p>Creates a new instance of <code>ExtentsHistory</code> with an history of <code>numEntries</code> extents.</p>
|
91 | 1034 | vcaballero | *
|
92 | 13537 | ppiqueras | * @param numEntries the maximum number of extents that will store the instance
|
93 | 1034 | vcaballero | */
|
94 | public ExtentHistory(int numEntries) { |
||
95 | NUMREC = numEntries; |
||
96 | } |
||
97 | 213 | fernando | |
98 | 1034 | vcaballero | /**
|
99 | 13537 | ppiqueras | * <p>Appends the specified extent to the end of this history.</p>
|
100 | 1034 | vcaballero | *
|
101 | 13537 | ppiqueras | * @param ext the new extent
|
102 | *
|
||
103 | * @see #get()
|
||
104 | * @see #hasPrevious()
|
||
105 | 1034 | vcaballero | */
|
106 | public void put(Rectangle2D ext) { |
||
107 | if ((ext != null) && ((num < 1) || (ext != extents[num - 1]))) { |
||
108 | if (num < (NUMREC)) {
|
||
109 | extents[num] = ext; |
||
110 | num = num + 1;
|
||
111 | } else {
|
||
112 | for (int i = 0; i < (NUMREC - 1); i++) { |
||
113 | extents[i] = extents[i + 1];
|
||
114 | } |
||
115 | 213 | fernando | |
116 | 1034 | vcaballero | extents[num - 1] = ext;
|
117 | } |
||
118 | } |
||
119 | } |
||
120 | 213 | fernando | |
121 | 1034 | vcaballero | /**
|
122 | 13537 | ppiqueras | * <p>Returns <code>true</code> if there are extents registered.</p>
|
123 | 1034 | vcaballero | *
|
124 | 13537 | ppiqueras | * @return <code>true</code> if there are extents registered; <code>false</code> otherwise
|
125 | *
|
||
126 | * @see #put(Rectangle2D)
|
||
127 | * @see #removePrev()
|
||
128 | * @see #get()
|
||
129 | 1034 | vcaballero | */
|
130 | public boolean hasPrevious() { |
||
131 | return num > 0; |
||
132 | } |
||
133 | 213 | fernando | |
134 | 1034 | vcaballero | /**
|
135 | 13537 | ppiqueras | * <p>Returns the last extent in the history.</p>
|
136 | 1034 | vcaballero | *
|
137 | 13537 | ppiqueras | * @return the last extent in the history?
|
138 | *
|
||
139 | * @see #put(Rectangle2D)
|
||
140 | * @see #getXMLEntity()
|
||
141 | 1034 | vcaballero | */
|
142 | public Rectangle2D get() { |
||
143 | Rectangle2D ext = extents[num - 1]; |
||
144 | 213 | fernando | |
145 | 1034 | vcaballero | return ext;
|
146 | } |
||
147 | 213 | fernando | |
148 | 1034 | vcaballero | /**
|
149 | 13537 | ppiqueras | * <p>Extracts the last extent from the history.</p>
|
150 | 1034 | vcaballero | *
|
151 | 13537 | ppiqueras | * @return last extent in the history
|
152 | *
|
||
153 | * @see #hasPrevious()
|
||
154 | 1034 | vcaballero | */
|
155 | public Rectangle2D removePrev() { |
||
156 | 8765 | jjdelcerro | Rectangle2D ext = extents[--num];
|
157 | 1034 | vcaballero | return ext;
|
158 | } |
||
159 | 485 | vcaballero | |
160 | 1034 | vcaballero | /**
|
161 | 13537 | ppiqueras | * <p>Returns an XML entity with information of this object. All information is stored as properties:<br></p>
|
162 | * <p><b>Properties:</b>
|
||
163 | * <ul>
|
||
164 | * <li><i>className</i>: name of this class.
|
||
165 | * <li><i>num</i>: number of extents registered.
|
||
166 | * <li><i>numrec</i>: maximum number of extents that can register.
|
||
167 | * <li><i>extentiX</i>: X coordinate of the upper left corner of the rectangle that defines the area.
|
||
168 | * <li><i>extentiY</i>: Y coordinate of the upper left corner of the rectangle that defines the area.
|
||
169 | * <li><i>extentiW</i>: width of the rectangle that defines the area.
|
||
170 | * <li><i>extentiH</i>: height of the rectangle that defines the area.
|
||
171 | * </ul>
|
||
172 | * </p>
|
||
173 | 1034 | vcaballero | *
|
174 | 13537 | ppiqueras | * @return XML entity that represents this object
|
175 | *
|
||
176 | * @see #createFromXML(XMLEntity)
|
||
177 | * @see #get()
|
||
178 | * @see #put(Rectangle2D)
|
||
179 | 1034 | vcaballero | */
|
180 | public XMLEntity getXMLEntity() {
|
||
181 | XMLEntity xml = new XMLEntity();
|
||
182 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
183 | 1034 | vcaballero | xml.putProperty("num", num);
|
184 | xml.putProperty("numrec", NUMREC);
|
||
185 | 485 | vcaballero | |
186 | 1034 | vcaballero | for (int i = 0; i < NUMREC; i++) { |
187 | if (extents[i] != null) { |
||
188 | xml.putProperty("extent" + i + "X", extents[i].getX()); |
||
189 | xml.putProperty("extent" + i + "Y", extents[i].getY()); |
||
190 | xml.putProperty("extent" + i + "W", extents[i].getWidth()); |
||
191 | xml.putProperty("extent" + i + "H", extents[i].getHeight()); |
||
192 | } |
||
193 | } |
||
194 | 485 | vcaballero | |
195 | 1034 | vcaballero | return xml;
|
196 | } |
||
197 | 485 | vcaballero | |
198 | 1034 | vcaballero | /**
|
199 | 13537 | ppiqueras | * @see #createFromXML(XMLEntity)
|
200 | 1034 | vcaballero | */
|
201 | 2183 | fernando | public static ExtentHistory createFromXML03(XMLEntity xml) { |
202 | ExtentHistory eh = new ExtentHistory();
|
||
203 | eh.num = xml.getIntProperty("num");
|
||
204 | eh.NUMREC = xml.getIntProperty("numrec");
|
||
205 | |||
206 | for (int i = 0; i < eh.NUMREC; i++) { |
||
207 | try {
|
||
208 | 13537 | ppiqueras | eh.extents[i] = new Rectangle2D.Double( |
209 | xml.getDoubleProperty("extent" + i + "X"), |
||
210 | 2183 | fernando | xml.getDoubleProperty("extent" + i + "Y"), |
211 | xml.getDoubleProperty("extent" + i + "W"), |
||
212 | xml.getDoubleProperty("extent" + i + "H")); |
||
213 | } catch (Exception e) { |
||
214 | ///System.out.println("En las ExtentHistory =" + e); //TODO o se captura de alguna forma o se mete un nuevo parametro en el xml para saber exactamente cuantos rect?gulos se han a?adido.
|
||
215 | } |
||
216 | } |
||
217 | |||
218 | return eh;
|
||
219 | } |
||
220 | |||
221 | /**
|
||
222 | 13537 | ppiqueras | * <p>Binds the information in the XML entity argument to create and return an <code>ExtentHistory</code>
|
223 | * object.</p>
|
||
224 | 2183 | fernando | *
|
225 | 13537 | ppiqueras | * @param xml an XML entity of a <code>ExtentHistory</code>
|
226 | 2183 | fernando | *
|
227 | 13537 | ppiqueras | * @return an <code>ExtentHistory</code> object with the information of the <code>xml</code> argument
|
228 | *
|
||
229 | * @see #getXMLEntity()
|
||
230 | 2183 | fernando | */
|
231 | 1034 | vcaballero | public static ExtentHistory createFromXML(XMLEntity xml) { |
232 | ExtentHistory eh = new ExtentHistory();
|
||
233 | eh.num = xml.getIntProperty("num");
|
||
234 | eh.NUMREC = xml.getIntProperty("numrec");
|
||
235 | 485 | vcaballero | |
236 | 1034 | vcaballero | for (int i = 0; i < eh.NUMREC; i++) { |
237 | try {
|
||
238 | 13537 | ppiqueras | eh.extents[i] = new Rectangle2D.Double( |
239 | xml.getDoubleProperty("extent" + i + "X"), |
||
240 | 1034 | vcaballero | xml.getDoubleProperty("extent" + i + "Y"), |
241 | xml.getDoubleProperty("extent" + i + "W"), |
||
242 | xml.getDoubleProperty("extent" + i + "H")); |
||
243 | } catch (Exception e) { |
||
244 | 1041 | vcaballero | ///System.out.println("En las ExtentHistory =" + e); //TODO o se captura de alguna forma o se mete un nuevo parametro en el xml para saber exactamente cuantos rect?gulos se han a?adido.
|
245 | 1034 | vcaballero | } |
246 | } |
||
247 | |||
248 | return eh;
|
||
249 | } |
||
250 | 213 | fernando | } |