Statistics
| Revision:

root / trunk / libraries / libIverUtiles / src / com / iver / utiles / ExtentsHistory.java @ 8106

History | View | Annotate | Download (4.38 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.utiles;
42

    
43
import java.awt.geom.Rectangle2D;
44

    
45

    
46
/**
47
 * Clase que representa un array circular de rect?ngulos
48
 *
49
 * @author Fernando Gonz?lez Cort?s
50
 */
51
public class ExtentsHistory {
52
    private int NUMREC;
53
    private Rectangle2D.Double[] extents;
54
    private int num = 0;
55

    
56
    /**
57
     * Creates a new ExtentsHistory object.
58
     */
59
    public ExtentsHistory() {
60
        NUMREC = 4;
61
        extents = new Rectangle2D.Double[NUMREC];
62
    }
63

    
64
    /**
65
     * Creates a new ExtentsHistory object.
66
     *
67
     * @param numEntries Numero de entradas que se guardan en el historico de
68
     *        rect?ngulos, por defecto 20
69
     */
70
    public ExtentsHistory(int numEntries) {
71
        NUMREC = numEntries;
72
    }
73

    
74
    /**
75
     * Pone un nuevo rect?ngulo al final del array
76
     *
77
     * @param ext Rect?ngulo que se a?ade al hist?rico
78
     */
79
    public void put(Rectangle2D.Double ext) {
80
        if ((ext != null) && ((num < 1) || (ext != extents[num - 1]))) {
81
            if (num < (NUMREC)) {
82
                extents[num] = ext;
83
                num = num + 1;
84
            } else {
85
                for (int i = 0; i < (NUMREC - 1); i++) {
86
                    extents[i] = extents[i + 1];
87
                }
88

    
89
                extents[num - 1] = ext;
90
            }
91
        }
92
    }
93

    
94
    /**
95
     * Devuelve true si hay alg?n rect?ngulo en el hist?rico
96
     *
97
     * @return true o false en caso de que haya o no haya rect?ngulos
98
     */
99
    public boolean hasPrevious() {
100
        return num > 0;
101
    }
102

    
103
    /**
104
     * Obtiene el ?ltimo rect?ngulo que se a?adi? al hist?rico
105
     *
106
     * @return Ultimo rect?ngulo a?adido
107
     */
108
    public Rectangle2D.Double get() {
109
        Rectangle2D.Double ext = extents[num - 1];
110

    
111
        return ext;
112
    }
113

    
114
    /**
115
     * Devuelve el ?ltimo rect?ngulo del hist?rico y lo elimina del mismo
116
     *
117
     * @return Ultimo rect?ngulo a?adido
118
     */
119
    public Rectangle2D.Double removePrev() {
120
        Rectangle2D.Double ext = extents[num - 1];
121
        num = num - 1;
122

    
123
        return ext;
124
    }
125
}
126

    
127
/*
128
   public class Extents{
129
           private final int NUMREC=20;
130
           private Rectangle2D.Double[] extents;
131
           private int num=0;
132
           public Extents(){
133
             extents = new Rectangle2D.Double[NUMREC];
134
           }
135
           public void put (Rectangle2D.Double ext){
136
           if((ext!=null)&&((num<1)||(ext!=extents[num-1]))){
137
            if (num<(NUMREC)){
138
             extents[num]=ext;
139
             num=num+1;
140
            }else{
141
                    for (int i=0;i<(NUMREC-1);i++){
142
                            extents[i]=extents[i+1];
143
                    }
144
                    extents[num-1]=ext;
145
            }
146
           }
147
           }
148

149
           public Rectangle2D.Double get(){
150
                   if(num>1){
151
                   Rectangle2D.Double ext = extents[num-2];
152
                     return ext;
153
                   }
154

155
             return null;
156
           }
157
           public Rectangle2D.Double getPrev(){
158
                           if(num>1){
159
                           Rectangle2D.Double ext = extents[num-2];
160
                           num=num-1;
161
                           return ext;
162
                           }
163

164
                     return null;
165
                   }
166
     }
167
 */