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