1 32 33 package it.businesslogic.ireport; 34 import it.businesslogic.ireport.gui.*; 35 import it.businesslogic.ireport.util.*; 36 import java.awt.*; 37 import java.awt.image.*; 38 import java.awt.geom.*; 39 import java.awt.font.*; 40 import java.util.*; 41 import java.util.List ; 42 import java.text.AttributedCharacterIterator ; 43 import java.text.AttributedString ; 44 45 46 47 public abstract class TextReportElement extends ReportElement implements BoxElement { 48 static public Rotation ROTATION_NONE; 49 static public Rotation ROTATION_LEFT; 50 static public Rotation ROTATION_RIGHT; 51 static public Rotation ROTATION_UPSIDEDOWN; 52 53 static 54 { 55 ROTATION_NONE = new Rotation("None", 0); 56 ROTATION_LEFT = new Rotation("Left", 1); 57 ROTATION_RIGHT = new Rotation("Right", 2); 58 ROTATION_UPSIDEDOWN = new Rotation("UpsideDown", 3); 59 } 60 61 private String text=""; 62 63 static public String ALIGN = "ALIGN"; 64 static public String VERTICAL_ALIGN = "VERTICAL_ALIGN"; 65 static public String IS_STYLED_TEXT = "IS_STYLED_TEXT"; 66 static public String LINE_SPACING = "LINE_SPACING"; 67 static public String ROTATE = "ROTATE"; 68 69 70 static public String DEFAULT_ALIGN = "Left"; 71 static public String DEFAULT_VERTICAL_ALIGN = "Top"; 72 static public boolean DEFAULT_IS_STYLED_TEXT = false; 73 static public String DEFAULT_LINE_SPACING = "single"; 74 static public String DEFAULT_ROTATE = "None"; 75 76 91 private java.awt.Font font=null; 92 93 94 97 private Box box = null; 98 private IReportFont iReportFont; 99 100 101 public TextReportElement(int x, int y, int width, int height) 102 { 103 super(x,y,width,height); 104 105 this.text = "Static text\nsecond line"; 110 box = new Box(); 114 transparentDefault = "Transparent"; 116 setIReportFont(new IReportFont()); 117 118 } 119 120 public void setIReportFont(IReportFont newIreportFont){ 121 122 if(newIreportFont == null){ 123 this.iReportFont = new IReportFont(); 124 } 125 else 126 { 127 this.iReportFont = (IReportFont)newIreportFont.clone(); 128 } 129 this.font = iReportFont.getJavaAWTFont(); 130 } 131 132 133 public IReportFont getIReportFont(){ 134 if (iReportFont == null) iReportFont = new IReportFont(); 135 return iReportFont; 136 } 137 138 public void drawObject(Graphics2D g,double zoom_factor, int x_shift_origin, int y_shift_origin) 139 { 140 142 position.x -= 10; 143 position.y -= 10; 144 x_shift_origin -= 10; 145 y_shift_origin -= 10; 146 147 148 this.zoom_factor = zoom_factor; 149 150 g.setColor( getBgcolor() ); 151 152 if (!getTransparent().equalsIgnoreCase("Transparent")) 153 { 154 g.fillRect(getZoomedDim(position.x)-x_shift_origin, 155 getZoomedDim(position.y)-y_shift_origin, 156 getZoomedDim(width), 157 getZoomedDim(height)); 158 } 159 g.setColor( getFgcolor() ); 160 161 164 if (font == null) 165 { 166 int style = 0; 167 if (isBold()) style |= Font.BOLD; 168 if (isItalic()) style |= Font.ITALIC; 169 if (style == 0) style = Font.PLAIN; 170 font = new Font( this.getFontName(), style , getZoomedDim( this.getFontSize() )); 171 } 172 173 175 int gfx_x = getZoomedDim(position.x + getBox().getLeftPadding() )-x_shift_origin; 176 int gfx_y = getZoomedDim(position.y + getBox().getTopPadding())-y_shift_origin; 177 int gfx_width = getZoomedDim(width - getBox().getLeftPadding() - getBox().getRightPadding()); 178 int gfx_height = getZoomedDim(height - getBox().getTopPadding() - getBox().getBottomPadding()); 179 180 181 188 189 190 double angle = 0; 191 double angle_restore = 0; 192 193 AffineTransform transform = null; 196 AffineTransform savedAT = g.getTransform(); 197 198 if(getRotate().equals(ROTATION_LEFT.getName())) 199 { 200 transform = g.getTransform(); 201 transform.rotate(-Math.PI / 2, gfx_x, gfx_y); 202 transform.translate(-gfx_height , -gfx_height); 203 gfx_y = gfx_y + gfx_height; 204 gfx_height = getZoomedDim(width - getBox().getLeftPadding() - getBox().getRightPadding()); 205 gfx_width = getZoomedDim(height - getBox().getTopPadding() - getBox().getBottomPadding()); 206 207 } 208 else if(getRotate().equals(ROTATION_RIGHT.getName())) 209 { 210 transform = g.getTransform(); 211 212 transform.rotate(Math.PI / 2, gfx_x, gfx_y); 213 transform.translate(-gfx_width, -gfx_width); 214 gfx_x = gfx_x + gfx_width; 215 gfx_width = getZoomedDim(height); 216 gfx_height = getZoomedDim(width - getBox().getLeftPadding() - getBox().getRightPadding()); 217 gfx_width = getZoomedDim(height - getBox().getTopPadding() - getBox().getBottomPadding()); 218 } 219 else if(getRotate().equals(ROTATION_UPSIDEDOWN.getName())) 220 { 221 transform = g.getTransform(); 222 223 transform.rotate(Math.PI, gfx_x, gfx_y); 224 transform.translate(-gfx_width, -gfx_height); 225 231 } 232 233 if (this.getText() != null && this.getText().length() > 0) 234 { 235 drawText(g, transform, gfx_x, gfx_y, gfx_height, gfx_width); 236 } 237 238 239 240 243 245 246 247 position.x += 10; 248 position.y += 10; 249 x_shift_origin += 10; 250 y_shift_origin += 10; 251 252 drawBorder( g, zoom_factor, x_shift_origin,y_shift_origin); 253 drawBorder( g, zoom_factor, x_shift_origin,y_shift_origin,getBox()); 254 } 256 257 261 public java.lang.String getAlign() 262 { 263 if (getPropertyValue(ALIGN) == null) 264 { 265 if (getStyle() != null) 267 { 268 return getStyle().getAttributeString( getStyle().ATTRIBUTE_hAlign, DEFAULT_ALIGN, true); 269 } 270 } 271 return getStringValue(ALIGN, DEFAULT_ALIGN ); 272 } 273 274 278 public void setAlign(java.lang.String align) 279 { 280 this.setPropertyValue(ALIGN, align); 281 } 282 283 287 public boolean isBold() 288 { 289 if (getIReportFont().getPropertyValue( IReportFont.IS_BOLD) == null) 290 { 291 if (getStyle() != null) 293 { 294 return getStyle().getAttributeBoolean( getStyle().ATTRIBUTE_isBold, IReportFont.DEFAULT_IS_BOLD, true); 295 } 296 } 297 return getIReportFont().getBooleanValue( IReportFont.IS_BOLD, IReportFont.DEFAULT_IS_BOLD ); 298 } 299 300 304 public void setBold(boolean bold) 305 { 306 getIReportFont().setPropertyValue( IReportFont.IS_BOLD, ""+bold); 307 } 308 309 313 public java.awt.Font getFont() 314 { 315 return font; 316 } 317 318 322 public void setFont(java.awt.Font font) 323 { 324 this.font = font; 325 } 326 327 331 public java.lang.String getFontName() 332 { 333 if (getIReportFont().getPropertyValue( IReportFont.FONT_NAME) == null) 334 { 335 if (getStyle() != null) 337 { 338 return getStyle().getAttributeString( getStyle().ATTRIBUTE_fontName, IReportFont.DEFAULT_FONT_NAME, true); 339 } 340 } 341 return getIReportFont().getStringValue( IReportFont.FONT_NAME, IReportFont.DEFAULT_FONT_NAME ); 342 } 343 344 348 public void setFontName(java.lang.String fontName) 349 { 350 getIReportFont().setPropertyValue( IReportFont.FONT_NAME, fontName); 351 } 352 353 357 public int getFontSize() 358 { 359 if (getIReportFont().getPropertyValue( IReportFont.FONT_SIZE) == null) 360 { 361 if (getStyle() != null) 363 { 364 return getStyle().getAttributeInteger( getStyle().ATTRIBUTE_fontSize, IReportFont.DEFAULT_FONT_SIZE, true); 365 } 366 } 367 return getIReportFont().getIntValue( IReportFont.FONT_SIZE, IReportFont.DEFAULT_FONT_SIZE ); 368 } 369 370 374 public void setFontSize(int fontSize) 375 { 376 getIReportFont().setPropertyValue( IReportFont.FONT_SIZE, ""+fontSize); 377 } 378 379 383 public void modifyFontSize(int delta) 384 { 385 int newFonsSize = getFontSize() + delta; 386 if ( newFonsSize >= 5) 387 this.setFontSize(newFonsSize ); 388 } 389 390 394 public boolean isItalic() 395 { 396 if (getIReportFont().getPropertyValue( IReportFont.IS_ITALIC) == null) 397 { 398 if (getStyle() != null) 400 { 401 return getStyle().getAttributeBoolean( getStyle().ATTRIBUTE_isItalic, IReportFont.DEFAULT_IS_ITALIC, true); 402 } 403 } 404 return getIReportFont().getBooleanValue( IReportFont.IS_ITALIC, IReportFont.DEFAULT_IS_ITALIC ); 405 } 406 407 411 public void setItalic(boolean italic) 412 { 413 getIReportFont().setPropertyValue( IReportFont.IS_ITALIC, ""+italic); 414 } 415 416 420 public java.lang.String getLineSpacing() 421 { 422 if (getPropertyValue( LINE_SPACING) == null) 423 { 424 if (getStyle() != null) 426 { 427 return getStyle().getAttributeString( getStyle().ATTRIBUTE_lineSpacing, DEFAULT_LINE_SPACING, true); 428 } 429 } 430 return getStringValue( LINE_SPACING, DEFAULT_LINE_SPACING ); 431 } 432 433 437 public void setLineSpacing(java.lang.String lineSpacing) 438 { 439 setPropertyValue( LINE_SPACING, lineSpacing); 440 } 441 442 446 public boolean isPdfEmbedded() 447 { 448 if (getIReportFont().getPropertyValue( IReportFont.IS_PDF_EMBEDDED) == null) 449 { 450 if (getStyle() != null) 452 { 453 return getStyle().getAttributeBoolean( getStyle().ATTRIBUTE_isPdfEmbedded, IReportFont.DEFAULT_IS_PDF_EMBEDDED, true); 454 } 455 } 456 return getIReportFont().getBooleanValue( IReportFont.IS_PDF_EMBEDDED, IReportFont.DEFAULT_IS_PDF_EMBEDDED ); 457 } 458 459 463 public void setPdfEmbedded(boolean pdfEmbedded) 464 { 465 getIReportFont().setPropertyValue( IReportFont.IS_PDF_EMBEDDED, ""+pdfEmbedded); 466 } 467 468 472 public java.lang.String getPdfEncoding() 473 { 474 if (getIReportFont().getPropertyValue( IReportFont.PDF_ENCODING) == null) 475 { 476 if (getStyle() != null) 478 { 479 return getStyle().getAttributeString( getStyle().ATTRIBUTE_pdfEncoding, IReportFont.DEFAULT_PDF_ENCODING, true); 480 } 481 } 482 return getIReportFont().getStringValue( IReportFont.PDF_ENCODING, IReportFont.DEFAULT_PDF_ENCODING ); 483 } 484 485 489 public void setPdfEncoding(java.lang.String pdfEncoding) 490 { 491 getIReportFont().setPropertyValue( IReportFont.PDF_ENCODING, pdfEncoding); 492 } 493 494 498 public java.lang.String getPDFFontName() 499 { 500 if (getIReportFont().getPropertyValue( IReportFont.PDF_FONT_NAME) == null) 501 { 502 if (getStyle() != null) 504 { 505 return getStyle().getAttributeString( getStyle().ATTRIBUTE_pdfFontName, IReportFont.DEFAULT_PDF_FONT_NAME, true); 506 } 507 } 508 return getIReportFont().getStringValue( IReportFont.PDF_FONT_NAME, IReportFont.DEFAULT_PDF_FONT_NAME ); 509 } 510 511 515 public void setPDFFontName(java.lang.String PDFFontName) 516 { 517 getIReportFont().setPropertyValue( IReportFont.PDF_FONT_NAME, PDFFontName); 518 } 519 520 524 public java.lang.String getReportFont() 525 { 526 return getIReportFont().getStringValue( IReportFont.REPORT_FONT, IReportFont.DEFAULT_REPORT_FONT); 527 } 528 529 533 public void setReportFont(java.lang.String reportFont) 534 { 535 getIReportFont().setPropertyValue( IReportFont.REPORT_FONT, reportFont); 536 } 537 538 542 public boolean isStrikeTrought() 543 { 544 if (getIReportFont().getPropertyValue( IReportFont.IS_STRIKETROUGHT) == null) 545 { 546 if (getStyle() != null) 548 { 549 return getStyle().getAttributeBoolean( getStyle().ATTRIBUTE_isStrikeThrough, IReportFont.DEFAULT_IS_STRIKETROUGHT, true); 550 } 551 } 552 return getIReportFont().getBooleanValue( IReportFont.IS_STRIKETROUGHT, IReportFont.DEFAULT_IS_STRIKETROUGHT ); 553 } 554 555 559 public void setStrikeTrought(boolean strikeTrought) 560 { 561 getIReportFont().setPropertyValue( IReportFont.IS_STRIKETROUGHT, ""+strikeTrought); 562 } 563 564 568 public java.lang.String getText() 569 { 570 return text; 571 } 572 573 577 public void setText(java.lang.String text) 578 { 579 this.text = text; 580 } 581 582 586 public java.lang.String getTTFFont() 587 { 588 if (getIReportFont().getPropertyValue( IReportFont.TTF_FONT_NAME) == null) 589 { 590 if (getStyle() != null) 592 { 593 return getStyle().getAttributeString( getStyle().ATTRIBUTE_pdfFontName, IReportFont.DEFAULT_TTF_FONT_NAME, true); 594 } 595 } 596 return getIReportFont().getStringValue( IReportFont.TTF_FONT_NAME, IReportFont.DEFAULT_TTF_FONT_NAME ); 597 } 598 599 603 public void setTTFFont(java.lang.String TTFFont) 604 { 605 getIReportFont().setPropertyValue( IReportFont.TTF_FONT_NAME, TTFFont ); 606 } 607 608 612 public boolean isUnderline() 613 { 614 if (getIReportFont().getPropertyValue( IReportFont.IS_UNDERLINE) == null) 615 { 616 if (getStyle() != null) 618 { 619 return getStyle().getAttributeBoolean( getStyle().ATTRIBUTE_isUnderline, IReportFont.DEFAULT_IS_UNDERLINE, true); 620 } 621 } 622 return getIReportFont().getBooleanValue( IReportFont.IS_UNDERLINE, IReportFont.DEFAULT_IS_UNDERLINE); 623 } 624 625 629 public void setUnderline(boolean underline) 630 { 631 getIReportFont().setPropertyValue( IReportFont.IS_UNDERLINE, ""+underline ); 632 } 633 634 638 public java.lang.String getVerticalAlign() 639 { 640 if (getPropertyValue( VERTICAL_ALIGN) == null) 641 { 642 if (getStyle() != null) 644 { 645 return getStyle().getAttributeString( getStyle().ATTRIBUTE_vAlign, DEFAULT_VERTICAL_ALIGN, true); 646 } 647 } 648 return getStringValue( VERTICAL_ALIGN, DEFAULT_VERTICAL_ALIGN ); 649 } 650 651 655 public void setVerticalAlign(java.lang.String verticalAlign) 656 { 657 setPropertyValue( VERTICAL_ALIGN, verticalAlign ); 658 } 659 660 664 public java.lang.String getRotate() 665 { 666 if (getPropertyValue( ROTATE) == null) 667 { 668 if (getStyle() != null) 670 { 671 return getStyle().getAttributeString( getStyle().ATTRIBUTE_rotation, DEFAULT_ROTATE, true); 672 } 673 } 674 return getStringValue( ROTATE, DEFAULT_ROTATE ); 675 } 676 677 681 public void setRotate(java.lang.String rotate) 682 { 683 setPropertyValue( ROTATE, rotate ); 684 } 685 686 public int getTextHeight(java.awt.FontMetrics fm) 687 { 688 return fm.getAscent() + (this.getLineCount()-1)*(fm.getHeight()); 690 } 691 692 public int getLineCount() 693 { 694 String text = this.getText(); 696 text = text.replace('\r', ' '); 697 int line=1; 698 while (text.indexOf('\n')>0) 699 { 700 line++; 701 text = text.substring( text.indexOf('\n') + 1); 702 } 703 return line; 704 } 705 706 public void copyBaseReportElement(ReportElement destination, ReportElement source) 707 { 708 super.copyBaseReportElement(destination, source); 709 710 if (destination instanceof TextReportElement && 711 source instanceof TextReportElement ) 712 { 713 TextReportElement tre = (TextReportElement)source; 714 TextReportElement tred = (TextReportElement)destination; 715 source.clone(tred); 716 tre.getIReportFont().clone( tred.getIReportFont() ); 717 733 ((TextReportElement)destination).setText(new String ( ((TextReportElement)source).getText() )); 734 ((TextReportElement)destination).setBox( ((TextReportElement)source).getBox().cloneMe() ); 735 } 736 } 737 738 739 private class TextReportElementLayout { 740 private TextLayout layout; 741 private float x; 742 private float y; 743 744 745 private TextReportElementLayout(TextLayout layout, float x, float y) { 746 this.layout = layout; 747 this.x = x; 748 this.y = y; 749 } 750 751 752 void drawWithOffset(Graphics2D g2, float yOffset) { 753 layout.draw(g2, x, y + yOffset); 754 } 755 } 756 757 758 static List getRotations() { 759 return Rotation.rotations; 760 } 761 762 766 public boolean isIsStyledText() { 767 if (getPropertyValue( IS_STYLED_TEXT) == null) 768 { 769 if (getStyle() != null) 771 { 772 return getStyle().getAttributeBoolean( getStyle().ATTRIBUTE_isStyledText, DEFAULT_IS_STYLED_TEXT, true); 773 } 774 } 775 return getBooleanValue( IS_STYLED_TEXT, DEFAULT_IS_STYLED_TEXT ); 776 } 777 778 782 public void setIsStyledText(boolean isStyledText) { 783 setPropertyValue( IS_STYLED_TEXT, "" + isStyledText ); 784 } 785 786 static class Rotation { 787 static private ArrayList rotations; 788 private String name; 789 private int number; 790 791 792 Rotation(String name, int number) { 793 this.name = name; 794 this.number = number; 795 rotations = new ArrayList(); 796 rotations.add(this); 797 } 798 799 800 public int getNumber() { 801 return number; 802 } 803 804 805 public String getName() { 806 return name; 807 } 808 809 810 public String toString() { 811 return getName(); 812 } 813 } 814 815 816 public Box getBox() { 817 return box; 818 } 819 820 public void setBox(Box box) { 821 this.box = box; 822 } 823 824 public void setStyle(Style style) { 825 826 super.setStyle(style); 827 828 if (style != null) 829 { 830 845 if (style.getAttributeString(style.ATTRIBUTE_border, null, true) != null) 847 this.getBox().setBorder( style.getAttributeString(style.ATTRIBUTE_border, null, true) ); 848 if (style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true) != null) 849 this.getBox().setBorderColor( style.getAttributeColor(style.ATTRIBUTE_borderColor, null, true)); 850 if (style.getAttributeString(style.ATTRIBUTE_padding, null, true) != null) 851 this.getBox().setPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_padding, null, true) )); 852 853 if (style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) != null) 854 this.getBox().setTopBorder( style.getAttributeString(style.ATTRIBUTE_topBorder, null, true) ); 855 if (style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true) != null) 856 this.getBox().setTopBorderColor( style.getAttributeColor(style.ATTRIBUTE_topBorderColor, null, true)); 857 if (style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) != null) 858 this.getBox().setTopPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_topPadding, null, true) )); 859 860 if (style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) != null) 861 this.getBox().setLeftBorder( style.getAttributeString(style.ATTRIBUTE_leftBorder, null, true) ); 862 if (style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true) != null) 863 this.getBox().setLeftBorderColor( style.getAttributeColor(style.ATTRIBUTE_leftBorderColor, null, true)); 864 if (style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) != null) 865 this.getBox().setLeftPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_leftPadding, null, true) )); 866 867 if (style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) != null) 868 this.getBox().setRightBorder( style.getAttributeString(style.ATTRIBUTE_rightBorder, null, true) ); 869 if (style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true) != null) 870 this.getBox().setRightBorderColor( style.getAttributeColor(style.ATTRIBUTE_rightBorderColor, null, true)); 871 if (style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) != null) 872 this.getBox().setRightPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_rightPadding, null, true) )); 873 874 if (style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) != null) 875 this.getBox().setBottomBorder( style.getAttributeString(style.ATTRIBUTE_bottomBorder, null, true) ); 876 if (style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true) != null) 877 this.getBox().setBottomBorderColor( style.getAttributeColor(style.ATTRIBUTE_bottomBorderColor, null, true)); 878 if (style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) != null) 879 this.getBox().setBottomPadding( Integer.parseInt( style.getAttributeString(style.ATTRIBUTE_bottomPadding, null, true) )); 880 881 } 882 } 883 884 885 private void drawText(Graphics2D g, AffineTransform transform, int gfx_x, int gfx_y, int gfx_height, int gfx_width) 886 { 887 int zoomedFieldHeight = gfx_height; 888 String allText = Misc.treatNewLineChars(this.getText()); 889 float formatWidth = (float)gfx_width; 890 float verticalOffset = 0f; 891 TextReportElementLayout textReportElementLayout; 892 893 894 ArrayList textLayouts; 895 float x, y; 896 897 898 FontRenderContext fontRenderContext = g.getFontRenderContext(); 899 java.util.Map fontAttributes = font.getAttributes(); 900 fontAttributes.put(TextAttribute.SIZE, new Float (getZoomedDim( this.getFontSize() )) ); 901 fontAttributes.put(TextAttribute.FAMILY, this.getFontName() ); 902 if (this.isBold()) 903 { 904 fontAttributes.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); 905 } 906 if (this.isItalic()) 907 { 908 fontAttributes.put(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); 909 } 910 if (this.isUnderline()) 911 { 912 fontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); 913 } 914 if (this.isStrikeTrought()) 915 { 916 fontAttributes.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); 917 } 918 919 float lineSpacing = 1f; 920 if (this.getLineSpacing().equals("Single")) lineSpacing = 1f; 921 else if (this.getLineSpacing().equals("1_1_2")) lineSpacing = 1.5f; 922 else if (this.getLineSpacing().equals("Double")) lineSpacing = 2f; 923 924 AttributedString atext; 925 AttributedCharacterIterator paragraph; 926 int paragraphStart; 927 int paragraphEnd; 928 LineBreakMeasurer lineMeasurer; 929 TextLayout layout = null; 930 931 932 String paragr_text = ""; 933 boolean isMaxHeightReached = false; 934 935 StringTokenizer tkzer = new StringTokenizer(allText, "\n"); 936 937 float drawPosY = 0; 938 float drawPosX = 0; 939 940 paragr_text = ""; 941 isMaxHeightReached = false; 942 943 tkzer = new StringTokenizer(allText, "\n"); 944 945 946 textLayouts = new ArrayList(); 947 948 while(tkzer.hasMoreTokens() && !isMaxHeightReached) 951 { 952 paragr_text = tkzer.nextToken(); 953 954 atext = new AttributedString (paragr_text, fontAttributes); 955 paragraph = atext.getIterator(); 956 paragraphStart = paragraph.getBeginIndex(); 957 paragraphEnd = paragraph.getEndIndex(); 958 lineMeasurer = new LineBreakMeasurer(paragraph, fontRenderContext); 959 lineMeasurer.setPosition(paragraphStart); 960 961 layout = null; 962 while (lineMeasurer.getPosition() < paragraphEnd && !isMaxHeightReached) 963 { 964 layout = lineMeasurer.nextLayout(formatWidth); 965 966 drawPosY += layout.getLeading() + lineSpacing * layout.getAscent(); 967 968 if (drawPosY + layout.getDescent() <= zoomedFieldHeight+1) 969 { 970 if (this.getAlign().equals("Justify")) 971 { 972 if (layout.isLeftToRight()) 973 { 974 drawPosX = 0; 975 } 976 else 977 { 978 drawPosX = formatWidth - layout.getAdvance(); 979 } 980 if (lineMeasurer.getPosition() < paragraphEnd) 981 { 982 layout = layout.getJustifiedLayout(formatWidth); 983 } 984 } 985 else if (this.getAlign().equals("Right")) 986 { 987 if (layout.isLeftToRight()) 988 { 989 drawPosX = formatWidth - layout.getAdvance(); 990 } 991 else 992 { 993 drawPosX = formatWidth; 994 } 995 } 996 else if (this.getAlign().equals("Center")) 997 { 998 drawPosX = (formatWidth - layout.getAdvance()) / 2; 999 } 1000 else { 1002 if (layout.isLeftToRight()) 1003 { 1004 drawPosX = 0; 1005 } 1006 else 1007 { 1008 drawPosX = formatWidth - layout.getAdvance(); 1009 } 1010 } 1011 1012 x = drawPosX + gfx_x; y = drawPosY + gfx_y; textReportElementLayout = new TextReportElementLayout(layout, x, y); 1015 textLayouts.add(textReportElementLayout); 1016 1017 1018 drawPosY += layout.getDescent(); 1019 } 1020 else 1021 { 1022 drawPosY -= layout.getLeading() + lineSpacing * layout.getAscent(); 1023 isMaxHeightReached = true; 1024 } 1025 } 1026 } 1027 1028 1029 float textHeight = drawPosY; 1031 if (this.getVerticalAlign().equals("Top")) 1032 { 1033 verticalOffset = 0f; 1034 } 1035 else if (this.getVerticalAlign().equals("Middle")) 1036 { 1037 verticalOffset = ((float)zoomedFieldHeight- textHeight) / 2f; 1038 } 1039 else if (this.getVerticalAlign().equals("Bottom")) 1040 { 1041 verticalOffset = (float)zoomedFieldHeight - (float)textHeight; 1042 } 1043 1044 1046 AffineTransform savedAT = g.getTransform(); 1047 if (transform != null) g.setTransform( transform); 1048 1049 for(Iterator i=textLayouts.iterator(); i.hasNext();) 1051 { 1052 textReportElementLayout = (TextReportElementLayout) i.next(); 1053 textReportElementLayout.drawWithOffset(g, verticalOffset); 1054 } 1055 1056 if(transform != null) 1057 { 1058 g.setTransform(savedAT); 1059 } 1060 1061 1062 } 1063} 1064 | Popular Tags |