1 28 package net.sf.jasperreports.engine.util; 29 30 import java.awt.Color ; 31 32 import net.sf.jasperreports.engine.JRAlignment; 33 import net.sf.jasperreports.engine.JRBox; 34 import net.sf.jasperreports.engine.JRElement; 35 import net.sf.jasperreports.engine.JRFont; 36 import net.sf.jasperreports.engine.JRGraphicElement; 37 import net.sf.jasperreports.engine.JRImage; 38 import net.sf.jasperreports.engine.JRPrintElement; 39 import net.sf.jasperreports.engine.JRPrintGraphicElement; 40 import net.sf.jasperreports.engine.JRPrintImage; 41 import net.sf.jasperreports.engine.JRPrintRectangle; 42 import net.sf.jasperreports.engine.JRPrintText; 43 import net.sf.jasperreports.engine.JRRectangle; 44 import net.sf.jasperreports.engine.JRStyle; 45 import net.sf.jasperreports.engine.JRStyleContainer; 46 import net.sf.jasperreports.engine.JRTextElement; 47 import net.sf.jasperreports.engine.JRTextField; 48 import net.sf.jasperreports.engine.fill.JRTemplateElement; 49 import net.sf.jasperreports.engine.fill.JRTemplateGraphicElement; 50 import net.sf.jasperreports.engine.fill.JRTemplateImage; 51 import net.sf.jasperreports.engine.fill.JRTemplateRectangle; 52 import net.sf.jasperreports.engine.fill.JRTemplateText; 53 54 55 59 public class JRStyleResolver 60 { 61 62 63 66 private static JRFont getBaseFont(JRFont font) 67 { 68 if (font.getReportFont() != null) 69 return font.getReportFont(); 70 if (font.getDefaultStyleProvider() != null) 71 return font.getDefaultStyleProvider().getDefaultFont(); 72 return null; 73 } 74 75 78 private static JRStyle getBaseStyle(JRStyleContainer styleContainer) 79 { 80 if (styleContainer.getStyle() != null) 81 return styleContainer.getStyle(); 82 if (styleContainer.getDefaultStyleProvider() != null) 83 return styleContainer.getDefaultStyleProvider().getDefaultStyle(); 84 return null; 85 } 86 87 88 91 public static byte getMode(JRElement element, byte defaultMode) 92 { 93 if (element.getOwnMode() != null) 94 return element.getOwnMode().byteValue(); 95 JRStyle style = getBaseStyle(element); 96 if (style != null && style.getMode() != null) 97 return style.getMode().byteValue(); 98 return defaultMode; 99 } 100 101 104 public static byte getMode(JRPrintElement element, byte defaultMode) 105 { 106 if (element.getOwnMode() != null) 107 return element.getOwnMode().byteValue(); 108 JRStyle style = getBaseStyle(element); 109 if (style != null && style.getMode() != null) 110 return style.getMode().byteValue(); 111 return defaultMode; 112 } 113 114 117 public static byte getMode(JRTemplateElement element, byte defaultMode) 118 { 119 if (element.getOwnMode() != null) 120 return element.getOwnMode().byteValue(); 121 JRStyle style = getBaseStyle(element); 122 if (style != null && style.getMode() != null) 123 return style.getMode().byteValue(); 124 return defaultMode; 125 } 126 127 130 public static Byte getMode(JRStyle style) 131 { 132 if (style.getOwnMode() != null) 133 return style.getOwnMode(); 134 JRStyle baseStyle = getBaseStyle(style); 135 if (baseStyle != null) 136 return baseStyle.getMode(); 137 return null; 138 } 139 140 143 public static Color getForecolor(JRElement element) 144 { 145 if (element.getOwnForecolor() != null) 146 return element.getOwnForecolor(); 147 JRStyle style = getBaseStyle(element); 148 if (style != null && style.getForecolor() != null) 149 return style.getForecolor(); 150 return Color.black; 151 } 152 153 156 public static Color getForecolor(JRPrintElement element) 157 { 158 if (element.getOwnForecolor() != null) 159 return element.getOwnForecolor(); 160 JRStyle style = getBaseStyle(element); 161 if (style != null && style.getForecolor() != null) 162 return style.getForecolor(); 163 return Color.black; 164 } 165 166 169 public static Color getForecolor(JRTemplateElement element) 170 { 171 if (element.getOwnForecolor() != null) 172 return element.getOwnForecolor(); 173 JRStyle style = getBaseStyle(element); 174 if (style != null && style.getForecolor() != null) 175 return style.getForecolor(); 176 return Color.black; 177 } 178 179 182 public static Color getForecolor(JRStyle style) 183 { 184 if (style.getOwnForecolor() != null) 185 return style.getOwnForecolor(); 186 JRStyle baseStyle = getBaseStyle(style); 187 if (baseStyle != null) 188 return baseStyle.getForecolor(); 189 return null; 190 } 191 192 195 public static Color getBackcolor(JRElement element) 196 { 197 if (element.getOwnBackcolor() != null) 198 return element.getOwnBackcolor(); 199 JRStyle style = getBaseStyle(element); 200 if (style != null && style.getBackcolor() != null) 201 return style.getBackcolor(); 202 return Color.white; 203 } 204 205 208 public static Color getBackcolor(JRPrintElement element) 209 { 210 if (element.getOwnBackcolor() != null) 211 return element.getOwnBackcolor(); 212 JRStyle style = getBaseStyle(element); 213 if (style != null && style.getBackcolor() != null) 214 return style.getBackcolor(); 215 return Color.white; 216 } 217 218 221 public static Color getBackcolor(JRTemplateElement element) 222 { 223 if (element.getOwnBackcolor() != null) 224 return element.getOwnBackcolor(); 225 JRStyle style = getBaseStyle(element); 226 if (style != null && style.getBackcolor() != null) 227 return style.getBackcolor(); 228 return Color.white; 229 } 230 231 234 public static Color getBackcolor(JRStyle style) 235 { 236 if (style.getOwnBackcolor() != null) 237 return style.getOwnBackcolor(); 238 JRStyle baseStyle = getBaseStyle(style); 239 if (baseStyle != null) 240 return baseStyle.getBackcolor(); 241 return null; 242 } 243 244 247 public static byte getPen(JRGraphicElement element, byte defaultPen) 248 { 249 if (element.getOwnPen() != null) 250 return element.getOwnPen().byteValue(); 251 JRStyle baseStyle = getBaseStyle(element); 252 if (baseStyle != null && baseStyle.getPen() != null) 253 return baseStyle.getPen().byteValue(); 254 return defaultPen; 255 } 256 257 260 public static byte getPen(JRPrintGraphicElement element, byte defaultPen) 261 { 262 if (element.getOwnPen() != null) 263 return element.getOwnPen().byteValue(); 264 JRStyle baseStyle = getBaseStyle(element); 265 if (baseStyle != null && baseStyle.getPen() != null) 266 return baseStyle.getPen().byteValue(); 267 return defaultPen; 268 } 269 270 273 public static byte getPen(JRTemplateGraphicElement element, byte defaultPen) 274 { 275 if (element.getOwnPen() != null) 276 return element.getOwnPen().byteValue(); 277 JRStyle baseStyle = getBaseStyle(element); 278 if (baseStyle != null && baseStyle.getPen() != null) 279 return baseStyle.getPen().byteValue(); 280 return defaultPen; 281 } 282 283 286 public static Byte getPen(JRStyle style) 287 { 288 if (style.getOwnPen() != null) 289 return style.getOwnPen(); 290 JRStyle baseStyle = getBaseStyle(style); 291 if (baseStyle != null) 292 return baseStyle.getPen(); 293 return null; 294 } 295 296 299 public static byte getFill(JRGraphicElement element, byte defaultFill) 300 { 301 if (element.getOwnFill() != null) 302 return element.getOwnFill().byteValue(); 303 JRStyle baseStyle = getBaseStyle(element); 304 if (baseStyle != null && baseStyle.getFill() != null) 305 return baseStyle.getFill().byteValue(); 306 return defaultFill; 307 } 308 309 312 public static byte getFill(JRPrintGraphicElement element, byte defaultFill) 313 { 314 if (element.getOwnFill() != null) 315 return element.getOwnFill().byteValue(); 316 JRStyle baseStyle = getBaseStyle(element); 317 if (baseStyle != null && baseStyle.getFill() != null) 318 return baseStyle.getFill().byteValue(); 319 return defaultFill; 320 } 321 322 325 public static byte getFill(JRTemplateGraphicElement element, byte defaultFill) 326 { 327 if (element.getOwnFill() != null) 328 return element.getOwnFill().byteValue(); 329 JRStyle baseStyle = getBaseStyle(element); 330 if (baseStyle != null && baseStyle.getFill() != null) 331 return baseStyle.getFill().byteValue(); 332 return defaultFill; 333 } 334 335 338 public static Byte getFill(JRStyle style) 339 { 340 if (style.getOwnFill() != null) 341 return style.getOwnFill(); 342 JRStyle baseStyle = getBaseStyle(style); 343 if (baseStyle != null) 344 return baseStyle.getFill(); 345 return null; 346 } 347 348 351 public static int getRadius(JRRectangle rectangle) 352 { 353 if (rectangle.getOwnRadius() != null) 354 return rectangle.getOwnRadius().intValue(); 355 JRStyle baseStyle = getBaseStyle(rectangle); 356 if (baseStyle != null && baseStyle.getRadius() != null) 357 return baseStyle.getRadius().intValue(); 358 return 0; 359 } 360 361 364 public static int getRadius(JRPrintRectangle rectangle) 365 { 366 if (rectangle.getOwnRadius() != null) 367 return rectangle.getOwnRadius().intValue(); 368 JRStyle baseStyle = getBaseStyle(rectangle); 369 if (baseStyle != null && baseStyle.getRadius() != null) 370 return baseStyle.getRadius().intValue(); 371 return 0; 372 } 373 374 377 public static int getRadius(JRTemplateRectangle rectangle) 378 { 379 if (rectangle.getOwnRadius() != null) 380 return rectangle.getOwnRadius().intValue(); 381 JRStyle baseStyle = getBaseStyle(rectangle); 382 if (baseStyle != null && baseStyle.getRadius() != null) 383 return baseStyle.getRadius().intValue(); 384 return 0; 385 } 386 387 390 public static Integer getRadius(JRStyle style) 391 { 392 if (style.getOwnRadius() != null) 393 return style.getOwnRadius(); 394 JRStyle baseStyle = getBaseStyle(style); 395 if (baseStyle != null) 396 return baseStyle.getRadius(); 397 return null; 398 } 399 400 403 public static byte getScaleImage(JRImage image) 404 { 405 if (image.getOwnScaleImage() != null) 406 return image.getOwnScaleImage().byteValue(); 407 JRStyle baseStyle = getBaseStyle(image); 408 if (baseStyle != null && baseStyle.getScaleImage() != null) 409 return baseStyle.getScaleImage().byteValue(); 410 return JRImage.SCALE_IMAGE_RETAIN_SHAPE; 411 } 412 413 416 public static byte getScaleImage(JRPrintImage image) 417 { 418 if (image.getOwnScaleImage() != null) 419 return image.getOwnScaleImage().byteValue(); 420 JRStyle baseStyle = getBaseStyle(image); 421 if (baseStyle != null && baseStyle.getScaleImage() != null) 422 return baseStyle.getScaleImage().byteValue(); 423 return JRImage.SCALE_IMAGE_RETAIN_SHAPE; 424 } 425 426 429 public static byte getScaleImage(JRTemplateImage image) 430 { 431 if (image.getOwnScaleImage() != null) 432 return image.getOwnScaleImage().byteValue(); 433 JRStyle baseStyle = getBaseStyle(image); 434 if (baseStyle != null && baseStyle.getScaleImage() != null) 435 return baseStyle.getScaleImage().byteValue(); 436 return JRImage.SCALE_IMAGE_RETAIN_SHAPE; 437 } 438 439 442 public static Byte getScaleImage(JRStyle style) 443 { 444 if (style.getOwnScaleImage() != null) 445 return style.getOwnScaleImage(); 446 JRStyle baseStyle = getBaseStyle(style); 447 if (baseStyle != null ) 448 return baseStyle.getScaleImage(); 449 return null; 450 } 451 452 455 public static byte getHorizontalAlignment(JRAlignment alignment) 456 { 457 if (alignment.getOwnHorizontalAlignment() != null) 458 return alignment.getOwnHorizontalAlignment().byteValue(); 459 JRStyle baseStyle = getBaseStyle(alignment); 460 if (baseStyle != null && baseStyle.getHorizontalAlignment() != null) 461 return baseStyle.getHorizontalAlignment().byteValue(); 462 return JRAlignment.HORIZONTAL_ALIGN_LEFT; 463 } 464 465 468 public static Byte getHorizontalAlignment(JRStyle style) 469 { 470 if (style.getOwnHorizontalAlignment() != null) 471 return style.getOwnHorizontalAlignment(); 472 JRStyle baseStyle = getBaseStyle(style); 473 if (baseStyle != null && baseStyle.getHorizontalAlignment() != null) 474 return baseStyle.getHorizontalAlignment(); 475 return null; 476 } 477 478 481 public static byte getVerticalAlignment(JRAlignment alignment) 482 { 483 if (alignment.getOwnVerticalAlignment() != null) 484 return alignment.getOwnVerticalAlignment().byteValue(); 485 JRStyle baseStyle = getBaseStyle(alignment); 486 if (baseStyle != null && baseStyle.getVerticalAlignment() != null) 487 return baseStyle.getVerticalAlignment().byteValue(); 488 return JRAlignment.VERTICAL_ALIGN_TOP; 489 } 490 491 494 public static Byte getVerticalAlignment(JRStyle style) 495 { 496 if (style.getOwnVerticalAlignment() != null) 497 return style.getOwnVerticalAlignment(); 498 JRStyle baseStyle = getBaseStyle(style); 499 if (baseStyle != null && baseStyle.getVerticalAlignment() != null) 500 return baseStyle.getVerticalAlignment(); 501 return null; 502 } 503 504 507 public static byte getRotation(JRTextElement element) 508 { 509 if (element.getOwnRotation() != null) 510 return element.getOwnRotation().byteValue(); 511 JRStyle baseStyle = getBaseStyle(element); 512 if (baseStyle != null && baseStyle.getRotation() != null) 513 return baseStyle.getRotation().byteValue(); 514 return JRTextElement.ROTATION_NONE; 515 } 516 517 520 public static byte getRotation(JRPrintText element) 521 { 522 if (element.getOwnRotation() != null) 523 return element.getOwnRotation().byteValue(); 524 JRStyle baseStyle = getBaseStyle(element); 525 if (baseStyle != null && baseStyle.getRotation() != null) 526 return baseStyle.getRotation().byteValue(); 527 return JRTextElement.ROTATION_NONE; 528 } 529 530 533 public static byte getRotation(JRTemplateText element) 534 { 535 if (element.getOwnRotation() != null) 536 return element.getOwnRotation().byteValue(); 537 JRStyle baseStyle = getBaseStyle(element); 538 if (baseStyle != null && baseStyle.getRotation() != null) 539 return baseStyle.getRotation().byteValue(); 540 return JRTextElement.ROTATION_NONE; 541 } 542 543 546 public static Byte getRotation(JRStyle style) 547 { 548 if (style.getOwnRotation() != null) 549 return style.getOwnRotation(); 550 JRStyle baseStyle = getBaseStyle(style); 551 if (baseStyle != null) 552 return baseStyle.getRotation(); 553 return null; 554 } 555 556 559 public static byte getLineSpacing(JRTextElement element) 560 { 561 if (element.getOwnLineSpacing() != null) 562 return element.getOwnLineSpacing().byteValue(); 563 JRStyle baseStyle = getBaseStyle(element); 564 if (baseStyle != null && baseStyle.getLineSpacing() != null) 565 return baseStyle.getLineSpacing().byteValue(); 566 return JRTextElement.LINE_SPACING_SINGLE; 567 } 568 569 572 public static byte getLineSpacing(JRPrintText element) 573 { 574 if (element.getOwnLineSpacing() != null) 575 return element.getOwnLineSpacing().byteValue(); 576 JRStyle baseStyle = getBaseStyle(element); 577 if (baseStyle != null && baseStyle.getLineSpacing() != null) 578 return baseStyle.getLineSpacing().byteValue(); 579 return JRTextElement.LINE_SPACING_SINGLE; 580 } 581 582 585 public static byte getLineSpacing(JRTemplateText element) 586 { 587 if (element.getOwnLineSpacing() != null) 588 return element.getOwnLineSpacing().byteValue(); 589 JRStyle baseStyle = getBaseStyle(element); 590 if (baseStyle != null && baseStyle.getLineSpacing() != null) 591 return baseStyle.getLineSpacing().byteValue(); 592 return JRTextElement.LINE_SPACING_SINGLE; 593 } 594 595 598 public static Byte getLineSpacing(JRStyle style) 599 { 600 if (style.getOwnLineSpacing() != null) 601 return style.getOwnLineSpacing(); 602 JRStyle baseStyle = getBaseStyle(style); 603 if (baseStyle != null) 604 return baseStyle.getLineSpacing(); 605 return null; 606 } 607 608 611 public static boolean isStyledText(JRTextElement element) 612 { 613 if (element.isOwnStyledText() != null) 614 return element.isOwnStyledText().booleanValue(); 615 JRStyle baseStyle = getBaseStyle(element); 616 if (baseStyle != null && baseStyle.isStyledText() != null) 617 return baseStyle.isStyledText().booleanValue(); 618 return false; 619 } 620 621 624 public static boolean isStyledText(JRPrintText element) 625 { 626 if (element.isOwnStyledText() != null) 627 return element.isOwnStyledText().booleanValue(); 628 JRStyle baseStyle = getBaseStyle(element); 629 if (baseStyle != null && baseStyle.isStyledText() != null) 630 return baseStyle.isStyledText().booleanValue(); 631 return false; 632 } 633 634 637 public static boolean isStyledText(JRTemplateText element) 638 { 639 if (element.isOwnStyledText() != null) 640 return element.isOwnStyledText().booleanValue(); 641 JRStyle baseStyle = getBaseStyle(element); 642 if (baseStyle != null && baseStyle.isStyledText() != null) 643 return baseStyle.isStyledText().booleanValue(); 644 return false; 645 } 646 647 650 public static Boolean isStyledText(JRStyle style) 651 { 652 if (style.isOwnStyledText() != null) 653 return style.isOwnStyledText(); 654 JRStyle baseStyle = getBaseStyle(style); 655 if (baseStyle != null) 656 return baseStyle.isStyledText(); 657 return null; 658 } 659 660 663 public static String getPattern(JRTextField element) 664 { 665 if (element.getOwnPattern() != null) 666 return element.getOwnPattern(); 667 JRStyle baseStyle = getBaseStyle(element); 668 if (baseStyle != null) 669 return baseStyle.getPattern(); 670 return null; 671 } 672 673 676 public static String getPattern(JRStyle style) 677 { 678 if (style.getOwnPattern() != null) 679 return style.getOwnPattern(); 680 JRStyle baseStyle = getBaseStyle(style); 681 if (baseStyle != null) 682 return baseStyle.getPattern(); 683 return null; 684 } 685 686 689 public static boolean isBlankWhenNull(JRTextField element) 690 { 691 if (element.isOwnBlankWhenNull() != null) 692 return element.isOwnBlankWhenNull().booleanValue(); 693 JRStyle baseStyle = getBaseStyle(element); 694 if (baseStyle != null && baseStyle.isBlankWhenNull() != null) 695 return baseStyle.isBlankWhenNull().booleanValue(); 696 return false; 697 } 698 699 702 public static Boolean isBlankWhenNull(JRStyle style) 703 { 704 if (style.isOwnBlankWhenNull() != null) 705 return style.isOwnBlankWhenNull(); 706 JRStyle baseStyle = getBaseStyle(style); 707 if (baseStyle != null) 708 return baseStyle.isBlankWhenNull(); 709 return null; 710 } 711 712 715 public static String getFontName(JRFont font) 716 { 717 if (font.getOwnFontName() != null) 718 return font.getOwnFontName(); 719 JRFont baseFont = getBaseFont(font); 720 if (baseFont != null && baseFont.getFontName() != null) 721 return baseFont.getFontName(); 722 JRStyle baseStyle = getBaseStyle(font); 723 if (baseStyle != null && baseStyle.getFontName() != null) 724 return baseStyle.getFontName(); 725 return JRProperties.getProperty(JRFont.DEFAULT_FONT_NAME); 726 } 727 728 731 public static String getFontName(JRStyle style) 732 { 733 if (style.getOwnFontName() != null) 734 return style.getOwnFontName(); 735 JRStyle baseStyle = getBaseStyle(style); 736 if (baseStyle != null && baseStyle.getFontName() != null) 737 return baseStyle.getFontName(); 738 return JRProperties.getProperty(JRFont.DEFAULT_FONT_NAME); 739 } 740 741 744 public static boolean isBold(JRFont font) 745 { 746 if (font.isOwnBold() != null) 747 return font.isOwnBold().booleanValue(); 748 JRFont baseFont = getBaseFont(font); 749 if (baseFont != null) 750 return baseFont.isBold(); 751 JRStyle baseStyle = getBaseStyle(font); 752 if (baseStyle != null && baseStyle.isBold() != null) 753 return baseStyle.isBold().booleanValue(); 754 return false; 755 } 756 757 760 public static Boolean isBold(JRStyle style) 761 { 762 if (style.isOwnBold() != null) 763 return style.isOwnBold(); 764 JRStyle baseStyle = getBaseStyle(style); 765 if (baseStyle != null) 766 return baseStyle.isBold(); 767 return null; 768 } 769 770 773 public static boolean isItalic(JRFont font) 774 { 775 if (font.isOwnItalic() != null) 776 return font.isOwnItalic().booleanValue(); 777 JRFont baseFont = getBaseFont(font); 778 if (baseFont != null) 779 return baseFont.isItalic(); 780 JRStyle baseStyle = getBaseStyle(font); 781 if (baseStyle != null && baseStyle.isItalic() != null) 782 return baseStyle.isItalic().booleanValue(); 783 return false; 784 } 785 786 789 public static Boolean isItalic(JRStyle style) 790 { 791 if (style.isOwnItalic() != null) 792 return style.isOwnItalic(); 793 JRStyle baseStyle = getBaseStyle(style); 794 if (baseStyle != null) 795 return baseStyle.isItalic(); 796 return null; 797 } 798 799 802 public static boolean isUnderline(JRFont font) 803 { 804 if (font.isOwnUnderline() != null) 805 return font.isOwnUnderline().booleanValue(); 806 JRFont baseFont = getBaseFont(font); 807 if (baseFont != null) 808 return baseFont.isUnderline(); 809 JRStyle baseStyle = getBaseStyle(font); 810 if (baseStyle != null && baseStyle.isUnderline() != null) 811 return baseStyle.isUnderline().booleanValue(); 812 return false; 813 } 814 815 818 public static Boolean isUnderline(JRStyle style) 819 { 820 if (style.isOwnUnderline() != null) 821 return style.isOwnUnderline(); 822 JRStyle baseStyle = getBaseStyle(style); 823 if (baseStyle != null) 824 return baseStyle.isUnderline(); 825 return null; 826 } 827 828 831 public static boolean isStrikeThrough(JRFont font) 832 { 833 if (font.isOwnStrikeThrough() != null) 834 return font.isOwnStrikeThrough().booleanValue(); 835 JRFont baseFont = getBaseFont(font); 836 if (baseFont != null) 837 return baseFont.isStrikeThrough(); 838 JRStyle baseStyle = getBaseStyle(font); 839 if (baseStyle != null && baseStyle.isStrikeThrough() != null) 840 return baseStyle.isStrikeThrough().booleanValue(); 841 return false; 842 } 843 844 847 public static Boolean isStrikeThrough(JRStyle style) 848 { 849 if (style.isOwnStrikeThrough() != null) 850 return style.isOwnStrikeThrough(); 851 JRStyle baseStyle = getBaseStyle(style); 852 if (baseStyle != null) 853 return baseStyle.isStrikeThrough(); 854 return null; 855 } 856 857 860 public static int getFontSize(JRFont font) 861 { 862 if (font.getOwnFontSize() != null) 863 return font.getOwnFontSize().intValue(); 864 JRFont baseFont = getBaseFont(font); 865 if (baseFont != null) 866 return baseFont.getFontSize(); 867 JRStyle baseStyle = getBaseStyle(font); 868 if (baseStyle != null && baseStyle.getFontSize() != null) 869 return baseStyle.getFontSize().intValue(); 870 return JRProperties.getIntegerProperty(JRFont.DEFAULT_FONT_SIZE); 871 } 872 873 876 public static Integer getFontSize(JRStyle style) 877 { 878 if (style.getOwnFontSize() != null) 879 return style.getOwnFontSize(); 880 JRStyle baseStyle = getBaseStyle(style); 881 if (baseStyle != null) 882 return baseStyle.getFontSize(); 883 return null; 884 } 885 886 889 public static String getPdfFontName(JRFont font) 890 { 891 if (font.getOwnPdfFontName() != null) 892 return font.getOwnPdfFontName(); 893 JRFont baseFont = getBaseFont(font); 894 if (baseFont != null && baseFont.getPdfFontName() != null) 895 return baseFont.getPdfFontName(); 896 JRStyle baseStyle = getBaseStyle(font); 897 if (baseStyle != null && baseStyle.getPdfFontName() != null) 898 return baseStyle.getPdfFontName(); 899 return JRProperties.getProperty(JRFont.DEFAULT_PDF_FONT_NAME); 900 } 901 902 905 public static String getPdfFontName(JRStyle style) 906 { 907 if (style.getOwnPdfFontName() != null) 908 return style.getOwnPdfFontName(); 909 JRStyle baseStyle = getBaseStyle(style); 910 if (baseStyle != null && baseStyle.getPdfFontName() != null) 911 return baseStyle.getPdfFontName(); 912 return JRProperties.getProperty(JRFont.DEFAULT_PDF_FONT_NAME); 913 } 914 915 918 public static String getPdfEncoding(JRFont font) 919 { 920 if (font.getOwnPdfEncoding() != null) 921 return font.getOwnPdfEncoding(); 922 JRFont baseFont = getBaseFont(font); 923 if (baseFont != null && baseFont.getPdfEncoding() != null) 924 return baseFont.getPdfEncoding(); 925 JRStyle baseStyle = getBaseStyle(font); 926 if (baseStyle != null && baseStyle.getPdfEncoding() != null) 927 return baseStyle.getPdfEncoding(); 928 return JRProperties.getProperty(JRFont.DEFAULT_PDF_ENCODING); 929 } 930 931 934 public static String getPdfEncoding(JRStyle style) 935 { 936 if (style.getOwnPdfEncoding() != null) 937 return style.getOwnPdfEncoding(); 938 JRStyle baseStyle = getBaseStyle(style); 939 if (baseStyle != null && baseStyle.getPdfEncoding() != null) 940 return baseStyle.getPdfEncoding(); 941 return JRProperties.getProperty(JRFont.DEFAULT_PDF_ENCODING); 942 } 943 944 947 public static boolean isPdfEmbedded(JRFont font) 948 { 949 if (font.isOwnPdfEmbedded() != null) 950 return font.isOwnPdfEmbedded().booleanValue(); 951 JRFont baseFont = getBaseFont(font); 952 if (baseFont != null) 953 return baseFont.isPdfEmbedded(); 954 JRStyle baseStyle = getBaseStyle(font); 955 if (baseStyle != null && baseStyle.isPdfEmbedded() != null) 956 return baseStyle.isPdfEmbedded().booleanValue(); 957 return JRProperties.getBooleanProperty(JRFont.DEFAULT_PDF_EMBEDDED); 958 } 959 960 963 public static Boolean isPdfEmbedded(JRStyle style) 964 { 965 if (style.isOwnPdfEmbedded() != null) 966 return style.isOwnPdfEmbedded(); 967 JRStyle baseStyle = getBaseStyle(style); 968 if (baseStyle != null) 969 return baseStyle.isPdfEmbedded(); 970 return null; 971 } 972 973 976 public static byte getBorder(JRBox box) 977 { 978 if (box.getOwnBorder() != null) 979 return box.getOwnBorder().byteValue(); 980 JRStyle baseStyle = getBaseStyle(box); 981 if (baseStyle != null && baseStyle.getBorder() != null) 982 return baseStyle.getBorder().byteValue(); 983 return JRGraphicElement.PEN_NONE; 984 } 985 986 989 public static Byte getBorder(JRStyle style) 990 { 991 if (style.getOwnBorder() != null) 992 return style.getOwnBorder(); 993 JRStyle baseStyle = getBaseStyle(style); 994 if (baseStyle != null) 995 return baseStyle.getBorder(); 996 return null; 997 } 998 999 1002 public static byte getTopBorder(JRBox box) 1003 { 1004 if (box.getOwnTopBorder() != null) 1005 return box.getOwnTopBorder().byteValue(); 1006 if (box.getOwnBorder() != null) 1007 return box.getOwnBorder().byteValue(); 1008 JRStyle style = getBaseStyle(box); 1009 if (style != null && style.getTopBorder() != null) 1010 return style.getTopBorder().byteValue(); 1011 return JRGraphicElement.PEN_NONE; 1012 } 1013 1014 1017 public static Byte getTopBorder(JRStyle style) 1018 { 1019 if (style.getOwnTopBorder() != null) 1020 return style.getOwnTopBorder(); 1021 if (style.getOwnBorder() != null) 1022 return style.getOwnBorder(); 1023 JRStyle baseStyle = getBaseStyle(style); 1024 if (baseStyle != null) 1025 return baseStyle.getTopBorder(); 1026 return null; 1027 } 1028 1029 1032 public static byte getLeftBorder(JRBox box) 1033 { 1034 if (box.getOwnLeftBorder() != null) 1035 return box.getOwnLeftBorder().byteValue(); 1036 if (box.getOwnBorder() != null) 1037 return box.getOwnBorder().byteValue(); 1038 JRStyle style = getBaseStyle(box); 1039 if (style != null && style.getLeftBorder() != null) 1040 return style.getLeftBorder().byteValue(); 1041 return JRGraphicElement.PEN_NONE; 1042 } 1043 1044 1047 public static Byte getLeftBorder(JRStyle style) 1048 { 1049 if (style.getOwnLeftBorder() != null) 1050 return style.getOwnLeftBorder(); 1051 if (style.getOwnBorder() != null) 1052 return style.getOwnBorder(); 1053 JRStyle baseStyle = getBaseStyle(style); 1054 if (baseStyle != null) 1055 return baseStyle.getLeftBorder(); 1056 return null; 1057 } 1058 1059 1062 public static byte getBottomBorder(JRBox box) 1063 { 1064 if (box.getOwnBottomBorder() != null) 1065 return box.getOwnBottomBorder().byteValue(); 1066 if (box.getOwnBorder() != null) 1067 return box.getOwnBorder().byteValue(); 1068 JRStyle style = getBaseStyle(box); 1069 if (style != null && style.getBottomBorder() != null) 1070 return style.getBottomBorder().byteValue(); 1071 return JRGraphicElement.PEN_NONE; 1072 } 1073 1074 1077 public static Byte getBottomBorder(JRStyle style) 1078 { 1079 if (style.getOwnBottomBorder() != null) 1080 return style.getOwnBottomBorder(); 1081 if (style.getOwnBorder() != null) 1082 return style.getOwnBorder(); 1083 JRStyle baseStyle = getBaseStyle(style); 1084 if (baseStyle != null) 1085 return baseStyle.getBottomBorder(); 1086 return null; 1087 } 1088 1089 1092 public static byte getRightBorder(JRBox box) 1093 { 1094 if (box.getOwnRightBorder() != null) 1095 return box.getOwnRightBorder().byteValue(); 1096 if (box.getOwnBorder() != null) 1097 return box.getOwnBorder().byteValue(); 1098 JRStyle style = getBaseStyle(box); 1099 if (style != null && style.getRightBorder() != null) 1100 return style.getRightBorder().byteValue(); 1101 return JRGraphicElement.PEN_NONE; 1102 } 1103 1104 1107 public static Byte getRightBorder(JRStyle style) 1108 { 1109 if (style.getOwnRightBorder() != null) 1110 return style.getOwnRightBorder(); 1111 if (style.getOwnBorder() != null) 1112 return style.getOwnBorder(); 1113 JRStyle baseStyle = getBaseStyle(style); 1114 if (baseStyle != null) 1115 return baseStyle.getRightBorder(); 1116 return null; 1117 } 1118 1119 1122 public static Color getBorderColor(JRBox box, Color defaultColor) 1123 { 1124 if (box.getOwnBorderColor() != null) 1125 return box.getOwnBorderColor(); 1126 JRStyle baseStyle = getBaseStyle(box); 1127 if (baseStyle != null && baseStyle.getBorderColor() != null) 1128 return baseStyle.getBorderColor(); 1129 return defaultColor; 1130 } 1131 1132 1135 public static Color getBorderColor(JRStyle style) 1136 { 1137 if (style.getOwnBorderColor() != null) 1138 return style.getOwnBorderColor(); 1139 JRStyle baseStyle = getBaseStyle(style); 1140 if (baseStyle != null) 1141 return baseStyle.getBorderColor(); 1142 return null; 1143 } 1144 1145 1148 public static Color getTopBorderColor(JRBox box, Color defaultColor) 1149 { 1150 if (box.getOwnTopBorderColor() != null) 1151 return box.getOwnTopBorderColor(); 1152 if (box.getOwnBorderColor() != null) 1153 return box.getOwnBorderColor(); 1154 JRStyle style = getBaseStyle(box); 1155 if (style != null && style.getTopBorderColor() != null) 1156 return style.getTopBorderColor(); 1157 return defaultColor; 1158 } 1159 1160 1163 public static Color getTopBorderColor(JRStyle style) 1164 { 1165 if (style.getOwnTopBorderColor() != null) 1166 return style.getOwnTopBorderColor(); 1167 if (style.getOwnBorderColor() != null) 1168 return style.getOwnBorderColor(); 1169 JRStyle baseStyle = getBaseStyle(style); 1170 if (baseStyle != null) 1171 return baseStyle.getTopBorderColor(); 1172 return null; 1173 } 1174 1175 1178 public static Color getLeftBorderColor(JRBox box, Color defaultColor) 1179 { 1180 if (box.getOwnLeftBorderColor() != null) 1181 return box.getOwnLeftBorderColor(); 1182 if (box.getOwnBorderColor() != null) 1183 return box.getOwnBorderColor(); 1184 JRStyle style = getBaseStyle(box); 1185 if (style != null && style.getLeftBorderColor() != null) 1186 return style.getLeftBorderColor(); 1187 return defaultColor; 1188 } 1189 1190 1193 public static Color getLeftBorderColor(JRStyle style) 1194 { 1195 if (style.getOwnLeftBorderColor() != null) 1196 return style.getOwnLeftBorderColor(); 1197 if (style.getOwnBorderColor() != null) 1198 return style.getOwnBorderColor(); 1199 JRStyle baseStyle = getBaseStyle(style); 1200 if (baseStyle != null) 1201 return baseStyle.getLeftBorderColor(); 1202 return null; 1203 } 1204 1205 1208 public static Color getBottomBorderColor(JRBox box, Color defaultColor) 1209 { 1210 if (box.getOwnBottomBorderColor() != null) 1211 return box.getOwnBottomBorderColor(); 1212 if (box.getOwnBorderColor() != null) 1213 return box.getOwnBorderColor(); 1214 JRStyle style = getBaseStyle(box); 1215 if (style != null && style.getBottomBorderColor() != null) 1216 return style.getBottomBorderColor(); 1217 return defaultColor; 1218 } 1219 1220 1223 public static Color getBottomBorderColor(JRStyle style) 1224 { 1225 if (style.getOwnBottomBorderColor() != null) 1226 return style.getOwnBottomBorderColor(); 1227 if (style.getOwnBorderColor() != null) 1228 return style.getOwnBorderColor(); 1229 JRStyle baseStyle = getBaseStyle(style); 1230 if (baseStyle != null) 1231 return baseStyle.getBottomBorderColor(); 1232 return null; 1233 } 1234 1235 1238 public static Color getRightBorderColor(JRBox box, Color defaultColor) 1239 { 1240 if (box.getOwnRightBorderColor() != null) 1241 return box.getOwnRightBorderColor(); 1242 if (box.getOwnBorderColor() != null) 1243 return box.getOwnBorderColor(); 1244 JRStyle style = getBaseStyle(box); 1245 if (style != null && style.getRightBorderColor() != null) 1246 return style.getRightBorderColor(); 1247 return defaultColor; 1248 } 1249 1250 1253 public static Color getRightBorderColor(JRStyle style) 1254 { 1255 if (style.getOwnRightBorderColor() != null) 1256 return style.getOwnRightBorderColor(); 1257 if (style.getOwnBorderColor() != null) 1258 return style.getOwnBorderColor(); 1259 JRStyle baseStyle = getBaseStyle(style); 1260 if (baseStyle != null) 1261 return baseStyle.getRightBorderColor(); 1262 return null; 1263 } 1264 1265 1268 public static int getPadding(JRBox box) 1269 { 1270 if (box.getOwnPadding() != null) 1271 return box.getOwnPadding().intValue(); 1272 JRStyle baseStyle = getBaseStyle(box); 1273 if (baseStyle != null && baseStyle.getPadding() != null) 1274 return baseStyle.getPadding().intValue(); 1275 return 0; 1276 } 1277 1278 1281 public static Integer getPadding(JRStyle style) 1282 { 1283 if (style.getOwnPadding() != null) 1284 return style.getOwnPadding(); 1285 JRStyle baseStyle = getBaseStyle(style); 1286 if (baseStyle != null) 1287 return baseStyle.getPadding(); 1288 return null; 1289 } 1290 1291 1294 public static int getTopPadding(JRBox box) 1295 { 1296 if (box.getOwnTopPadding() != null) 1297 return box.getOwnTopPadding().intValue(); 1298 if (box.getOwnPadding() != null) 1299 return box.getOwnPadding().intValue(); 1300 JRStyle style = getBaseStyle(box); 1301 if (style != null && style.getTopPadding() != null) 1302 return style.getTopPadding().intValue(); 1303 return 0; 1304 } 1305 1306 1309 public static Integer getTopPadding(JRStyle style) 1310 { 1311 if (style.getOwnTopPadding() != null) 1312 return style.getOwnTopPadding(); 1313 if (style.getOwnPadding() != null) 1314 return style.getOwnPadding(); 1315 JRStyle baseStyle = getBaseStyle(style); 1316 if (baseStyle != null) 1317 return baseStyle.getTopPadding(); 1318 return null; 1319 } 1320 1321 1324 public static int getLeftPadding(JRBox box) 1325 { 1326 if (box.getOwnLeftPadding() != null) 1327 return box.getOwnLeftPadding().intValue(); 1328 if (box.getOwnPadding() != null) 1329 return box.getOwnPadding().intValue(); 1330 JRStyle style = getBaseStyle(box); 1331 if (style != null && style.getLeftPadding() != null) 1332 return style.getLeftPadding().intValue(); 1333 return 0; 1334 } 1335 1336 1339 public static Integer getLeftPadding(JRStyle style) 1340 { 1341 if (style.getOwnLeftPadding() != null) 1342 return style.getOwnLeftPadding(); 1343 if (style.getOwnPadding() != null) 1344 return style.getOwnPadding(); 1345 JRStyle baseStyle = getBaseStyle(style); 1346 if (baseStyle != null) 1347 return baseStyle.getLeftPadding(); 1348 return null; 1349 } 1350 1351 1354 public static int getBottomPadding(JRBox box) 1355 { 1356 if (box.getOwnBottomPadding() != null) 1357 return box.getOwnBottomPadding().intValue(); 1358 if (box.getOwnPadding() != null) 1359 return box.getOwnPadding().intValue(); 1360 JRStyle style = getBaseStyle(box); 1361 if (style != null && style.getBottomPadding() != null) 1362 return style.getBottomPadding().intValue(); 1363 return 0; 1364 } 1365 1366 1369 public static Integer getBottomPadding(JRStyle style) 1370 { 1371 if (style.getOwnBottomPadding() != null) 1372 return style.getOwnBottomPadding(); 1373 if (style.getOwnPadding() != null) 1374 return style.getOwnPadding(); 1375 JRStyle baseStyle = getBaseStyle(style); 1376 if (baseStyle != null) 1377 return baseStyle.getBottomPadding(); 1378 return null; 1379 } 1380 1381 1384 public static int getRightPadding(JRBox box) 1385 { 1386 if (box.getOwnRightPadding() != null) 1387 return box.getOwnRightPadding().intValue(); 1388 if (box.getOwnPadding() != null) 1389 return box.getOwnPadding().intValue(); 1390 JRStyle style = getBaseStyle(box); 1391 if (style != null && style.getRightPadding() != null) 1392 return style.getRightPadding().intValue(); 1393 return 0; 1394 } 1395 1396 1399 public static Integer getRightPadding(JRStyle style) 1400 { 1401 if (style.getOwnRightPadding() != null) 1402 return style.getOwnRightPadding(); 1403 if (style.getOwnPadding() != null) 1404 return style.getOwnPadding(); 1405 JRStyle baseStyle = getBaseStyle(style); 1406 if (baseStyle != null) 1407 return baseStyle.getRightPadding(); 1408 return null; 1409 } 1410 1411 1412 1415 public static void appendStyle(JRStyle destStyle, JRStyle srcStyle) 1416 { 1417 if (srcStyle.getOwnMode() != null) 1418 destStyle.setMode(srcStyle.getOwnMode()); 1419 if (srcStyle.getOwnForecolor() != null) 1420 destStyle.setForecolor(srcStyle.getOwnForecolor()); 1421 if (srcStyle.getOwnBackcolor() != null) 1422 destStyle.setBackcolor(srcStyle.getOwnBackcolor()); 1423 1424 if (srcStyle.getOwnPen() != null) 1425 destStyle.setPen(srcStyle.getOwnPen()); 1426 if (srcStyle.getOwnFill() != null) 1427 destStyle.setFill(srcStyle.getOwnFill()); 1428 1429 if (srcStyle.getOwnRadius() != null) 1430 destStyle.setRadius(srcStyle.getOwnRadius()); 1431 1432 if (srcStyle.getOwnScaleImage() != null) 1433 destStyle.setScaleImage(srcStyle.getOwnScaleImage()); 1434 if (srcStyle.getOwnHorizontalAlignment() != null) 1435 destStyle.setHorizontalAlignment(srcStyle.getOwnHorizontalAlignment()); 1436 if (srcStyle.getOwnVerticalAlignment() != null) 1437 destStyle.setVerticalAlignment(srcStyle.getOwnVerticalAlignment()); 1438 1439 if (srcStyle.getOwnBorder() != null) 1440 destStyle.setBorder(srcStyle.getOwnBorder()); 1441 if (srcStyle.getOwnTopBorder() != null) 1442 destStyle.setTopBorder(srcStyle.getOwnTopBorder()); 1443 if (srcStyle.getOwnLeftBorder() != null) 1444 destStyle.setLeftBorder(srcStyle.getOwnLeftBorder()); 1445 if (srcStyle.getOwnBottomBorder() != null) 1446 destStyle.setBottomBorder(srcStyle.getOwnBottomBorder()); 1447 if (srcStyle.getOwnRightBorder() != null) 1448 destStyle.setRightBorder(srcStyle.getOwnRightBorder()); 1449 if (srcStyle.getOwnBorderColor() != null) 1450 destStyle.setBorderColor(srcStyle.getOwnBorderColor()); 1451 if (srcStyle.getOwnTopBorderColor() != null) 1452 destStyle.setTopBorderColor(srcStyle.getOwnTopBorderColor()); 1453 if (srcStyle.getOwnLeftBorderColor() != null) 1454 destStyle.setLeftBorderColor(srcStyle.getOwnLeftBorderColor()); 1455 if (srcStyle.getOwnBottomBorderColor() != null) 1456 destStyle.setBottomBorderColor(srcStyle.getOwnBottomBorderColor()); 1457 if (srcStyle.getOwnRightBorderColor() != null) 1458 destStyle.setRightBorderColor(srcStyle.getOwnRightBorderColor()); 1459 if (srcStyle.getOwnPadding() != null) 1460 destStyle.setPadding(srcStyle.getOwnPadding()); 1461 if (srcStyle.getOwnTopPadding() != null) 1462 destStyle.setTopPadding(srcStyle.getOwnTopPadding()); 1463 if (srcStyle.getOwnLeftPadding() != null) 1464 destStyle.setLeftPadding(srcStyle.getOwnLeftPadding()); 1465 if (srcStyle.getOwnBottomPadding() != null) 1466 destStyle.setBottomPadding(srcStyle.getOwnBottomPadding()); 1467 if (srcStyle.getOwnRightPadding() != null) 1468 destStyle.setRightPadding(srcStyle.getOwnRightPadding()); 1469 1470 if (srcStyle.getOwnRotation() != null) 1471 destStyle.setRotation(srcStyle.getOwnRotation()); 1472 if (srcStyle.getOwnLineSpacing() != null) 1473 destStyle.setLineSpacing(srcStyle.getOwnLineSpacing()); 1474 if (srcStyle.isOwnStyledText() != null) 1475 destStyle.setStyledText(srcStyle.isOwnStyledText()); 1476 1477 if (srcStyle.getOwnPattern() != null) 1478 destStyle.setPattern(srcStyle.getOwnPattern()); 1479 1480 if (srcStyle.getOwnFontName() != null) 1481 destStyle.setFontName(srcStyle.getOwnFontName()); 1482 if (srcStyle.isOwnBold() != null) 1483 destStyle.setBold(srcStyle.isOwnBold()); 1484 if (srcStyle.isOwnItalic() != null) 1485 destStyle.setItalic(srcStyle.isOwnItalic()); 1486 if (srcStyle.isOwnUnderline() != null) 1487 destStyle.setUnderline(srcStyle.isOwnUnderline()); 1488 if (srcStyle.isOwnStrikeThrough() != null) 1489 destStyle.setStrikeThrough(srcStyle.isOwnStrikeThrough()); 1490 if (srcStyle.getOwnFontSize() != null) 1491 destStyle.setFontSize(srcStyle.getOwnFontSize()); 1492 if (srcStyle.getOwnPdfFontName() != null) 1493 destStyle.setPdfFontName(srcStyle.getOwnPdfFontName()); 1494 if (srcStyle.getOwnPdfEncoding() != null) 1495 destStyle.setPdfEncoding(srcStyle.getOwnPdfEncoding()); 1496 if (srcStyle.isOwnPdfEmbedded() != null) 1497 destStyle.setPdfEmbedded(srcStyle.isOwnPdfEmbedded()); 1498 } 1499} 1500 | Popular Tags |