svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / utils / StackZoom.java @ 5697
History | View | Annotate | Download (4.67 KB)
1 |
/*
|
---|---|
2 |
* Created on 20-sep-2005
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package org.gvsig.georeferencing.utils; |
48 |
|
49 |
import java.util.ArrayList; |
50 |
|
51 |
import org.cresques.px.Extent; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.layers.IStackZoom; |
54 |
|
55 |
/**
|
56 |
* Clase para almacenar los extents que se van seleccionando al manipular
|
57 |
* una imagen para su georreferenciaci?n. Esto permite recuperar extents anteriores.
|
58 |
*
|
59 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
60 |
*/
|
61 |
public class StackZoom implements IStackZoom{ |
62 |
|
63 |
//**********************Vars****************************************
|
64 |
/**
|
65 |
* N?mero m?ximo de elementos en la pila
|
66 |
*/
|
67 |
private static final int MAX = 10; |
68 |
private ArrayList extentList = new ArrayList(); |
69 |
private Extent initExtent = null; |
70 |
private int selectElem = -1; |
71 |
private int top = -1; |
72 |
//**********************End Vars************************************
|
73 |
|
74 |
//**********************Methods*************************************
|
75 |
public StackZoom(){}
|
76 |
|
77 |
/**
|
78 |
* Vacia la pila de Extents
|
79 |
*/
|
80 |
public void clear(){ |
81 |
extentList.clear(); |
82 |
selectElem = 0;
|
83 |
} |
84 |
//**********************End Methods**********************************
|
85 |
|
86 |
//**********************Setters & Getters****************************
|
87 |
/**
|
88 |
* A?ade un extent a la lista
|
89 |
* @param ext
|
90 |
*/
|
91 |
public void setZoom(Extent ext){ |
92 |
if(selectElem < (MAX - 1)){ |
93 |
if(selectElem == top)
|
94 |
top++; |
95 |
else
|
96 |
top = selectElem + 1;
|
97 |
selectElem ++; |
98 |
extentList.add(selectElem, ext); |
99 |
} |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Recupera el ?ltimo extent aplicado.
|
104 |
* <P>Si la pila est? vacia o est? situada en el primer
|
105 |
* elemento devuelve null sino devuelve el Extent guardado anterior al actual.</P>
|
106 |
* @return Extent anterior.
|
107 |
*/
|
108 |
public Extent getLastZoom(){
|
109 |
if(extentList.size() == 0) |
110 |
return null; |
111 |
|
112 |
if(selectElem == -1) |
113 |
return null; |
114 |
|
115 |
selectElem --; |
116 |
|
117 |
Extent ex = null;
|
118 |
try{
|
119 |
ex = (Extent)extentList.get(selectElem); |
120 |
}catch (ArrayIndexOutOfBoundsException exc){ |
121 |
//Elemento recuperado valdr? null y colocamos el puntero en el primer elemento
|
122 |
selectElem = 0;
|
123 |
System.err.println("Zoom Stack Empty"); |
124 |
} |
125 |
|
126 |
return ex;
|
127 |
} |
128 |
|
129 |
/**
|
130 |
* Recupera el siguiente zoom. Se usa cuando se ha recuperado el ?ltimo
|
131 |
* zoom y se quiere volver al siguiente.
|
132 |
* <P>Si estamos en el tope de la pila o hemos llegado a su m?xima capacidad o no tiene
|
133 |
* elementos devuelve null sino devuelve el siguiente</P>
|
134 |
*
|
135 |
* @return
|
136 |
*/
|
137 |
public Extent getNextZoom(){
|
138 |
if( selectElem == (MAX -1) || |
139 |
selectElem == top || |
140 |
extentList.size() == 0 )
|
141 |
return null; |
142 |
|
143 |
selectElem ++; |
144 |
|
145 |
Extent ex = null;
|
146 |
try{
|
147 |
ex = (Extent)extentList.get(selectElem); |
148 |
}catch (ArrayIndexOutOfBoundsException exc){ |
149 |
//No hacemos nada y el elemento recuperado valdr? null
|
150 |
System.err.println("Zoom Stack On Top"); |
151 |
} |
152 |
return ex;
|
153 |
} |
154 |
|
155 |
/**
|
156 |
* @return Returns the initExtent.
|
157 |
*/
|
158 |
public Extent getInitExtent() {
|
159 |
return initExtent;
|
160 |
} |
161 |
|
162 |
/**
|
163 |
* @param initExtent The initExtent to set.
|
164 |
*/
|
165 |
public void setInitExtent(Extent initExtent, boolean incr) { |
166 |
if(incr)
|
167 |
selectElem ++; |
168 |
extentList.add(0, initExtent);
|
169 |
this.initExtent = initExtent;
|
170 |
} |
171 |
|
172 |
/**
|
173 |
* Obtiene el apuntador a elementos
|
174 |
* @return
|
175 |
*/
|
176 |
public int getSelectElem() { |
177 |
return selectElem;
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Obtiene el n?mero de elementos de la pila
|
182 |
* @return N?mero de elementos de la pila
|
183 |
*/
|
184 |
public int getStackSize(){ |
185 |
return top;
|
186 |
} |
187 |
//**********************End Setters & Getters************************
|
188 |
} |