Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / ExtentHistory.java @ 1100

History | View | Annotate | Download (4.63 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.Double[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 (ext instanceof Rectangle) {
85
                                //Esto solo hace falta cuando se pasa como par?metro el fullextent del DGN.
86
                                ext = new Rectangle2D.Double(ext.getX(), ext.getY(),
87
                                                ext.getWidth(), ext.getHeight());
88
                        }
89

    
90
                        if (num < (NUMREC)) {
91
                                extents[num] = ext;
92
                                num = num + 1;
93
                        } else {
94
                                for (int i = 0; i < (NUMREC - 1); i++) {
95
                                        extents[i] = extents[i + 1];
96
                                }
97

    
98
                                extents[num - 1] = ext;
99
                        }
100
                }
101
        }
102

    
103
        /**
104
         * Devuelve true si hay alg?n rect?ngulo en el hist?rico
105
         *
106
         * @return true o false en caso de que haya o no haya rect?ngulos
107
         */
108
        public boolean hasPrevious() {
109
                return num > 0;
110
        }
111

    
112
        /**
113
         * Obtiene el ?ltimo rect?ngulo que se a?adi? al hist?rico
114
         *
115
         * @return Ultimo rect?ngulo a?adido
116
         */
117
        public Rectangle2D get() {
118
                Rectangle2D ext = extents[num - 1];
119

    
120
                return ext;
121
        }
122

    
123
        /**
124
         * Devuelve el ?ltimo rect?ngulo del hist?rico y lo elimina del mismo
125
         *
126
         * @return Ultimo rect?ngulo a?adido
127
         */
128
        public Rectangle2D removePrev() {
129
                Rectangle2D ext = extents[num - 1];
130
                num = num - 1;
131

    
132
                return ext;
133
        }
134

    
135
        /**
136
         * Devuelve el XMLEntity con la informaci?n para poder reproducir de nuevo
137
         * el objeto actual.
138
         *
139
         * @return XMLEntity.
140
         */
141
        public XMLEntity getXMLEntity() {
142
                XMLEntity xml = new XMLEntity();
143
                xml.putProperty("className",this.getClass().getName());
144
                xml.putProperty("num", num);
145
                xml.putProperty("numrec", NUMREC);
146

    
147
                for (int i = 0; i < NUMREC; i++) {
148
                        if (extents[i] != null) {
149
                                xml.putProperty("extent" + i + "X", extents[i].getX());
150
                                xml.putProperty("extent" + i + "Y", extents[i].getY());
151
                                xml.putProperty("extent" + i + "W", extents[i].getWidth());
152
                                xml.putProperty("extent" + i + "H", extents[i].getHeight());
153
                        }
154
                }
155

    
156
                return xml;
157
        }
158

    
159
        /**
160
         * Crea un nuevo ExtentHistory a partir del XMLEntity.
161
         *
162
         * @param xml XMLEntity
163
         *
164
         * @return Nuevo ExtentHistory.
165
         */
166
        public static ExtentHistory createFromXML(XMLEntity xml) {
167
                ExtentHistory eh = new ExtentHistory();
168
                eh.num = xml.getIntProperty("num");
169
                eh.NUMREC = xml.getIntProperty("numrec");
170

    
171
                for (int i = 0; i < eh.NUMREC; i++) {
172
                        try {
173
                                eh.extents[i] = new Rectangle2D.Double(xml.getDoubleProperty(
174
                                                        "extent" + i + "X"),
175
                                                xml.getDoubleProperty("extent" + i + "Y"),
176
                                                xml.getDoubleProperty("extent" + i + "W"),
177
                                                xml.getDoubleProperty("extent" + i + "H"));
178
                        } catch (Exception e) {
179
                                ///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.
180
                        }
181
                }
182

    
183
                return eh;
184
        }
185
}