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