svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutZooms.java @ 4203
History | View | Annotate | Download (12.9 KB)
1 |
/*
|
---|---|
2 |
* Created on 17-sep-2004
|
3 |
*
|
4 |
*/
|
5 |
/* 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 |
package com.iver.cit.gvsig.gui.layout; |
46 |
|
47 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
48 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameUseFMap; |
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 |
private Layout layout = null; |
63 |
private static double FACTOR=2; |
64 |
|
65 |
/**
|
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 |
} |
73 |
|
74 |
/**
|
75 |
* Realiza un zoom por rect?ngulo o por punto con un escalado por defecto
|
76 |
* sobre el Layout que se le pasa como par?metro.
|
77 |
*
|
78 |
* @param p1 punto de inicio del rect?ngulo.
|
79 |
* @param p2 punto final del rec?ngulo.
|
80 |
*/
|
81 |
public void setZoomIn(Point p1, Point p2) { |
82 |
if (p1.getX()>p2.getX()){
|
83 |
int aux=p2.x;
|
84 |
p2.x=p1.x; |
85 |
p1.x=aux; |
86 |
} |
87 |
if (p1.getY()>p2.getY()){
|
88 |
int aux=p2.y;
|
89 |
p2.y=p1.y; |
90 |
p1.y=aux; |
91 |
} |
92 |
Point2D.Double pSheet1 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
93 |
p1.getX(), p1.getY()), layout.getAT()); |
94 |
Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
95 |
p2.getX(), p2.getY()), layout.getAT()); |
96 |
|
97 |
double xmin;
|
98 |
double xmax;
|
99 |
double ymin;
|
100 |
double ymax = 0; |
101 |
|
102 |
if (pSheet1.x > pSheet2.x) {
|
103 |
xmin = pSheet2.x; |
104 |
xmax = pSheet1.x; |
105 |
} else {
|
106 |
xmin = pSheet1.x; |
107 |
xmax = pSheet2.x; |
108 |
} |
109 |
|
110 |
if (pSheet1.y > pSheet2.y) {
|
111 |
ymin = pSheet2.y; |
112 |
ymax = pSheet1.y; |
113 |
} else {
|
114 |
ymin = pSheet1.y; |
115 |
ymax = pSheet2.y; |
116 |
} |
117 |
if (java.lang.Math.abs(layout.getFirstPoint().x - p2.x) < 4) { |
118 |
setZoom(FACTOR,p2); |
119 |
} else {
|
120 |
|
121 |
double wv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
122 |
.getWidth(), |
123 |
layout.getAT()); |
124 |
double hv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
125 |
.getHeight(), |
126 |
layout.getAT()); |
127 |
double mw = xmax - xmin;
|
128 |
double mh = ymax - ymin;
|
129 |
double difw = wv / mw;
|
130 |
double difh = hv / mh;
|
131 |
|
132 |
if (difw < difh) {
|
133 |
setZoom(difw,new Point((int)(p1.getX()+p2.getX())/2,(int)(p1.getY()+p2.getY())/2)); |
134 |
} else {
|
135 |
setZoom(difh,new Point((int)(p1.getX()+p2.getX())/2,(int)(p1.getY()+p2.getY())/2)); |
136 |
} |
137 |
} |
138 |
} |
139 |
|
140 |
/**
|
141 |
* Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
142 |
*
|
143 |
* @param p2 punto final del rec?ngulo.
|
144 |
*/
|
145 |
public void setZoomOut(Point p2) { |
146 |
setZoom(1/FACTOR, p2);
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
151 |
*
|
152 |
* @param dif punto de inicio del rect?ngulo.
|
153 |
* @param p2 punto final del rec?ngulo.
|
154 |
*/
|
155 |
public void setZoom(double dif, Point p2) { |
156 |
Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
157 |
p2.getX(), p2.getY()), layout.getAT()); |
158 |
Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
159 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
160 |
|
161 |
double difw = dif;
|
162 |
double x = FLayoutUtilities.toSheetDistance(layout.getRect().getX(),
|
163 |
layout.getAT()); |
164 |
double y = FLayoutUtilities.toSheetDistance(layout.getRect().getY(),
|
165 |
layout.getAT()); |
166 |
double w = FLayoutUtilities.toSheetDistance(layout.getRect().getWidth(),
|
167 |
layout.getAT()); |
168 |
double h = FLayoutUtilities.toSheetDistance(layout.getRect().getHeight(),
|
169 |
layout.getAT()); |
170 |
|
171 |
rSheet.x = (-pSheet2.getX() * difw) - x + |
172 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
173 |
layout.getAT()); |
174 |
rSheet.y = (-pSheet2.getY() * difw) - y + |
175 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
176 |
layout.getAT()); |
177 |
|
178 |
rSheet.width = w * difw; |
179 |
rSheet.height = h * difw; |
180 |
|
181 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
182 |
|
183 |
if (FLayoutUtilities.isPosible(rScreen)) {
|
184 |
layout.setRect(rScreen); |
185 |
} |
186 |
////////////
|
187 |
if (dif < 1) |
188 |
setZoomOutClip(difw,p2); |
189 |
else if (dif > 1) |
190 |
setZoomOutClip(difw,p2); |
191 |
/////////////
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* Realiza un zoom a escala 1:1.
|
196 |
*/
|
197 |
public void realZoom() { |
198 |
double cm = layout.getAtributes().getPixXCm(layout.getRect());
|
199 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
200 |
int resolution = kit.getScreenResolution();
|
201 |
double dif = (cm * Attributes.PULGADA) / resolution; |
202 |
setZoom(1 / dif,
|
203 |
new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
204 |
layout.setStatus(Layout.DESACTUALIZADO); |
205 |
layout.repaint(); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* Realiza un zoom m?s a partir del punto central de pantalla.
|
210 |
*/
|
211 |
public void zoomIn() { |
212 |
setZoom(FACTOR, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
213 |
layout.setStatus(Layout.DESACTUALIZADO); |
214 |
layout.repaint(); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* Realiza un zoom menos a partir del punto central de pantalla.
|
219 |
*/
|
220 |
public void zoomOut() { |
221 |
setZoom(1/FACTOR, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
222 |
layout.setStatus(Layout.DESACTUALIZADO); |
223 |
layout.repaint(); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* Realiza un zoom a los elementos que esten seleccionados, si no hay
|
228 |
* ning?n elemento seleccionado no realiza ning?n zoom
|
229 |
*/
|
230 |
public void zoomSelect() { |
231 |
Rectangle2D.Double recaux = null; |
232 |
|
233 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
234 |
if (((IFFrame) layout.getFFrame(i)).getSelected() != IFFrame.NOSELECT) {
|
235 |
if (recaux == null) { |
236 |
recaux = ((IFFrame) layout.getFFrame(i)).getBoundingBox(layout.getAT()); |
237 |
} else {
|
238 |
recaux.add(((IFFrame) layout.getFFrame(i)).getBoundingBox( |
239 |
layout.getAT())); |
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
if (recaux != null) { |
245 |
Point p1 = new Point((int) recaux.x, (int) recaux.y); |
246 |
Point p2 = new Point((int) recaux.getMaxX(), (int) recaux.getMaxY()); |
247 |
setZoomIn(p1, p2); |
248 |
layout.setStatus(Layout.DESACTUALIZADO); |
249 |
layout.repaint(); |
250 |
} |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Realiza un zoom m?s sobre la vista del FFrameView seleccionado.
|
255 |
*
|
256 |
* @param p1 punto inicial.
|
257 |
* @param p2 punto final.
|
258 |
*/
|
259 |
public void setViewZoomIn(Point2D p1, Point2D p2) { |
260 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
261 |
if (layout.getFFrame(i) instanceof IFFrameUseFMap) { |
262 |
IFFrameUseFMap fframe = (IFFrameUseFMap) layout.getFFrame(i); |
263 |
|
264 |
if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) {
|
265 |
p1 = FLayoutFunctions.toMapPoint(p1, fframe.getATMap()); |
266 |
p2 = FLayoutFunctions.toMapPoint(p2, fframe.getATMap()); |
267 |
|
268 |
// Borramos el anterior
|
269 |
layout.setStatus(Layout.DESACTUALIZADO); |
270 |
|
271 |
if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) { |
272 |
double nuevoX;
|
273 |
double nuevoY;
|
274 |
double cX;
|
275 |
double cY;
|
276 |
|
277 |
cX = p2.getX(); |
278 |
cY = p2.getY(); |
279 |
|
280 |
double factor = 0.6; |
281 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
282 |
|
283 |
nuevoX = cX - |
284 |
((fframe.getFMap().getViewPort().getExtent() |
285 |
.getWidth() * factor) / 2.0);
|
286 |
nuevoY = cY - |
287 |
((fframe.getFMap().getViewPort().getExtent() |
288 |
.getHeight() * factor) / 2.0);
|
289 |
r.x = nuevoX; |
290 |
r.y = nuevoY; |
291 |
r.width = fframe.getFMap().getViewPort().getExtent() |
292 |
.getWidth() * factor; |
293 |
r.height = fframe.getFMap().getViewPort().getExtent() |
294 |
.getHeight() * factor; |
295 |
|
296 |
fframe.setNewExtent(r); |
297 |
} else {
|
298 |
// Fijamos el nuevo extent
|
299 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
300 |
|
301 |
r.setFrameFromDiagonal(p1, p2); |
302 |
|
303 |
fframe.setNewExtent(r); |
304 |
} |
305 |
fframe.refresh(); |
306 |
// Fin del else
|
307 |
//layout.repaint();
|
308 |
} |
309 |
} |
310 |
} |
311 |
} |
312 |
/**
|
313 |
* Realiza un zoom m?s sobre las vistas FFrameView.
|
314 |
*
|
315 |
* @param p1 punto inicial.
|
316 |
* @param p2 punto final.
|
317 |
*/
|
318 |
public void setZoomInClip(double dif,Point2D p1, Point2D p2) { |
319 |
double factor=1/dif; |
320 |
IFFrame[] fframes=layout.getFFrames();
|
321 |
for (int i = 0; i < fframes.length; i++) { |
322 |
if (fframes[i] instanceof IFFrameUseFMap) { |
323 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
324 |
Rectangle2D rect=new Rectangle2D.Double(); |
325 |
rect.setFrameFromDiagonal(p1, p2); |
326 |
if (p1.equals(p2)){
|
327 |
rect.setRect(p1.getX()-(layout.getBounds().width*factor)/2,p1.getY()-(layout.getBounds().height*factor)/2,layout.getBounds().width*factor,layout.getBounds().height*factor); |
328 |
} |
329 |
if (((IFFrame)fframes[i]).getBoundingBox(layout.getAT()).intersects(rect)){
|
330 |
p1 = FLayoutFunctions.toMapPoint(p1, fframe.getATMap()); |
331 |
p2 = FLayoutFunctions.toMapPoint(p2, fframe.getATMap()); |
332 |
|
333 |
// Borramos el anterior
|
334 |
layout.setStatus(Layout.DESACTUALIZADO); |
335 |
|
336 |
if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) { |
337 |
double nuevoX;
|
338 |
double nuevoY;
|
339 |
double cX;
|
340 |
double cY;
|
341 |
|
342 |
cX = p2.getX(); |
343 |
cY = p2.getY(); |
344 |
|
345 |
|
346 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
347 |
|
348 |
nuevoX = cX - |
349 |
((fframe.getFMap().getViewPort().getExtent() |
350 |
.getWidth() * factor) / 2.0);
|
351 |
nuevoY = cY - |
352 |
((fframe.getFMap().getViewPort().getExtent() |
353 |
.getHeight() * factor) / 2.0);
|
354 |
r.x = nuevoX; |
355 |
r.y = nuevoY; |
356 |
r.width = fframe.getFMap().getViewPort().getExtent() |
357 |
.getWidth() * factor; |
358 |
r.height = fframe.getFMap().getViewPort().getExtent() |
359 |
.getHeight() * factor; |
360 |
|
361 |
fframe.setNewExtent(r); |
362 |
} else {
|
363 |
// Fijamos el nuevo extent
|
364 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
365 |
|
366 |
r.setFrameFromDiagonal(p1, p2); |
367 |
|
368 |
fframe.setNewExtent(r); |
369 |
} |
370 |
fframe.refresh(); |
371 |
} |
372 |
} |
373 |
} |
374 |
} |
375 |
/**
|
376 |
* Realiza un zoom menos sobre la vista del FFrameView seleccionado.
|
377 |
*
|
378 |
* @param p2 Punto sobre el que realizar el zoom menos.
|
379 |
*/
|
380 |
public void setViewZoomOut(Point p2) { |
381 |
Point2D.Double pWorld;
|
382 |
|
383 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
384 |
if (layout.getFFrame(i) instanceof IFFrameUseFMap) { |
385 |
IFFrameUseFMap fframe = (IFFrameUseFMap) layout.getFFrame(i); |
386 |
|
387 |
if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) {
|
388 |
double nuevoX;
|
389 |
double nuevoY;
|
390 |
double cX;
|
391 |
double cY;
|
392 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
393 |
pWorld = FLayoutFunctions.toMapPoint(pScreen, fframe.getATMap()); |
394 |
|
395 |
cX = pWorld.getX(); |
396 |
cY = pWorld.getY(); |
397 |
|
398 |
double factor = 1.8; |
399 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
400 |
|
401 |
nuevoX = cX - |
402 |
((fframe.getFMap().getViewPort().getExtent().getWidth() * factor) / 2.0);
|
403 |
nuevoY = cY - |
404 |
((fframe.getFMap().getViewPort().getExtent().getHeight() * factor) / 2.0);
|
405 |
r.x = nuevoX; |
406 |
r.y = nuevoY; |
407 |
r.width = fframe.getFMap().getViewPort().getExtent() |
408 |
.getWidth() * factor; |
409 |
r.height = fframe.getFMap().getViewPort().getExtent() |
410 |
.getHeight() * factor; |
411 |
|
412 |
fframe.setNewExtent(r); |
413 |
fframe.refresh(); |
414 |
///fframe.getFMap().setCancelDrawing(false);
|
415 |
} |
416 |
} |
417 |
} |
418 |
} |
419 |
/**
|
420 |
* Realiza un zoom menos sobre la vista.
|
421 |
*
|
422 |
* @param p2 Punto sobre el que realizar el zoom menos.
|
423 |
*/
|
424 |
public void setZoomOutClip(double dif,Point p2) { |
425 |
Point2D.Double pWorld;
|
426 |
double factor=1/dif; |
427 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
428 |
IFFrame[] fframes=layout.getFFrames();
|
429 |
if (fframes[i] instanceof IFFrameUseFMap) { |
430 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
431 |
Rectangle2D rect=layout.getBounds();
|
432 |
if (((IFFrame)fframes[i]).getBoundingBox(layout.getAT()).intersects(rect)){
|
433 |
double nuevoX;
|
434 |
double nuevoY;
|
435 |
double cX;
|
436 |
double cY;
|
437 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
438 |
pWorld = FLayoutFunctions.toMapPoint(pScreen, fframe.getATMap()); |
439 |
|
440 |
cX = pWorld.getX(); |
441 |
cY = pWorld.getY(); |
442 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
443 |
nuevoX = cX - |
444 |
((fframe.getFMap().getViewPort().getExtent().getWidth() * factor) / 2.0);
|
445 |
nuevoY = cY - |
446 |
((fframe.getFMap().getViewPort().getExtent().getHeight() * factor) / 2.0);
|
447 |
r.x = nuevoX; |
448 |
r.y = nuevoY; |
449 |
r.width = fframe.getFMap().getViewPort().getExtent() |
450 |
.getWidth() * factor; |
451 |
r.height = fframe.getFMap().getViewPort().getExtent() |
452 |
.getHeight() * factor; |
453 |
|
454 |
fframe.setNewExtent(r); |
455 |
fframe.refresh(); |
456 |
///fframe.getFMap().setCancelDrawing(false);
|
457 |
} |
458 |
} |
459 |
} |
460 |
} |
461 |
} |