Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.utils / src / main / java / org / gvsig / utils / ExtentsHistory.java @ 40561

History | View | Annotate | Download (4.13 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.utils;
25

    
26
import java.awt.geom.Rectangle2D;
27

    
28

    
29
/**
30
 * Clase que representa un array circular de rect?ngulos
31
 *
32
 * @author Fernando Gonz?lez Cort?s
33
 */
34
public class ExtentsHistory {
35
    private int NUMREC;
36
    private Rectangle2D.Double[] extents;
37
    private int num = 0;
38

    
39
    /**
40
     * Creates a new ExtentsHistory object.
41
     */
42
    public ExtentsHistory() {
43
        NUMREC = 4;
44
        extents = new Rectangle2D.Double[NUMREC];
45
    }
46

    
47
    /**
48
     * Creates a new ExtentsHistory object.
49
     *
50
     * @param numEntries Numero de entradas que se guardan en el historico de
51
     *        rect?ngulos, por defecto 20
52
     */
53
    public ExtentsHistory(int numEntries) {
54
        NUMREC = numEntries;
55
    }
56

    
57
    /**
58
     * Pone un nuevo rect?ngulo al final del array
59
     *
60
     * @param ext Rect?ngulo que se a?ade al hist?rico
61
     */
62
    public void put(Rectangle2D.Double ext) {
63
        if ((ext != null) && ((num < 1) || (ext != extents[num - 1]))) {
64
            if (num < (NUMREC)) {
65
                extents[num] = ext;
66
                num = num + 1;
67
            } else {
68
                for (int i = 0; i < (NUMREC - 1); i++) {
69
                    extents[i] = extents[i + 1];
70
                }
71

    
72
                extents[num - 1] = ext;
73
            }
74
        }
75
    }
76

    
77
    /**
78
     * Devuelve true si hay alg?n rect?ngulo en el hist?rico
79
     *
80
     * @return true o false en caso de que haya o no haya rect?ngulos
81
     */
82
    public boolean hasPrevious() {
83
        return num > 0;
84
    }
85

    
86
    /**
87
     * Obtiene el ?ltimo rect?ngulo que se a?adi? al hist?rico
88
     *
89
     * @return Ultimo rect?ngulo a?adido
90
     */
91
    public Rectangle2D.Double get() {
92
        Rectangle2D.Double ext = extents[num - 1];
93

    
94
        return ext;
95
    }
96

    
97
    /**
98
     * Devuelve el ?ltimo rect?ngulo del hist?rico y lo elimina del mismo
99
     *
100
     * @return Ultimo rect?ngulo a?adido
101
     */
102
    public Rectangle2D.Double removePrev() {
103
        Rectangle2D.Double ext = extents[num - 1];
104
        num = num - 1;
105

    
106
        return ext;
107
    }
108
}
109

    
110
/*
111
   public class Extents{
112
           private final int NUMREC=20;
113
           private Rectangle2D.Double[] extents;
114
           private int num=0;
115
           public Extents(){
116
             extents = new Rectangle2D.Double[NUMREC];
117
           }
118
           public void put (Rectangle2D.Double ext){
119
           if((ext!=null)&&((num<1)||(ext!=extents[num-1]))){
120
            if (num<(NUMREC)){
121
             extents[num]=ext;
122
             num=num+1;
123
            }else{
124
                    for (int i=0;i<(NUMREC-1);i++){
125
                            extents[i]=extents[i+1];
126
                    }
127
                    extents[num-1]=ext;
128
            }
129
           }
130
           }
131

132
           public Rectangle2D.Double get(){
133
                   if(num>1){
134
                   Rectangle2D.Double ext = extents[num-2];
135
                     return ext;
136
                   }
137

138
             return null;
139
           }
140
           public Rectangle2D.Double getPrev(){
141
                           if(num>1){
142
                           Rectangle2D.Double ext = extents[num-2];
143
                           num=num-1;
144
                           return ext;
145
                           }
146

147
                     return null;
148
                   }
149
     }
150
 */