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