Revision 383 trunk/org.gvsig.app.document.layout2.app/org.gvsig.app.document.layout2.app.mainplugin/src/main/java/org/gvsig/app/project/documents/layout/fframes/FFrameView.java
FFrameView.java | ||
---|---|---|
90 | 90 |
* no MapControl is used in current implementation, but a similar behavior |
91 | 91 |
* is simulated by the FFrameView. The original MapContext is cloned when |
92 | 92 |
* assigned to the FFrameView, which is then used for drawing. |
93 |
*
|
|
93 |
* |
|
94 | 94 |
* The FFrameView and the associated View can be synchronized, depending |
95 | 95 |
* on the values of {@link #getTypeScale()} and {@link #getLinked()}. |
96 |
*
|
|
97 |
* The main synchronization logic is kept on two internal classes:
|
|
96 |
* |
|
97 |
* The main synchronization logic is kept on two internal classes: |
|
98 | 98 |
* {@link OwnMapContextListener} and {@link ViewDocListener}. The first one |
99 | 99 |
* listens for events on the FFrameView and synchronizes the View accordingly. |
100 | 100 |
* The second one listens for events on the View and synchronizes the FFrameView |
101 | 101 |
* accordingly. There synchronization process is flagged using |
102 | 102 |
* {@link #b_updating} and {@link #b_updating}, in order |
103 |
* to avoid incurring on infinite synchronization loops.
|
|
104 |
*
|
|
103 |
* to avoid incurring on infinite synchronization loops. |
|
104 |
* |
|
105 | 105 |
* @author Vicente Caballero Navarro |
106 | 106 |
* @author Cesar Martinez Izquierdo |
107 | 107 |
*/ |
... | ... | |
121 | 121 |
private static final String LAYER_SYNC_FIELD = "layerSync"; |
122 | 122 |
private static final String EXTENT_SYNC_FIELD = "extentSync"; |
123 | 123 |
private static final String SCALE_TYPE_FIELD = "scaleType"; |
124 |
// following fields are unused - they are kept for backward-compatibility
|
|
124 |
// following fields are unused - they are kept for backward-compatibility |
|
125 | 125 |
private static final String EXTENSION_FIELD = "extension"; |
126 | 126 |
private static final String BLINKED_FIELD = "bLinked"; |
127 | 127 |
private static final String MODE_FIELD = "mode"; |
... | ... | |
162 | 162 |
/** |
163 | 163 |
* When we load a FFrameview from project, it will receive a wrong |
164 | 164 |
* extentChanged event the first time the View is painted, so we must |
165 |
* ignore this first event.
|
|
165 |
* ignore this first event. |
|
166 | 166 |
*/ |
167 | 167 |
private boolean b_frameInitialized = true; |
168 | 168 |
|
... | ... | |
181 | 181 |
num++; |
182 | 182 |
createListeners(); |
183 | 183 |
} |
184 |
|
|
184 |
|
|
185 | 185 |
protected void createListeners() { |
186 | 186 |
viewDocListener = new ViewDocListener(); |
187 | 187 |
ownMapContextListener = new OwnMapContextListener(); |
... | ... | |
189 | 189 |
|
190 | 190 |
/** |
191 | 191 |
* Returns a description of the FFrame |
192 |
*
|
|
192 |
* |
|
193 | 193 |
* @return Description. |
194 | 194 |
*/ |
195 | 195 |
public String toString() { |
... | ... | |
202 | 202 |
|
203 | 203 |
/** |
204 | 204 |
* Sets the scale of the MapContext contained in this FFrameView |
205 |
*
|
|
205 |
* |
|
206 | 206 |
* @param d Scale to be set |
207 | 207 |
*/ |
208 | 208 |
public void setScale(double d) { |
... | ... | |
214 | 214 |
/** |
215 | 215 |
* Sets a new Envelope on the MapContext contained in |
216 | 216 |
* this FFrameView |
217 |
*
|
|
217 |
* |
|
218 | 218 |
* @param r Envelope to be set |
219 | 219 |
*/ |
220 | 220 |
public void setNewEnvelope(Envelope r) { |
221 | 221 |
getMapContext().getViewPort().setEnvelope(r); |
222 | 222 |
updateScaleCtrl(); |
223 | 223 |
} |
224 |
|
|
224 |
|
|
225 | 225 |
/** |
226 | 226 |
* Calculates the resolution (measured on dots per inch, DPI) to be |
227 | 227 |
* considered to draw the FFrameView on screen. It is calculated by |
... | ... | |
233 | 233 |
if (getLayoutContext()!=null) { |
234 | 234 |
at = getLayoutContext().getAT(); |
235 | 235 |
} |
236 |
return (2.54*getBoundingBox(at).width)/getBoundBox().width;
|
|
236 |
return (2.54*getBoundingBox(at).width)/getBoundBox().width; |
|
237 | 237 |
} |
238 | 238 |
|
239 | 239 |
/** |
... | ... | |
241 | 241 |
* usually a clone of the associated View. This MapContext |
242 | 242 |
* may be synchronized with the View one, depending on the |
243 | 243 |
* scale type that has been set (see {{@link #getTypeScale()}. |
244 |
*
|
|
244 |
* |
|
245 | 245 |
* @return The mapContext object |
246 | 246 |
*/ |
247 | 247 |
public MapContext getMapContext() { |
... | ... | |
253 | 253 |
* Valid values include {@link #DRAFT} and {@link #PRESENTATION}. |
254 | 254 |
* Draft will disable the frame normal drawing, which will be |
255 | 255 |
* replaced by an empty rectangle only showing the name of the |
256 |
* frame.
|
|
257 |
*
|
|
256 |
* frame. |
|
257 |
* |
|
258 | 258 |
* @param q Integer representing the quality. |
259 | 259 |
*/ |
260 | 260 |
public void setQuality(int q) { |
... | ... | |
266 | 266 |
* Valid values include {@link #DRAFT} and {@link #PRESENTATION}. |
267 | 267 |
* Draft will disable the frame normal drawing, which will be |
268 | 268 |
* replaced by an empty rectangle only showing the name of the |
269 |
* frame.
|
|
270 |
*
|
|
269 |
* frame. |
|
270 |
* |
|
271 | 271 |
* @param q The selected quality |
272 | 272 |
*/ |
273 | 273 |
public int getQuality() { |
... | ... | |
277 | 277 |
/** |
278 | 278 |
* Sets the MapContext associated with this FFrameView, which will |
279 | 279 |
* be used to clone the layers and synchronize the FFrameView with |
280 |
* the associated View
|
|
281 |
*
|
|
280 |
* the associated View |
|
281 |
* |
|
282 | 282 |
* @param viewMapContext |
283 | 283 |
*/ |
284 | 284 |
public void setViewMapContext(MapContext viewMapContext) { |
... | ... | |
333 | 333 |
* Sets the View associated with this FFrameView, which will |
334 | 334 |
* be used to clone the MapContext and the layers. It will |
335 | 335 |
* also used to synchronize the FFrameView with |
336 |
* the associated View, depending on the selected scale type
|
|
337 |
*
|
|
336 |
* the associated View, depending on the selected scale type |
|
337 |
* |
|
338 | 338 |
* @param viewMapContext |
339 | 339 |
*/ |
340 | 340 |
public void setView(ViewDocument dvd) { |
... | ... | |
355 | 355 |
|
356 | 356 |
/** |
357 | 357 |
* Gets the associated View |
358 |
*
|
|
358 |
* |
|
359 | 359 |
* @return The associated view |
360 | 360 |
* @see {@link #setView(ViewDocument)} |
361 | 361 |
*/ |
... | ... | |
366 | 366 |
/** |
367 | 367 |
* Draws the FFrameView on the provided Graphics, according to the |
368 | 368 |
* provided affine transform and the visible rectangle. |
369 |
*
|
|
369 |
* |
|
370 | 370 |
* @param g Graphics2D |
371 | 371 |
* @param at Affine transform to translate sheet coordinates (in cm) |
372 | 372 |
* to screen coordinates (in pixels) |
... | ... | |
401 | 401 |
|
402 | 402 |
} else { |
403 | 403 |
drawDraft(g); |
404 |
}
|
|
404 |
} |
|
405 | 405 |
} |
406 | 406 |
} |
407 |
postDraw(g, fframeViewRect, at);
|
|
408 |
if (showGrid && grid != null) {
|
|
407 |
postDraw(g, fframeViewRect, at); |
|
408 |
if (showGrid && grid != null) { |
|
409 | 409 |
grid.draw(g, at, visibleLayoutDocRect, imgBase); |
410 |
}
|
|
410 |
} |
|
411 | 411 |
} |
412 |
|
|
412 |
|
|
413 | 413 |
private void drawMessage(Graphics2D g, String msg) { |
414 |
|
|
414 |
|
|
415 | 415 |
Rectangle2D r = getBoundingBox(null); |
416 | 416 |
g.setColor(Color.lightGray); |
417 | 417 |
g.fillRect((int) r.getX(), (int) r.getY(), (int) r.getWidth(), |
... | ... | |
434 | 434 |
|
435 | 435 |
/** |
436 | 436 |
* Gets the visible envelope, in map coordinates |
437 |
*
|
|
437 |
* |
|
438 | 438 |
* @param fframeViewRect Rectangle defining the bounding box of the |
439 | 439 |
* FFrameView, in screen coordinates |
440 | 440 |
* @param visiblefframeViewRect Rectangle defining the bounding box |
... | ... | |
446 | 446 |
Envelope oldEnv = getMapContext().getViewPort().getAdjustedEnvelope(); |
447 | 447 |
double widthFactor = ((int)visiblefframeViewRect.width) / fframeViewRect.width; |
448 | 448 |
double heightFactor = ((int)visiblefframeViewRect.height) / fframeViewRect.height; |
449 |
|
|
449 |
|
|
450 | 450 |
double newWidth = oldEnv.getLength(0)*widthFactor; |
451 | 451 |
double newHeight = oldEnv.getLength(1)*heightFactor; |
452 |
|
|
452 |
|
|
453 | 453 |
double translateX = visiblefframeViewRect.x - fframeViewRect.x; |
454 | 454 |
double translateY = visiblefframeViewRect.y - fframeViewRect.y; |
455 | 455 |
double translateFactorX = translateX / fframeViewRect.width; |
456 | 456 |
double translateFactorY = translateY / fframeViewRect.height; |
457 |
|
|
457 |
|
|
458 | 458 |
double newX = oldEnv.getMinimum(0) + translateFactorX*oldEnv.getLength(0); |
459 | 459 |
double newMaxY = oldEnv.getMaximum(1) - translateFactorY*oldEnv.getLength(1); |
460 | 460 |
double newMaxX = newX + newWidth; |
... | ... | |
467 | 467 |
logger.error("Error calculating visible extent", e); |
468 | 468 |
} |
469 | 469 |
return newEnv; |
470 |
|
|
470 |
|
|
471 | 471 |
} |
472 |
|
|
472 |
|
|
473 | 473 |
protected void drawPresentation( |
474 | 474 |
Graphics2D g, |
475 | 475 |
AffineTransform affineTransform, |
476 | 476 |
Rectangle2D.Double fframeViewRect, |
477 | 477 |
Rectangle2D.Double visibleRect, |
478 | 478 |
BufferedImage imgBase) throws Exception { |
479 |
|
|
479 |
|
|
480 | 480 |
b_drawing = true; |
481 | 481 |
int drawWidth = (int)visibleRect.width; |
482 | 482 |
int drawHeight = (int)visibleRect.height; |
... | ... | |
500 | 500 |
getMapContext().getViewPort().setImageSize(new Dimension(drawWidth, drawHeight)); |
501 | 501 |
getMapContext().getViewPort().refreshExtent(); |
502 | 502 |
} |
503 |
|
|
503 |
|
|
504 | 504 |
// map origin should be calculated using the full fframeview, as the visible position will be relative |
505 | 505 |
Point mapOrigin = new Point((int)fframeViewRect.getMinX(), (int)fframeViewRect.getMaxY()); |
506 | 506 |
|
... | ... | |
509 | 509 |
|
510 | 510 |
//Draw the created image |
511 | 511 |
drawImage(g, m_image, visibleRect); |
512 |
|
|
512 |
|
|
513 | 513 |
if (oldEnvelope!=null) { |
514 | 514 |
// restore real envelope and image size |
515 | 515 |
getMapContext().getViewPort().setImageSize(new Dimension((int)fframeViewRect.width, (int) fframeViewRect.height)); |
516 | 516 |
getMapContext().getViewPort().setEnvelope(oldEnvelope); |
517 | 517 |
} |
518 |
|
|
518 |
|
|
519 | 519 |
scaleAnt = affineTransform.getScaleX(); |
520 | 520 |
origin = mapOrigin; |
521 | 521 |
b_drawing = false; |
522 | 522 |
} |
523 |
|
|
523 |
|
|
524 | 524 |
protected void createImage(AffineTransform affineTransform, |
525 | 525 |
int width, int height, Point mapOrigin) throws ReadException, MapContextException { |
526 | 526 |
ViewPort viewPort = this.getMapContext().getViewPort(); |
... | ... | |
530 | 530 |
!origin.equals(mapOrigin) || |
531 | 531 |
affineTransform.getScaleX() != scaleAnt || |
532 | 532 |
m_image == null || |
533 |
!b_validCache) {
|
|
533 |
!b_validCache) { |
|
534 | 534 |
|
535 | 535 |
viewPort.setDPI(getDrawPaperDPI()); |
536 |
viewPort.setImageSize(new Dimension(width, height));
|
|
537 |
|
|
536 |
viewPort.setImageSize(new Dimension(width, height)); |
|
537 |
|
|
538 | 538 |
m_image = |
539 | 539 |
new BufferedImage( |
540 | 540 |
width, |
... | ... | |
545 | 545 |
getMapContext().draw(m_image, gimg, getScale()); |
546 | 546 |
gimg.dispose(); |
547 | 547 |
b_validCache = true; |
548 |
}
|
|
548 |
} |
|
549 | 549 |
|
550 | 550 |
} |
551 |
|
|
551 |
|
|
552 | 552 |
protected void drawImage(Graphics2D g, BufferedImage image, |
553 | 553 |
Rectangle2D.Double visibleRectangle) { |
554 | 554 |
|
... | ... | |
559 | 559 |
(int)visibleRectangle.width, |
560 | 560 |
(int)visibleRectangle.height); |
561 | 561 |
} |
562 |
g.drawImage(m_image,
|
|
562 |
g.drawImage(m_image, |
|
563 | 563 |
(int) visibleRectangle.x, |
564 | 564 |
(int) visibleRectangle.y, |
565 |
null);
|
|
565 |
null); |
|
566 | 566 |
} |
567 | 567 |
|
568 | 568 |
protected void preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D.Double visibleRect){ |
569 | 569 |
originalGraphicsAT = (AffineTransform) g.getTransform().clone(); |
570 |
|
|
570 |
|
|
571 | 571 |
if (g.getClipBounds() != null) { |
572 | 572 |
originalClip = (Rectangle) g.getClipBounds().clone(); |
573 | 573 |
} |
... | ... | |
578 | 578 |
g.setClip((int) visibleRect.getMinX(), (int) visibleRect.getMinY(), |
579 | 579 |
(int) visibleRect.getWidth(), (int) visibleRect.getHeight()); |
580 | 580 |
} |
581 |
|
|
581 |
|
|
582 | 582 |
protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, AffineTransform at){ |
583 | 583 |
g.setTransform(originalGraphicsAT); |
584 | 584 |
if (getMapContext() != null) { |
... | ... | |
586 | 586 |
} |
587 | 587 |
if (originalClip != null) { |
588 | 588 |
g.setClip(originalClip.x, originalClip.y, originalClip.width, originalClip.height); |
589 |
}
|
|
589 |
} |
|
590 | 590 |
} |
591 |
|
|
592 | 591 |
|
592 |
|
|
593 | 593 |
/** |
594 | 594 |
* @deprecated Use {@link #postDraw(Graphics2D, java.awt.geom.Rectangle2D.Double, AffineTransform)} instead. |
595 | 595 |
*/ |
596 | 596 |
@Deprecated |
597 | 597 |
protected void postDraw(Graphics2D g, Rectangle2D.Double rectangleLayout, Rectangle2D rectangleView, BufferedImage imgBase, Rectangle originalClip, AffineTransform at) { |
598 | 598 |
postDraw(g, rectangleLayout, at); |
599 |
|
|
599 |
|
|
600 | 600 |
} |
601 |
|
|
601 |
|
|
602 | 602 |
/** |
603 | 603 |
* @deprecated Use {@link #preDraw(Graphics2D, java.awt.geom.Rectangle2D.Double, java.awt.geom.Rectangle2D.Double) instead |
604 | 604 |
*/ |
... | ... | |
614 | 614 |
|
615 | 615 |
public void print(Graphics2D g, AffineTransform at, Geometry geom, |
616 | 616 |
PrintAttributes printAttributes) { |
617 |
Rectangle2D.Double rectangleLayout = getBoundingBox(at);
|
|
618 |
|
|
617 |
Rectangle2D.Double rectangleLayout = getBoundingBox(at); |
|
618 |
|
|
619 | 619 |
preDraw(g, rectangleLayout, rectangleLayout); |
620 | 620 |
print(g, at, printAttributes); |
621 | 621 |
postDraw(g, rectangleLayout, at); |
622 | 622 |
if (showGrid && grid != null) { |
623 | 623 |
grid.print(g, at, geom, printAttributes); |
624 |
}
|
|
624 |
} |
|
625 | 625 |
} |
626 | 626 |
|
627 | 627 |
protected void print(Graphics2D g, AffineTransform at, PrintAttributes printAttributes) { |
628 | 628 |
Rectangle2D.Double layoutRectangle = getBoundingBox(at); |
629 |
|
|
629 |
|
|
630 | 630 |
// FIXME: should we clone the mapcontext and viewport before printing ?? |
631 | 631 |
// otherwise we will probably have unexpected results if the user modifies |
632 | 632 |
// the layout while printing (answer: not an issue at the moment as printing is |
633 | 633 |
// a blocking operation) |
634 | 634 |
ViewPort viewPort = this.getMapContext().getViewPort(); |
635 |
|
|
635 |
|
|
636 | 636 |
Point2D old_offset = viewPort.getOffset(); |
637 | 637 |
Dimension old_imgsize = viewPort.getImageSize(); |
638 | 638 |
double oldDpi = viewPort.getDPI(); |
639 |
|
|
639 |
|
|
640 | 640 |
viewPort.setOffset(new Point2D.Double(layoutRectangle.x, layoutRectangle.y)); |
641 | 641 |
viewPort.setImageSize(new Dimension((int) layoutRectangle.width, (int) layoutRectangle.height)); |
642 | 642 |
double dpi = PrintAttributes.PRINT_QUALITY_DPI[printAttributes.getPrintQuality()]; |
... | ... | |
649 | 649 |
g.fillRect((int) layoutRectangle.x, (int) layoutRectangle.y, viewPort |
650 | 650 |
.getImageWidth(), viewPort |
651 | 651 |
.getImageHeight()); |
652 |
}
|
|
653 |
|
|
652 |
} |
|
653 |
|
|
654 | 654 |
//Print the map |
655 | 655 |
try { |
656 | 656 |
this.getMapContext().print(g, getScale(), printAttributes); |
... | ... | |
658 | 658 |
NotificationManager.addError(e.getMessage(), e); |
659 | 659 |
} catch (MapContextException e) { |
660 | 660 |
NotificationManager.addError(e.getMessage(), e); |
661 |
}
|
|
662 |
|
|
661 |
} |
|
662 |
|
|
663 | 663 |
// Restore offset, imgsize |
664 | 664 |
viewPort.setOffset(old_offset); |
665 | 665 |
viewPort.setImageSize(old_imgsize); |
... | ... | |
669 | 669 |
|
670 | 670 |
/** |
671 | 671 |
* Rellena la unidad de medida en la que est? la vista. |
672 |
*
|
|
672 |
* |
|
673 | 673 |
* @param i |
674 | 674 |
* entero que representa la unidad de medida de la vista. |
675 | 675 |
*/ |
... | ... | |
679 | 679 |
|
680 | 680 |
/** |
681 | 681 |
* Obtiene la unidad de medida en la que est? la vista. |
682 |
*
|
|
682 |
* |
|
683 | 683 |
* @return Unidad de medida. |
684 | 684 |
*/ |
685 | 685 |
public int getMapUnits() { |
... | ... | |
689 | 689 |
/** |
690 | 690 |
* Devuelve la escala seg?n el tipo de escala que se haya seleccionado al |
691 | 691 |
* a?adida la vista. |
692 |
*
|
|
692 |
* |
|
693 | 693 |
* @return escala. |
694 | 694 |
*/ |
695 | 695 |
public long getScale() { |
... | ... | |
698 | 698 |
|
699 | 699 |
/** |
700 | 700 |
* Inserta la imagen para repintar el FFrameView. |
701 |
*
|
|
701 |
* |
|
702 | 702 |
* @param bi |
703 | 703 |
* Imagen para repintar. |
704 | 704 |
*/ |
... | ... | |
708 | 708 |
|
709 | 709 |
/** |
710 | 710 |
* Devuelve la imagen para repintar. |
711 |
*
|
|
711 |
* |
|
712 | 712 |
* @return Imagen para repintar. |
713 | 713 |
*/ |
714 | 714 |
public BufferedImage getBufferedImage() { |
... | ... | |
717 | 717 |
|
718 | 718 |
/** |
719 | 719 |
* Devuelve la MAtriz de transformaci?n utilizada por la FFrameView. |
720 |
*
|
|
720 |
* |
|
721 | 721 |
* @return MAtriz de transformaci?n. |
722 | 722 |
*/ |
723 | 723 |
public AffineTransform getATMap() { |
... | ... | |
726 | 726 |
|
727 | 727 |
/** |
728 | 728 |
* Inserta la matriz de transformaci?n. |
729 |
*
|
|
729 |
* |
|
730 | 730 |
* @param transform |
731 | 731 |
* Matriz de transformaci?n. |
732 | 732 |
*/ |
... | ... | |
736 | 736 |
|
737 | 737 |
/** |
738 | 738 |
* Inserta el proyecto. |
739 |
*
|
|
739 |
* |
|
740 | 740 |
* @param p |
741 | 741 |
* Proyecto. |
742 | 742 |
*/ |
... | ... | |
757 | 757 |
|
758 | 758 |
/** |
759 | 759 |
* DOCUMENT ME! |
760 |
*
|
|
760 |
* |
|
761 | 761 |
* @param arg0 |
762 | 762 |
* DOCUMENT ME! |
763 |
*
|
|
763 |
* |
|
764 | 764 |
* @return DOCUMENT ME! |
765 | 765 |
*/ |
766 | 766 |
public boolean compare(Object arg0) { |
... | ... | |
796 | 796 |
} |
797 | 797 |
return true; |
798 | 798 |
} |
799 |
|
|
799 |
|
|
800 | 800 |
public void updateScaleCtrl() { |
801 | 801 |
NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar(); |
802 | 802 |
MapContext mapContext = this.getMapContext(); |
... | ... | |
805 | 805 |
} |
806 | 806 |
statusbar.setMessage("units", |
807 | 807 |
PluginServices.getText(this, mapContext.getDistanceName())); |
808 |
String scale;
|
|
808 |
String scale; |
|
809 | 809 |
if (fixedScale!=null && getScaleType()==SCALE_TYPE.FIXED_SCALE) { |
810 | 810 |
// prefer fixedScale as getScaleView() may offer slight differences |
811 | 811 |
// because the influence of the adjusted envelope |
... | ... | |
894 | 894 |
|
895 | 895 |
public static void registerPersistent() { |
896 | 896 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
897 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
|
|
897 |
if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) { |
|
898 | 898 |
DynStruct definition = |
899 | 899 |
manager.addDefinition(FFrameView.class, |
900 | 900 |
PERSISTENCE_DEFINITION_NAME, |
... | ... | |
944 | 944 |
syncLayers = true; |
945 | 945 |
} |
946 | 946 |
Double layoutScale = null; |
947 |
if (state.hasValue(SCALE_FIELD)) {
|
|
947 |
if (state.hasValue(SCALE_FIELD)) { |
|
948 | 948 |
layoutScale = state.getDouble(SCALE_FIELD); |
949 | 949 |
} |
950 |
Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD);
|
|
950 |
Envelope envelope = (Envelope) state.get(ENVELOPE_FIELD); |
|
951 | 951 |
|
952 | 952 |
if (state.hasValue(SCALE_TYPE_FIELD)) { |
953 | 953 |
int value = state.getInt(SCALE_TYPE_FIELD); |
... | ... | |
966 | 966 |
if (state.hasValue(HAS_TOC_FIELD)) { |
967 | 967 |
this.b_hasToc = state.getBoolean(HAS_TOC_FIELD); |
968 | 968 |
} |
969 |
|
|
969 |
|
|
970 | 970 |
// When copying and pasting layout documents (in project manager), the view |
971 | 971 |
// is first persisted (copy action) and then re-created from persistence (paste action). |
972 | 972 |
// This is a problem, as the re-created view is not the same view as the original one |
... | ... | |
989 | 989 |
if (layoutScale!=null) { |
990 | 990 |
getMapContext().setScaleView(layoutScale.longValue()); |
991 | 991 |
} |
992 |
getMapContext().getViewPort().setEnvelope(envelope);
|
|
992 |
getMapContext().getViewPort().setEnvelope(envelope); |
|
993 | 993 |
if (this.getLayoutContext()!=null) { |
994 | 994 |
this.getLayoutContext().setTocModel(getMapContext()); |
995 | 995 |
} |
... | ... | |
1019 | 1019 |
state.set(SCALE_FIELD, (double)fixedScale); |
1020 | 1020 |
} |
1021 | 1021 |
else { |
1022 |
state.set(SCALE_FIELD, (double)getMapContext().getScaleView());
|
|
1022 |
state.set(SCALE_FIELD, (double)getMapContext().getScaleView()); |
|
1023 | 1023 |
} |
1024 | 1024 |
if (scaleType == SCALE_TYPE.FIXED_EXTENT) { |
1025 | 1025 |
if (fixedExtent==null) { |
... | ... | |
1029 | 1029 |
} |
1030 | 1030 |
else { |
1031 | 1031 |
state.set(ENVELOPE_FIELD, getMapContext().getViewPort() |
1032 |
.getAdjustedEnvelope());
|
|
1032 |
.getAdjustedEnvelope()); |
|
1033 | 1033 |
} |
1034 | 1034 |
} |
1035 | 1035 |
|
1036 | 1036 |
state.set(SHOWGRID_FIELD, showGrid); |
1037 | 1037 |
state.set(GRID_FIELD, grid); |
1038 | 1038 |
} |
1039 |
|
|
1039 |
|
|
1040 | 1040 |
@Override |
1041 | 1041 |
public void setBoundBox(Rectangle2D r) { |
1042 | 1042 |
super.setBoundBox(r); |
... | ... | |
1052 | 1052 |
updateScaleCtrl(); |
1053 | 1053 |
refresh(); |
1054 | 1054 |
} |
1055 |
}
|
|
1055 |
} |
|
1056 | 1056 |
|
1057 | 1057 |
/** |
1058 | 1058 |
* Gets the rotation of the frame |
1059 |
*
|
|
1059 |
* |
|
1060 | 1060 |
* @return Rotation in degrees |
1061 | 1061 |
*/ |
1062 | 1062 |
public double getMapRotation() { |
1063 | 1063 |
return 0; |
1064 | 1064 |
} |
1065 |
|
|
1065 |
|
|
1066 | 1066 |
protected void invalidateLayout() { |
1067 | 1067 |
b_validCache = false; |
1068 | 1068 |
if (getLayoutContext()!=null) { |
1069 | 1069 |
getLayoutContext().notifAllObservers(); |
1070 | 1070 |
} |
1071 |
observers.notifyObservers(this,
|
|
1071 |
observers.notifyObservers(this, |
|
1072 | 1072 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH)); |
1073 | 1073 |
} |
1074 |
|
|
1074 |
|
|
1075 | 1075 |
protected void invalidateToc() { |
1076 | 1076 |
if (getLayoutContext()!=null) { |
1077 | 1077 |
getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.ITEM_UPDATED); |
1078 | 1078 |
} |
1079 | 1079 |
} |
1080 |
|
|
1080 |
|
|
1081 | 1081 |
protected void refreshToc() { |
1082 | 1082 |
if (getLayoutContext()!=null) { |
1083 | 1083 |
getLayoutContext().notifyTocUpdated(TocModelChangedNotification.Type.MODEL_CHANGED); |
... | ... | |
1085 | 1085 |
} |
1086 | 1086 |
|
1087 | 1087 |
public void refresh() { |
1088 |
// force re-creating the cache on the next drawing cycle
|
|
1088 |
// force re-creating the cache on the next drawing cycle |
|
1089 | 1089 |
b_validCache = false; |
1090 | 1090 |
} |
1091 |
|
|
1091 |
|
|
1092 | 1092 |
protected void resetListeners() { |
1093 | 1093 |
if (this.getMapContext()!=null) { |
1094 | 1094 |
clearOwnListeners(this.getMapContext()); |
... | ... | |
1098 | 1098 |
} |
1099 | 1099 |
setListeners(); |
1100 | 1100 |
} |
1101 |
|
|
1101 |
|
|
1102 | 1102 |
protected void setListeners() { |
1103 | 1103 |
if (getView()!=null) { |
1104 | 1104 |
if (syncLayers) { |
... | ... | |
1127 | 1127 |
mapContext.getLayers().removeLayerCollectionListener(viewDocListener); |
1128 | 1128 |
mapContext.removeAtomicEventListener(viewDocListener); |
1129 | 1129 |
} |
1130 |
|
|
1130 |
|
|
1131 | 1131 |
/* |
1132 | 1132 |
* (non-Javadoc) |
1133 | 1133 |
* @see org.gvsig.tools.dispose.Disposable#dispose() |
... | ... | |
1164 | 1164 |
setTocModel(); |
1165 | 1165 |
updateScaleCtrl(); |
1166 | 1166 |
} |
1167 |
|
|
1167 |
|
|
1168 | 1168 |
public void setHasToc(boolean hasToc) { |
1169 | 1169 |
this.b_hasToc = hasToc; |
1170 | 1170 |
setTocModel(); |
1171 | 1171 |
} |
1172 |
|
|
1172 |
|
|
1173 | 1173 |
protected void setTocModel() { |
1174 | 1174 |
if (getLayoutContext()!=null) { |
1175 | 1175 |
if (b_hasToc && getMapContext()!=null) { |
... | ... | |
1180 | 1180 |
} |
1181 | 1181 |
} |
1182 | 1182 |
} |
1183 |
|
|
1183 |
|
|
1184 | 1184 |
@Override |
1185 | 1185 |
protected void doSetSelected(int selectedStatus) { |
1186 | 1186 |
boolean oldSelectedStatus = isSelected(); |
... | ... | |
1190 | 1190 |
updateScaleCtrl(); |
1191 | 1191 |
} |
1192 | 1192 |
} |
1193 |
|
|
1193 |
|
|
1194 | 1194 |
public boolean getLayerSynced() { |
1195 | 1195 |
return syncLayers; |
1196 | 1196 |
} |
... | ... | |
1208 | 1208 |
syncExtents = synced; |
1209 | 1209 |
resetListeners(); |
1210 | 1210 |
} |
1211 |
|
|
1211 |
|
|
1212 | 1212 |
/** |
1213 | 1213 |
* Returns true if the newEnvelope represents a pan operation on oldEnvelope, |
1214 | 1214 |
* (both extents have the same height and width) |
... | ... | |
1217 | 1217 |
if (oldEnvelope!=null && newEnvelope!=null) { |
1218 | 1218 |
double toleranceX = 0.00000001*Math.min(oldEnvelope.getLength(0), newEnvelope.getLength(0)); |
1219 | 1219 |
double toleranceY = 0.00000001*Math.min(oldEnvelope.getLength(1), newEnvelope.getLength(1)); |
1220 |
|
|
1221 |
// we consider it to be a pan if both lengths are equal
|
|
1220 |
|
|
1221 |
// we consider it to be a pan if both lengths are equal |
|
1222 | 1222 |
// (we use tolerance to avoid direct comparison of double values) |
1223 | 1223 |
if ( ((oldEnvelope.getLength(0)-newEnvelope.getLength(0))<toleranceX) |
1224 | 1224 |
&& ((oldEnvelope.getLength(1)-newEnvelope.getLength(1))<toleranceY) ) { |
... | ... | |
1227 | 1227 |
} |
1228 | 1228 |
return false; |
1229 | 1229 |
} |
1230 |
|
|
1230 |
|
|
1231 | 1231 |
/** |
1232 | 1232 |
* Calculates the new extent for the FFrame. It is necessary to avoid |
1233 | 1233 |
* scale changes when a pan is triggered from the view, as the different |
1234 | 1234 |
* size factors from View/FFrameView introduces scale changes even for |
1235 | 1235 |
* pans |
1236 |
*
|
|
1236 |
* |
|
1237 | 1237 |
* @param newEnvelope |
1238 | 1238 |
* @return |
1239 | 1239 |
*/ |
... | ... | |
1242 | 1242 |
Envelope oldViewEnvelope = null; |
1243 | 1243 |
try { |
1244 | 1244 |
if (getView().getMapContext().getViewPort().getEnvelopes().hasPrevious()) { |
1245 |
Rectangle2D r = getView().getMapContext().getViewPort().getEnvelopes().get(); |
|
1245 |
Rectangle2D r = getView().getMapContext().getViewPort().getEnvelopes().getPrev();
|
|
1246 | 1246 |
oldViewEnvelope = GeometryLocator.getGeometryManager().createEnvelope(r.getMinX(), r.getMinY(), r.getMaxX(), r.getMaxY(), SUBTYPES.GEOM2D); |
1247 | 1247 |
} |
1248 | 1248 |
if (isPan(oldViewEnvelope, newEnvelope)) { |
... | ... | |
1280 | 1280 |
else { |
1281 | 1281 |
getMapContext().getViewPort().setEnvelope(calculateNewExtent()); |
1282 | 1282 |
if (scaleType==SCALE_TYPE.FIXED_SCALE) { |
1283 |
getMapContext().setScaleView(Math.round(fixedScale));
|
|
1283 |
getMapContext().setScaleView(Math.round(fixedScale)); |
|
1284 | 1284 |
getView().getMapContext().getViewPort().setEnvelope(getMapContext().getViewPort().getAdjustedEnvelope()); |
1285 | 1285 |
} |
1286 | 1286 |
updateScaleCtrl(); |
... | ... | |
1288 | 1288 |
} |
1289 | 1289 |
} |
1290 | 1290 |
b_updating = false; |
1291 |
}
|
|
1291 |
} |
|
1292 | 1292 |
} |
1293 | 1293 |
|
1294 | 1294 |
public void backColorChanged(ColorEvent e) { |
... | ... | |
1320 | 1320 |
invalidateLayout(); |
1321 | 1321 |
// the view should also receive the event and update automatically |
1322 | 1322 |
b_updating = false; |
1323 |
}
|
|
1323 |
} |
|
1324 | 1324 |
} |
1325 | 1325 |
|
1326 | 1326 |
public void legendChanged(LegendChangedEvent e) { |
... | ... | |
1413 | 1413 |
updateScaleCtrl(); |
1414 | 1414 |
invalidateLayout(); |
1415 | 1415 |
b_updating = false; |
1416 |
}
|
|
1416 |
} |
|
1417 | 1417 |
} |
1418 | 1418 |
|
1419 | 1419 |
public void backColorChanged(ColorEvent e) { |
... | ... | |
1463 | 1463 |
try { |
1464 | 1464 |
b_updating = true; |
1465 | 1465 |
fullExtent(); |
1466 |
|
|
1466 |
|
|
1467 | 1467 |
} catch (ReadException e1) { |
1468 | 1468 |
} finally { |
1469 | 1469 |
b_updating = false; |
... | ... | |
1520 | 1520 |
public void setScaleType(SCALE_TYPE scaleType) { |
1521 | 1521 |
this.scaleType = scaleType; |
1522 | 1522 |
} |
1523 |
|
|
1523 |
|
|
1524 | 1524 |
public void setScaleType(SCALE_TYPE scaleType, double fixedScale) { |
1525 | 1525 |
if (scaleType == SCALE_TYPE.FIXED_SCALE) { |
1526 | 1526 |
this.scaleType = scaleType; |
... | ... | |
1528 | 1528 |
setScale(fixedScale); |
1529 | 1529 |
} |
1530 | 1530 |
} |
1531 |
|
|
1531 |
|
|
1532 | 1532 |
public void setScaleType(SCALE_TYPE scaleType, Envelope fixedExtent) { |
1533 | 1533 |
if (scaleType == SCALE_TYPE.FIXED_EXTENT) { |
1534 | 1534 |
this.scaleType = scaleType; |
... | ... | |
1557 | 1557 |
// as the control instance is shared for all the windows |
1558 | 1558 |
updateScaleCtrl(); |
1559 | 1559 |
} |
1560 |
|
|
1560 |
|
|
1561 | 1561 |
} |
1562 | 1562 |
|
1563 | 1563 |
public void windowClosed() { |
Also available in: Unified diff