Revision 4203 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/FLayoutZooms.java
FLayoutZooms.java | ||
---|---|---|
44 | 44 |
*/ |
45 | 45 |
package com.iver.cit.gvsig.gui.layout; |
46 | 46 |
|
47 |
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView; |
|
48 | 47 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrame; |
49 | 48 |
import com.iver.cit.gvsig.gui.layout.fframes.IFFrameUseFMap; |
50 | 49 |
|
... | ... | |
61 | 60 |
*/ |
62 | 61 |
public class FLayoutZooms { |
63 | 62 |
private Layout layout = null; |
64 |
private FLayoutFunctions functions = null;
|
|
63 |
private static double FACTOR=2;
|
|
65 | 64 |
|
66 | 65 |
/** |
67 | 66 |
* Crea un nuevo Zooms. |
... | ... | |
70 | 69 |
*/ |
71 | 70 |
public FLayoutZooms(Layout l) { |
72 | 71 |
layout = l; |
73 |
functions = new FLayoutFunctions(layout); |
|
74 | 72 |
} |
75 | 73 |
|
76 | 74 |
/** |
... | ... | |
81 | 79 |
* @param p2 punto final del rec?ngulo. |
82 | 80 |
*/ |
83 | 81 |
public void setZoomIn(Point p1, Point p2) { |
84 |
/*if (p1.y != p2.y) { |
|
85 |
double points = (p2.getX() - p1.getX()) / (p2.getY() - p1.getY()); |
|
86 |
double window = (double) layout.getWidth() / (double)layout.getHeight(); |
|
87 |
|
|
88 |
if (points < window) { |
|
89 |
p2.x = (int) (p1.x + ((p2.x - p1.x) * window)); |
|
90 |
} |
|
91 |
} |
|
92 |
*/ |
|
93 |
|
|
94 | 82 |
if (p1.getX()>p2.getX()){ |
95 | 83 |
int aux=p2.x; |
96 | 84 |
p2.x=p1.x; |
... | ... | |
126 | 114 |
ymin = pSheet1.y; |
127 | 115 |
ymax = pSheet2.y; |
128 | 116 |
} |
129 |
|
|
130 |
Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
|
131 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
|
132 |
double x = FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
|
133 |
layout.getAT()); |
|
134 |
double y = FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
|
135 |
layout.getAT()); |
|
136 |
double w = FLayoutUtilities.toSheetDistance(layout.getRect().getWidth(), |
|
137 |
layout.getAT()); |
|
138 |
double h = FLayoutUtilities.toSheetDistance(layout.getRect().getHeight(), |
|
139 |
layout.getAT()); |
|
140 |
|
|
141 | 117 |
if (java.lang.Math.abs(layout.getFirstPoint().x - p2.x) < 4) { |
142 |
double difw = 2; |
|
143 |
|
|
144 |
rSheet.x = (-pSheet2.getX() * difw) - x + |
|
145 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2, |
|
146 |
layout.getAT()); |
|
147 |
rSheet.y = (-pSheet2.getY() * difw) - y + |
|
148 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2, |
|
149 |
layout.getAT()); |
|
150 |
|
|
151 |
rSheet.width = w * difw; |
|
152 |
rSheet.height = h * difw; |
|
153 |
|
|
154 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
|
155 |
layout.getAT())); |
|
156 |
IFFrame[] fframes=layout.getFFrames(); |
|
157 |
for (int i=0;i<fframes.length;i++){ |
|
158 |
if (fframes[i] instanceof FFrameView){ |
|
159 |
Point2D point1=new Point2D.Double(p2.getX()-(layout.getWidth()/2)*difw,p2.getY()-(layout.getHeight()/2)*difw); |
|
160 |
Point2D point2=new Point2D.Double(p2.getX()+(layout.getWidth()/2)*difw,p2.getY()+(layout.getHeight()/2)*difw); |
|
161 |
((FFrameView)fframes[i]).getRectView(point1,point2); |
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
|
|
118 |
setZoom(FACTOR,p2); |
|
166 | 119 |
} else { |
120 |
|
|
167 | 121 |
double wv = FLayoutUtilities.toSheetDistance(layout.getVisibleRect() |
168 | 122 |
.getWidth(), |
169 | 123 |
layout.getAT()); |
... | ... | |
176 | 130 |
double difh = hv / mh; |
177 | 131 |
|
178 | 132 |
if (difw < difh) { |
179 |
rSheet.x = (-xmin * difw) - x + |
|
180 |
((wv - ((pSheet2.getX() - pSheet1.getX()) * difw)) / 2); |
|
181 |
rSheet.y = (-ymin * difw) - y + |
|
182 |
((hv - ((pSheet2.getY() - pSheet1.getY()) * difw)) / 2); |
|
183 |
|
|
184 |
rSheet.width = w * difw; |
|
185 |
rSheet.height = h * difw; |
|
133 |
setZoom(difw,new Point((int)(p1.getX()+p2.getX())/2,(int)(p1.getY()+p2.getY())/2)); |
|
186 | 134 |
} else { |
187 |
rSheet.x = (-xmin * difh) - x + |
|
188 |
((wv - ((pSheet2.getX() - pSheet1.getX()) * difh)) / 2); |
|
189 |
rSheet.y = (-ymin * difh) - y + |
|
190 |
((hv - ((pSheet2.getY() - pSheet1.getY()) * difh)) / 2); |
|
191 |
|
|
192 |
rSheet.width = w * difh; |
|
193 |
rSheet.height = h * difh; |
|
135 |
setZoom(difh,new Point((int)(p1.getX()+p2.getX())/2,(int)(p1.getY()+p2.getY())/2)); |
|
194 | 136 |
} |
195 |
|
|
196 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, |
|
197 |
layout.getAT())); |
|
198 |
|
|
199 |
IFFrame[] fframes=layout.getFFrames(); |
|
200 |
for (int i=0;i<fframes.length;i++){ |
|
201 |
if (fframes[i] instanceof FFrameView){ |
|
202 |
((FFrameView)fframes[i]).getRectView(p1,p2); |
|
203 |
} |
|
204 |
} |
|
205 | 137 |
} |
206 |
|
|
207 |
if (FLayoutUtilities.isPosible(rScreen)) { |
|
208 |
layout.getRect().setRect(rScreen); |
|
209 |
} |
|
210 |
|
|
211 | 138 |
} |
212 | 139 |
|
213 | 140 |
/** |
... | ... | |
216 | 143 |
* @param p2 punto final del rec?ngulo. |
217 | 144 |
*/ |
218 | 145 |
public void setZoomOut(Point p2) { |
219 |
Point2D.Double pSheet2 = FLayoutUtilities.toSheetPoint(new Point2D.Double( |
|
220 |
p2.getX(), p2.getY()), layout.getAT()); |
|
221 |
|
|
222 |
Rectangle2D.Double rScreen = new Rectangle2D.Double(); |
|
223 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
|
224 |
|
|
225 |
double difw = 0.5; |
|
226 |
|
|
227 |
rSheet.x = (-pSheet2.getX() * difw) - |
|
228 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
|
229 |
layout.getAT()) + |
|
230 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2, |
|
231 |
layout.getAT()); |
|
232 |
rSheet.y = (-pSheet2.getY() * difw) - |
|
233 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
|
234 |
layout.getAT()) + |
|
235 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2, |
|
236 |
layout.getAT()); |
|
237 |
|
|
238 |
rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
|
239 |
.getWidth(), |
|
240 |
layout.getAT()) * difw; |
|
241 |
rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
|
242 |
.getHeight(), |
|
243 |
layout.getAT()) * difw; |
|
244 |
|
|
245 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
|
246 |
|
|
247 |
if (FLayoutUtilities.isPosible(rScreen)) { |
|
248 |
layout.getRect().setRect(rScreen); |
|
249 |
} |
|
250 |
IFFrame[] fframes=layout.getFFrames(); |
|
251 |
for (int i=0;i<fframes.length;i++){ |
|
252 |
if (fframes[i] instanceof FFrameView){ |
|
253 |
Point2D point1=new Point2D.Double(p2.getX()-(layout.getWidth()/2)*difw,p2.getY()-(layout.getHeight()/2)*difw); |
|
254 |
Point2D point2=new Point2D.Double(p2.getX()+(layout.getWidth()/2)*difw,p2.getY()+(layout.getHeight()/2)*difw); |
|
255 |
((FFrameView)fframes[i]).getRectView(point1,point2); |
|
256 |
} |
|
257 |
} |
|
146 |
setZoom(1/FACTOR, p2); |
|
258 | 147 |
} |
259 | 148 |
|
260 | 149 |
/** |
... | ... | |
270 | 159 |
Rectangle2D.Double rSheet = new Rectangle2D.Double(); |
271 | 160 |
|
272 | 161 |
double difw = dif; |
162 |
double x = FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
|
163 |
layout.getAT()); |
|
164 |
double y = FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
|
165 |
layout.getAT()); |
|
166 |
double w = FLayoutUtilities.toSheetDistance(layout.getRect().getWidth(), |
|
167 |
layout.getAT()); |
|
168 |
double h = FLayoutUtilities.toSheetDistance(layout.getRect().getHeight(), |
|
169 |
layout.getAT()); |
|
273 | 170 |
|
274 |
rSheet.x = (-pSheet2.getX() * difw) - |
|
275 |
FLayoutUtilities.toSheetDistance(layout.getRect().getX(), |
|
276 |
layout.getAT()) + |
|
171 |
rSheet.x = (-pSheet2.getX() * difw) - x + |
|
277 | 172 |
FLayoutUtilities.toSheetDistance(layout.getWidth() / 2, |
278 | 173 |
layout.getAT()); |
279 |
rSheet.y = (-pSheet2.getY() * difw) - |
|
280 |
FLayoutUtilities.toSheetDistance(layout.getRect().getY(), |
|
281 |
layout.getAT()) + |
|
174 |
rSheet.y = (-pSheet2.getY() * difw) - y + |
|
282 | 175 |
FLayoutUtilities.toSheetDistance(layout.getHeight() / 2, |
283 | 176 |
layout.getAT()); |
284 | 177 |
|
285 |
rSheet.width = FLayoutUtilities.toSheetDistance(layout.getRect() |
|
286 |
.getWidth(), |
|
287 |
layout.getAT()) * difw; |
|
288 |
rSheet.height = FLayoutUtilities.toSheetDistance(layout.getRect() |
|
289 |
.getHeight(), |
|
290 |
layout.getAT()) * difw; |
|
178 |
rSheet.width = w * difw; |
|
179 |
rSheet.height = h * difw; |
|
291 | 180 |
|
292 | 181 |
rScreen.setRect(FLayoutUtilities.fromSheetRect(rSheet, layout.getAT())); |
293 | 182 |
|
294 | 183 |
if (FLayoutUtilities.isPosible(rScreen)) { |
295 |
layout.getRect().setRect(rScreen);
|
|
184 |
layout.setRect(rScreen); |
|
296 | 185 |
} |
186 |
//////////// |
|
187 |
if (dif < 1) |
|
188 |
setZoomOutClip(difw,p2); |
|
189 |
else if (dif > 1) |
|
190 |
setZoomOutClip(difw,p2); |
|
191 |
///////////// |
|
297 | 192 |
} |
298 | 193 |
|
299 | 194 |
/** |
... | ... | |
314 | 209 |
* Realiza un zoom m?s a partir del punto central de pantalla. |
315 | 210 |
*/ |
316 | 211 |
public void zoomIn() { |
317 |
setZoom(2, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
|
|
212 |
setZoom(FACTOR, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
|
|
318 | 213 |
layout.setStatus(Layout.DESACTUALIZADO); |
319 | 214 |
layout.repaint(); |
320 | 215 |
} |
... | ... | |
323 | 218 |
* Realiza un zoom menos a partir del punto central de pantalla. |
324 | 219 |
*/ |
325 | 220 |
public void zoomOut() { |
326 |
setZoom(0.5, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
|
|
221 |
setZoom(1/FACTOR, new Point(layout.getWidth() / 2, layout.getHeight() / 2));
|
|
327 | 222 |
layout.setStatus(Layout.DESACTUALIZADO); |
328 | 223 |
layout.repaint(); |
329 | 224 |
} |
... | ... | |
367 | 262 |
IFFrameUseFMap fframe = (IFFrameUseFMap) layout.getFFrame(i); |
368 | 263 |
|
369 | 264 |
if (((IFFrame)fframe).getSelected() != IFFrame.NOSELECT) { |
370 |
p1 = functions.toMapPoint(p1, fframe.getATMap());
|
|
371 |
p2 = functions.toMapPoint(p2, fframe.getATMap());
|
|
265 |
p1 = FLayoutFunctions.toMapPoint(p1, fframe.getATMap());
|
|
266 |
p2 = FLayoutFunctions.toMapPoint(p2, fframe.getATMap());
|
|
372 | 267 |
|
373 | 268 |
// Borramos el anterior |
374 | 269 |
layout.setStatus(Layout.DESACTUALIZADO); |
... | ... | |
414 | 309 |
} |
415 | 310 |
} |
416 | 311 |
} |
312 |
/** |
|
313 |
* Realiza un zoom m?s sobre las vistas FFrameView. |
|
314 |
* |
|
315 |
* @param p1 punto inicial. |
|
316 |
* @param p2 punto final. |
|
317 |
*/ |
|
318 |
public void setZoomInClip(double dif,Point2D p1, Point2D p2) { |
|
319 |
double factor=1/dif; |
|
320 |
IFFrame[] fframes=layout.getFFrames(); |
|
321 |
for (int i = 0; i < fframes.length; i++) { |
|
322 |
if (fframes[i] instanceof IFFrameUseFMap) { |
|
323 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
|
324 |
Rectangle2D rect=new Rectangle2D.Double(); |
|
325 |
rect.setFrameFromDiagonal(p1, p2); |
|
326 |
if (p1.equals(p2)){ |
|
327 |
rect.setRect(p1.getX()-(layout.getBounds().width*factor)/2,p1.getY()-(layout.getBounds().height*factor)/2,layout.getBounds().width*factor,layout.getBounds().height*factor); |
|
328 |
} |
|
329 |
if (((IFFrame)fframes[i]).getBoundingBox(layout.getAT()).intersects(rect)){ |
|
330 |
p1 = FLayoutFunctions.toMapPoint(p1, fframe.getATMap()); |
|
331 |
p2 = FLayoutFunctions.toMapPoint(p2, fframe.getATMap()); |
|
417 | 332 |
|
333 |
// Borramos el anterior |
|
334 |
layout.setStatus(Layout.DESACTUALIZADO); |
|
335 |
|
|
336 |
if (java.lang.Math.abs(p1.getX() - p2.getX()) <= 3) { |
|
337 |
double nuevoX; |
|
338 |
double nuevoY; |
|
339 |
double cX; |
|
340 |
double cY; |
|
341 |
|
|
342 |
cX = p2.getX(); |
|
343 |
cY = p2.getY(); |
|
344 |
|
|
345 |
|
|
346 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
347 |
|
|
348 |
nuevoX = cX - |
|
349 |
((fframe.getFMap().getViewPort().getExtent() |
|
350 |
.getWidth() * factor) / 2.0); |
|
351 |
nuevoY = cY - |
|
352 |
((fframe.getFMap().getViewPort().getExtent() |
|
353 |
.getHeight() * factor) / 2.0); |
|
354 |
r.x = nuevoX; |
|
355 |
r.y = nuevoY; |
|
356 |
r.width = fframe.getFMap().getViewPort().getExtent() |
|
357 |
.getWidth() * factor; |
|
358 |
r.height = fframe.getFMap().getViewPort().getExtent() |
|
359 |
.getHeight() * factor; |
|
360 |
|
|
361 |
fframe.setNewExtent(r); |
|
362 |
} else { |
|
363 |
// Fijamos el nuevo extent |
|
364 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
365 |
|
|
366 |
r.setFrameFromDiagonal(p1, p2); |
|
367 |
|
|
368 |
fframe.setNewExtent(r); |
|
369 |
} |
|
370 |
fframe.refresh(); |
|
371 |
} |
|
372 |
} |
|
373 |
} |
|
374 |
} |
|
418 | 375 |
/** |
419 | 376 |
* Realiza un zoom menos sobre la vista del FFrameView seleccionado. |
420 | 377 |
* |
... | ... | |
433 | 390 |
double cX; |
434 | 391 |
double cY; |
435 | 392 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
436 |
pWorld = functions.toMapPoint(pScreen, fframe.getATMap());
|
|
393 |
pWorld = FLayoutFunctions.toMapPoint(pScreen, fframe.getATMap());
|
|
437 | 394 |
|
438 | 395 |
cX = pWorld.getX(); |
439 | 396 |
cY = pWorld.getY(); |
... | ... | |
459 | 416 |
} |
460 | 417 |
} |
461 | 418 |
} |
419 |
/** |
|
420 |
* Realiza un zoom menos sobre la vista. |
|
421 |
* |
|
422 |
* @param p2 Punto sobre el que realizar el zoom menos. |
|
423 |
*/ |
|
424 |
public void setZoomOutClip(double dif,Point p2) { |
|
425 |
Point2D.Double pWorld; |
|
426 |
double factor=1/dif; |
|
427 |
for (int i = 0; i < layout.getFFrames().length; i++) { |
|
428 |
IFFrame[] fframes=layout.getFFrames(); |
|
429 |
if (fframes[i] instanceof IFFrameUseFMap) { |
|
430 |
IFFrameUseFMap fframe = (IFFrameUseFMap) fframes[i]; |
|
431 |
Rectangle2D rect=layout.getBounds(); |
|
432 |
if (((IFFrame)fframes[i]).getBoundingBox(layout.getAT()).intersects(rect)){ |
|
433 |
double nuevoX; |
|
434 |
double nuevoY; |
|
435 |
double cX; |
|
436 |
double cY; |
|
437 |
Point pScreen = new Point((int) p2.getX(), (int) p2.getY()); |
|
438 |
pWorld = FLayoutFunctions.toMapPoint(pScreen, fframe.getATMap()); |
|
439 |
|
|
440 |
cX = pWorld.getX(); |
|
441 |
cY = pWorld.getY(); |
|
442 |
Rectangle2D.Double r = new Rectangle2D.Double(); |
|
443 |
nuevoX = cX - |
|
444 |
((fframe.getFMap().getViewPort().getExtent().getWidth() * factor) / 2.0); |
|
445 |
nuevoY = cY - |
|
446 |
((fframe.getFMap().getViewPort().getExtent().getHeight() * factor) / 2.0); |
|
447 |
r.x = nuevoX; |
|
448 |
r.y = nuevoY; |
|
449 |
r.width = fframe.getFMap().getViewPort().getExtent() |
|
450 |
.getWidth() * factor; |
|
451 |
r.height = fframe.getFMap().getViewPort().getExtent() |
|
452 |
.getHeight() * factor; |
|
453 |
|
|
454 |
fframe.setNewExtent(r); |
|
455 |
fframe.refresh(); |
|
456 |
///fframe.getFMap().setCancelDrawing(false); |
|
457 |
} |
|
458 |
} |
|
459 |
} |
|
460 |
} |
|
462 | 461 |
} |
Also available in: Unified diff