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