root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / FLayoutZooms.java @ 1074
History | View | Annotate | Download (10.9 KB)
1 |
/*
|
---|---|
2 |
* Created on 17-sep-2004
|
3 |
*
|
4 |
*/
|
5 |
package com.iver.cit.gvsig.gui.layout; |
6 |
|
7 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrame; |
8 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
9 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
10 |
|
11 |
import java.awt.Point; |
12 |
import java.awt.Toolkit; |
13 |
import java.awt.geom.Point2D; |
14 |
import java.awt.geom.Rectangle2D; |
15 |
|
16 |
|
17 |
/**
|
18 |
* Clase contenedora de los m?todos para cambiar los zooms.
|
19 |
*
|
20 |
* @author Vicente Caballero Navarro
|
21 |
*/
|
22 |
public class FLayoutZooms { |
23 |
private Layout layout = null; |
24 |
private FLayoutFunctions functions = null; |
25 |
|
26 |
/**
|
27 |
* Crea un nuevo Zooms.
|
28 |
*
|
29 |
* @param l Mapa sobre el que se actua.
|
30 |
*/
|
31 |
public FLayoutZooms(Layout l) {
|
32 |
layout = l; |
33 |
functions = new FLayoutFunctions(layout);
|
34 |
} |
35 |
|
36 |
/**
|
37 |
* Realiza un zoom por rect?ngulo o por punto con un escalado por defecto
|
38 |
* sobre el Layout que se le pasa como par?metro.
|
39 |
*
|
40 |
* @param p1 punto de inicio del rect?ngulo.
|
41 |
* @param p2 punto final del rec?ngulo.
|
42 |
*/
|
43 |
public void setZoomIn(Point p1, Point p2) { |
44 |
if (p1.y != p2.y) {
|
45 |
double points = (p2.x - p1.x) / (p2.y - p1.y);
|
46 |
double window = (double) layout.getWidth() / layout.getHeight(); |
47 |
|
48 |
if (points < window) {
|
49 |
p2.x = (int) (p1.x + ((p2.x - p1.x) * window));
|
50 |
} |
51 |
} |
52 |
|
53 |
Point2D.Double pSheet1 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
54 |
p1.getX(), p1.getY()), layout.getAT()); |
55 |
Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
56 |
p2.getX(), p2.getY()), layout.getAT()); |
57 |
|
58 |
double xmin = 0; |
59 |
double xmax = 0; |
60 |
double ymin = 0; |
61 |
|
62 |
if (pSheet1.x > pSheet2.x) {
|
63 |
xmin = pSheet2.x; |
64 |
xmax = pSheet1.x; |
65 |
} else {
|
66 |
xmin = pSheet1.x; |
67 |
xmax = pSheet2.x; |
68 |
} |
69 |
|
70 |
if (pSheet1.y > pSheet2.y) {
|
71 |
ymin = pSheet2.y; |
72 |
} else {
|
73 |
ymin = pSheet1.y; |
74 |
} |
75 |
|
76 |
Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
77 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
78 |
|
79 |
if (java.lang.Math.abs(layout.getFirstPoint().x - p2.x) < 4) { |
80 |
double w = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
81 |
.getWidth(), |
82 |
layout.getAT()); |
83 |
double difw = 2; |
84 |
|
85 |
rSheet.x = (-pSheet2.getX() * difw) - |
86 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
87 |
layout.getAT()) + |
88 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
89 |
layout.getAT()); |
90 |
rSheet.y = (-pSheet2.getY() * difw) - |
91 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
92 |
layout.getAT()) + |
93 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
94 |
layout.getAT()); |
95 |
|
96 |
rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
97 |
.getWidth(), |
98 |
layout.getAT()) * difw; |
99 |
rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
100 |
.getHeight(), |
101 |
layout.getAT()) * difw; |
102 |
|
103 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
104 |
layout.getAT())); |
105 |
} else {
|
106 |
double w = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
107 |
.getWidth(), |
108 |
layout.getAT()); |
109 |
double mw = xmax - xmin;
|
110 |
double difw = w / mw;
|
111 |
|
112 |
rSheet.x = (-xmin * difw) - |
113 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
114 |
layout.getAT()); |
115 |
rSheet.y = (-ymin * difw) - |
116 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
117 |
layout.getAT()); |
118 |
|
119 |
rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
120 |
.getWidth(), |
121 |
layout.getAT()) * difw; |
122 |
rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
123 |
.getHeight(), |
124 |
layout.getAT()) * difw; |
125 |
|
126 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
127 |
layout.getAT())); |
128 |
} |
129 |
|
130 |
if (FLayoutUtilities.isPosible(rScreen)) {
|
131 |
layout.getRect().setRect(rScreen); |
132 |
} |
133 |
} |
134 |
|
135 |
/**
|
136 |
* Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
137 |
*
|
138 |
* @param p2 punto final del rec?ngulo.
|
139 |
*/
|
140 |
public void setZoomOut(Point p2) { |
141 |
Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
142 |
p2.getX(), p2.getY()), layout.getAT()); |
143 |
|
144 |
Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
145 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
146 |
|
147 |
double w = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
148 |
.getWidth(), |
149 |
layout.getAT()); |
150 |
double difw = 0.5; |
151 |
|
152 |
rSheet.x = (-pSheet2.getX() * difw) - |
153 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
154 |
layout.getAT()) + |
155 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
156 |
layout.getAT()); |
157 |
rSheet.y = (-pSheet2.getY() * difw) - |
158 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
159 |
layout.getAT()) + |
160 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
161 |
layout.getAT()); |
162 |
|
163 |
rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
164 |
.getWidth(), |
165 |
layout.getAT()) * difw; |
166 |
rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
167 |
.getHeight(), |
168 |
layout.getAT()) * difw; |
169 |
|
170 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
171 |
|
172 |
if (FLayoutUtilities.isPosible(rScreen)) {
|
173 |
layout.getRect().setRect(rScreen); |
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Realiza un zoom out sobre el Layout que se le pasa como par?metro.
|
179 |
*
|
180 |
* @param dif punto de inicio del rect?ngulo.
|
181 |
* @param p2 punto final del rec?ngulo.
|
182 |
*/
|
183 |
public void setZoom(double dif, Point p2) { |
184 |
Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
185 |
p2.getX(), p2.getY()), layout.getAT()); |
186 |
Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
187 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
188 |
|
189 |
double w = FLayoutUtilities.toSheetDistance(layout.getVisibleRect()
|
190 |
.getWidth(), |
191 |
layout.getAT()); |
192 |
double difw = dif;
|
193 |
|
194 |
rSheet.x = (-pSheet2.getX() * difw) - |
195 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
196 |
layout.getAT()) + |
197 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2,
|
198 |
layout.getAT()); |
199 |
rSheet.y = (-pSheet2.getY() * difw) - |
200 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
201 |
layout.getAT()) + |
202 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2,
|
203 |
layout.getAT()); |
204 |
|
205 |
rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
206 |
.getWidth(), |
207 |
layout.getAT()) * difw; |
208 |
rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
209 |
.getHeight(), |
210 |
layout.getAT()) * difw; |
211 |
|
212 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
213 |
|
214 |
if (FLayoutUtilities.isPosible(rScreen)) {
|
215 |
layout.getRect().setRect(rScreen); |
216 |
} |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Realiza un zoom a escala 1:1.
|
221 |
*/
|
222 |
public void realZoom() { |
223 |
double cm = layout.getAtributes().getPixXCm(layout.getRect());
|
224 |
Toolkit kit = Toolkit.getDefaultToolkit(); |
225 |
int resolution = kit.getScreenResolution();
|
226 |
double dif = (cm * Attributes.PULGADA) / resolution; |
227 |
setZoom(1 / dif,
|
228 |
new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
229 |
layout.setStatus(Layout.DESACTUALIZADO); |
230 |
layout.repaint(); |
231 |
} |
232 |
|
233 |
/**
|
234 |
* Realiza un zoom m?s a partir del punto central de pantalla.
|
235 |
*/
|
236 |
public void zoomIn() { |
237 |
setZoom(2, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
238 |
layout.setStatus(Layout.DESACTUALIZADO); |
239 |
layout.repaint(); |
240 |
} |
241 |
|
242 |
/**
|
243 |
* Realiza un zoom menos a partir del punto central de pantalla.
|
244 |
*/
|
245 |
public void zoomOut() { |
246 |
setZoom(0.5, new Point(layout.getWidth() / 2, layout.getHeight() / 2)); |
247 |
layout.setStatus(Layout.DESACTUALIZADO); |
248 |
layout.repaint(); |
249 |
} |
250 |
|
251 |
/**
|
252 |
* Realiza un zoom a los elementos que esten seleccionados, si no hay
|
253 |
* ning?n elemento seleccionado no realiza ning?n zoom
|
254 |
*/
|
255 |
public void zoomSelect() { |
256 |
Rectangle2D.Double recaux = null; |
257 |
|
258 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
259 |
if (((IFFrame) layout.getFFrames().get(i)).getSelected() != FFrame.NOSELECT) {
|
260 |
if (recaux == null) { |
261 |
recaux = ((IFFrame) layout.getFFrames().get(i)).getBoundingBox(layout.getAT()); |
262 |
} else {
|
263 |
recaux.add(((IFFrame) layout.getFFrames().get(i)).getBoundingBox( |
264 |
layout.getAT())); |
265 |
} |
266 |
} |
267 |
} |
268 |
|
269 |
if (recaux != null) { |
270 |
Point p1 = new Point((int) recaux.x, (int) recaux.y); |
271 |
Point p2 = new Point((int) recaux.getMaxX(), (int) recaux.getMaxY()); |
272 |
setZoomIn(p1, p2); |
273 |
layout.setStatus(Layout.DESACTUALIZADO); |
274 |
layout.repaint(); |
275 |
} |
276 |
} |
277 |
|
278 |
/**
|
279 |
* Realiza un zoom m?s sobre la vista del FFrameView seleccionado.
|
280 |
*
|
281 |
* @param p1 punto inicial.
|
282 |
* @param p2 punto final.
|
283 |
*/
|
284 |
public void setViewZoomIn(Point2D p1, Point2D p2) { |
285 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
286 |
if (layout.getFFrames().get(i) instanceof FFrameView) { |
287 |
FFrameView fframe = (FFrameView) layout.getFFrames().get(i); |
288 |
|
289 |
if (fframe.getSelected() != FFrame.NOSELECT) {
|
290 |
p1 = functions.toMapPoint(p1, fframe.getAt()); |
291 |
p2 = functions.toMapPoint(p2, fframe.getAt()); |
292 |
|
293 |
// Borramos el anterior
|
294 |
layout.setStatus(Layout.DESACTUALIZADO); |
295 |
|
296 |
if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) { |
297 |
double nuevoX;
|
298 |
double nuevoY;
|
299 |
double cX;
|
300 |
double cY;
|
301 |
|
302 |
cX = p2.getX(); |
303 |
cY = p2.getY(); |
304 |
|
305 |
double factor = 0.6; |
306 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
307 |
|
308 |
nuevoX = cX - |
309 |
((fframe.getFMap().getViewPort().getExtent() |
310 |
.getWidth() * factor) / 2.0);
|
311 |
nuevoY = cY - |
312 |
((fframe.getFMap().getViewPort().getExtent() |
313 |
.getHeight() * factor) / 2.0);
|
314 |
r.x = nuevoX; |
315 |
r.y = nuevoY; |
316 |
r.width = fframe.getFMap().getViewPort().getExtent() |
317 |
.getWidth() * factor; |
318 |
r.height = fframe.getFMap().getViewPort().getExtent() |
319 |
.getHeight() * factor; |
320 |
|
321 |
fframe.setNewExtent(r); |
322 |
} else {
|
323 |
// Fijamos el nuevo extent
|
324 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
325 |
|
326 |
r.setFrameFromDiagonal(p1, p2); |
327 |
|
328 |
fframe.setNewExtent(r); |
329 |
} |
330 |
|
331 |
// Fin del else
|
332 |
layout.repaint(); |
333 |
} |
334 |
} |
335 |
} |
336 |
} |
337 |
|
338 |
/**
|
339 |
* Realiza un zoom menos sobre la vista del FFrameView seleccionado.
|
340 |
*
|
341 |
* @param p2 Punto sobre el que realizar el zoom menos.
|
342 |
*/
|
343 |
public void setViewZoomOut(Point p2) { |
344 |
Point2D.Double pWorld;
|
345 |
|
346 |
for (int i = 0; i < layout.getFFrames().size(); i++) { |
347 |
if (layout.getFFrames().get(i) instanceof FFrameView) { |
348 |
FFrameView fframe = (FFrameView) layout.getFFrames().get(i); |
349 |
|
350 |
if (fframe.getSelected() != FFrame.NOSELECT) {
|
351 |
double nuevoX;
|
352 |
double nuevoY;
|
353 |
double cX;
|
354 |
double cY;
|
355 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
356 |
pWorld = functions.toMapPoint(pScreen, fframe.getAt()); |
357 |
|
358 |
cX = pWorld.getX(); |
359 |
cY = pWorld.getY(); |
360 |
|
361 |
double factor = 1.8; |
362 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
363 |
|
364 |
nuevoX = cX - |
365 |
((fframe.getFMap().getViewPort().getExtent().getWidth() * factor) / 2.0);
|
366 |
nuevoY = cY - |
367 |
((fframe.getFMap().getViewPort().getExtent().getHeight() * factor) / 2.0);
|
368 |
r.x = nuevoX; |
369 |
r.y = nuevoY; |
370 |
r.width = fframe.getFMap().getViewPort().getExtent() |
371 |
.getWidth() * factor; |
372 |
r.height = fframe.getFMap().getViewPort().getExtent() |
373 |
.getHeight() * factor; |
374 |
|
375 |
fframe.setNewExtent(r); |
376 |
|
377 |
///fframe.getFMap().setCancelDrawing(false);
|
378 |
} |
379 |
} |
380 |
} |
381 |
} |
382 |
} |