1 28 package net.sf.jasperreports.engine.fill; 29 30 import java.awt.Color ; 31 import java.awt.Image ; 32 import java.io.File ; 33 import java.io.IOException ; 34 import java.io.InputStream ; 35 import java.net.URL ; 36 37 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 38 import net.sf.jasperreports.engine.JRBox; 39 import net.sf.jasperreports.engine.JRChild; 40 import net.sf.jasperreports.engine.JRException; 41 import net.sf.jasperreports.engine.JRExpression; 42 import net.sf.jasperreports.engine.JRExpressionCollector; 43 import net.sf.jasperreports.engine.JRGroup; 44 import net.sf.jasperreports.engine.JRHyperlinkParameter; 45 import net.sf.jasperreports.engine.JRImage; 46 import net.sf.jasperreports.engine.JRImageRenderer; 47 import net.sf.jasperreports.engine.JRPrintElement; 48 import net.sf.jasperreports.engine.JRPrintHyperlinkParameters; 49 import net.sf.jasperreports.engine.JRPrintImage; 50 import net.sf.jasperreports.engine.JRRenderable; 51 import net.sf.jasperreports.engine.JRStyle; 52 import net.sf.jasperreports.engine.util.JRStyleResolver; 53 import net.sf.jasperreports.engine.xml.JRXmlWriter; 54 55 56 60 public class JRFillImage extends JRFillGraphicElement implements JRImage 61 { 62 63 64 67 private JRGroup evaluationGroup = null; 68 69 72 private JRRenderable renderer = null; 73 private String anchorName = null; 74 private String hyperlinkReference = null; 75 private String hyperlinkAnchor = null; 76 private Integer hyperlinkPage = null; 77 private String hyperlinkTooltip; 78 private JRPrintHyperlinkParameters hyperlinkParameters; 79 80 81 84 protected JRFillImage( 85 JRBaseFiller filler, 86 JRImage image, 87 JRFillObjectFactory factory 88 ) 89 { 90 super(filler, image, factory); 91 92 evaluationGroup = factory.getGroup(image.getEvaluationGroup()); 93 } 94 95 96 protected JRFillImage(JRFillImage image, JRFillCloneFactory factory) 97 { 98 super(image, factory); 99 100 evaluationGroup = image.evaluationGroup; 101 } 102 103 104 107 public byte getMode() 108 { 109 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 110 } 111 112 115 public byte getPen() 116 { 117 return JRStyleResolver.getPen(this, PEN_NONE); 118 } 119 120 123 public byte getScaleImage() 124 { 125 return JRStyleResolver.getScaleImage(this); 126 } 127 128 public Byte getOwnScaleImage() 129 { 130 return ((JRImage)this.parent).getOwnScaleImage(); 131 } 132 133 136 public void setScaleImage(byte scaleImage) 137 { 138 } 139 140 143 public void setScaleImage(Byte scaleImage) 144 { 145 } 146 147 150 public byte getHorizontalAlignment() 151 { 152 return JRStyleResolver.getHorizontalAlignment(this); 153 } 154 155 public Byte getOwnHorizontalAlignment() 156 { 157 return ((JRImage)this.parent).getOwnHorizontalAlignment(); 158 } 159 160 163 public void setHorizontalAlignment(byte horizontalAlignment) 164 { 165 } 166 167 170 public void setHorizontalAlignment(Byte horizontalAlignment) 171 { 172 } 173 174 177 public byte getVerticalAlignment() 178 { 179 return JRStyleResolver.getVerticalAlignment(this); 180 } 181 182 public Byte getOwnVerticalAlignment() 183 { 184 return ((JRImage)this.parent).getOwnVerticalAlignment(); 185 } 186 187 190 public void setVerticalAlignment(byte verticalAlignment) 191 { 192 } 193 194 197 public void setVerticalAlignment(Byte verticalAlignment) 198 { 199 } 200 201 204 public boolean isUsingCache() 205 { 206 return ((JRImage)this.parent).isUsingCache(); 207 } 208 209 212 public Boolean isOwnUsingCache() 213 { 214 return ((JRImage)this.parent).isOwnUsingCache(); 215 } 216 217 220 public void setUsingCache(boolean isUsingCache) 221 { 222 } 223 224 227 public void setUsingCache(Boolean isUsingCache) 228 { 229 } 230 231 234 public boolean isLazy() 235 { 236 return ((JRImage)this.parent).isLazy(); 237 } 238 239 242 public void setLazy(boolean isLazy) 243 { 244 } 245 246 249 public byte getOnErrorType() 250 { 251 return ((JRImage)this.parent).getOnErrorType(); 252 } 253 254 257 public void setOnErrorType(byte onErrorType) 258 { 259 } 260 261 264 public byte getEvaluationTime() 265 { 266 return ((JRImage)this.parent).getEvaluationTime(); 267 } 268 269 272 public JRGroup getEvaluationGroup() 273 { 274 return this.evaluationGroup; 275 } 276 277 280 public JRBox getBox() 281 { 282 return this; 283 } 284 285 288 public byte getHyperlinkType() 289 { 290 return ((JRImage)this.parent).getHyperlinkType(); 291 } 292 293 296 public byte getHyperlinkTarget() 297 { 298 return ((JRImage)this.parent).getHyperlinkTarget(); 299 } 300 301 304 public JRExpression getExpression() 305 { 306 return ((JRImage)this.parent).getExpression(); 307 } 308 309 312 public JRExpression getAnchorNameExpression() 313 { 314 return ((JRImage)this.parent).getAnchorNameExpression(); 315 } 316 317 320 public JRExpression getHyperlinkReferenceExpression() 321 { 322 return ((JRImage)this.parent).getHyperlinkReferenceExpression(); 323 } 324 325 328 public JRExpression getHyperlinkAnchorExpression() 329 { 330 return ((JRImage)this.parent).getHyperlinkAnchorExpression(); 331 } 332 333 336 public JRExpression getHyperlinkPageExpression() 337 { 338 return ((JRImage)this.parent).getHyperlinkPageExpression(); 339 } 340 341 342 345 protected JRRenderable getRenderer() 346 { 347 return this.renderer; 348 } 349 350 353 protected String getAnchorName() 354 { 355 return this.anchorName; 356 } 357 358 361 protected String getHyperlinkReference() 362 { 363 return this.hyperlinkReference; 364 } 365 366 369 protected String getHyperlinkAnchor() 370 { 371 return this.hyperlinkAnchor; 372 } 373 374 377 protected Integer getHyperlinkPage() 378 { 379 return this.hyperlinkPage; 380 } 381 382 383 protected String getHyperlinkTooltip() 384 { 385 return this.hyperlinkTooltip; 386 } 387 388 389 392 protected JRTemplateImage getJRTemplateImage() 393 { 394 JRStyle style = getStyle(); 395 JRTemplateImage template = (JRTemplateImage) getTemplate(style); 396 if (template == null) 397 { 398 template = new JRTemplateImage(filler.getJasperPrint().getDefaultStyleProvider(), this); 399 registerTemplate(style, template); 400 } 401 return template; 402 } 403 404 405 408 protected void evaluate( 409 byte evaluation 410 ) throws JRException 411 { 412 initDelayedEvaluations(); 413 414 this.reset(); 415 416 this.evaluatePrintWhenExpression(evaluation); 417 418 if ( 419 (this.isPrintWhenExpressionNull() || 420 (!this.isPrintWhenExpressionNull() && 421 this.isPrintWhenTrue())) 422 ) 423 { 424 if (isEvaluateNow()) 425 { 426 this.evaluateImage(evaluation); 427 } 428 } 429 } 430 431 432 435 protected void evaluateImage( 436 byte evaluation 437 ) throws JRException 438 { 439 JRExpression expression = this.getExpression(); 440 441 JRRenderable newRenderer = null; 442 443 Object source = evaluateExpression(expression, evaluation); 444 if (source != null) 445 { 446 if (this.isUsingCache() && this.filler.fillContext.hasLoadedImage(source)) 447 { 448 newRenderer = this.filler.fillContext.getLoadedImage(source).getRenderer(); 449 } 450 else 451 { 452 Class expressionClass = expression.getValueClass(); 453 454 if (Image .class.getName().equals(expressionClass.getName())) 455 { 456 Image img = (Image ) source; 457 newRenderer = JRImageRenderer.getInstance(img, getOnErrorType()); 458 } 459 else if (InputStream .class.getName().equals(expressionClass.getName())) 460 { 461 InputStream is = (InputStream ) source; 462 newRenderer = JRImageRenderer.getInstance(is, getOnErrorType()); 463 } 464 else if (URL .class.getName().equals(expressionClass.getName())) 465 { 466 URL url = (URL ) source; 467 newRenderer = JRImageRenderer.getInstance(url, getOnErrorType()); 468 } 469 else if (File .class.getName().equals(expressionClass.getName())) 470 { 471 File file = (File ) source; 472 newRenderer = JRImageRenderer.getInstance(file, getOnErrorType()); 473 } 474 else if (String .class.getName().equals(expressionClass.getName())) 475 { 476 String location = (String ) source; 477 newRenderer = JRImageRenderer.getInstance(location, getOnErrorType(), isLazy(), filler.reportClassLoader, 478 filler.urlHandlerFactory); 479 } 480 else if (JRRenderable.class.getName().equals(expressionClass.getName())) 481 { 482 newRenderer = (JRRenderable) source; 483 } 484 485 if (this.isUsingCache()) 486 { 487 JRPrintImage img = new JRTemplatePrintImage(this.getJRTemplateImage()); 488 img.setRenderer(newRenderer); 489 this.filler.fillContext.registerLoadedImage(source, img); 490 } 491 } 492 } 493 494 setValueRepeating(this.renderer == newRenderer); 495 496 this.renderer = newRenderer; 497 498 this.anchorName = (String ) evaluateExpression(this.getAnchorNameExpression(), evaluation); 499 this.hyperlinkReference = (String ) evaluateExpression(this.getHyperlinkReferenceExpression(), evaluation); 500 this.hyperlinkAnchor = (String ) evaluateExpression(this.getHyperlinkAnchorExpression(), evaluation); 501 this.hyperlinkPage = (Integer ) evaluateExpression(this.getHyperlinkPageExpression(), evaluation); 502 this.hyperlinkTooltip = (String ) evaluateExpression(this.getHyperlinkTooltipExpression(), evaluation); 503 hyperlinkParameters = JRFillHyperlinkHelper.evaluateHyperlinkParameters(this, expressionEvaluator, evaluation); 504 } 505 506 507 510 protected boolean prepare( 511 int availableStretchHeight, 512 boolean isOverflow 513 ) 514 { 515 boolean willOverflow = false; 516 517 if ( 518 this.isPrintWhenExpressionNull() || 519 ( !this.isPrintWhenExpressionNull() && 520 this.isPrintWhenTrue() ) 521 ) 522 { 523 this.setToPrint(true); 524 } 525 else 526 { 527 this.setToPrint(false); 528 } 529 530 if (!this.isToPrint()) 531 { 532 return willOverflow; 533 } 534 535 boolean isToPrint = true; 536 boolean isReprinted = false; 537 538 if (isEvaluateNow()) 539 { 540 if (isOverflow && this.isAlreadyPrinted() && !this.isPrintWhenDetailOverflows()) 541 { 542 isToPrint = false; 543 } 544 545 if ( 546 isToPrint && 547 this.isPrintWhenExpressionNull() && 548 !this.isPrintRepeatedValues() && 549 isValueRepeating() 550 ) 551 { 552 if ( 553 ( !this.isPrintInFirstWholeBand() || !this.getBand().isFirstWholeOnPageColumn() ) && 554 ( this.getPrintWhenGroupChanges() == null || !this.getBand().isNewGroup(this.getPrintWhenGroupChanges()) ) && 555 ( !isOverflow || !this.isPrintWhenDetailOverflows() ) 556 ) 557 { 558 isToPrint = false; 559 } 560 } 561 562 if ( 563 isToPrint && 564 availableStretchHeight < this.getRelativeY() - this.getY() - this.getBandBottomY() 565 ) 566 { 567 isToPrint = false; 568 willOverflow = true; 569 } 570 571 if ( 572 isToPrint && 573 isOverflow && 574 (this.isPrintWhenDetailOverflows() && (this.isAlreadyPrinted() || (!this.isAlreadyPrinted() && !this.isPrintRepeatedValues()))) 576 ) 577 { 578 isReprinted = true; 579 } 580 581 if ( 582 isToPrint && 583 this.isRemoveLineWhenBlank() && 584 this.getRenderer() == null 585 ) 586 { 587 isToPrint = false; 588 } 589 } 590 else 591 { 592 if (isOverflow && this.isAlreadyPrinted() && !this.isPrintWhenDetailOverflows()) 593 { 594 isToPrint = false; 595 } 596 597 if ( 598 isToPrint && 599 availableStretchHeight < this.getRelativeY() - this.getY() - this.getBandBottomY() 600 ) 601 { 602 isToPrint = false; 603 willOverflow = true; 604 } 605 606 if ( 607 isToPrint && 608 isOverflow && 609 (this.isPrintWhenDetailOverflows() && (this.isAlreadyPrinted() || (!this.isAlreadyPrinted() && !this.isPrintRepeatedValues()))) 611 ) 612 { 613 isReprinted = true; 614 } 615 } 616 617 this.setToPrint(isToPrint); 618 this.setReprinted(isReprinted); 619 620 return willOverflow; 621 } 622 623 624 627 protected JRPrintElement fill() throws JRException 628 { 629 byte evaluationType = this.getEvaluationTime(); 630 JRTemplatePrintImage printImage; 631 JRRecordedValuesPrintImage recordedValuesImage; 632 if (isEvaluateAuto()) 633 { 634 printImage = recordedValuesImage = new JRRecordedValuesPrintImage(getJRTemplateImage()); 635 } 636 else 637 { 638 printImage = new JRTemplatePrintImage(getJRTemplateImage()); 639 recordedValuesImage = null; 640 } 641 642 printImage.setX(this.getX()); 643 printImage.setY(this.getRelativeY()); 644 printImage.setWidth(getWidth()); 645 printImage.setHeight(this.getStretchHeight()); 646 647 if (isEvaluateNow()) 648 { 649 this.copy(printImage); 650 } 651 else if (isEvaluateAuto()) 652 { 653 initDelayedEvaluationPrint(recordedValuesImage); 654 } 655 else 656 { 657 filler.addBoundElement(this, printImage, evaluationType, getEvaluationGroup(), band); 658 } 659 660 return printImage; 661 } 662 663 664 667 protected void copy(JRPrintImage printImage) 668 { 669 printImage.setRenderer( 670 this.getRenderer() 671 ); 672 printImage.setAnchorName(this.getAnchorName()); 673 printImage.setHyperlinkReference(this.getHyperlinkReference()); 674 printImage.setHyperlinkAnchor(this.getHyperlinkAnchor()); 675 printImage.setHyperlinkPage(this.getHyperlinkPage()); 676 printImage.setHyperlinkTooltip(getHyperlinkTooltip()); 677 printImage.setBookmarkLevel(this.getBookmarkLevel()); 678 printImage.setHyperlinkParameters(hyperlinkParameters); 679 } 680 681 682 685 public JRChild getCopy(JRAbstractObjectFactory factory) 686 { 687 return factory.getImage(this); 688 } 689 690 693 public void collectExpressions(JRExpressionCollector collector) 694 { 695 collector.collect(this); 696 } 697 698 701 public void writeXml(JRXmlWriter xmlWriter) throws IOException 702 { 703 xmlWriter.writeImage(this); 704 } 705 706 707 protected void resolveElement(JRPrintElement element, byte evaluation) throws JRException 708 { 709 evaluateImage(evaluation); 710 711 copy((JRPrintImage) element); 712 } 713 714 715 public int getBookmarkLevel() 716 { 717 return ((JRImage)this.parent).getBookmarkLevel(); 718 } 719 720 723 public byte getBorder() 724 { 725 return JRStyleResolver.getBorder(this); 726 } 727 728 public Byte getOwnBorder() 729 { 730 return ((JRBox)parent).getOwnBorder(); 731 } 732 733 736 public void setBorder(byte border) 737 { 738 } 739 740 743 public Color getBorderColor() 744 { 745 return JRStyleResolver.getBorderColor(this, getForecolor()); 746 } 747 748 public Color getOwnBorderColor() 749 { 750 return ((JRBox)parent).getOwnBorderColor(); 751 } 752 753 756 public void setBorderColor(Color borderColor) 757 { 758 } 759 760 763 public int getPadding() 764 { 765 return JRStyleResolver.getPadding(this); 766 } 767 768 public Integer getOwnPadding() 769 { 770 return ((JRBox)parent).getOwnPadding(); 771 } 772 773 776 public void setPadding(int padding) 777 { 778 } 779 780 783 public byte getTopBorder() 784 { 785 return JRStyleResolver.getTopBorder(this); 786 } 787 788 791 public Byte getOwnTopBorder() 792 { 793 return ((JRBox)parent).getOwnTopBorder(); 794 } 795 796 799 public void setTopBorder(byte topBorder) 800 { 801 } 802 803 806 public Color getTopBorderColor() 807 { 808 return JRStyleResolver.getTopBorderColor(this, getForecolor()); 809 } 810 811 814 public Color getOwnTopBorderColor() 815 { 816 return ((JRBox)parent).getOwnTopBorderColor(); 817 } 818 819 822 public void setTopBorderColor(Color topBorderColor) 823 { 824 } 825 826 829 public int getTopPadding() 830 { 831 return JRStyleResolver.getTopPadding(this); 832 } 833 834 837 public Integer getOwnTopPadding() 838 { 839 return ((JRBox)parent).getOwnTopPadding(); 840 } 841 842 845 public void setTopPadding(int topPadding) 846 { 847 } 848 849 852 public byte getLeftBorder() 853 { 854 return JRStyleResolver.getLeftBorder(this); 855 } 856 857 860 public Byte getOwnLeftBorder() 861 { 862 return ((JRBox)parent).getOwnLeftBorder(); 863 } 864 865 868 public void setLeftBorder(byte leftBorder) 869 { 870 } 871 872 875 public Color getLeftBorderColor() 876 { 877 return JRStyleResolver.getLeftBorderColor(this, getForecolor()); 878 } 879 880 883 public Color getOwnLeftBorderColor() 884 { 885 return ((JRBox)parent).getOwnLeftBorderColor(); 886 } 887 888 891 public void setLeftBorderColor(Color leftBorderColor) 892 { 893 } 894 895 898 public int getLeftPadding() 899 { 900 return JRStyleResolver.getLeftPadding(this); 901 } 902 903 906 public Integer getOwnLeftPadding() 907 { 908 return ((JRBox)parent).getOwnLeftPadding(); 909 } 910 911 914 public void setLeftPadding(int leftPadding) 915 { 916 } 917 918 921 public byte getBottomBorder() 922 { 923 return JRStyleResolver.getBottomBorder(this); 924 } 925 926 929 public Byte getOwnBottomBorder() 930 { 931 return ((JRBox)parent).getOwnBottomBorder(); 932 } 933 934 937 public void setBottomBorder(byte bottomBorder) 938 { 939 } 940 941 944 public Color getBottomBorderColor() 945 { 946 return JRStyleResolver.getBottomBorderColor(this, getForecolor()); 947 } 948 949 952 public Color getOwnBottomBorderColor() 953 { 954 return ((JRBox)parent).getOwnBottomBorderColor(); 955 } 956 957 960 public void setBottomBorderColor(Color bottomBorderColor) 961 { 962 } 963 964 967 public int getBottomPadding() 968 { 969 return JRStyleResolver.getBottomPadding(this); 970 } 971 972 975 public Integer getOwnBottomPadding() 976 { 977 return ((JRBox)parent).getOwnBottomPadding(); 978 } 979 980 983 public void setBottomPadding(int bottomPadding) 984 { 985 } 986 987 990 public byte getRightBorder() 991 { 992 return JRStyleResolver.getRightBorder(this); 993 } 994 995 998 public Byte getOwnRightBorder() 999 { 1000 return ((JRBox)parent).getOwnRightBorder(); 1001 } 1002 1003 1006 public void setRightBorder(byte rightBorder) 1007 { 1008 } 1009 1010 1013 public Color getRightBorderColor() 1014 { 1015 return JRStyleResolver.getRightBorderColor(this, getForecolor()); 1016 } 1017 1018 1021 public Color getOwnRightBorderColor() 1022 { 1023 return ((JRBox)parent).getOwnRightBorderColor(); 1024 } 1025 1026 1029 public void setRightBorderColor(Color rightBorderColor) 1030 { 1031 } 1032 1033 1036 public int getRightPadding() 1037 { 1038 return JRStyleResolver.getRightPadding(this); 1039 } 1040 1041 1044 public Integer getOwnRightPadding() 1045 { 1046 return ((JRBox)parent).getOwnRightPadding(); 1047 } 1048 1049 1052 public void setRightPadding(int rightPadding) 1053 { 1054 } 1055 1056 1059 public void setBorder(Byte border) 1060 { 1061 } 1062 1063 1066 public void setPadding(Integer padding) 1067 { 1068 } 1069 1070 1073 public void setTopBorder(Byte topBorder) 1074 { 1075 } 1076 1077 1080 public void setTopPadding(Integer topPadding) 1081 { 1082 } 1083 1084 1087 public void setLeftBorder(Byte leftBorder) 1088 { 1089 } 1090 1091 1094 public void setLeftPadding(Integer leftPadding) 1095 { 1096 } 1097 1098 1101 public void setBottomBorder(Byte bottomBorder) 1102 { 1103 } 1104 1105 1108 public void setBottomPadding(Integer bottomPadding) 1109 { 1110 } 1111 1112 1115 public void setRightBorder(Byte rightBorder) 1116 { 1117 } 1118 1119 1122 public void setRightPadding(Integer rightPadding) 1123 { 1124 } 1125 1126 1127 public JRCloneable createClone(JRFillCloneFactory factory) 1128 { 1129 return new JRFillImage(this, factory); 1130 } 1131 1132 protected void collectDelayedEvaluations() 1133 { 1134 collectDelayedEvaluations(getExpression()); 1135 collectDelayedEvaluations(getAnchorNameExpression()); 1136 collectDelayedEvaluations(getHyperlinkReferenceExpression()); 1137 collectDelayedEvaluations(getHyperlinkAnchorExpression()); 1138 collectDelayedEvaluations(getHyperlinkPageExpression()); 1139 } 1140 1141 1142 public JRHyperlinkParameter[] getHyperlinkParameters() 1143 { 1144 return ((JRImage) parent).getHyperlinkParameters(); 1145 } 1146 1147 1148 public String getLinkType() 1149 { 1150 return ((JRImage) parent).getLinkType(); 1151 } 1152 1153 1154 public JRExpression getHyperlinkTooltipExpression() 1155 { 1156 return ((JRImage) parent).getHyperlinkTooltipExpression(); 1157 } 1158 1159} 1160 | Popular Tags |