Revision 142 branches/usability_v2/org.gvsig.app.document.layout.app/org.gvsig.app.document.layout.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java
FFrameView.java | ||
---|---|---|
36 | 36 |
import java.awt.image.BufferedImage; |
37 | 37 |
|
38 | 38 |
import javax.swing.SwingUtilities; |
39 |
import javax.swing.plaf.InternalFrameUI; |
|
39 | 40 |
|
40 | 41 |
import org.cresques.cts.IProjection; |
41 | 42 |
import org.slf4j.Logger; |
... | ... | |
65 | 66 |
import org.gvsig.fmap.mapcontext.events.ExtentEvent; |
66 | 67 |
import org.gvsig.fmap.mapcontext.events.ProjectionEvent; |
67 | 68 |
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener; |
69 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
|
70 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionEvent; |
|
71 |
import org.gvsig.fmap.mapcontext.layers.LayerCollectionListener; |
|
72 |
import org.gvsig.fmap.mapcontext.layers.LayerPositionEvent; |
|
68 | 73 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendChangedEvent; |
69 | 74 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.listeners.LegendListener; |
70 | 75 |
import org.gvsig.gui.beans.Messages; |
... | ... | |
79 | 84 |
* |
80 | 85 |
* @author Vicente Caballero Navarro |
81 | 86 |
*/ |
82 |
public class FFrameView extends FFrame implements ViewPortListener, |
|
83 |
LegendListener, IFFrameUseProject, IFFrameUseFMap { |
|
87 |
public class FFrameView extends FFrame implements IFFrameUseProject, IFFrameUseFMap { |
|
84 | 88 |
|
85 | 89 |
public static final String PERSISTENCE_DEFINITION_NAME = "FFrameView"; |
86 | 90 |
|
... | ... | |
110 | 114 |
protected boolean linked = true; |
111 | 115 |
protected ViewDocument viewDocument = null; |
112 | 116 |
protected MapContext mapContext = null; |
113 |
protected double mapScale = 0; |
|
114 | 117 |
protected int mapUnits = 1; // Meters. |
115 | 118 |
|
116 | 119 |
protected BufferedImage m_image = null; |
117 | 120 |
protected AffineTransform at = null; |
118 | 121 |
protected Project project = null; |
119 | 122 |
protected double scaleAnt; |
120 |
protected boolean refresh = false; |
|
121 | 123 |
protected Point origin; |
122 | 124 |
protected Point2D p1; |
123 | 125 |
protected Point2D p2; |
124 | 126 |
protected IFFrame grid; |
125 | 127 |
protected boolean showGrid = false; |
126 | 128 |
|
129 |
private boolean b_viewOriginatedUpdate = false; |
|
130 |
private boolean b_fframeOriginatedUpdate = false; |
|
131 |
private boolean b_validCache = false; |
|
132 |
protected ViewDocListener viewDocListener = new ViewDocListener(); |
|
133 |
protected OwnMapContextListener ownMapContextListener = new OwnMapContextListener(); |
|
134 |
|
|
135 |
|
|
127 | 136 |
/** |
128 | 137 |
* Creates a new FFrameView object. |
129 | 138 |
*/ |
... | ... | |
151 | 160 |
* escala de la vista. |
152 | 161 |
*/ |
153 | 162 |
public void setScale(double d) { |
154 |
mapScale = d; |
|
163 |
if (getMapContext()!=null) { |
|
164 |
getMapContext().setScaleView((long) d); |
|
165 |
} |
|
155 | 166 |
} |
156 | 167 |
|
157 | 168 |
/** |
... | ... | |
161 | 172 |
* Rect?ngulo a ocupar por el FFrameView. |
162 | 173 |
*/ |
163 | 174 |
public void setNewEnvelope(Envelope r) { |
164 |
getMapContext().getViewPort().setEnvelope(r); |
|
165 |
refresh = true; |
|
166 |
mapScale = |
|
167 |
FLayoutUtilities.getScaleView(getMapContext().getViewPort(), |
|
168 |
getBoundBox().width, getBoundingBox(null).width); |
|
169 |
updateScaleCtrl(); |
|
175 |
getMapContext().getViewPort().setEnvelope(r); |
|
176 |
updateScaleCtrl(); |
|
170 | 177 |
} |
171 | 178 |
|
172 | 179 |
/** |
... | ... | |
208 | 215 |
return quality; |
209 | 216 |
} |
210 | 217 |
|
218 |
public void setViewMapContext(MapContext viewMapContext) { |
|
219 |
if (viewMapContext!=null) { |
|
220 |
clearViewListeners(viewMapContext); |
|
221 |
} |
|
222 |
if (mapContext!=null) { |
|
223 |
clearOwnListeners(mapContext); |
|
224 |
} |
|
225 |
try { |
|
226 |
if (linked){ |
|
227 |
mapContext = |
|
228 |
viewMapContext.createNewFMap( |
|
229 |
(ViewPort) viewMapContext.getViewPort().clone()); |
|
230 |
} |
|
231 |
else { |
|
232 |
mapContext = viewMapContext.cloneFMap(); |
|
233 |
mapContext.setViewPort((ViewPort) viewMapContext |
|
234 |
.getViewPort().clone()); |
|
235 |
} |
|
236 |
ViewPort newViewPort = getMapContext().getViewPort(); |
|
237 |
newViewPort.setImageSize(new Dimension((int) getBoundingBox(null).width, |
|
238 |
(int) getBoundingBox(null).height)); |
|
239 |
newViewPort.setDPI(getDrawPaperDPI()); |
|
240 |
setListeners(); |
|
241 |
updateScaleCtrl(); |
|
242 |
} catch (CloneNotSupportedException e1) { |
|
243 |
NotificationManager.addError("Excepci?n :", e1); |
|
244 |
} |
|
245 |
|
|
246 |
} |
|
211 | 247 |
/** |
212 | 248 |
* Inserta el ProjectView de donde obtener las propiedades de la vista a |
213 | 249 |
* mostrar. |
... | ... | |
216 | 252 |
* Modelo de la vista. |
217 | 253 |
*/ |
218 | 254 |
public void setView(ViewDocument dvd) { |
219 |
|
|
220 | 255 |
viewDocument = dvd; |
221 |
MapContext mctxt = dvd.getMapContext(); |
|
222 |
|
|
223 |
ViewPort vp = null; |
|
224 |
if (getMapContext() != null) { |
|
225 |
vp = getMapContext().getViewPort(); |
|
226 |
}else{ |
|
227 |
try { |
|
228 |
vp = (ViewPort) mctxt.getViewPort().clone(); |
|
229 |
} catch (CloneNotSupportedException e1) { |
|
230 |
NotificationManager.addError("Excepci?n :", e1); |
|
231 |
} |
|
232 |
|
|
256 |
if (dvd!=null) { |
|
257 |
setViewMapContext(dvd.getMapContext()); |
|
233 | 258 |
} |
234 |
vp.setImageSize(new Dimension((int) getBoundingBox(null).width, |
|
235 |
(int) getBoundingBox(null).height)); |
|
236 |
|
|
237 |
if (linked){ |
|
238 |
if (getTypeScale() == AUTOMATICO) { |
|
239 |
try { |
|
240 |
mapContext = |
|
241 |
mctxt.createNewFMap( |
|
242 |
(ViewPort) mctxt.getViewPort().clone()); |
|
243 |
} catch (CloneNotSupportedException e1) { |
|
244 |
NotificationManager.addError("Excepci?n :", e1); |
|
245 |
} |
|
246 |
|
|
247 |
mapContext.getViewPort().setImageSize( |
|
248 |
new Dimension((int) getBoundingBox(null).width, |
|
249 |
(int) getBoundingBox(null).height)); |
|
250 |
mctxt.getViewPort().addViewPortListener(this); |
|
251 |
mctxt.addLayerListener(this); |
|
252 |
}else{ |
|
253 |
if (getTypeScale() == CONSTANTE) { |
|
254 |
mapContext = mctxt.createNewFMap(vp); |
|
255 |
vp.setEnvelope(getNewEnvelope(getScale())); |
|
256 |
mctxt.getViewPort().addViewPortListener(this); |
|
257 |
mctxt.addLayerListener(this); |
|
258 |
}else{ |
|
259 |
if (getTypeScale() == MANUAL) { |
|
260 |
mapContext = mctxt.createNewFMap(vp); |
|
261 |
vp.setEnvelope(getNewEnvelope(getScale())); |
|
262 |
mctxt.getViewPort() |
|
263 |
.addViewPortListener(this); |
|
264 |
mctxt.addLayerListener(this); |
|
265 |
} |
|
266 |
} |
|
267 |
} |
|
268 |
}else{ |
|
269 |
if (!linked) { |
|
270 |
|
|
271 |
if (getTypeScale() == AUTOMATICO) { |
|
272 |
mapContext = mctxt.cloneFMap(); |
|
273 |
// (v.getMapContext().getViewPort().cloneViewPort()); |
|
274 |
try { |
|
275 |
mapContext.setViewPort((ViewPort) mctxt |
|
276 |
.getViewPort().clone()); |
|
277 |
} catch (CloneNotSupportedException e1) { |
|
278 |
NotificationManager.addError("Excepci?n :", e1); |
|
279 |
} |
|
280 |
mapContext.getViewPort().setImageSize( |
|
281 |
new Dimension((int) getBoundingBox(null).width, |
|
282 |
(int) getBoundingBox(null).height)); |
|
283 |
mctxt.getViewPort().addViewPortListener(this); |
|
284 |
}else{ |
|
285 |
if (getTypeScale() == CONSTANTE) { |
|
286 |
mapContext = mctxt.cloneFMap(); |
|
287 |
vp.setEnvelope(getNewEnvelope(getScale())); |
|
288 |
mapContext.setViewPort(vp); |
|
289 |
mctxt.getViewPort().addViewPortListener(this); |
|
290 |
}else{ |
|
291 |
if (getTypeScale() == MANUAL) { |
|
292 |
mapContext = mctxt.cloneFMap(); |
|
293 |
vp.setEnvelope(getNewEnvelope(getScale())); |
|
294 |
mapContext.setViewPort(vp); |
|
295 |
mctxt.getViewPort() |
|
296 |
.addViewPortListener(this); |
|
297 |
} |
|
298 |
} |
|
299 |
} |
|
300 |
} |
|
301 |
} |
|
302 | 259 |
} |
303 | 260 |
|
304 | 261 |
/** |
... | ... | |
311 | 268 |
} |
312 | 269 |
|
313 | 270 |
/** |
314 |
* Devuelve un Rect?ngulo que representa el extent de la vista que se |
|
315 |
* requiere a partir de una escala. |
|
316 |
* |
|
317 |
* @param scale |
|
318 |
* Escala a mostrar. |
|
319 |
* |
|
320 |
* @return Rect?ngulo. |
|
321 |
*/ |
|
322 |
protected Envelope getNewEnvelope(long scale) { |
|
323 |
double hview = getBoundBox().getHeight(); |
|
324 |
double wview = getBoundBox().getWidth(); |
|
325 |
double hextent = (scale * hview) / 100.0; |
|
326 |
double wextent = (scale * wview) / 100.0; |
|
327 |
|
|
328 |
if (mapContext.getViewPort().getEnvelope() == null) { |
|
329 |
try { |
|
330 |
return geomManager.createEnvelope(0, 0, 0, 0, SUBTYPES.GEOM2D); |
|
331 |
} catch (CreateEnvelopeException e) { |
|
332 |
logger.error("Error creating the envelope", e); |
|
333 |
return null; |
|
334 |
} |
|
335 |
} |
|
336 |
double newx = |
|
337 |
mapContext.getViewPort().getEnvelope().getCenter(Geometry.DIMENSIONS.X) |
|
338 |
- (wextent / 2.0); |
|
339 |
double newy = |
|
340 |
mapContext.getViewPort().getEnvelope().getCenter(Geometry.DIMENSIONS.Y) |
|
341 |
- (hextent / 2.0); |
|
342 |
IProjection proj = mapContext.getViewPort().getProjection(); |
|
343 |
Envelope r = null; |
|
344 |
try { |
|
345 |
r = |
|
346 |
geomManager.createEnvelope(newx, newy, newx + wextent, newy |
|
347 |
+ hextent, SUBTYPES.GEOM2D); |
|
348 |
} catch (CreateEnvelopeException e) { |
|
349 |
logger.error("Error creating the envelope", e); |
|
350 |
} |
|
351 |
if (!proj.isProjected()) { |
|
352 |
Rectangle2D auxR = |
|
353 |
new Rectangle2D.Double(newx, newy, wextent, hextent); |
|
354 |
Rectangle2D aux = |
|
355 |
mapContext.getViewPort().getProjection() |
|
356 |
.getExtent(auxR, scale, wview, hview, 1, 100, 2.54); |
|
357 |
try { |
|
358 |
r = |
|
359 |
geomManager.createEnvelope(aux.getX(), aux.getY(), |
|
360 |
aux.getMaxX(), aux.getMaxY(), SUBTYPES.GEOM2D); |
|
361 |
} catch (CreateEnvelopeException e) { |
|
362 |
logger.error("Error creating the envelope", e); |
|
363 |
} |
|
364 |
} |
|
365 |
return r; |
|
366 |
} |
|
367 |
|
|
368 |
/** |
|
369 | 271 |
* Draws the FFrameView on the provided Graphics, according to the |
370 | 272 |
* provided affine transform and the visible rectangle. |
371 | 273 |
* |
... | ... | |
443 | 345 |
Color theBackColor = viewPort.getBackColor(); |
444 | 346 |
int drawWidth = (int)fframeViewRect.width; |
445 | 347 |
int drawHeight = (int)fframeViewRect.height; |
446 |
|
|
348 |
/* |
|
349 |
* TODO INVERTIR LA CONDICION |
|
350 |
if (origin == null || |
|
351 |
!origin.equals(mapOrigin) || |
|
352 |
affineTransform.getScaleX() != scaleAnt || |
|
353 |
m_image == null || |
|
354 |
!b_validCache || |
|
355 |
) { |
|
356 |
} |
|
357 |
*/ |
|
447 | 358 |
//If the image has to be created... |
448 | 359 |
if (!(origin != null |
449 | 360 |
&& origin.equals(mapOrigin) |
450 | 361 |
&& affineTransform.getScaleX() == scaleAnt |
451 | 362 |
&& m_image != null |
452 |
&& !refresh
|
|
363 |
&& b_validCache
|
|
453 | 364 |
&& !(fframeViewRect.getWidth() > visibleLayoutDocRect.getWidth() || fframeViewRect.getHeight() > visibleLayoutDocRect.getHeight()))) { |
454 | 365 |
|
455 | 366 |
viewPort.setImageSize(new Dimension(drawWidth, drawHeight)); |
456 |
viewPort.refreshExtent(); // comprobar si es necesario; el setImageSize ya calcula la nueva AT, pero no lanza el evento extentChanged |
|
457 | 367 |
viewPort.setDPI(getDrawPaperDPI()); |
458 | 368 |
m_image = |
459 | 369 |
new BufferedImage( |
... | ... | |
461 | 371 |
drawHeight, |
462 | 372 |
BufferedImage.TYPE_INT_ARGB); |
463 | 373 |
|
464 |
Graphics2D gimg = (Graphics2D) m_image.createGraphics(); |
|
465 |
|
|
466 |
|
|
467 |
getMapContext().draw(m_image, gimg, getScale()); |
|
468 |
gimg.dispose(); |
|
469 |
refresh = false; |
|
374 |
Graphics2D gimg = (Graphics2D) m_image.createGraphics(); |
|
375 |
getMapContext().draw(m_image, gimg, getScale()); |
|
376 |
gimg.dispose(); |
|
377 |
b_validCache = true; |
|
470 | 378 |
} |
471 | 379 |
|
472 | 380 |
//Draw the created image |
... | ... | |
512 | 420 |
} |
513 | 421 |
} |
514 | 422 |
|
515 |
private Envelope calculateEnvelope() { |
|
516 |
if (p1 == null || p2 == null) { |
|
517 |
try { |
|
518 |
return geomManager.createEnvelope(0, 0, 0, 0, SUBTYPES.GEOM2D); |
|
519 |
} catch (CreateEnvelopeException e) { |
|
520 |
logger.error("Error creating the envelope", e); |
|
521 |
} |
|
522 |
} |
|
523 |
Envelope r = null; |
|
524 |
try { |
|
525 |
r = |
|
526 |
geomManager.createEnvelope(p1.getX(), p1.getY(), p2.getX(), |
|
527 |
p2.getY(), SUBTYPES.GEOM2D); |
|
528 |
} catch (CreateEnvelopeException e) { |
|
529 |
logger.error("Error creating the envelope", e); |
|
530 |
} |
|
531 |
return r; |
|
532 |
} |
|
533 |
|
|
534 | 423 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
535 | 424 |
PrintAttributes printAttributes) { |
536 | 425 |
Rectangle2D.Double rectangleLayout = getBoundingBox(at); |
... | ... | |
545 | 434 |
|
546 | 435 |
protected void print(Graphics2D g, AffineTransform at, PrintAttributes printAttributes) { |
547 | 436 |
Rectangle2D.Double layoutRectangle = getBoundingBox(at); |
548 |
|
|
437 |
|
|
438 |
// FIXME: should we clone the mapcontext and viewport before printing ?? |
|
439 |
// otherwise we will probably have unexpected results if the user modifies |
|
440 |
// the layout while printing |
|
549 | 441 |
ViewPort viewPort = this.getMapContext().getViewPort(); |
550 | 442 |
|
551 | 443 |
Point2D old_offset = viewPort.getOffset(); |
... | ... | |
603 | 495 |
* @return escala. |
604 | 496 |
*/ |
605 | 497 |
public long getScale() { |
606 |
/* |
|
607 |
* if (m_bLinked){ |
|
608 |
* return getScaleView1(METROS); |
|
609 |
* } |
|
610 |
*/ |
|
611 |
if (getMapContext() == null) { |
|
612 |
return 0; |
|
613 |
} |
|
614 |
if (getTypeScale() == AUTOMATICO) { |
|
615 |
return FLayoutUtilities.getScaleView(getMapContext().getViewPort(), |
|
616 |
getBoundBox().width, getBoundingBox(null).width); |
|
617 |
} else |
|
618 |
if (getTypeScale() == CONSTANTE) { |
|
619 |
return (long) mapScale; |
|
620 |
} else |
|
621 |
if (getTypeScale() == MANUAL) { |
|
622 |
return (long) mapScale; |
|
623 |
} |
|
624 |
|
|
625 |
return (long) mapScale; |
|
498 |
return (long) getMapContext().getScaleView(); |
|
626 | 499 |
} |
627 | 500 |
|
628 | 501 |
/** |
... | ... | |
633 | 506 |
*/ |
634 | 507 |
public void setLinked(boolean b) { |
635 | 508 |
linked = b; |
509 |
resetListeners(); |
|
636 | 510 |
} |
637 | 511 |
|
638 | 512 |
/** |
... | ... | |
645 | 519 |
} |
646 | 520 |
|
647 | 521 |
/** |
648 |
* Devuelve la opci?n seleccionada:Rellenar marco de la vista o recorte a |
|
649 |
* la vista. |
|
650 |
* |
|
651 |
* @return entero que representa la opci?n elegida. |
|
652 |
*/ |
|
653 |
public int getExtension() { |
|
654 |
return extension; |
|
655 |
} |
|
656 |
|
|
657 |
/** |
|
658 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO,CONSTANTE o |
|
522 |
* Devuelve el tipo de escala que est? seleccionada AUTOMATICO o |
|
659 | 523 |
* MANUAL. |
660 | 524 |
* |
661 | 525 |
* @return entero que representa el tipo seleccionado. |
... | ... | |
665 | 529 |
} |
666 | 530 |
|
667 | 531 |
/** |
668 |
* Rellenar si se quiere:Rellenar marco de la vista o recorte a la vista. |
|
669 |
* |
|
670 |
* @param i |
|
671 |
* entero que representa la opci?n elegida. |
|
672 |
*/ |
|
673 |
public void setExtension(int i) { |
|
674 |
extension = i; |
|
675 |
} |
|
676 |
|
|
677 |
/** |
|
678 | 532 |
* Rellenar el tipo de escala que se desea. |
679 | 533 |
* |
680 | 534 |
* @param i |
... | ... | |
682 | 536 |
*/ |
683 | 537 |
public void setTypeScale(int i) { |
684 | 538 |
typeScale = i; |
539 |
resetListeners(); |
|
685 | 540 |
} |
686 | 541 |
|
687 | 542 |
/** |
... | ... | |
744 | 599 |
} |
745 | 600 |
|
746 | 601 |
/** |
747 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(org.gvsig.fmap.mapcontext.events.ExtentEvent) |
|
748 |
*/ |
|
749 |
public void extentChanged(ExtentEvent e) { |
|
750 |
if (linked){ |
|
751 |
if (getTypeScale() == AUTOMATICO) { |
|
752 |
mapContext.getViewPort().setEnvelope(e.getNewExtent()); |
|
753 |
// observers.notifyObservers(this, |
|
754 |
// new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
755 |
observers.notifyObservers(this, |
|
756 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH)); |
|
757 |
} else |
|
758 |
if (getTypeScale() == MANUAL) { |
|
759 |
Envelope oldExtent = mapContext.getViewPort().getEnvelope(); |
|
760 |
Envelope newExtent = e.getNewExtent(); |
|
761 |
double xDif = newExtent.getCenter(0) - oldExtent.getCenter(0); |
|
762 |
double yDif = newExtent.getCenter(1) - oldExtent.getCenter(1); |
|
763 |
try { |
|
764 |
mapContext.getViewPort().setEnvelope( |
|
765 |
geomManager.createEnvelope(oldExtent.getMinimum(0) |
|
766 |
+ xDif, oldExtent.getMinimum(1) + yDif, |
|
767 |
oldExtent.getMaximum(0) + xDif, |
|
768 |
oldExtent.getMaximum(1) + yDif, SUBTYPES.GEOM2D)); |
|
769 |
} catch (CreateEnvelopeException e1) { |
|
770 |
e1.printStackTrace(); |
|
771 |
} |
|
772 |
|
|
773 |
observers.notifyObservers(this, |
|
774 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
775 |
|
|
776 |
} |
|
777 |
refresh = true; |
|
778 |
} |
|
779 |
updateScaleCtrl(); |
|
780 |
} |
|
781 |
|
|
782 |
/** |
|
783 |
* @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#backColorChanged(org.gvsig.fmap.mapcontext.events.ColorEvent) |
|
784 |
*/ |
|
785 |
public void backColorChanged(ColorEvent e) { |
|
786 |
if (getLinked()) { |
|
787 |
mapContext.getViewPort().setBackColor(e.getNewColor()); |
|
788 |
observers.notifyObservers(this, |
|
789 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
790 |
} |
|
791 |
} |
|
792 |
|
|
793 |
/** |
|
794 |
* @see org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener#projectionChanged(org.gvsig.fmap.mapcontext.events.ProjectionEvent) |
|
795 |
*/ |
|
796 |
public void projectionChanged(ProjectionEvent e) { |
|
797 |
if (getTypeScale() == AUTOMATICO) { |
|
798 |
mapContext.getViewPort().setProjection(e.getNewProjection()); |
|
799 |
observers.notifyObservers(this, |
|
800 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
801 |
} |
|
802 |
} |
|
803 |
|
|
804 |
/** |
|
805 | 602 |
* DOCUMENT ME! |
806 | 603 |
* |
807 |
* @param e |
|
808 |
* DOCUMENT ME! |
|
809 |
*/ |
|
810 |
public void legendChanged(final LegendChangedEvent e) { |
|
811 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
812 |
SwingUtilities.invokeLater(new Runnable() { |
|
813 |
|
|
814 |
public void run() { |
|
815 |
legendChanged(e); |
|
816 |
} |
|
817 |
}); |
|
818 |
return; |
|
819 |
} |
|
820 |
if (getLinked()) { |
|
821 |
observers.notifyObservers(this, |
|
822 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
823 |
refresh = true; |
|
824 |
} |
|
825 |
} |
|
826 |
|
|
827 |
/** |
|
828 |
* DOCUMENT ME! |
|
829 |
* |
|
830 | 604 |
* @param arg0 |
831 | 605 |
* DOCUMENT ME! |
832 | 606 |
* |
... | ... | |
865 | 639 |
} |
866 | 640 |
return true; |
867 | 641 |
} |
868 |
|
|
869 |
/* |
|
870 |
* This was causing issues with the notifications |
|
871 |
* because different instances were considered the same |
|
872 |
* after cloning a frame (the frame is cloned for example |
|
873 |
* when the user changes size of frame) |
|
874 |
* |
|
875 |
public boolean equals(Object arg0) { |
|
876 |
return this.compare(arg0); |
|
877 |
} |
|
878 |
*/ |
|
879 |
|
|
880 |
public void refresh() { |
|
881 |
if (viewDocument != null |
|
882 |
&& (getTypeScale() == MANUAL || getTypeScale() == CONSTANTE)) { |
|
883 |
getMapContext().getViewPort().setEnvelope( |
|
884 |
getNewEnvelope(getScale())); |
|
885 |
updateScaleCtrl(); |
|
886 |
} |
|
887 |
refresh = true; |
|
888 |
} |
|
889 | 642 |
|
890 | 643 |
public void updateScaleCtrl() { |
891 | 644 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar(); |
... | ... | |
893 | 646 |
statusbar.setMessage("units", |
894 | 647 |
PluginServices.getText(this, mapContext.getDistanceName())); |
895 | 648 |
statusbar.setControlValue("layout-view-change-scale", |
896 |
String.valueOf(getScale()));
|
|
649 |
String.valueOf(getMapContext().getScaleView()));
|
|
897 | 650 |
IProjection proj = mapContext.getViewPort().getProjection(); |
898 | 651 |
if (proj != null) { |
899 | 652 |
statusbar.setMessage("projection", proj.getAbrev()); |
... | ... | |
927 | 680 |
* that 'this' instance is doing. |
928 | 681 |
*/ |
929 | 682 |
protected void cloneActions(FFrameView frame) { |
930 |
if (viewDocument == null || viewDocument.getMapContext() == null) { |
|
931 |
return; |
|
932 |
} |
|
933 |
|
|
934 |
frame.setTypeScale(this.getTypeScale()); |
|
935 |
frame.setLinked(linked); |
|
936 |
|
|
937 |
if (linked) { |
|
938 |
if (getTypeScale() == AUTOMATICO) { |
|
939 |
frame.viewDocument.getMapContext().getViewPort().addViewPortListener(frame); |
|
940 |
frame.viewDocument.getMapContext().addLayerListener(frame); |
|
941 |
} else |
|
942 |
if (getTypeScale() == CONSTANTE) { |
|
943 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
|
944 |
frame.viewDocument.getMapContext().addLayerListener(frame); |
|
945 |
} else |
|
946 |
if (getTypeScale() == MANUAL) { |
|
947 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
|
948 |
frame.viewDocument.getMapContext().addLayerListener(frame); |
|
949 |
} |
|
950 |
} else |
|
951 |
if (!linked) { |
|
952 |
if (getTypeScale() == AUTOMATICO) { |
|
953 |
frame.viewDocument.getMapContext().getViewPort().addViewPortListener(frame); |
|
954 |
} else |
|
955 |
if (getTypeScale() == CONSTANTE) { |
|
956 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
|
957 |
} else |
|
958 |
if (getTypeScale() == MANUAL) { |
|
959 |
frame.viewDocument.getMapContext().getViewPort().removeViewPortListener(frame); |
|
960 |
} |
|
961 |
} |
|
962 |
/* |
|
963 |
((FFrameView) frame).viewDocument.getMapContext().removeLayerListener( |
|
964 |
(FFrameView) frame); |
|
965 |
((FFrameView) frame).viewDocument.getMapContext().getViewPort() |
|
966 |
.removeViewPortListener((FFrameView) frame); |
|
967 |
*/ |
|
968 | 683 |
} |
969 | 684 |
|
970 | 685 |
public Object clone() throws CloneNotSupportedException { |
971 | 686 |
FFrameView frame = (FFrameView) super.clone(); |
687 |
frame.setSelected(this.isSelected()); |
|
688 |
frame.setTypeScale(this.getTypeScale()); |
|
689 |
frame.setLinked(linked); |
|
690 |
frame.setView(this.getView()); |
|
972 | 691 |
|
973 |
frame.setSelected(this.getSelected() != IFFrame.NOSELECT); |
|
974 |
|
|
975 | 692 |
if (grid != null) { |
976 | 693 |
FFrameGrid newGrid = (FFrameGrid) this.grid.clone(); |
977 | 694 |
newGrid.setFFrameDependence(frame); |
... | ... | |
1006 | 723 |
} |
1007 | 724 |
|
1008 | 725 |
public void refreshOriginalExtent() { |
726 |
/* |
|
1009 | 727 |
if (getTypeScale() == AUTOMATICO) { |
1010 | 728 |
viewDocument.getMapContext().getViewPort() |
1011 | 729 |
.setEnvelope(getMapContext().getViewPort().getEnvelope()); |
... | ... | |
1031 | 749 |
} |
1032 | 750 |
viewDocument.getMapContext().getViewPort().refreshExtent(); |
1033 | 751 |
} |
752 |
*/ |
|
1034 | 753 |
} |
1035 | 754 |
|
1036 | 755 |
public static void registerPersistent() { |
... | ... | |
1050 | 769 |
definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true); |
1051 | 770 |
definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(true); |
1052 | 771 |
definition.addDynFieldInt(MAPUNITS_FIELD).setMandatory(true); |
1053 |
definition.addDynFieldDouble(SCALE_FIELD).setMandatory(true);
|
|
772 |
definition.addDynFieldDouble(SCALE_FIELD).setMandatory(false);
|
|
1054 | 773 |
definition.addDynFieldObject(VIEW_FIELD) |
1055 | 774 |
.setClassOfValue(ViewDocument.class).setMandatory(false); |
1056 | 775 |
definition.addDynFieldObject(ENVELOPE_FIELD) |
... | ... | |
1072 | 791 |
extension = state.getInt(EXTENSION_FIELD); |
1073 | 792 |
quality = state.getInt(QUALITY_FIELD); |
1074 | 793 |
linked = state.getBoolean(BLINKED_FIELD); |
1075 |
mapUnits = state.getInt(MAPUNITS_FIELD); |
|
1076 |
mapScale = state.getDouble(SCALE_FIELD); |
|
794 |
mapUnits = state.getInt(MAPUNITS_FIELD);; |
|
1077 | 795 |
viewDocument = (ViewDocument) state.get(VIEW_FIELD); |
1078 | 796 |
|
1079 | 797 |
if (state.hasValue(MAPCONTEXT_FIELD)) { |
1080 | 798 |
mapContext = (MapContext) state.get(MAPCONTEXT_FIELD); |
799 |
double mapScale = state.getDouble(SCALE_FIELD); |
|
800 |
mapContext.setScaleView((long)mapScale); // FIXME: really needed?? probably already persisted on Mapcontext |
|
1081 | 801 |
mapContext.getViewPort().setEnvelope( |
1082 | 802 |
(Envelope) state.get(ENVELOPE_FIELD)); |
1083 | 803 |
} |
... | ... | |
1095 | 815 |
state.set(QUALITY_FIELD, quality); |
1096 | 816 |
state.set(BLINKED_FIELD, linked); |
1097 | 817 |
state.set(MAPUNITS_FIELD, mapUnits); |
1098 |
state.set(SCALE_FIELD, mapScale); |
|
1099 | 818 |
state.set(VIEW_FIELD, viewDocument); |
1100 | 819 |
|
1101 | 820 |
if (getMapContext() != null |
1102 | 821 |
&& getMapContext().getViewPort().getEnvelope() != null) { |
1103 | 822 |
state.set(ENVELOPE_FIELD, getMapContext().getViewPort() |
1104 | 823 |
.getEnvelope()); |
824 |
state.set(SCALE_FIELD, getMapContext().getScaleView()); |
|
1105 | 825 |
state.set(MAPCONTEXT_FIELD, mapContext); |
1106 | 826 |
} |
1107 | 827 |
|
... | ... | |
1110 | 830 |
} |
1111 | 831 |
|
1112 | 832 |
@Override |
1113 |
public void setBoundBox(Rectangle2D r) { |
|
1114 |
super.setBoundBox(r); |
|
1115 |
refresh(); |
|
833 |
public void setBoundBox(Rectangle2D r) { |
|
834 |
super.setBoundBox(r); |
|
835 |
if (getMapContext()!=null) { |
|
836 |
getMapContext().getViewPort().setImageSize( |
|
837 |
new Dimension((int)r.getWidth(), (int)r.getHeight())); |
|
838 |
getMapContext().getViewPort().setDPI(getDrawPaperDPI()); |
|
839 |
updateScaleCtrl(); |
|
840 |
// FIXME: what should we do here? should we invalidate the cache? |
|
841 |
// should we also trigger a Layout redraw? |
|
842 |
refresh(); |
|
843 |
} |
|
1116 | 844 |
} |
1117 | 845 |
|
1118 | 846 |
/** |
... | ... | |
1124 | 852 |
public double getMapRotation() { |
1125 | 853 |
return 0; |
1126 | 854 |
} |
855 |
|
|
856 |
protected void invalidateLayout() { |
|
857 |
b_validCache = false; |
|
858 |
observers.notifyObservers(this, |
|
859 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED)); |
|
860 |
} |
|
861 |
|
|
862 |
protected class ViewDocListener |
|
863 |
implements ViewPortListener, LegendListener, LayerCollectionListener { |
|
864 |
|
|
865 |
public void extentChanged(ExtentEvent e) { |
|
866 |
if (!b_fframeOriginatedUpdate && getTypeScale()==AUTOMATICO) { |
|
867 |
if (getMapContext()!=null) { |
|
868 |
b_viewOriginatedUpdate = true; |
|
869 |
getMapContext().getViewPort().setEnvelope(e.getNewExtent()); |
|
870 |
updateScaleCtrl(); |
|
871 |
invalidateLayout(); |
|
872 |
b_viewOriginatedUpdate = false; |
|
873 |
} |
|
874 |
} |
|
875 |
} |
|
876 |
|
|
877 |
public void backColorChanged(ColorEvent e) { |
|
878 |
if (!b_fframeOriginatedUpdate && linked) { |
|
879 |
if (getMapContext()!=null) { |
|
880 |
b_viewOriginatedUpdate = true; |
|
881 |
mapContext.getViewPort().setBackColor(e.getNewColor()); |
|
882 |
invalidateLayout(); |
|
883 |
b_viewOriginatedUpdate = true; |
|
884 |
} |
|
885 |
} |
|
886 |
} |
|
887 |
|
|
888 |
public void projectionChanged(ProjectionEvent e) { |
|
889 |
if (!b_fframeOriginatedUpdate && getTypeScale()==AUTOMATICO) { |
|
890 |
if (getMapContext()!=null) { |
|
891 |
b_viewOriginatedUpdate = true; |
|
892 |
getMapContext().getViewPort().setProjection(e.getNewProjection()); |
|
893 |
invalidateLayout(); |
|
894 |
// FIXME: force also a view redraw someway?? |
|
895 |
b_viewOriginatedUpdate = false; |
|
896 |
} |
|
897 |
} |
|
898 |
} |
|
899 |
|
|
900 |
public void conditionalRedraw() { |
|
901 |
if (!b_fframeOriginatedUpdate && linked) { |
|
902 |
b_viewOriginatedUpdate = true; |
|
903 |
invalidateLayout(); |
|
904 |
// the view should also receive the event and update automatically |
|
905 |
b_viewOriginatedUpdate = false; |
|
906 |
} |
|
907 |
} |
|
908 |
|
|
909 |
public void legendChanged(LegendChangedEvent e) { |
|
910 |
conditionalRedraw(); |
|
911 |
} |
|
912 |
|
|
913 |
public void layerAdded(LayerCollectionEvent e) { |
|
914 |
conditionalRedraw(); |
|
915 |
} |
|
916 |
|
|
917 |
public void layerMoved(LayerPositionEvent e) { |
|
918 |
conditionalRedraw(); |
|
919 |
} |
|
920 |
|
|
921 |
public void layerRemoved(LayerCollectionEvent e) { |
|
922 |
conditionalRedraw(); |
|
923 |
} |
|
924 |
|
|
925 |
public void layerAdding(LayerCollectionEvent e) |
|
926 |
throws CancelationException { |
|
927 |
// nothing needed |
|
928 |
} |
|
929 |
|
|
930 |
public void layerMoving(LayerPositionEvent e) |
|
931 |
throws CancelationException { |
|
932 |
// nothing needed |
|
933 |
} |
|
934 |
|
|
935 |
public void layerRemoving(LayerCollectionEvent e) |
|
936 |
throws CancelationException { |
|
937 |
// nothing needed |
|
938 |
} |
|
939 |
|
|
940 |
public void visibilityChanged(LayerCollectionEvent e) |
|
941 |
throws CancelationException { |
|
942 |
conditionalRedraw(); |
|
943 |
} |
|
944 |
} |
|
945 |
|
|
946 |
protected class OwnMapContextListener |
|
947 |
implements ViewPortListener, LegendListener, LayerCollectionListener { |
|
948 |
|
|
949 |
public void extentChanged(ExtentEvent e) { |
|
950 |
if (!b_viewOriginatedUpdate && (getTypeScale() == AUTOMATICO)) { |
|
951 |
if (getView()!=null) { |
|
952 |
b_fframeOriginatedUpdate = true; |
|
953 |
getView().getMapContext().getViewPort().setEnvelope(e.getNewExtent()); |
|
954 |
updateScaleCtrl(); |
|
955 |
invalidateLayout(); |
|
956 |
b_fframeOriginatedUpdate = false; |
|
957 |
} |
|
958 |
} |
|
959 |
} |
|
960 |
|
|
961 |
public void backColorChanged(ColorEvent e) { |
|
962 |
if (!b_viewOriginatedUpdate && linked) { |
|
963 |
if (getView()!=null) { |
|
964 |
b_fframeOriginatedUpdate = true; |
|
965 |
getView().getMapContext().getViewPort().setBackColor(e.getNewColor()); |
|
966 |
invalidateLayout(); |
|
967 |
b_fframeOriginatedUpdate = false; |
|
968 |
} |
|
969 |
} |
|
970 |
} |
|
971 |
|
|
972 |
public void projectionChanged(ProjectionEvent e) { |
|
973 |
if (!b_viewOriginatedUpdate && (getTypeScale() == AUTOMATICO)) { |
|
974 |
if (getView()!=null) { |
|
975 |
b_fframeOriginatedUpdate = true; |
|
976 |
getView().getMapContext().getViewPort().setProjection(e.getNewProjection()); |
|
977 |
invalidateLayout(); |
|
978 |
// FIXME: force also a view redraw someway?? |
|
979 |
b_fframeOriginatedUpdate = false; |
|
980 |
} |
|
981 |
} |
|
982 |
} |
|
983 |
|
|
984 |
public void conditionalRedraw() { |
|
985 |
if (!b_viewOriginatedUpdate && linked) { |
|
986 |
b_fframeOriginatedUpdate = true; |
|
987 |
invalidateLayout(); |
|
988 |
// the view should also receive the event and update automatically |
|
989 |
b_fframeOriginatedUpdate = false; |
|
990 |
} |
|
991 |
} |
|
992 |
|
|
993 |
public void legendChanged(final LegendChangedEvent e) { |
|
994 |
conditionalRedraw(); |
|
995 |
} |
|
996 |
|
|
997 |
public void layerAdded(final LayerCollectionEvent e) { |
|
998 |
conditionalRedraw(); |
|
999 |
} |
|
1000 |
|
|
1001 |
public void layerMoved(final LayerPositionEvent e) { |
|
1002 |
conditionalRedraw(); |
|
1003 |
} |
|
1004 |
|
|
1005 |
public void layerRemoved(final LayerCollectionEvent e) { |
|
1006 |
conditionalRedraw(); |
|
1007 |
} |
|
1008 |
|
|
1009 |
public void layerAdding(LayerCollectionEvent e) |
|
1010 |
throws CancelationException { |
|
1011 |
// nothing neededO |
|
1012 |
|
|
1013 |
} |
|
1014 |
|
|
1015 |
public void layerMoving(LayerPositionEvent e) |
|
1016 |
throws CancelationException { |
|
1017 |
// nothing needed |
|
1018 |
|
|
1019 |
} |
|
1020 |
|
|
1021 |
public void layerRemoving(LayerCollectionEvent e) |
|
1022 |
throws CancelationException { |
|
1023 |
// nothing needed |
|
1024 |
|
|
1025 |
} |
|
1026 |
|
|
1027 |
public void visibilityChanged(LayerCollectionEvent e) |
|
1028 |
throws CancelationException { |
|
1029 |
conditionalRedraw(); |
|
1030 |
} |
|
1031 |
|
|
1032 |
} |
|
1033 |
|
|
1034 |
@Deprecated |
|
1035 |
public void refresh() { |
|
1036 |
// FIXME: what should we do here? do we really need to invalidate cache?? |
|
1037 |
b_validCache = false; |
|
1038 |
} |
|
1039 |
|
|
1040 |
protected void resetListeners() { |
|
1041 |
if (this.getMapContext()!=null) { |
|
1042 |
clearOwnListeners(this.getMapContext()); |
|
1043 |
} |
|
1044 |
if (this.getView()!=null && this.getView().getMapContext()!=null) { |
|
1045 |
clearViewListeners(this.getView().getMapContext()); |
|
1046 |
} |
|
1047 |
setListeners(); |
|
1048 |
} |
|
1049 |
|
|
1050 |
protected void setListeners() { |
|
1051 |
if (getView()!=null) { |
|
1052 |
if (linked) { |
|
1053 |
getView().getMapContext().addLayerListener(viewDocListener); |
|
1054 |
getView().getMapContext().getLayers().addLayerCollectionListener(viewDocListener); |
|
1055 |
} |
|
1056 |
if (getTypeScale()==IFFrameUseFMap.AUTOMATICO) { |
|
1057 |
getView().getMapContext().getViewPort().addViewPortListener(viewDocListener); |
|
1058 |
} |
|
1059 |
} |
|
1060 |
if (getMapContext()!=null) { |
|
1061 |
getMapContext().addLayerListener(ownMapContextListener); |
|
1062 |
getMapContext().getLayers().addLayerCollectionListener(ownMapContextListener); |
|
1063 |
getMapContext().getViewPort().addViewPortListener(ownMapContextListener); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
protected void clearOwnListeners(MapContext mapContext) { |
|
1067 |
mapContext.removeLayerListener(ownMapContextListener); |
|
1068 |
mapContext.getViewPort().removeViewPortListener(ownMapContextListener); |
|
1069 |
mapContext.getLayers().removeLayerCollectionListener(ownMapContextListener); |
|
1070 |
} |
|
1071 |
protected void clearViewListeners(MapContext mapContext) { |
|
1072 |
mapContext.removeLayerListener(viewDocListener); |
|
1073 |
mapContext.getViewPort().removeViewPortListener(viewDocListener); |
|
1074 |
mapContext.getLayers().removeLayerCollectionListener(viewDocListener); |
|
1075 |
} |
|
1076 |
|
|
1077 |
/* |
|
1078 |
* (non-Javadoc) |
|
1079 |
* @see org.gvsig.tools.dispose.Disposable#dispose() |
|
1080 |
*/ |
|
1081 |
public void dispose() { |
|
1082 |
try { |
|
1083 |
if (this.getMapContext()!=null) { |
|
1084 |
clearOwnListeners(this.getMapContext()); |
|
1085 |
} |
|
1086 |
if (this.getView()!=null && this.getView().getMapContext()!=null) { |
|
1087 |
clearViewListeners(this.getView().getMapContext()); |
|
1088 |
} |
|
1089 |
} |
|
1090 |
catch (Exception ex) {} |
|
1091 |
this.viewDocument = null; |
|
1092 |
this.mapContext = null; |
|
1093 |
} |
|
1094 |
|
|
1127 | 1095 |
} |
Also available in: Unified diff