svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / clip / ClipData.java @ 29717
History | View | Annotate | Download (7.63 KB)
1 | 22397 | nbrodin | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 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.rastertools.vectorizacion.clip; |
||
20 | |||
21 | import java.awt.geom.Point2D; |
||
22 | import java.util.Observable; |
||
23 | |||
24 | /**
|
||
25 | * Datos asociados a la interfaz de usuario CoordinatesSelectionPanel.
|
||
26 | *
|
||
27 | * 12/06/2008
|
||
28 | * @author Nacho Brodin nachobrodin@gmail.com
|
||
29 | */
|
||
30 | public class ClipData extends Observable { |
||
31 | /**
|
||
32 | * N?mero de decimales a mostrar en visualizaci?n
|
||
33 | */
|
||
34 | public static final int DEC = 4; |
||
35 | private String[] scales = {"1/4", "1/3", "1/2", "1", "2", "3", "4", "5"}; |
||
36 | private int scaleSelected = 3; |
||
37 | /**
|
||
38 | * Coordenadas reales y pixel
|
||
39 | */
|
||
40 | private Point2D ulWc = new Point2D.Double(); |
||
41 | private Point2D lrWc = new Point2D.Double(); |
||
42 | private Point2D ulPx = new Point2D.Double(); |
||
43 | private Point2D lrPx = new Point2D.Double(); |
||
44 | |||
45 | /**
|
||
46 | * Actualiza datos y llama al update de los observadores
|
||
47 | */
|
||
48 | public void updateObservers() { |
||
49 | setChanged(); |
||
50 | notifyObservers(); |
||
51 | } |
||
52 | |||
53 | /**
|
||
54 | * Obtiene las coordenadas del mundo real
|
||
55 | * @return double[]
|
||
56 | */
|
||
57 | public double[] getWCCoordinates() { |
||
58 | return new double[]{ulWc.getX(), ulWc.getY(), lrWc.getX(), lrWc.getY()}; |
||
59 | } |
||
60 | |||
61 | /**
|
||
62 | * Obtiene la coordenada de m?xima X en pixel.
|
||
63 | * @return Coordenada de m?xima X en pixel
|
||
64 | */
|
||
65 | public double getPxMaxX() { |
||
66 | return Math.max(ulPx.getX(), lrPx.getX()); |
||
67 | } |
||
68 | |||
69 | /**
|
||
70 | * Obtiene la coordenada de m?xima Y en pixel.
|
||
71 | * @return Coordenada de m?xima Y en pixel
|
||
72 | */
|
||
73 | public double getPxMaxY() { |
||
74 | return Math.max(ulPx.getY(), lrPx.getY()); |
||
75 | } |
||
76 | |||
77 | /**
|
||
78 | * Obtiene la coordenada de m?nima X en pixel.
|
||
79 | * @return Coordenada de m?nima X en pixel
|
||
80 | */
|
||
81 | public double getPxMinX() { |
||
82 | return Math.min(ulPx.getX(), lrPx.getX()); |
||
83 | } |
||
84 | |||
85 | /**
|
||
86 | * Obtiene la coordenada de m?nima Y en pixel.
|
||
87 | * @return Coordenada de m?nima Y en pixel
|
||
88 | */
|
||
89 | public double getPxMinY() { |
||
90 | return Math.min(ulPx.getY(), lrPx.getY()); |
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | * Obtiene la coordenada de m?xima X real.
|
||
95 | * @return Coordenada de m?xima X real.
|
||
96 | */
|
||
97 | public double getUlxWc() { |
||
98 | return ulWc.getX();
|
||
99 | } |
||
100 | |||
101 | /**
|
||
102 | * Obtiene la coordenada de m?xima Y real.
|
||
103 | * @return Coordenada de m?xima Y real
|
||
104 | */
|
||
105 | public double getUlyWc() { |
||
106 | return ulWc.getY();
|
||
107 | } |
||
108 | |||
109 | /**
|
||
110 | * Obtiene la coordenada de m?nima X real.
|
||
111 | * @return Coordenada de m?nima X real
|
||
112 | */
|
||
113 | public double getLrxWc() { |
||
114 | return lrWc.getX();
|
||
115 | } |
||
116 | |||
117 | /**
|
||
118 | * Obtiene la coordenada de m?nima Y real.
|
||
119 | * @return Coordenada de m?nima Y real
|
||
120 | */
|
||
121 | public double getLryWc() { |
||
122 | return lrWc.getY();
|
||
123 | } |
||
124 | |||
125 | /**
|
||
126 | * Obtiene la coordenada de m?xima X pixel
|
||
127 | * @return Coordenada de m?xima X pixel
|
||
128 | */
|
||
129 | public double getUlxPx() { |
||
130 | return ulPx.getX();
|
||
131 | } |
||
132 | |||
133 | /**
|
||
134 | * Obtiene la coordenada de m?xima Y pixel.
|
||
135 | * @return Coordenada de m?xima Y pixel
|
||
136 | */
|
||
137 | public double getUlyPx() { |
||
138 | return ulPx.getY();
|
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Obtiene la coordenada de m?nima X pixel
|
||
143 | * @return Coordenada de m?nima X pixel
|
||
144 | */
|
||
145 | public double getLrxPx() { |
||
146 | return lrPx.getX();
|
||
147 | } |
||
148 | |||
149 | /**
|
||
150 | * Obtiene la coordenada de m?nima Y pixel.
|
||
151 | * @return Coordenada de m?nima Y pixel
|
||
152 | */
|
||
153 | public double getLryPx() { |
||
154 | return lrPx.getY();
|
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | * Asigna las coordenadas del mundo real a partir de n?meros en coma flotante.
|
||
159 | * @param minx coordenada m?nima de X
|
||
160 | * @param miny coordenada m?nima de Y
|
||
161 | * @param maxx coordenada m?xima de X
|
||
162 | * @param maxy coordenada m?xima de Y
|
||
163 | * @param dec N?mero de decimales a mostrar en la caja de texto
|
||
164 | */
|
||
165 | public void setCoorRealFromDouble(double ulx, double uly, double lrx, double lry) { |
||
166 | ulWc = new Point2D.Double(ulx, uly); |
||
167 | lrWc = new Point2D.Double(lrx, lry); |
||
168 | updateObservers(); |
||
169 | } |
||
170 | |||
171 | /**
|
||
172 | * Asigna las coordenadas pixel a partir de n?meros en coma flotante.
|
||
173 | * @param minx coordenada m?nima de X
|
||
174 | * @param miny coordenada m?nima de Y
|
||
175 | * @param maxx coordenada m?xima de X
|
||
176 | * @param maxy coordenada m?xima de Y
|
||
177 | * @param dec N?mero de decimales a mostrar en la caja de texto
|
||
178 | */
|
||
179 | public void setCoorPixelFromDouble(double minx, double miny, double maxx, double maxy) { |
||
180 | ulPx = new Point2D.Double(minx, miny); |
||
181 | lrPx = new Point2D.Double(maxx, maxy); |
||
182 | updateObservers(); |
||
183 | } |
||
184 | |||
185 | /**
|
||
186 | * Asigna la coordenada X de la esquina superior izquierda en coordenadas reales
|
||
187 | * @param ulx
|
||
188 | */
|
||
189 | public void setUlxWc(double ulx) { |
||
190 | ulWc = new Point2D.Double(ulx, ulWc.getY()); |
||
191 | } |
||
192 | |||
193 | /**
|
||
194 | * Asigna la coordenada Y de la esquina superior izquierda en coordenadas reales
|
||
195 | * @param uly
|
||
196 | */
|
||
197 | public void setUlyWc(double uly) { |
||
198 | ulWc = new Point2D.Double(ulWc.getX(), uly); |
||
199 | } |
||
200 | |||
201 | /**
|
||
202 | * Asigna la coordenada X de la esquina superior izquierda en p?xeles
|
||
203 | * @param ulx
|
||
204 | */
|
||
205 | public void setUlxPx(double ulx) { |
||
206 | ulPx = new Point2D.Double(ulx, ulPx.getY()); |
||
207 | } |
||
208 | |||
209 | /**
|
||
210 | * Asigna la coordenada Y de la esquina superior izquierda en p?xeles
|
||
211 | * @param uly
|
||
212 | */
|
||
213 | public void setUlyPx(double uly) { |
||
214 | ulPx = new Point2D.Double(ulPx.getX(), uly); |
||
215 | } |
||
216 | |||
217 | /**
|
||
218 | * Asigna la coordenada X de la esquina inferior derecha en coordenadas reales
|
||
219 | * @param lrx
|
||
220 | */
|
||
221 | public void setLrxWc(double lrx) { |
||
222 | lrWc = new Point2D.Double(lrx, lrWc.getY()); |
||
223 | } |
||
224 | |||
225 | /**
|
||
226 | * Asigna la coordenada Y de la esquina inferior derecha en coordenadas reales
|
||
227 | * @param lry
|
||
228 | */
|
||
229 | public void setLryWc(double lry) { |
||
230 | lrWc = new Point2D.Double(lrWc.getX(), lry); |
||
231 | } |
||
232 | |||
233 | /**
|
||
234 | * Asigna la coordenada X de la esquina inferior derecha en p?xeles
|
||
235 | * @param ulx
|
||
236 | */
|
||
237 | public void setLrxPx(double lrx) { |
||
238 | lrPx = new Point2D.Double(lrx, lrPx.getY()); |
||
239 | } |
||
240 | |||
241 | /**
|
||
242 | * Asigna la coordenada Y de la esquina inferior derecha en p?xeles
|
||
243 | * @param uly
|
||
244 | */
|
||
245 | public void setLryPx(double lry) { |
||
246 | lrPx = new Point2D.Double(lrPx.getX(), lry); |
||
247 | } |
||
248 | |||
249 | /**
|
||
250 | * Inicializa los valores a cero. Esto se hace cuando la selecci?n es fuera del ?rea.
|
||
251 | */
|
||
252 | public void setOutOfArea() { |
||
253 | ulWc = new Point2D.Double(); |
||
254 | lrWc = new Point2D.Double(); |
||
255 | ulPx = new Point2D.Double(); |
||
256 | lrPx = new Point2D.Double(); |
||
257 | } |
||
258 | |||
259 | /**
|
||
260 | * Obtiene el texto del desplegable de escalas.
|
||
261 | * @return Lista de textos con las escalas
|
||
262 | */
|
||
263 | public String[] getScales() { |
||
264 | return scales;
|
||
265 | } |
||
266 | |||
267 | /**
|
||
268 | * Asigna el texto del desplegable de escalas.
|
||
269 | * @param Lista de textos con las escalas
|
||
270 | */
|
||
271 | public void setScales(String[] scales) { |
||
272 | this.scales = scales;
|
||
273 | updateObservers(); |
||
274 | } |
||
275 | |||
276 | /**
|
||
277 | * Obtiene la escala seleccionada en el selector
|
||
278 | * @return posici?n en la lista de escalas
|
||
279 | */
|
||
280 | public int getScaleSelected() { |
||
281 | return scaleSelected;
|
||
282 | } |
||
283 | |||
284 | /**
|
||
285 | * Asigna la escala seleccionada
|
||
286 | * @param posici?n en la lista de escalas
|
||
287 | */
|
||
288 | public void setScaleSelected(int scaleSelected) { |
||
289 | this.scaleSelected = scaleSelected;
|
||
290 | } |
||
291 | |||
292 | /**
|
||
293 | * Obtiene el valor de escala a partir de la posici?n
|
||
294 | * seleccionada en la lista.
|
||
295 | * @return
|
||
296 | */
|
||
297 | public double getScaleSelectedValue() { |
||
298 | switch (getScaleSelected()) {
|
||
299 | case 0: return 0.25; |
||
300 | case 1: return 0.33; |
||
301 | case 2: return 0.5; |
||
302 | case 3: return 1; |
||
303 | case 4: return 2; |
||
304 | case 5: return 3; |
||
305 | case 6: return 4; |
||
306 | case 7: return 5; |
||
307 | } |
||
308 | return 1; |
||
309 | } |
||
310 | } |