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