root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / ExtentHistory.java @ 11140
History | View | Annotate | Download (5.2 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 | import java.awt.geom.Rectangle2D; |
||
44 | |||
45 | 10627 | caballero | import com.iver.utiles.XMLEntity; |
46 | 449 | vcaballero | |
47 | 10627 | caballero | |
48 | 485 | vcaballero | /**
|
49 | 1034 | vcaballero | * Clase que gestiona los diferentes extent por los que ha pasado la vista.
|
50 | 485 | vcaballero | *
|
51 | * @author Vicente Caballero Navarro
|
||
52 | */
|
||
53 | 213 | fernando | public class ExtentHistory { |
54 | 1034 | vcaballero | private int NUMREC; |
55 | private Rectangle2D[] extents; |
||
56 | private int num = 0; |
||
57 | 213 | fernando | |
58 | 1034 | vcaballero | /**
|
59 | * Creates a new ExtentsHistory object.
|
||
60 | */
|
||
61 | public ExtentHistory() {
|
||
62 | NUMREC = 10;
|
||
63 | 1326 | fernando | extents = new Rectangle2D[NUMREC]; |
64 | 1034 | vcaballero | } |
65 | 213 | fernando | |
66 | 1034 | vcaballero | /**
|
67 | * Creates a new ExtentsHistory object.
|
||
68 | *
|
||
69 | * @param numEntries Numero de entradas que se guardan en el historico de
|
||
70 | * rect?ngulos, por defecto 20
|
||
71 | */
|
||
72 | public ExtentHistory(int numEntries) { |
||
73 | NUMREC = numEntries; |
||
74 | } |
||
75 | 213 | fernando | |
76 | 1034 | vcaballero | /**
|
77 | * Pone un nuevo rect?ngulo al final del array
|
||
78 | *
|
||
79 | * @param ext Rect?ngulo que se a?ade al hist?rico
|
||
80 | */
|
||
81 | public void put(Rectangle2D ext) { |
||
82 | if ((ext != null) && ((num < 1) || (ext != extents[num - 1]))) { |
||
83 | if (num < (NUMREC)) {
|
||
84 | extents[num] = ext; |
||
85 | num = num + 1;
|
||
86 | } else {
|
||
87 | for (int i = 0; i < (NUMREC - 1); i++) { |
||
88 | extents[i] = extents[i + 1];
|
||
89 | } |
||
90 | 213 | fernando | |
91 | 1034 | vcaballero | extents[num - 1] = ext;
|
92 | } |
||
93 | } |
||
94 | } |
||
95 | 213 | fernando | |
96 | 1034 | vcaballero | /**
|
97 | * Devuelve true si hay alg?n rect?ngulo en el hist?rico
|
||
98 | *
|
||
99 | * @return true o false en caso de que haya o no haya rect?ngulos
|
||
100 | */
|
||
101 | public boolean hasPrevious() { |
||
102 | return num > 0; |
||
103 | } |
||
104 | 213 | fernando | |
105 | 1034 | vcaballero | /**
|
106 | * Obtiene el ?ltimo rect?ngulo que se a?adi? al hist?rico
|
||
107 | *
|
||
108 | * @return Ultimo rect?ngulo a?adido
|
||
109 | */
|
||
110 | public Rectangle2D get() { |
||
111 | Rectangle2D ext = extents[num - 1]; |
||
112 | 213 | fernando | |
113 | 1034 | vcaballero | return ext;
|
114 | } |
||
115 | 213 | fernando | |
116 | 1034 | vcaballero | /**
|
117 | * Devuelve el ?ltimo rect?ngulo del hist?rico y lo elimina del mismo
|
||
118 | *
|
||
119 | * @return Ultimo rect?ngulo a?adido
|
||
120 | */
|
||
121 | public Rectangle2D removePrev() { |
||
122 | 7625 | jaume | Rectangle2D ext = extents[--num];
|
123 | 1034 | vcaballero | return ext;
|
124 | } |
||
125 | 485 | vcaballero | |
126 | 1034 | vcaballero | /**
|
127 | * Devuelve el XMLEntity con la informaci?n para poder reproducir de nuevo
|
||
128 | * el objeto actual.
|
||
129 | *
|
||
130 | * @return XMLEntity.
|
||
131 | */
|
||
132 | public XMLEntity getXMLEntity() {
|
||
133 | XMLEntity xml = new XMLEntity();
|
||
134 | 1094 | vcaballero | xml.putProperty("className",this.getClass().getName()); |
135 | 1034 | vcaballero | xml.putProperty("num", num);
|
136 | xml.putProperty("numrec", NUMREC);
|
||
137 | 485 | vcaballero | |
138 | 1034 | vcaballero | for (int i = 0; i < NUMREC; i++) { |
139 | if (extents[i] != null) { |
||
140 | xml.putProperty("extent" + i + "X", extents[i].getX()); |
||
141 | xml.putProperty("extent" + i + "Y", extents[i].getY()); |
||
142 | xml.putProperty("extent" + i + "W", extents[i].getWidth()); |
||
143 | xml.putProperty("extent" + i + "H", extents[i].getHeight()); |
||
144 | } |
||
145 | } |
||
146 | 485 | vcaballero | |
147 | 1034 | vcaballero | return xml;
|
148 | } |
||
149 | 485 | vcaballero | |
150 | 1034 | vcaballero | /**
|
151 | * Crea un nuevo ExtentHistory a partir del XMLEntity.
|
||
152 | *
|
||
153 | * @param xml XMLEntity
|
||
154 | *
|
||
155 | * @return Nuevo ExtentHistory.
|
||
156 | */
|
||
157 | 2183 | fernando | public static ExtentHistory createFromXML03(XMLEntity xml) { |
158 | ExtentHistory eh = new ExtentHistory();
|
||
159 | eh.num = xml.getIntProperty("num");
|
||
160 | eh.NUMREC = xml.getIntProperty("numrec");
|
||
161 | |||
162 | for (int i = 0; i < eh.NUMREC; i++) { |
||
163 | try {
|
||
164 | eh.extents[i] = new Rectangle2D.Double(xml.getDoubleProperty( |
||
165 | "extent" + i + "X"), |
||
166 | xml.getDoubleProperty("extent" + i + "Y"), |
||
167 | xml.getDoubleProperty("extent" + i + "W"), |
||
168 | xml.getDoubleProperty("extent" + i + "H")); |
||
169 | } catch (Exception e) { |
||
170 | ///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.
|
||
171 | } |
||
172 | } |
||
173 | |||
174 | return eh;
|
||
175 | } |
||
176 | |||
177 | /**
|
||
178 | * Crea un nuevo ExtentHistory a partir del XMLEntity.
|
||
179 | *
|
||
180 | * @param xml XMLEntity
|
||
181 | *
|
||
182 | * @return Nuevo ExtentHistory.
|
||
183 | */
|
||
184 | 1034 | vcaballero | public static ExtentHistory createFromXML(XMLEntity xml) { |
185 | ExtentHistory eh = new ExtentHistory();
|
||
186 | eh.num = xml.getIntProperty("num");
|
||
187 | eh.NUMREC = xml.getIntProperty("numrec");
|
||
188 | 485 | vcaballero | |
189 | 1034 | vcaballero | for (int i = 0; i < eh.NUMREC; i++) { |
190 | try {
|
||
191 | eh.extents[i] = new Rectangle2D.Double(xml.getDoubleProperty( |
||
192 | "extent" + i + "X"), |
||
193 | xml.getDoubleProperty("extent" + i + "Y"), |
||
194 | xml.getDoubleProperty("extent" + i + "W"), |
||
195 | xml.getDoubleProperty("extent" + i + "H")); |
||
196 | } catch (Exception e) { |
||
197 | 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.
|
198 | 1034 | vcaballero | } |
199 | } |
||
200 | |||
201 | return eh;
|
||
202 | } |
||
203 | 213 | fernando | } |