Revision 4256 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/v02/FGraphicUtilities.java
FGraphicUtilities.java | ||
---|---|---|
53 | 53 |
import java.awt.Rectangle; |
54 | 54 |
import java.awt.geom.AffineTransform; |
55 | 55 |
import java.awt.geom.Point2D; |
56 |
import java.awt.geom.Rectangle2D; |
|
57 | 56 |
|
58 | 57 |
import org.apache.batik.ext.awt.geom.PathLength; |
59 | 58 |
|
60 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
61 | 59 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
62 | 60 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
63 | 61 |
import com.iver.cit.gvsig.fmap.core.FPolyline2D; |
... | ... | |
75 | 73 |
* @author fjp |
76 | 74 |
*/ |
77 | 75 |
public class FGraphicUtilities { |
76 |
|
|
77 |
|
|
78 | 78 |
/** |
79 | 79 |
* Dibuja el s?mbolo que se le pasa como par?metro en el Graphics. |
80 | 80 |
* |
... | ... | |
492 | 492 |
* @param theSymbol S?mbolo para aplicar. |
493 | 493 |
* @param theLabel FLabel que contiene el texto que se debe dibujar. |
494 | 494 |
*/ |
495 |
public static void DrawLabel2(Graphics2D g2, ViewPort vp,
|
|
496 |
FSymbol theSymbol, FLabel theLabel,FontMetrics metrics) { |
|
495 |
public static void DrawAnnotation(Graphics2D g2, AffineTransform at,
|
|
496 |
FSymbol theSymbol, FLabel theLabel,FontMetrics metrics,boolean isSelected) {
|
|
497 | 497 |
//float angle; |
498 | 498 |
float x; |
499 | 499 |
float y; |
500 |
boolean isInPixels=theSymbol.isFontSizeInPixels(); |
|
500 | 501 |
Point2D pAux = null; |
501 | 502 |
// Las etiquetas que pongamos a nulo ser? porque no la queremos dibujar. |
502 | 503 |
// ?til para cuando queramos eliminar duplicados. |
503 | 504 |
if (theLabel.getString() == null) { |
504 | 505 |
return; |
505 | 506 |
} |
507 |
Font font=theLabel.getFont(at,isInPixels); |
|
508 |
if (font.getSize()<3){ |
|
509 |
return; |
|
510 |
} |
|
511 |
g2.setFont(font); |
|
512 |
g2.setColor(theLabel.getColor()); |
|
513 |
if (isSelected){ |
|
514 |
g2.setColor(FSymbol.getSelectionColor()); |
|
515 |
} |
|
506 | 516 |
|
507 |
g2.setFont(theSymbol.getFont()); |
|
508 |
g2.setColor(theSymbol.getFontColor()); |
|
509 | 517 |
|
518 |
|
|
519 |
/* Font font=Font.getFont(theLabel.getTypeFont()+"-"+theLabel.getHeight(),theSymbol.getFont()); |
|
520 |
g2.setColor(theLabel.getColor()); |
|
521 |
g2.setFont(font); |
|
522 |
if (isSelected){ |
|
523 |
g2.setColor(FSymbol.getSelectionColor()); |
|
524 |
} |
|
525 |
|
|
510 | 526 |
// Aqu? hay que mirar m_Size y m_useSize... |
511 |
if (!theSymbol.isFontSizeInPixels()) {
|
|
527 |
if (!isInPixels) {
|
|
512 | 528 |
// Suponemos que m_Size viene en coordenadas de mundo real |
513 | 529 |
// Esto habr? que cambiarlo. Probablemente usar Style2d de geotools en lugar |
514 | 530 |
// de FSymbol. |
515 | 531 |
// CAMBIO: La altura del texto la miramos en FLabel |
516 | 532 |
// float alturaPixels = (float) (theSymbol.m_FontSize * mT.getScaleX()); |
517 |
float alturaPixels = (float) (theLabel.getHeight() * vp.getAffineTransform().getScaleX());
|
|
533 |
float alturaPixels = (float) ((theLabel.getHeight() * at.getScaleX())*FLabel.SQUARE);
|
|
518 | 534 |
|
519 |
/* System.out.println("m_bUseSize = " + theSymbol.m_bUseSize + |
|
520 |
" Escala: " + mT.getScaleX() + " alturaPixels = " + alturaPixels); */ |
|
535 |
|
|
521 | 536 |
if (alturaPixels < 3) { |
522 | 537 |
return; // No leemos nada |
523 | 538 |
} |
524 | 539 |
|
525 |
Font nuevaFuente = theSymbol.getFont().deriveFont(alturaPixels);
|
|
540 |
Font nuevaFuente = font.deriveFont(alturaPixels);
|
|
526 | 541 |
g2.setFont(nuevaFuente); |
527 | 542 |
//width = g2.getFontMetrics().stringWidth(theLabel.getString()); |
528 | 543 |
} |
544 |
*/ |
|
545 |
pAux = at.transform(theLabel.getOrig(), null); |
|
529 | 546 |
|
530 |
pAux = vp.getAffineTransform().transform(theLabel.getOrig(), null); |
|
531 |
|
|
532 | 547 |
AffineTransform ant = g2.getTransform(); |
533 | 548 |
|
534 | 549 |
x = (float) pAux.getX(); |
... | ... | |
538 | 553 |
Tx.translate(x, y); // S3: final translation |
539 | 554 |
Tx.rotate(theLabel.getRotation()); // S2: rotate around anchor |
540 | 555 |
g2.setTransform(Tx); |
541 |
// Rectangle2D borde=textLayout.getBoundingBox(theLabel.getOrig(),theLabel.getJustification(),g2,vp);//theLabel.getBoundingBox(); |
|
542 |
///textLayout.draw(g2,theLabel.getJustification()); |
|
543 |
//g2.setColor(Color.blue); |
|
544 |
// g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight()); |
|
545 | 556 |
|
546 |
String s=theLabel.getString(); |
|
547 |
float width = metrics.stringWidth(s); |
|
548 |
float height = metrics.getMaxAscent(); |
|
557 |
|
|
558 |
String s=theLabel.getString(); |
|
559 |
|
|
560 |
|
|
549 | 561 |
switch (theLabel.getJustification()) { |
550 | 562 |
|
551 | 563 |
case FLabel.LEFT_BOTTOM: |
... | ... | |
554 | 566 |
break; |
555 | 567 |
|
556 | 568 |
case FLabel.LEFT_CENTER: |
569 |
float height = metrics.getMaxAscent(); |
|
557 | 570 |
g2.drawString(s, 0, 0 - (height / 2)); |
558 | 571 |
|
559 | 572 |
break; |
560 | 573 |
|
561 | 574 |
case FLabel.LEFT_TOP: |
575 |
height = metrics.getMaxAscent(); |
|
562 | 576 |
g2.drawString(s, 0, 0 - height); |
563 | 577 |
|
564 | 578 |
break; |
565 | 579 |
|
566 | 580 |
case FLabel.CENTER_BOTTOM: |
581 |
float width = metrics.stringWidth(s); |
|
567 | 582 |
g2.drawString(s, 0 - (width / 2), 0 - 3); |
568 | 583 |
|
569 | 584 |
break; |
570 | 585 |
|
571 | 586 |
case FLabel.CENTER_CENTER: |
587 |
height = metrics.getMaxAscent(); |
|
588 |
width = metrics.stringWidth(s); |
|
572 | 589 |
g2.drawString(s, 0 - (width / 2), |
573 | 590 |
0 - (height / 2)); |
574 | 591 |
|
575 | 592 |
break; |
576 | 593 |
|
577 | 594 |
case FLabel.CENTER_TOP: |
595 |
width = metrics.stringWidth(s); |
|
596 |
height = metrics.getMaxAscent(); |
|
578 | 597 |
g2.drawString(s, 0 - (width / 2), 0 - |
579 | 598 |
height); |
580 | 599 |
|
581 | 600 |
break; |
582 | 601 |
|
583 | 602 |
case FLabel.RIGHT_BOTTOM: |
603 |
width = metrics.stringWidth(s); |
|
584 | 604 |
g2.drawString(s, 0 - width, 0 - 3); |
585 | 605 |
|
586 | 606 |
break; |
587 | 607 |
|
588 | 608 |
case FLabel.RIGHT_CENTER: |
609 |
width = metrics.stringWidth(s); |
|
610 |
height = metrics.getMaxAscent(); |
|
589 | 611 |
g2.drawString(s, 0 - width, 0 - |
590 | 612 |
(height / 2)); |
591 | 613 |
|
592 | 614 |
break; |
593 | 615 |
|
594 | 616 |
case FLabel.RIGHT_TOP: |
617 |
width = metrics.stringWidth(s); |
|
618 |
height = metrics.getMaxAscent(); |
|
595 | 619 |
g2.drawString(s, 0 - width, 0 - height); |
596 | 620 |
|
597 | 621 |
break; |
598 | 622 |
} |
623 |
///Rectangle2D borde=vp.fromMapRectangle(theLabel.getBoundBox());//theLabel.getBoundingBox(); |
|
624 |
///g2.setColor(Color.blue); |
|
625 |
///g2.drawRect((int)borde.getX(),(int)borde.getY(),(int)borde.getWidth(),(int)borde.getHeight()); |
|
599 | 626 |
// Restauramos |
600 | 627 |
g2.setTransform(ant); |
601 | 628 |
} |
Also available in: Unified diff