root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / utils / StackZoom.java @ 12546
History | View | Annotate | Download (4.16 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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 |
package org.gvsig.georeferencing.utils; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
import org.gvsig.raster.datastruct.Extent; |
23 |
import com.iver.cit.gvsig.fmap.layers.IStackZoom; |
24 |
|
25 |
/**
|
26 |
* Clase para almacenar los extents que se van seleccionando al manipular
|
27 |
* una imagen para su georreferenciaci?n. Esto permite recuperar extents anteriores.
|
28 |
*
|
29 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
30 |
*/
|
31 |
public class StackZoom implements IStackZoom{ |
32 |
|
33 |
//**********************Vars****************************************
|
34 |
/**
|
35 |
* N?mero m?ximo de elementos en la pila
|
36 |
*/
|
37 |
private static final int MAX = 10; |
38 |
private ArrayList extentList = new ArrayList(); |
39 |
private Extent initExtent = null; |
40 |
private int selectElem = -1; |
41 |
private int top = -1; |
42 |
//**********************End Vars************************************
|
43 |
|
44 |
//**********************Methods*************************************
|
45 |
public StackZoom(){}
|
46 |
|
47 |
/**
|
48 |
* Vacia la pila de Extents
|
49 |
*/
|
50 |
public void clear(){ |
51 |
extentList.clear(); |
52 |
selectElem = 0;
|
53 |
} |
54 |
//**********************End Methods**********************************
|
55 |
|
56 |
//**********************Setters & Getters****************************
|
57 |
/**
|
58 |
* A?ade un extent a la lista
|
59 |
* @param ext
|
60 |
*/
|
61 |
public void setZoom(Extent ext){ |
62 |
if(selectElem < (MAX - 1)){ |
63 |
if(selectElem == top)
|
64 |
top++; |
65 |
else
|
66 |
top = selectElem + 1;
|
67 |
selectElem ++; |
68 |
extentList.add(selectElem, ext); |
69 |
} |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Recupera el ?ltimo extent aplicado.
|
74 |
* <P>Si la pila est? vacia o est? situada en el primer
|
75 |
* elemento devuelve null sino devuelve el Extent guardado anterior al actual.</P>
|
76 |
* @return Extent anterior.
|
77 |
*/
|
78 |
public Extent getLastZoom(){
|
79 |
if(extentList.size() == 0) |
80 |
return null; |
81 |
|
82 |
if(selectElem == -1) |
83 |
return null; |
84 |
|
85 |
selectElem --; |
86 |
|
87 |
Extent ex = null;
|
88 |
try{
|
89 |
ex = (Extent)extentList.get(selectElem); |
90 |
}catch (ArrayIndexOutOfBoundsException exc){ |
91 |
//Elemento recuperado valdr? null y colocamos el puntero en el primer elemento
|
92 |
selectElem = 0;
|
93 |
System.err.println("Zoom Stack Empty"); |
94 |
} |
95 |
|
96 |
return ex;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Recupera el siguiente zoom. Se usa cuando se ha recuperado el ?ltimo
|
101 |
* zoom y se quiere volver al siguiente.
|
102 |
* <P>Si estamos en el tope de la pila o hemos llegado a su m?xima capacidad o no tiene
|
103 |
* elementos devuelve null sino devuelve el siguiente</P>
|
104 |
*
|
105 |
* @return
|
106 |
*/
|
107 |
public Extent getNextZoom(){
|
108 |
if( selectElem == (MAX -1) || |
109 |
selectElem == top || |
110 |
extentList.size() == 0 )
|
111 |
return null; |
112 |
|
113 |
selectElem ++; |
114 |
|
115 |
Extent ex = null;
|
116 |
try{
|
117 |
ex = (Extent)extentList.get(selectElem); |
118 |
}catch (ArrayIndexOutOfBoundsException exc){ |
119 |
//No hacemos nada y el elemento recuperado valdr? null
|
120 |
System.err.println("Zoom Stack On Top"); |
121 |
} |
122 |
return ex;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* @return Returns the initExtent.
|
127 |
*/
|
128 |
public Extent getInitExtent() {
|
129 |
return initExtent;
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* @param initExtent The initExtent to set.
|
134 |
*/
|
135 |
public void setInitExtent(Extent initExtent, boolean incr) { |
136 |
if(incr)
|
137 |
selectElem ++; |
138 |
extentList.add(0, initExtent);
|
139 |
this.initExtent = initExtent;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Obtiene el apuntador a elementos
|
144 |
* @return
|
145 |
*/
|
146 |
public int getSelectElem() { |
147 |
return selectElem;
|
148 |
} |
149 |
|
150 |
/**
|
151 |
* Obtiene el n?mero de elementos de la pila
|
152 |
* @return N?mero de elementos de la pila
|
153 |
*/
|
154 |
public int getStackSize(){ |
155 |
return top;
|
156 |
} |
157 |
//**********************End Setters & Getters************************
|
158 |
} |