1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.awt.Color ; 31 import java.io.IOException ; 32 import java.io.ObjectInputStream ; 33 34 import net.sf.jasperreports.engine.JRAlignment; 35 import net.sf.jasperreports.engine.JRBox; 36 import net.sf.jasperreports.engine.JRConstants; 37 import net.sf.jasperreports.engine.JRDefaultStyleProvider; 38 import net.sf.jasperreports.engine.JRElement; 39 import net.sf.jasperreports.engine.JRFont; 40 import net.sf.jasperreports.engine.JRHyperlink; 41 import net.sf.jasperreports.engine.JRHyperlinkHelper; 42 import net.sf.jasperreports.engine.JRReportFont; 43 import net.sf.jasperreports.engine.JRStaticText; 44 import net.sf.jasperreports.engine.JRStyle; 45 import net.sf.jasperreports.engine.JRTextElement; 46 import net.sf.jasperreports.engine.JRTextField; 47 import net.sf.jasperreports.engine.util.JRStyleResolver; 48 49 50 54 public class JRTemplateText extends JRTemplateElement implements JRAlignment, JRBox, JRFont 55 { 56 57 58 61 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 62 63 66 private Byte horizontalAlignment = null; 67 private Byte verticalAlignment = null; 68 private Byte rotation = null; 69 private Byte lineSpacing = null; 70 private Boolean isStyledText = null; 71 private byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL; 72 private String linkType; 73 private byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF; 74 75 78 protected Byte border; 79 protected Byte topBorder = null; 80 protected Byte leftBorder = null; 81 protected Byte bottomBorder = null; 82 protected Byte rightBorder = null; 83 protected Color borderColor = null; 84 protected Color topBorderColor = null; 85 protected Color leftBorderColor = null; 86 protected Color bottomBorderColor = null; 87 protected Color rightBorderColor = null; 88 protected Integer padding; 89 protected Integer topPadding = null; 90 protected Integer leftPadding = null; 91 protected Integer bottomPadding = null; 92 protected Integer rightPadding = null; 93 94 protected JRReportFont reportFont = null; 95 protected String fontName = null; 96 protected Boolean isBold = null; 97 protected Boolean isItalic = null; 98 protected Boolean isUnderline = null; 99 protected Boolean isStrikeThrough = null; 100 protected Integer fontSize = null; 101 protected String pdfFontName = null; 102 protected String pdfEncoding = null; 103 protected Boolean isPdfEmbedded = null; 104 protected String valueClassName; 105 protected String pattern; 106 protected String formatFactoryClass; 107 protected String localeCode; 108 protected String timeZoneId; 109 110 111 114 protected JRTemplateText(JRDefaultStyleProvider defaultStyleProvider, JRStaticText staticText) 115 { 116 super(defaultStyleProvider); 117 118 setStaticText(staticText); 119 } 120 121 124 protected JRTemplateText(JRDefaultStyleProvider defaultStyleProvider, JRTextField textField) 125 { 126 super(defaultStyleProvider); 127 128 setTextField(textField); 129 } 130 131 132 135 protected void setStaticText(JRStaticText staticText) 136 { 137 setTextElement(staticText); 138 } 139 140 143 protected void setTextField(JRTextField textField) 144 { 145 setTextElement(textField); 146 147 setLinkType(textField.getLinkType()); 148 hyperlinkTarget = textField.getHyperlinkTarget(); 149 } 150 151 154 protected void setTextElement(JRTextElement textElement) 155 { 156 super.setElement(textElement); 157 158 border = textElement.getOwnBorder(); 159 topBorder = textElement.getOwnTopBorder(); 160 leftBorder = textElement.getOwnLeftBorder(); 161 bottomBorder = textElement.getOwnBottomBorder(); 162 rightBorder = textElement.getOwnRightBorder(); 163 borderColor = textElement.getOwnBorderColor(); 164 topBorderColor = textElement.getOwnTopBorderColor(); 165 leftBorderColor = textElement.getOwnLeftBorderColor(); 166 bottomBorderColor = textElement.getOwnBottomBorderColor(); 167 rightBorderColor = textElement.getOwnRightBorderColor(); 168 padding = textElement.getOwnPadding(); 169 topPadding = textElement.getOwnTopPadding(); 170 leftPadding = textElement.getOwnLeftPadding(); 171 bottomPadding = textElement.getOwnBottomPadding(); 172 rightPadding = textElement.getOwnRightPadding(); 173 174 reportFont = textElement.getReportFont(); 175 176 fontName = textElement.getOwnFontName(); 177 isBold = textElement.isOwnBold(); 178 isItalic = textElement.isOwnItalic(); 179 isUnderline = textElement.isOwnUnderline(); 180 isStrikeThrough = textElement.isOwnStrikeThrough(); 181 fontSize = textElement.getOwnFontSize(); 182 pdfFontName = textElement.getOwnPdfFontName(); 183 pdfEncoding = textElement.getOwnPdfEncoding(); 184 isPdfEmbedded = textElement.isOwnPdfEmbedded(); 185 186 horizontalAlignment = textElement.getOwnHorizontalAlignment(); 187 verticalAlignment = textElement.getOwnVerticalAlignment(); 188 rotation = textElement.getOwnRotation(); 189 lineSpacing = textElement.getOwnLineSpacing(); 190 isStyledText = textElement.isOwnStyledText(); 191 } 192 193 194 197 protected JRFont getBaseFont() 198 { 199 if (reportFont != null) 200 return reportFont; 201 if (defaultStyleProvider != null) 202 return defaultStyleProvider.getDefaultFont(); 203 return null; 204 } 205 206 209 public byte getMode() 210 { 211 return JRStyleResolver.getMode(this, JRElement.MODE_TRANSPARENT); 212 } 213 214 217 public byte getTextAlignment() 218 { 219 return getHorizontalAlignment(); 220 } 221 222 225 public byte getHorizontalAlignment() 226 { 227 return JRStyleResolver.getHorizontalAlignment(this); 228 } 229 230 233 public Byte getOwnHorizontalAlignment() 234 { 235 return horizontalAlignment; 236 } 237 238 241 public void setHorizontalAlignment(byte horizontalAlignment) 242 { 243 this.horizontalAlignment = new Byte (horizontalAlignment); 244 } 245 246 249 public void setHorizontalAlignment(Byte horizontalAlignment) 250 { 251 this.horizontalAlignment = horizontalAlignment; 252 } 253 254 257 public byte getVerticalAlignment() 258 { 259 return JRStyleResolver.getVerticalAlignment(this); 260 } 261 262 265 public Byte getOwnVerticalAlignment() 266 { 267 return verticalAlignment; 268 } 269 270 273 public void setVerticalAlignment(byte verticalAlignment) 274 { 275 this.verticalAlignment = new Byte (verticalAlignment); 276 } 277 278 281 public void setVerticalAlignment(Byte verticalAlignment) 282 { 283 this.verticalAlignment = verticalAlignment; 284 } 285 286 289 public byte getRotation() 290 { 291 return JRStyleResolver.getRotation(this); 292 } 293 294 297 public Byte getOwnRotation() 298 { 299 return rotation; 300 } 301 302 305 public byte getLineSpacing() 306 { 307 return JRStyleResolver.getLineSpacing(this); 308 } 309 310 313 public Byte getOwnLineSpacing() 314 { 315 return lineSpacing; 316 } 317 318 321 public boolean isStyledText() 322 { 323 return JRStyleResolver.isStyledText(this); 324 } 325 326 329 public Boolean isOwnStyledText() 330 { 331 return isStyledText; 332 } 333 334 337 public JRBox getBox() 338 { 339 return this; 340 } 341 342 345 public JRFont getFont() 346 { 347 return this; 348 } 349 350 351 362 public byte getHyperlinkType() 363 { 364 return JRHyperlinkHelper.getHyperlinkType(getLinkType()); 365 } 366 367 370 public byte getHyperlinkTarget() 371 { 372 return hyperlinkTarget; 373 } 374 375 378 public byte getBorder() 379 { 380 return JRStyleResolver.getBorder(this); 381 } 382 383 public Byte getOwnBorder() 384 { 385 return border; 386 } 387 388 391 public void setBorder(byte border) 392 { 393 this.border = new Byte (border); 394 } 395 396 399 public Color getBorderColor() 400 { 401 return JRStyleResolver.getBorderColor(this, getForecolor()); 402 } 403 404 public Color getOwnBorderColor() 405 { 406 return borderColor; 407 } 408 409 412 public void setBorderColor(Color borderColor) 413 { 414 this.borderColor = borderColor; 415 } 416 417 420 public int getPadding() 421 { 422 return JRStyleResolver.getPadding(this); 423 } 424 425 public Integer getOwnPadding() 426 { 427 return padding; 428 } 429 430 433 public void setPadding(int padding) 434 { 435 this.padding = new Integer (padding); 436 } 437 438 441 public byte getTopBorder() 442 { 443 return JRStyleResolver.getTopBorder(this); 444 } 445 446 449 public Byte getOwnTopBorder() 450 { 451 return topBorder; 452 } 453 454 457 public void setTopBorder(byte topBorder) 458 { 459 this.topBorder = new Byte (topBorder); 460 } 461 462 465 public Color getTopBorderColor() 466 { 467 return JRStyleResolver.getTopBorderColor(this, getForecolor()); 468 } 469 470 473 public Color getOwnTopBorderColor() 474 { 475 return topBorderColor; 476 } 477 478 481 public void setTopBorderColor(Color topBorderColor) 482 { 483 this.topBorderColor = topBorderColor; 484 } 485 486 489 public int getTopPadding() 490 { 491 return JRStyleResolver.getTopPadding(this); 492 } 493 494 497 public Integer getOwnTopPadding() 498 { 499 return topPadding; 500 } 501 502 505 public void setTopPadding(int topPadding) 506 { 507 this.topPadding = new Integer (topPadding); 508 } 509 510 513 public byte getLeftBorder() 514 { 515 return JRStyleResolver.getLeftBorder(this); 516 } 517 518 521 public Byte getOwnLeftBorder() 522 { 523 return leftBorder; 524 } 525 526 529 public void setLeftBorder(byte leftBorder) 530 { 531 this.leftBorder = new Byte (leftBorder); 532 } 533 534 537 public Color getLeftBorderColor() 538 { 539 return JRStyleResolver.getLeftBorderColor(this, getForecolor()); 540 } 541 542 545 public Color getOwnLeftBorderColor() 546 { 547 return leftBorderColor; 548 } 549 550 553 public void setLeftBorderColor(Color leftBorderColor) 554 { 555 this.leftBorderColor = leftBorderColor; 556 } 557 558 561 public int getLeftPadding() 562 { 563 return JRStyleResolver.getLeftPadding(this); 564 } 565 566 569 public Integer getOwnLeftPadding() 570 { 571 return leftPadding; 572 } 573 574 577 public void setLeftPadding(int leftPadding) 578 { 579 this.leftPadding = new Integer (leftPadding); 580 } 581 582 585 public byte getBottomBorder() 586 { 587 return JRStyleResolver.getBottomBorder(this); 588 } 589 590 593 public Byte getOwnBottomBorder() 594 { 595 return bottomBorder; 596 } 597 598 601 public void setBottomBorder(byte bottomBorder) 602 { 603 this.bottomBorder = new Byte (bottomBorder); 604 } 605 606 609 public Color getBottomBorderColor() 610 { 611 return JRStyleResolver.getBottomBorderColor(this, getForecolor()); 612 } 613 614 617 public Color getOwnBottomBorderColor() 618 { 619 return bottomBorderColor; 620 } 621 622 625 public void setBottomBorderColor(Color bottomBorderColor) 626 { 627 this.bottomBorderColor = bottomBorderColor; 628 } 629 630 633 public int getBottomPadding() 634 { 635 return JRStyleResolver.getBottomPadding(this); 636 } 637 638 641 public Integer getOwnBottomPadding() 642 { 643 return bottomPadding; 644 } 645 646 649 public void setBottomPadding(int bottomPadding) 650 { 651 this.bottomPadding = new Integer (bottomPadding); 652 } 653 654 657 public byte getRightBorder() 658 { 659 return JRStyleResolver.getRightBorder(this); 660 } 661 662 665 public Byte getOwnRightBorder() 666 { 667 return rightBorder; 668 } 669 670 673 public void setRightBorder(byte rightBorder) 674 { 675 this.rightBorder = new Byte (rightBorder); 676 } 677 678 681 public Color getRightBorderColor() 682 { 683 return JRStyleResolver.getRightBorderColor(this, getForecolor()); 684 } 685 686 689 public Color getOwnRightBorderColor() 690 { 691 return rightBorderColor; 692 } 693 694 697 public void setRightBorderColor(Color rightBorderColor) 698 { 699 this.rightBorderColor = rightBorderColor; 700 } 701 702 705 public int getRightPadding() 706 { 707 return JRStyleResolver.getRightPadding(this); 708 } 709 710 713 public Integer getOwnRightPadding() 714 { 715 return rightPadding; 716 } 717 718 721 public void setRightPadding(int rightPadding) 722 { 723 this.rightPadding = new Integer (rightPadding); 724 } 725 726 727 730 public JRReportFont getReportFont() 731 { 732 return reportFont; 733 } 734 735 738 public void setReportFont(JRReportFont reportFont) 739 { 740 this.reportFont = reportFont; 741 } 742 743 746 public String getFontName() 747 { 748 return JRStyleResolver.getFontName(this); 749 } 750 751 754 public String getOwnFontName() 755 { 756 return fontName; 757 } 758 759 762 public void setFontName(String fontName) 763 { 764 this.fontName = fontName; 765 } 766 767 768 771 public boolean isBold() 772 { 773 return JRStyleResolver.isBold(this); 774 } 775 776 779 public Boolean isOwnBold() 780 { 781 return isBold; 782 } 783 784 787 public void setBold(boolean isBold) 788 { 789 setBold(isBold ? Boolean.TRUE : Boolean.FALSE); 790 } 791 792 796 public void setBold(Boolean isBold) 797 { 798 this.isBold = isBold; 799 } 800 801 802 805 public boolean isItalic() 806 { 807 return JRStyleResolver.isItalic(this); 808 } 809 810 813 public Boolean isOwnItalic() 814 { 815 return isItalic; 816 } 817 818 821 public void setItalic(boolean isItalic) 822 { 823 setItalic(isItalic ? Boolean.TRUE : Boolean.FALSE); 824 } 825 826 830 public void setItalic(Boolean isItalic) 831 { 832 this.isItalic = isItalic; 833 } 834 835 838 public boolean isUnderline() 839 { 840 return JRStyleResolver.isUnderline(this); 841 } 842 843 846 public Boolean isOwnUnderline() 847 { 848 return isUnderline; 849 } 850 851 854 public void setUnderline(boolean isUnderline) 855 { 856 setUnderline(isUnderline ? Boolean.TRUE : Boolean.FALSE); 857 } 858 859 863 public void setUnderline(Boolean isUnderline) 864 { 865 this.isUnderline = isUnderline; 866 } 867 868 871 public boolean isStrikeThrough() 872 { 873 return JRStyleResolver.isStrikeThrough(this); 874 } 875 876 879 public Boolean isOwnStrikeThrough() 880 { 881 return isStrikeThrough; 882 } 883 884 887 public void setStrikeThrough(boolean isStrikeThrough) 888 { 889 setStrikeThrough(isStrikeThrough ? Boolean.TRUE : Boolean.FALSE); 890 } 891 892 896 public void setStrikeThrough(Boolean isStrikeThrough) 897 { 898 this.isStrikeThrough = isStrikeThrough; 899 } 900 901 904 public int getFontSize() 905 { 906 return JRStyleResolver.getFontSize(this); 907 } 908 909 912 public Integer getOwnFontSize() 913 { 914 return fontSize; 915 } 916 917 920 public void setFontSize(int fontSize) 921 { 922 setFontSize(new Integer (fontSize)); 923 } 924 925 929 public void setFontSize(Integer fontSize) 930 { 931 this.fontSize = fontSize; 932 } 933 934 937 public int getSize() 938 { 939 return getFontSize(); 940 } 941 942 945 public Integer getOwnSize() 946 { 947 return getOwnFontSize(); 948 } 949 950 953 public void setSize(int size) 954 { 955 setFontSize(size); 956 } 957 958 961 public void setSize(Integer size) 962 { 963 setFontSize(size); 964 } 965 966 969 public String getPdfFontName() 970 { 971 return JRStyleResolver.getPdfFontName(this); 972 } 973 974 977 public String getOwnPdfFontName() 978 { 979 return pdfFontName; 980 } 981 982 985 public void setPdfFontName(String pdfFontName) 986 { 987 this.pdfFontName = pdfFontName; 988 } 989 990 991 994 public String getPdfEncoding() 995 { 996 return JRStyleResolver.getPdfEncoding(this); 997 } 998 999 1002 public String getOwnPdfEncoding() 1003 { 1004 return pdfEncoding; 1005 } 1006 1007 1010 public void setPdfEncoding(String pdfEncoding) 1011 { 1012 this.pdfEncoding = pdfEncoding; 1013 } 1014 1015 1016 1019 public boolean isPdfEmbedded() 1020 { 1021 return JRStyleResolver.isPdfEmbedded(this); 1022 } 1023 1024 1027 public Boolean isOwnPdfEmbedded() 1028 { 1029 return isPdfEmbedded; 1030 } 1031 1032 1035 public void setPdfEmbedded(boolean isPdfEmbedded) 1036 { 1037 setPdfEmbedded(isPdfEmbedded ? Boolean.TRUE : Boolean.FALSE); 1038 } 1039 1040 1044 public void setPdfEmbedded(Boolean isPdfEmbedded) 1045 { 1046 this.isPdfEmbedded = isPdfEmbedded; 1047 } 1048 1049 1052 public void setBorder(Byte border) 1053 { 1054 this.border = border; 1055 } 1056 1057 1060 public void setPadding(Integer padding) 1061 { 1062 this.padding = padding; 1063 } 1064 1065 1068 public void setTopBorder(Byte topBorder) 1069 { 1070 this.topBorder = topBorder; 1071 } 1072 1073 1076 public void setTopPadding(Integer topPadding) 1077 { 1078 this.topPadding = topPadding; 1079 } 1080 1081 1084 public void setLeftBorder(Byte leftBorder) 1085 { 1086 this.leftBorder = leftBorder; 1087 } 1088 1089 1092 public void setLeftPadding(Integer leftPadding) 1093 { 1094 this.leftPadding = leftPadding; 1095 } 1096 1097 1100 public void setBottomBorder(Byte bottomBorder) 1101 { 1102 this.bottomBorder = bottomBorder; 1103 } 1104 1105 1108 public void setBottomPadding(Integer bottomPadding) 1109 { 1110 this.bottomPadding = bottomPadding; 1111 } 1112 1113 1116 public void setRightBorder(Byte rightBorder) 1117 { 1118 this.rightBorder = rightBorder; 1119 } 1120 1121 1124 public void setRightPadding(Integer rightPadding) 1125 { 1126 this.rightPadding = rightPadding; 1127 } 1128 1129 1132 public JRStyle getStyle() 1133 { 1134 return parentStyle; 1135 } 1136 1137 1138 public String getPattern() 1139 { 1140 return pattern; 1141 } 1142 1143 1144 public void setPattern(String pattern) 1145 { 1146 this.pattern = pattern; 1147 } 1148 1149 1150 public String getValueClassName() 1151 { 1152 return valueClassName; 1153 } 1154 1155 1156 public void setValueClassName(String valueClassName) 1157 { 1158 this.valueClassName = valueClassName; 1159 } 1160 1161 1162 public String getFormatFactoryClass() 1163 { 1164 return formatFactoryClass; 1165 } 1166 1167 1168 public void setFormatFactoryClass(String formatFactoryClass) 1169 { 1170 this.formatFactoryClass = formatFactoryClass; 1171 } 1172 1173 1174 public String getLocaleCode() 1175 { 1176 return localeCode; 1177 } 1178 1179 1180 public void setLocaleCode(String localeCode) 1181 { 1182 this.localeCode = localeCode; 1183 } 1184 1185 1186 public String getTimeZoneId() 1187 { 1188 return timeZoneId; 1189 } 1190 1191 1192 public void setTimeZoneId(String timeZoneId) 1193 { 1194 this.timeZoneId = timeZoneId; 1195 } 1196 1197 1198 1207 public String getLinkType() 1208 { 1209 return linkType; 1210 } 1211 1212 1213 1222 public void setLinkType(String linkType) 1223 { 1224 this.linkType = linkType; 1225 } 1226 1227 1228 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException 1229 { 1230 in.defaultReadObject(); 1231 normalizeLinkType(); 1232 } 1233 1234 1235 protected void normalizeLinkType() 1236 { 1237 if (linkType == null) 1238 { 1239 linkType = JRHyperlinkHelper.getLinkType(hyperlinkType); 1240 } 1241 hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL; 1242 } 1243 1244} 1245 | Popular Tags |