svn-gvsig-desktop / tags / Root_v06 / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutZooms.java @ 4811
History | View | Annotate | Download (12.1 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 |
|
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 FLayoutFunctions functions = null; |
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 |
functions = new FLayoutFunctions(layout);
|
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 (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 |
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 |
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 |
|
108 |
double xmin;
|
109 |
double xmax;
|
110 |
double ymin;
|
111 |
double ymax = 0; |
112 |
|
113 |
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 |
|
121 |
if (pSheet1.y > pSheet2.y) {
|
122 |
ymin = pSheet2.y; |
123 |
ymax = pSheet1.y; |
124 |
} else {
|
125 |
ymin = pSheet1.y; |
126 |
ymax = pSheet2.y; |
127 |
} |
128 |
|
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 |
if (java.lang.Math.abs(layout.getFirstPoint().x - p2.x) < 4) { |
141 |
double difw = 2; |
142 |
|
143 |
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 |
double wv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
157 |
.getWidth(), |
158 |
layout.getAT()); |
159 |
double hv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
160 |
.getHeight(), |
161 |
layout.getAT()); |
162 |
double mw = xmax - xmin;
|
163 |
double mh = ymax - ymin;
|
164 |
double difw = wv / mw;
|
165 |
double difh = hv / mh;
|
166 |
|
167 |
if (difw < difh) {
|
168 |
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 |
} else {
|
176 |
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 |
} |
184 |
|
185 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
186 |
layout.getAT())); |
187 |
} |
188 |
|
189 |
if (FLayoutUtilities.isPosible(rScreen)) {
|
190 |
layout.getRect().setRect(rScreen); |
191 |
} |
192 |
} |
193 |
|
194 |
/**
|
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 |
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 |
} |
232 |
|
233 |
/**
|
234 |
* Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
235 |
*
|
236 |
* @param dif punto de inicio del rect?ngulo.
|
237 |
* @param p2 punto final del rec?ngulo.
|
238 |
*/
|
239 |
public void setZoom(double dif, Point p2) { |
240 |
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 |
|
245 |
double difw = dif;
|
246 |
|
247 |
rSheet.x = (-pSheet2.getX() * difw) - |
248 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
249 |
layout.getAT()) + |
250 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
251 |
layout.getAT()); |
252 |
rSheet.y = (-pSheet2.getY() * difw) - |
253 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
254 |
layout.getAT()) + |
255 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
256 |
layout.getAT()); |
257 |
|
258 |
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 |
|
265 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
266 |
|
267 |
if (FLayoutUtilities.isPosible(rScreen)) {
|
268 |
layout.getRect().setRect(rScreen); |
269 |
} |
270 |
} |
271 |
|
272 |
/**
|
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 |
setZoom(1 / dif,
|
281 |
new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
282 |
layout.setStatus(Layout.DESACTUALIZADO); |
283 |
layout.repaint(); |
284 |
} |
285 |
|
286 |
/**
|
287 |
* Realiza un zoom m?s a partir del punto central de pantalla.
|
288 |
*/
|
289 |
public void zoomIn() { |
290 |
setZoom(2, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
291 |
layout.setStatus(Layout.DESACTUALIZADO); |
292 |
layout.repaint(); |
293 |
} |
294 |
|
295 |
/**
|
296 |
* Realiza un zoom menos a partir del punto central de pantalla.
|
297 |
*/
|
298 |
public void zoomOut() { |
299 |
setZoom(0.5, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
300 |
layout.setStatus(Layout.DESACTUALIZADO); |
301 |
layout.repaint(); |
302 |
} |
303 |
|
304 |
/**
|
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 |
|
311 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
312 |
if (((IFFrame) layout.getFFrames().get(i)).getSelected() != IFFrame.NOSELECT) {
|
313 |
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 |
|
322 |
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 |
|
331 |
/**
|
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 |
|
342 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
343 |
p1 = functions.toMapPoint(p1, fframe.getAt()); |
344 |
p2 = functions.toMapPoint(p2, fframe.getAt()); |
345 |
|
346 |
// Borramos el anterior
|
347 |
layout.setStatus(Layout.DESACTUALIZADO); |
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 = 0.6; |
359 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
360 |
|
361 |
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 |
|
374 |
fframe.setNewExtent(r); |
375 |
} else {
|
376 |
// Fijamos el nuevo extent
|
377 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
378 |
|
379 |
r.setFrameFromDiagonal(p1, p2); |
380 |
|
381 |
fframe.setNewExtent(r); |
382 |
} |
383 |
|
384 |
// Fin del else
|
385 |
layout.repaint(); |
386 |
} |
387 |
} |
388 |
} |
389 |
} |
390 |
|
391 |
/**
|
392 |
* 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 |
|
399 |
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 |
|
403 |
if (fframe.getSelected() != IFFrame.NOSELECT) {
|
404 |
double nuevoX;
|
405 |
double nuevoY;
|
406 |
double cX;
|
407 |
double cY;
|
408 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
409 |
pWorld = functions.toMapPoint(pScreen, fframe.getAt()); |
410 |
|
411 |
cX = pWorld.getX(); |
412 |
cY = pWorld.getY(); |
413 |
|
414 |
double factor = 1.8; |
415 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
416 |
|
417 |
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 |
|
428 |
fframe.setNewExtent(r); |
429 |
|
430 |
///fframe.getFMap().setCancelDrawing(false);
|
431 |
} |
432 |
} |
433 |
} |
434 |
} |
435 |
} |