88 |
88 |
private static final String TYPESCALE_FIELD = "typeScale";
|
89 |
89 |
private static final String EXTENSION_FIELD = "extension";
|
90 |
90 |
private static final String QUALITY_FIELD = "quality";
|
91 |
|
private static final String VIEWING_FIELD = "viewing";
|
92 |
91 |
private static final String BLINKED_FIELD = "bLinked";
|
93 |
92 |
private static final String MAPUNITS_FIELD = "mapUnits";
|
94 |
93 |
private static final String SCALE_FIELD = "scale";
|
... | ... | |
108 |
107 |
protected int typeScale = AUTOMATICO;
|
109 |
108 |
protected int extension = 0;
|
110 |
109 |
protected int quality = PRESENTATION;
|
111 |
|
protected int viewing = 0;
|
112 |
110 |
protected boolean linked = true;
|
113 |
111 |
protected ViewDocument viewDocument = null;
|
114 |
112 |
protected MapContext mapContext = null;
|
... | ... | |
167 |
165 |
refresh = true;
|
168 |
166 |
mapScale =
|
169 |
167 |
FLayoutUtilities.getScaleView(getMapContext().getViewPort(),
|
170 |
|
getBoundBox().width, getBoundingBox(null).width
|
171 |
|
/ getBoundBox().width);
|
|
168 |
getBoundBox().width, getBoundingBox(null).width);
|
|
169 |
updateScaleCtrl();
|
172 |
170 |
}
|
|
171 |
|
|
172 |
/**
|
|
173 |
* Calculates the resolution (measured on dots per inch, DPI) to be
|
|
174 |
* considered to draw the FFrameView on screen. It is calculated by
|
|
175 |
* dividing the width (in pixels) of the FFrame divided by the width
|
|
176 |
* in inches of the paper.
|
|
177 |
*/
|
|
178 |
protected double getDrawPaperDPI() {
|
|
179 |
return (2.54*getBoundingBox(null).width)/getBoundBox().width;
|
|
180 |
}
|
173 |
181 |
|
174 |
182 |
/**
|
175 |
183 |
* Devuelve el FMap de la vista o una clonaci?n de este si se utiliza una
|
... | ... | |
201 |
209 |
}
|
202 |
210 |
|
203 |
211 |
/**
|
204 |
|
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
205 |
|
*
|
206 |
|
* @return forma que se actualiza la vista.
|
207 |
|
*/
|
208 |
|
public int getViewing() {
|
209 |
|
return viewing;
|
210 |
|
}
|
211 |
|
|
212 |
|
/**
|
213 |
|
* Rellena la forma de actualizar la vista(cuando activo o siempre). De
|
214 |
|
* momento esta opci?n esta deshabilitada.
|
215 |
|
*
|
216 |
|
* @param v
|
217 |
|
* entero que representa la forma de actualizar la vista.
|
218 |
|
*/
|
219 |
|
public void setViewing(int v) {
|
220 |
|
viewing = v;
|
221 |
|
}
|
222 |
|
|
223 |
|
/**
|
224 |
212 |
* Inserta el ProjectView de donde obtener las propiedades de la vista a
|
225 |
213 |
* mostrar.
|
226 |
214 |
*
|
... | ... | |
378 |
366 |
}
|
379 |
367 |
|
380 |
368 |
/**
|
381 |
|
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
382 |
|
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
383 |
|
* de dibujar.
|
|
369 |
* Draws the FFrameView on the provided Graphics, according to the
|
|
370 |
* provided affine transform and the visible rectangle.
|
384 |
371 |
*
|
385 |
|
* @param g
|
386 |
|
* Graphics2D
|
387 |
|
* @param at
|
388 |
|
* Transformada af?n.
|
389 |
|
* @param rectangleView
|
390 |
|
* rect?ngulo sobre el que hacer un clip.
|
391 |
|
* @param imgBase
|
392 |
|
* Imagen para acelerar el dibujado.
|
|
372 |
* @param g Graphics2D
|
|
373 |
* @param at Affine transform to translate sheet coordinates (in cm)
|
|
374 |
* to screen coordinates (in pixels)
|
|
375 |
* @param visibleLayoutDocRect visible rectangle
|
|
376 |
* @param imgBase Image used to speed up the drawing process
|
393 |
377 |
*/
|
394 |
|
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rectangleView, BufferedImage imgBase) {
|
395 |
|
Rectangle2D.Double rectangleLayout = getBoundingBox(at);
|
396 |
|
Rectangle originalClip = preDraw(g, rectangleLayout);
|
397 |
|
if (intersects(rectangleView, rectangleLayout)) {
|
|
378 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase) {
|
|
379 |
Rectangle2D.Double fframeViewRect = getBoundingBox(at);
|
|
380 |
Rectangle originalClip = preDraw(g, fframeViewRect);
|
|
381 |
if (intersects(visibleLayoutDocRect, fframeViewRect)) {
|
398 |
382 |
if (getMapContext() == null) {
|
399 |
383 |
drawEmpty(g);
|
400 |
384 |
} else {
|
... | ... | |
409 |
393 |
} else {
|
410 |
394 |
if (getQuality() == PRESENTATION) {
|
411 |
395 |
try {
|
412 |
|
drawPresentation(g, at, rectangleLayout, rectangleView, imgBase);
|
|
396 |
drawPresentation(g, at, fframeViewRect, visibleLayoutDocRect, imgBase);
|
413 |
397 |
} catch (Exception exc) {
|
414 |
398 |
drawMessage(g, FLayoutFunctions.getLastMessage(exc));
|
415 |
399 |
}
|
... | ... | |
420 |
404 |
}
|
421 |
405 |
}
|
422 |
406 |
}
|
423 |
|
postDraw(g, rectangleLayout, rectangleView, imgBase, originalClip, at);
|
|
407 |
postDraw(g, fframeViewRect, visibleLayoutDocRect, imgBase, originalClip, at);
|
424 |
408 |
if (showGrid && grid != null) {
|
425 |
|
grid.draw(g, at, rectangleView, imgBase);
|
|
409 |
grid.draw(g, at, visibleLayoutDocRect, imgBase);
|
426 |
410 |
}
|
427 |
411 |
}
|
428 |
412 |
|
... | ... | |
449 |
433 |
protected void drawPresentation(
|
450 |
434 |
Graphics2D g,
|
451 |
435 |
AffineTransform affineTransform,
|
452 |
|
Rectangle2D.Double rectangleLayout,
|
453 |
|
Rectangle2D rectangleView,
|
|
436 |
Rectangle2D.Double fframeViewRect,
|
|
437 |
Rectangle2D visibleLayoutDocRect,
|
454 |
438 |
BufferedImage imgBase) throws Exception {
|
455 |
439 |
|
456 |
|
Point mapOrigin = new Point((int)rectangleView.getMinX(), (int)rectangleView.getMaxY());
|
|
440 |
Point mapOrigin = new Point((int)visibleLayoutDocRect.getMinX(), (int)visibleLayoutDocRect.getMaxY());
|
457 |
441 |
|
458 |
442 |
ViewPort viewPort = this.getMapContext().getViewPort();
|
459 |
443 |
Color theBackColor = viewPort.getBackColor();
|
|
444 |
int drawWidth = (int)fframeViewRect.width;
|
|
445 |
int drawHeight = (int)fframeViewRect.height;
|
460 |
446 |
|
461 |
447 |
//If the image has to be created...
|
462 |
448 |
if (!(origin != null
|
... | ... | |
464 |
450 |
&& affineTransform.getScaleX() == scaleAnt
|
465 |
451 |
&& m_image != null
|
466 |
452 |
&& !refresh
|
467 |
|
&& !(rectangleLayout.getWidth() > rectangleView.getWidth() || rectangleLayout.getHeight() > rectangleView.getHeight()))) {
|
|
453 |
&& !(fframeViewRect.getWidth() > visibleLayoutDocRect.getWidth() || fframeViewRect.getHeight() > visibleLayoutDocRect.getHeight()))) {
|
468 |
454 |
|
469 |
|
double scale1_1 = viewPort.getDPI() / 2.54;
|
470 |
|
/*
|
471 |
|
* This is the ratio between the size assumed by the
|
472 |
|
* mapcontext drawer and the true size on screen
|
473 |
|
*/
|
474 |
|
double visible_factor = affineTransform.getScaleX() / scale1_1;
|
475 |
|
int draw_w = (int) (1d * rectangleLayout.width / visible_factor);
|
476 |
|
int draw_h = (int) (1d * rectangleLayout.height / visible_factor);
|
477 |
|
|
478 |
|
viewPort.setImageSize(new Dimension(draw_w, draw_h));
|
479 |
|
viewPort.refreshExtent();
|
480 |
|
|
481 |
|
/*
|
482 |
|
viewPort.setOffset(new Point2D.Double(rectangleLayout.x, rectangleLayout.y));
|
483 |
|
*/
|
484 |
|
|
|
455 |
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 |
viewPort.setDPI(getDrawPaperDPI());
|
485 |
458 |
m_image =
|
486 |
|
new BufferedImage(
|
487 |
|
draw_w, //(int) rectangleLayout.getWidth(),
|
488 |
|
draw_h, //(int) rectangleLayout.getHeight(),
|
489 |
|
BufferedImage.TYPE_INT_ARGB);
|
|
459 |
new BufferedImage(
|
|
460 |
drawWidth,
|
|
461 |
drawHeight,
|
|
462 |
BufferedImage.TYPE_INT_ARGB);
|
490 |
463 |
|
491 |
|
Graphics2D gimg = (Graphics2D) m_image.createGraphics();
|
492 |
|
|
493 |
|
/*
|
494 |
|
gimg.translate(-((int) rectangleLayout.getX()),
|
495 |
|
-((int) rectangleLayout.getY()));
|
496 |
|
*/
|
|
464 |
Graphics2D gimg = (Graphics2D) m_image.createGraphics();
|
|
465 |
|
497 |
466 |
|
498 |
|
getMapContext().draw(m_image, gimg, getScale());
|
499 |
|
gimg.dispose();
|
500 |
|
/*
|
501 |
|
gimg.translate(((int) rectangleLayout.getX()),
|
502 |
|
((int) rectangleLayout.getY()));
|
503 |
|
*/
|
|
467 |
getMapContext().draw(m_image, gimg, getScale());
|
|
468 |
gimg.dispose();
|
504 |
469 |
refresh = false;
|
505 |
470 |
}
|
506 |
471 |
|
507 |
472 |
//Draw the created image
|
508 |
473 |
if (theBackColor != null) {
|
509 |
474 |
g.setColor(theBackColor);
|
510 |
|
g.fillRect((int) rectangleLayout.x, (int) rectangleLayout.y,
|
511 |
|
viewPort.getImageWidth(),
|
512 |
|
viewPort.getImageHeight());
|
|
475 |
g.fillRect((int) fframeViewRect.x, (int) fframeViewRect.y,
|
|
476 |
(int)fframeViewRect.width,
|
|
477 |
(int)fframeViewRect.height);
|
513 |
478 |
}
|
|
479 |
g.drawImage(m_image,
|
|
480 |
(int) fframeViewRect.x,
|
|
481 |
(int) fframeViewRect.y,
|
|
482 |
null);
|
514 |
483 |
|
515 |
|
m_image = copyForcingImageSize(
|
516 |
|
m_image,
|
517 |
|
(int) rectangleLayout.getWidth(),
|
518 |
|
(int) rectangleLayout.getHeight());
|
519 |
|
|
520 |
|
g.drawImage(m_image,
|
521 |
|
(int) rectangleLayout.getX(),
|
522 |
|
(int) rectangleLayout.getY(), null);
|
523 |
|
|
524 |
484 |
scaleAnt = affineTransform.getScaleX();
|
525 |
485 |
origin = mapOrigin;
|
526 |
486 |
}
|
527 |
|
|
528 |
|
/**
|
529 |
|
* @param m_image2
|
530 |
|
* @param width
|
531 |
|
* @param height
|
532 |
|
* @return
|
533 |
|
*/
|
534 |
|
protected BufferedImage copyForcingImageSize(
|
535 |
|
BufferedImage disp_img, int w, int h) {
|
536 |
|
|
537 |
|
Graphics rg = null;
|
538 |
|
|
539 |
|
try {
|
540 |
|
if (disp_img == null || w < 1 || h < 1) {
|
541 |
|
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
542 |
|
}
|
543 |
|
int from_w = disp_img.getWidth(null);
|
544 |
|
int from_h = disp_img.getHeight(null);
|
545 |
|
if (from_w < 1 || from_h < 1) {
|
546 |
|
return new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
|
547 |
|
}
|
548 |
|
|
549 |
|
BufferedImage resp =
|
550 |
|
new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
551 |
|
rg = resp.createGraphics();
|
552 |
|
|
553 |
|
double rat_w = (1d*w) / (1d*from_w);
|
554 |
|
double rat_h = (1d*h) / (1d*from_h);
|
555 |
|
int offset_w = 0;
|
556 |
|
int offset_h = 0;
|
557 |
|
Image aux = null;
|
558 |
487 |
|
559 |
|
if (rat_w <= rat_h) {
|
560 |
|
// apply resize of width
|
561 |
|
int target_h = Math.max(1, (int) (from_h * rat_w));
|
562 |
|
// w, target_h
|
563 |
|
offset_w = 0;
|
564 |
|
offset_h = (h - target_h) / 2;
|
565 |
|
aux = disp_img.getScaledInstance(w, target_h, Image.SCALE_FAST);
|
566 |
|
rg.drawImage(aux, offset_w, offset_h, null);
|
567 |
|
|
568 |
|
} else {
|
569 |
|
// apply resize from height
|
570 |
|
int target_w = Math.max(1, (int) (from_w * rat_h));
|
571 |
|
// target_w, h
|
572 |
|
offset_w = (w - target_w) / 2;
|
573 |
|
offset_h = 0;
|
574 |
|
aux = disp_img.getScaledInstance(target_w, h, Image.SCALE_FAST);
|
575 |
|
rg.drawImage(aux, offset_w, offset_h, null);
|
576 |
|
}
|
577 |
|
|
578 |
|
aux = null;
|
579 |
|
resp.flush();
|
580 |
|
rg.dispose();
|
581 |
|
return resp;
|
582 |
|
} catch (Throwable th) {
|
583 |
|
logger.info("While resizing image.", th);
|
584 |
|
if (rg != null) {
|
585 |
|
rg.dispose();
|
586 |
|
}
|
587 |
|
return null;
|
588 |
|
}
|
589 |
|
|
590 |
|
}
|
591 |
|
|
592 |
|
protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double rectangleLayout){
|
|
488 |
protected Rectangle preDraw(Graphics2D g, Rectangle2D.Double fframeViewRect){
|
593 |
489 |
Rectangle originalClip = null;
|
594 |
490 |
if (g.getClipBounds() != null) {
|
595 |
491 |
originalClip = (Rectangle) g.getClipBounds().clone();
|
596 |
492 |
}
|
597 |
493 |
if (getRotation() != 0) {
|
598 |
|
g.rotate(Math.toRadians(getRotation()), rectangleLayout.getCenterX(), rectangleLayout.getCenterY()
|
599 |
|
+ (rectangleLayout.height / 2));
|
|
494 |
g.rotate(Math.toRadians(getRotation()), fframeViewRect.getCenterX(), fframeViewRect.getCenterY()
|
|
495 |
+ (fframeViewRect.height / 2));
|
600 |
496 |
}
|
601 |
|
g.clipRect((int) rectangleLayout.getMinX(), (int) rectangleLayout.getMinY(),
|
602 |
|
(int) rectangleLayout.getWidth(), (int) rectangleLayout.getHeight());
|
|
497 |
g.clipRect((int) fframeViewRect.getMinX(), (int) fframeViewRect.getMinY(),
|
|
498 |
(int) fframeViewRect.getWidth(), (int) fframeViewRect.getHeight());
|
603 |
499 |
return originalClip;
|
604 |
500 |
}
|
605 |
501 |
|
606 |
|
protected void postDraw(Graphics2D g, Rectangle2D.Double rectangleLayout, Rectangle2D rectangleView, BufferedImage imgBase,
|
|
502 |
protected void postDraw(Graphics2D g, Rectangle2D.Double fframeViewRect, Rectangle2D visibleLayoutDocRect, BufferedImage imgBase,
|
607 |
503 |
Rectangle originalClip, AffineTransform at){
|
608 |
504 |
if (getRotation() != 0) {
|
609 |
|
g.rotate(Math.toRadians(-getRotation()), rectangleLayout.getCenterX(), rectangleLayout.getCenterY());
|
|
505 |
g.rotate(Math.toRadians(-getRotation()), fframeViewRect.getCenterX(), fframeViewRect.getCenterY());
|
610 |
506 |
}
|
611 |
507 |
if (getMapContext() != null) {
|
612 |
508 |
setATMap(getMapContext().getViewPort().getAffineTransform());
|
... | ... | |
854 |
750 |
if (linked){
|
855 |
751 |
if (getTypeScale() == AUTOMATICO) {
|
856 |
752 |
mapContext.getViewPort().setEnvelope(e.getNewExtent());
|
|
753 |
// observers.notifyObservers(this,
|
|
754 |
// new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
857 |
755 |
observers.notifyObservers(this,
|
858 |
|
new DefaultLayoutNotification(LayoutNotification.LAYOUT_INVALIDATED));
|
|
756 |
new DefaultLayoutNotification(LayoutNotification.LAYOUT_REFRESH));
|
859 |
757 |
} else
|
860 |
758 |
if (getTypeScale() == MANUAL) {
|
861 |
759 |
Envelope oldExtent = mapContext.getViewPort().getEnvelope();
|
... | ... | |
878 |
776 |
}
|
879 |
777 |
refresh = true;
|
880 |
778 |
}
|
|
779 |
updateScaleCtrl();
|
881 |
780 |
}
|
882 |
781 |
|
883 |
782 |
/**
|
... | ... | |
994 |
893 |
statusbar.setMessage("units",
|
995 |
894 |
PluginServices.getText(this, mapContext.getDistanceName()));
|
996 |
895 |
statusbar.setControlValue("layout-view-change-scale",
|
997 |
|
String.valueOf(mapContext.getScaleView()));
|
|
896 |
String.valueOf(getScale()));
|
998 |
897 |
IProjection proj = mapContext.getViewPort().getProjection();
|
999 |
898 |
if (proj != null) {
|
1000 |
899 |
statusbar.setMessage("projection", proj.getAbrev());
|
... | ... | |
1149 |
1048 |
definition.addDynFieldInt(TYPESCALE_FIELD).setMandatory(true);
|
1150 |
1049 |
definition.addDynFieldInt(EXTENSION_FIELD).setMandatory(true);
|
1151 |
1050 |
definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);
|
1152 |
|
definition.addDynFieldInt(VIEWING_FIELD).setMandatory(true);
|
1153 |
1051 |
definition.addDynFieldBoolean(BLINKED_FIELD).setMandatory(true);
|
1154 |
1052 |
definition.addDynFieldInt(MAPUNITS_FIELD).setMandatory(true);
|
1155 |
1053 |
definition.addDynFieldDouble(SCALE_FIELD).setMandatory(true);
|
... | ... | |
1173 |
1071 |
typeScale = state.getInt(TYPESCALE_FIELD);
|
1174 |
1072 |
extension = state.getInt(EXTENSION_FIELD);
|
1175 |
1073 |
quality = state.getInt(QUALITY_FIELD);
|
1176 |
|
viewing = state.getInt(VIEWING_FIELD);
|
1177 |
1074 |
linked = state.getBoolean(BLINKED_FIELD);
|
1178 |
1075 |
mapUnits = state.getInt(MAPUNITS_FIELD);
|
1179 |
1076 |
mapScale = state.getDouble(SCALE_FIELD);
|
... | ... | |
1196 |
1093 |
state.set(TYPESCALE_FIELD, typeScale);
|
1197 |
1094 |
state.set(EXTENSION_FIELD, extension);
|
1198 |
1095 |
state.set(QUALITY_FIELD, quality);
|
1199 |
|
state.set(VIEWING_FIELD, viewing);
|
1200 |
1096 |
state.set(BLINKED_FIELD, linked);
|
1201 |
1097 |
state.set(MAPUNITS_FIELD, mapUnits);
|
1202 |
1098 |
state.set(SCALE_FIELD, mapScale);
|