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