svn-gvsig-desktop / tags / Root_v061 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutZooms.java @ 4812
History | View | Annotate | Download (12.1 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 17-sep-2004
|
||
3 | *
|
||
4 | */
|
||
5 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
6 | *
|
||
7 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
8 | *
|
||
9 | * This program is free software; you can redistribute it and/or
|
||
10 | * modify it under the terms of the GNU General Public License
|
||
11 | * as published by the Free Software Foundation; either version 2
|
||
12 | * of the License, or (at your option) any later version.
|
||
13 | *
|
||
14 | * This program is distributed in the hope that it will be useful,
|
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
17 | * GNU General Public License for more details.
|
||
18 | *
|
||
19 | * You should have received a copy of the GNU General Public License
|
||
20 | * along with this program; if not, write to the Free Software
|
||
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
22 | *
|
||
23 | * For more information, contact:
|
||
24 | *
|
||
25 | * Generalitat Valenciana
|
||
26 | * Conselleria d'Infraestructures i Transport
|
||
27 | * Av. Blasco Ib??ez, 50
|
||
28 | * 46010 VALENCIA
|
||
29 | * SPAIN
|
||
30 | *
|
||
31 | * +34 963862235
|
||
32 | * gvsig@gva.es
|
||
33 | * www.gvsig.gva.es
|
||
34 | *
|
||
35 | * or
|
||
36 | *
|
||
37 | * IVER T.I. S.A
|
||
38 | * Salamanca 50
|
||
39 | * 46005 Valencia
|
||
40 | * Spain
|
||
41 | *
|
||
42 | * +34 963163400
|
||
43 | * dac@iver.es
|
||
44 | */
|
||
45 | 312 | fernando | package com.iver.cit.gvsig.gui.layout; |
46 | |||
47 | import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
||
48 | import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
||
49 | |||
50 | import java.awt.Point; |
||
51 | import java.awt.Toolkit; |
||
52 | import java.awt.geom.Point2D; |
||
53 | import java.awt.geom.Rectangle2D; |
||
54 | |||
55 | |||
56 | /**
|
||
57 | * Clase contenedora de los m?todos para cambiar los zooms.
|
||
58 | *
|
||
59 | * @author Vicente Caballero Navarro
|
||
60 | */
|
||
61 | public class FLayoutZooms { |
||
62 | 1074 | vcaballero | private Layout layout = null; |
63 | 4452 | caballero | private FLayoutFunctions functions = null; |
64 | 312 | fernando | |
65 | 1074 | vcaballero | /**
|
66 | * Crea un nuevo Zooms.
|
||
67 | *
|
||
68 | * @param l Mapa sobre el que se actua.
|
||
69 | */
|
||
70 | public FLayoutZooms(Layout l) {
|
||
71 | layout = l; |
||
72 | 4452 | caballero | functions = new FLayoutFunctions(layout);
|
73 | 1074 | vcaballero | } |
74 | 312 | fernando | |
75 | 1074 | vcaballero | /**
|
76 | * Realiza un zoom por rect?ngulo o por punto con un escalado por defecto
|
||
77 | * sobre el Layout que se le pasa como par?metro.
|
||
78 | *
|
||
79 | * @param p1 punto de inicio del rect?ngulo.
|
||
80 | * @param p2 punto final del rec?ngulo.
|
||
81 | */
|
||
82 | public void setZoomIn(Point p1, Point p2) { |
||
83 | 4452 | caballero | /*if (p1.y != p2.y) {
|
84 | double points = (p2.getX() - p1.getX()) / (p2.getY() - p1.getY());
|
||
85 | double window = (double) layout.getWidth() / (double)layout.getHeight();
|
||
86 | |||
87 | if (points < window) {
|
||
88 | p2.x = (int) (p1.x + ((p2.x - p1.x) * window));
|
||
89 | }
|
||
90 | }
|
||
91 | */
|
||
92 | |||
93 | 3121 | caballero | if (p1.getX()>p2.getX()){
|
94 | int aux=p2.x;
|
||
95 | p2.x=p1.x; |
||
96 | p1.x=aux; |
||
97 | } |
||
98 | if (p1.getY()>p2.getY()){
|
||
99 | int aux=p2.y;
|
||
100 | p2.y=p1.y; |
||
101 | p1.y=aux; |
||
102 | } |
||
103 | 1074 | vcaballero | Point2D.Double pSheet1 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
104 | p1.getX(), p1.getY()), layout.getAT()); |
||
105 | Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
||
106 | p2.getX(), p2.getY()), layout.getAT()); |
||
107 | 312 | fernando | |
108 | 2425 | caballero | double xmin;
|
109 | double xmax;
|
||
110 | double ymin;
|
||
111 | double ymax = 0; |
||
112 | 312 | fernando | |
113 | 1074 | vcaballero | if (pSheet1.x > pSheet2.x) {
|
114 | xmin = pSheet2.x; |
||
115 | xmax = pSheet1.x; |
||
116 | } else {
|
||
117 | xmin = pSheet1.x; |
||
118 | xmax = pSheet2.x; |
||
119 | } |
||
120 | 312 | fernando | |
121 | 1074 | vcaballero | if (pSheet1.y > pSheet2.y) {
|
122 | ymin = pSheet2.y; |
||
123 | 2425 | caballero | ymax = pSheet1.y; |
124 | 1074 | vcaballero | } else {
|
125 | ymin = pSheet1.y; |
||
126 | 2425 | caballero | ymax = pSheet2.y; |
127 | 1074 | vcaballero | } |
128 | 4452 | caballero | |
129 | Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
||
130 | Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
||
131 | double x = FLayoutUtilities.toSheetDistance(layout.getRect().getX(),
|
||
132 | layout.getAT()); |
||
133 | double y = FLayoutUtilities.toSheetDistance(layout.getRect().getY(),
|
||
134 | layout.getAT()); |
||
135 | double w = FLayoutUtilities.toSheetDistance(layout.getRect().getWidth(),
|
||
136 | layout.getAT()); |
||
137 | double h = FLayoutUtilities.toSheetDistance(layout.getRect().getHeight(),
|
||
138 | layout.getAT()); |
||
139 | |||
140 | 1074 | vcaballero | if (java.lang.Math.abs(layout.getFirstPoint().x - p2.x) < 4) { |
141 | 4452 | caballero | double difw = 2; |
142 | 312 | fernando | |
143 | 4452 | caballero | rSheet.x = (-pSheet2.getX() * difw) - x + |
144 | FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
||
145 | layout.getAT()); |
||
146 | rSheet.y = (-pSheet2.getY() * difw) - y + |
||
147 | FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
||
148 | layout.getAT()); |
||
149 | |||
150 | rSheet.width = w * difw; |
||
151 | rSheet.height = h * difw; |
||
152 | |||
153 | rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
||
154 | layout.getAT())); |
||
155 | } else {
|
||
156 | 2425 | caballero | double wv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
157 | .getWidth(), |
||
158 | 1074 | vcaballero | layout.getAT()); |
159 | 2425 | caballero | double hv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
160 | .getHeight(), |
||
161 | layout.getAT()); |
||
162 | 1074 | vcaballero | double mw = xmax - xmin;
|
163 | 2425 | caballero | double mh = ymax - ymin;
|
164 | double difw = wv / mw;
|
||
165 | double difh = hv / mh;
|
||
166 | 312 | fernando | |
167 | 2425 | caballero | if (difw < difh) {
|
168 | 4452 | caballero | rSheet.x = (-xmin * difw) - x + |
169 | ((wv - ((pSheet2.getX() - pSheet1.getX()) * difw)) / 2);
|
||
170 | rSheet.y = (-ymin * difw) - y + |
||
171 | ((hv - ((pSheet2.getY() - pSheet1.getY()) * difw)) / 2);
|
||
172 | |||
173 | rSheet.width = w * difw; |
||
174 | rSheet.height = h * difw; |
||
175 | 2425 | caballero | } else {
|
176 | 4452 | caballero | rSheet.x = (-xmin * difh) - x + |
177 | ((wv - ((pSheet2.getX() - pSheet1.getX()) * difh)) / 2);
|
||
178 | rSheet.y = (-ymin * difh) - y + |
||
179 | ((hv - ((pSheet2.getY() - pSheet1.getY()) * difh)) / 2);
|
||
180 | |||
181 | rSheet.width = w * difh; |
||
182 | rSheet.height = h * difh; |
||
183 | 2425 | caballero | } |
184 | 4452 | caballero | |
185 | rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
||
186 | layout.getAT())); |
||
187 | 1074 | vcaballero | } |
188 | 4452 | caballero | |
189 | if (FLayoutUtilities.isPosible(rScreen)) {
|
||
190 | layout.getRect().setRect(rScreen); |
||
191 | } |
||
192 | 1074 | vcaballero | } |
193 | 312 | fernando | |
194 | 1074 | vcaballero | /**
|
195 | * Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
||
196 | *
|
||
197 | * @param p2 punto final del rec?ngulo.
|
||
198 | */
|
||
199 | public void setZoomOut(Point p2) { |
||
200 | 4452 | caballero | Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
201 | p2.getX(), p2.getY()), layout.getAT()); |
||
202 | |||
203 | Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
||
204 | Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
||
205 | |||
206 | double difw = 0.5; |
||
207 | |||
208 | rSheet.x = (-pSheet2.getX() * difw) - |
||
209 | FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
||
210 | layout.getAT()) + |
||
211 | FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
||
212 | layout.getAT()); |
||
213 | rSheet.y = (-pSheet2.getY() * difw) - |
||
214 | FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
||
215 | layout.getAT()) + |
||
216 | FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
||
217 | layout.getAT()); |
||
218 | |||
219 | rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
||
220 | .getWidth(), |
||
221 | layout.getAT()) * difw; |
||
222 | rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
||
223 | .getHeight(), |
||
224 | layout.getAT()) * difw; |
||
225 | |||
226 | rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
||
227 | |||
228 | if (FLayoutUtilities.isPosible(rScreen)) {
|
||
229 | layout.getRect().setRect(rScreen); |
||
230 | } |
||
231 | 1074 | vcaballero | } |
232 | 312 | fernando | |
233 | 1074 | vcaballero | /**
|
234 | 4452 | caballero | * Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
235 | 1074 | vcaballero | *
|
236 | 4452 | caballero | * @param dif punto de inicio del rect?ngulo.
|
237 | * @param p2 punto final del rec?ngulo.
|
||
238 | 1074 | vcaballero | */
|
239 | 4452 | caballero | public void setZoom(double dif, Point p2) { |
240 | 1074 | vcaballero | Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
241 | p2.getX(), p2.getY()), layout.getAT()); |
||
242 | Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
||
243 | Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
||
244 | 312 | fernando | |
245 | 4452 | caballero | double difw = dif;
|
246 | 312 | fernando | |
247 | 4452 | caballero | rSheet.x = (-pSheet2.getX() * difw) - |
248 | FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
||
249 | layout.getAT()) + |
||
250 | FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
||
251 | 1074 | vcaballero | layout.getAT()); |
252 | 4452 | caballero | rSheet.y = (-pSheet2.getY() * difw) - |
253 | FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
||
254 | layout.getAT()) + |
||
255 | FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
||
256 | 1074 | vcaballero | layout.getAT()); |
257 | 312 | fernando | |
258 | 4452 | caballero | rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
259 | .getWidth(), |
||
260 | layout.getAT()) * difw; |
||
261 | rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
||
262 | .getHeight(), |
||
263 | layout.getAT()) * difw; |
||
264 | 312 | fernando | |
265 | 1074 | vcaballero | rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
266 | 312 | fernando | |
267 | 1074 | vcaballero | if (FLayoutUtilities.isPosible(rScreen)) {
|
268 | 4452 | caballero | layout.getRect().setRect(rScreen); |
269 | 1074 | vcaballero | } |
270 | } |
||
271 | 312 | fernando | |
272 | 1074 | vcaballero | /**
|
273 | * Realiza un zoom a escala 1:1.
|
||
274 | */
|
||
275 | public void realZoom() { |
||
276 | double cm = layout.getAtributes().getPixXCm(layout.getRect());
|
||
277 | Toolkit kit = Toolkit.getDefaultToolkit(); |
||
278 | int resolution = kit.getScreenResolution();
|
||
279 | double dif = (cm * Attributes.PULGADA) / resolution; |
||
280 | 4452 | caballero | setZoom(1 / dif,
|
281 | 1074 | vcaballero | new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
282 | layout.setStatus(Layout.DESACTUALIZADO); |
||
283 | layout.repaint(); |
||
284 | } |
||
285 | 312 | fernando | |
286 | 1074 | vcaballero | /**
|
287 | * Realiza un zoom m?s a partir del punto central de pantalla.
|
||
288 | */
|
||
289 | 4452 | caballero | public void zoomIn() { |
290 | setZoom(2, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
||
291 | layout.setStatus(Layout.DESACTUALIZADO); |
||
292 | layout.repaint(); |
||
293 | } |
||
294 | 312 | fernando | |
295 | 1074 | vcaballero | /**
|
296 | * Realiza un zoom menos a partir del punto central de pantalla.
|
||
297 | */
|
||
298 | 4452 | caballero | public void zoomOut() { |
299 | setZoom(0.5, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
||
300 | 1074 | vcaballero | layout.setStatus(Layout.DESACTUALIZADO); |
301 | layout.repaint(); |
||
302 | } |
||
303 | 312 | fernando | |
304 | 1074 | vcaballero | /**
|
305 | * Realiza un zoom a los elementos que esten seleccionados, si no hay
|
||
306 | * ning?n elemento seleccionado no realiza ning?n zoom
|
||
307 | */
|
||
308 | public void zoomSelect() { |
||
309 | Rectangle2D.Double recaux = null; |
||
310 | 312 | fernando | |
311 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
312 | 2263 | vcaballero | if (((IFFrame) layout.getFFrames().get(i)).getSelected() != IFFrame.NOSELECT) {
|
313 | 1074 | vcaballero | if (recaux == null) { |
314 | recaux = ((IFFrame) layout.getFFrames().get(i)).getBoundingBox(layout.getAT()); |
||
315 | } else {
|
||
316 | recaux.add(((IFFrame) layout.getFFrames().get(i)).getBoundingBox( |
||
317 | layout.getAT())); |
||
318 | } |
||
319 | } |
||
320 | } |
||
321 | 312 | fernando | |
322 | 1074 | vcaballero | if (recaux != null) { |
323 | Point p1 = new Point((int) recaux.x, (int) recaux.y); |
||
324 | Point p2 = new Point((int) recaux.getMaxX(), (int) recaux.getMaxY()); |
||
325 | setZoomIn(p1, p2); |
||
326 | layout.setStatus(Layout.DESACTUALIZADO); |
||
327 | layout.repaint(); |
||
328 | } |
||
329 | } |
||
330 | 312 | fernando | |
331 | 1074 | vcaballero | /**
|
332 | * Realiza un zoom m?s sobre la vista del FFrameView seleccionado.
|
||
333 | *
|
||
334 | * @param p1 punto inicial.
|
||
335 | * @param p2 punto final.
|
||
336 | */
|
||
337 | public void setViewZoomIn(Point2D p1, Point2D p2) { |
||
338 | for (int i = 0; i < layout.getFFrames().size(); i++) { |
||
339 | if (layout.getFFrames().get(i) instanceof FFrameView) { |
||
340 | FFrameView fframe = (FFrameView) layout.getFFrames().get(i); |
||
341 | 312 | fernando | |
342 | 2263 | vcaballero | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
343 | 4452 | caballero | p1 = functions.toMapPoint(p1, fframe.getAt()); |
344 | p2 = functions.toMapPoint(p2, fframe.getAt()); |
||
345 | 312 | fernando | |
346 | 1074 | vcaballero | // Borramos el anterior
|
347 | layout.setStatus(Layout.DESACTUALIZADO); |
||
348 | 312 | fernando | |
349 | 1074 | vcaballero | if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) { |
350 | double nuevoX;
|
||
351 | double nuevoY;
|
||
352 | double cX;
|
||
353 | double cY;
|
||
354 | 312 | fernando | |
355 | 1074 | vcaballero | cX = p2.getX(); |
356 | cY = p2.getY(); |
||
357 | 312 | fernando | |
358 | 1074 | vcaballero | double factor = 0.6; |
359 | Rectangle2D.Double r = new Rectangle2D.Double(); |
||
360 | 312 | fernando | |
361 | 1074 | vcaballero | nuevoX = cX - |
362 | ((fframe.getFMap().getViewPort().getExtent() |
||
363 | .getWidth() * factor) / 2.0);
|
||
364 | nuevoY = cY - |
||
365 | ((fframe.getFMap().getViewPort().getExtent() |
||
366 | .getHeight() * factor) / 2.0);
|
||
367 | r.x = nuevoX; |
||
368 | r.y = nuevoY; |
||
369 | r.width = fframe.getFMap().getViewPort().getExtent() |
||
370 | .getWidth() * factor; |
||
371 | r.height = fframe.getFMap().getViewPort().getExtent() |
||
372 | .getHeight() * factor; |
||
373 | 312 | fernando | |
374 | fframe.setNewExtent(r); |
||
375 | 1074 | vcaballero | } else {
|
376 | // Fijamos el nuevo extent
|
||
377 | Rectangle2D.Double r = new Rectangle2D.Double(); |
||
378 | 312 | fernando | |
379 | 1074 | vcaballero | r.setFrameFromDiagonal(p1, p2); |
380 | 312 | fernando | |
381 | 1074 | vcaballero | fframe.setNewExtent(r); |
382 | } |
||
383 | 4452 | caballero | |
384 | 1074 | vcaballero | // Fin del else
|
385 | 4452 | caballero | layout.repaint(); |
386 | 1074 | vcaballero | } |
387 | } |
||
388 | } |
||
389 | } |
||
390 | 4451 | caballero | |
391 | 4209 | jaume | /**
|
392 | 1074 | vcaballero | * Realiza un zoom menos sobre la vista del FFrameView seleccionado.
|
393 | *
|
||
394 | * @param p2 Punto sobre el que realizar el zoom menos.
|
||
395 | */
|
||
396 | public void setViewZoomOut(Point p2) { |
||
397 | Point2D.Double pWorld;
|
||
398 | 312 | fernando | |
399 | 1074 | vcaballero | for (int i = 0; i < layout.getFFrames().size(); i++) { |
400 | if (layout.getFFrames().get(i) instanceof FFrameView) { |
||
401 | FFrameView fframe = (FFrameView) layout.getFFrames().get(i); |
||
402 | 312 | fernando | |
403 | 2263 | vcaballero | if (fframe.getSelected() != IFFrame.NOSELECT) {
|
404 | 1074 | vcaballero | double nuevoX;
|
405 | double nuevoY;
|
||
406 | double cX;
|
||
407 | double cY;
|
||
408 | Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
||
409 | 4452 | caballero | pWorld = functions.toMapPoint(pScreen, fframe.getAt()); |
410 | 312 | fernando | |
411 | 1074 | vcaballero | cX = pWorld.getX(); |
412 | cY = pWorld.getY(); |
||
413 | 312 | fernando | |
414 | 1074 | vcaballero | double factor = 1.8; |
415 | Rectangle2D.Double r = new Rectangle2D.Double(); |
||
416 | 312 | fernando | |
417 | 1074 | vcaballero | nuevoX = cX - |
418 | ((fframe.getFMap().getViewPort().getExtent().getWidth() * factor) / 2.0);
|
||
419 | nuevoY = cY - |
||
420 | ((fframe.getFMap().getViewPort().getExtent().getHeight() * factor) / 2.0);
|
||
421 | r.x = nuevoX; |
||
422 | r.y = nuevoY; |
||
423 | r.width = fframe.getFMap().getViewPort().getExtent() |
||
424 | .getWidth() * factor; |
||
425 | r.height = fframe.getFMap().getViewPort().getExtent() |
||
426 | .getHeight() * factor; |
||
427 | 312 | fernando | |
428 | fframe.setNewExtent(r); |
||
429 | 1074 | vcaballero | |
430 | ///fframe.getFMap().setCancelDrawing(false);
|
||
431 | } |
||
432 | } |
||
433 | } |
||
434 | 4452 | caballero | } |
435 | 312 | fernando | } |