Statistics
| Revision:

svn-gvsig-desktop / tags / v1_1_Build_1008 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / ExtentHistory.java @ 12520

History | View | Annotate | Download (5.23 KB)

1
/* 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.fmap;
42

    
43
import com.iver.utiles.XMLEntity;
44

    
45
import java.awt.Rectangle;
46
import java.awt.geom.Rectangle2D;
47

    
48

    
49
/**
50
 * Clase que gestiona los diferentes extent por los que ha pasado la vista.
51
 *
52
 * @author Vicente Caballero Navarro
53
 */
54
public class ExtentHistory {
55
        private int NUMREC;
56
        private Rectangle2D[] extents;
57
        private int num = 0;
58

    
59
        /**
60
         * Creates a new ExtentsHistory object.
61
         */
62
        public ExtentHistory() {
63
                NUMREC = 10;
64
                extents = new Rectangle2D[NUMREC];
65
        }
66

    
67
        /**
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

    
77
        /**
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

    
92
                                extents[num - 1] = ext;
93
                        }
94
                }
95
        }
96

    
97
        /**
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

    
106
        /**
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

    
114
                return ext;
115
        }
116

    
117
        /**
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
                Rectangle2D ext = extents[--num];
124
                return ext;
125
        }
126

    
127
        /**
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
                xml.putProperty("className",this.getClass().getName());
136
                xml.putProperty("num", num);
137
                xml.putProperty("numrec", NUMREC);
138

    
139
                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

    
148
                return xml;
149
        }
150

    
151
        /**
152
         * Crea un nuevo ExtentHistory a partir del XMLEntity.
153
         *
154
         * @param xml XMLEntity
155
         *
156
         * @return Nuevo ExtentHistory.
157
         */
158
        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
        public static ExtentHistory createFromXML(XMLEntity xml) {
186
                ExtentHistory eh = new ExtentHistory();
187
                eh.num = xml.getIntProperty("num");
188
                eh.NUMREC = xml.getIntProperty("numrec");
189

    
190
                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
                                ///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
                        }
200
                }
201

    
202
                return eh;
203
        }
204
}