1 28 package net.sf.jasperreports.engine.design; 29 30 import java.awt.Color ; 31 import java.io.IOException ; 32 import java.io.ObjectInputStream ; 33 import java.util.ArrayList ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 37 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 38 import net.sf.jasperreports.engine.JRAnchor; 39 import net.sf.jasperreports.engine.JRBox; 40 import net.sf.jasperreports.engine.JRChild; 41 import net.sf.jasperreports.engine.JRConstants; 42 import net.sf.jasperreports.engine.JRDefaultStyleProvider; 43 import net.sf.jasperreports.engine.JRExpression; 44 import net.sf.jasperreports.engine.JRExpressionCollector; 45 import net.sf.jasperreports.engine.JRGroup; 46 import net.sf.jasperreports.engine.JRHyperlink; 47 import net.sf.jasperreports.engine.JRHyperlinkHelper; 48 import net.sf.jasperreports.engine.JRHyperlinkParameter; 49 import net.sf.jasperreports.engine.JRImage; 50 import net.sf.jasperreports.engine.util.JRStyleResolver; 51 import net.sf.jasperreports.engine.xml.JRXmlWriter; 52 53 54 59 public class JRDesignImage extends JRDesignGraphicElement implements JRImage 60 { 61 62 63 66 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 67 68 71 protected Byte scaleImage; 72 protected Byte horizontalAlignment; 73 protected Byte verticalAlignment; 74 protected Boolean isUsingCache = null; 75 protected boolean isLazy = false; 76 protected byte onErrorType = ON_ERROR_TYPE_ERROR; 77 protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW; 78 protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL; 79 protected String linkType; 80 protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF; 81 private List hyperlinkParameters; 82 83 86 protected Byte border; 87 protected Byte topBorder = null; 88 protected Byte leftBorder = null; 89 protected Byte bottomBorder = null; 90 protected Byte rightBorder = null; 91 protected Color borderColor = null; 92 protected Color topBorderColor = null; 93 protected Color leftBorderColor = null; 94 protected Color bottomBorderColor = null; 95 protected Color rightBorderColor = null; 96 protected Integer padding; 97 protected Integer topPadding = null; 98 protected Integer leftPadding = null; 99 protected Integer bottomPadding = null; 100 protected Integer rightPadding = null; 101 102 103 106 108 111 protected JRGroup evaluationGroup = null; 112 protected JRExpression expression = null; 113 protected JRExpression anchorNameExpression = null; 114 protected JRExpression hyperlinkReferenceExpression = null; 115 protected JRExpression hyperlinkAnchorExpression = null; 116 protected JRExpression hyperlinkPageExpression = null; 117 private JRExpression hyperlinkTooltipExpression; 118 119 123 protected int bookmarkLevel = JRAnchor.NO_BOOKMARK; 124 125 126 129 public JRDesignImage(JRDefaultStyleProvider defaultStyleProvider) 130 { 131 super(defaultStyleProvider); 132 133 hyperlinkParameters = new ArrayList (); 134 } 135 136 137 140 public byte getPen() 141 { 142 return JRStyleResolver.getPen(this, PEN_NONE); 143 } 144 145 148 public byte getMode() 149 { 150 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 151 } 152 153 154 157 public byte getScaleImage() 158 { 159 return JRStyleResolver.getScaleImage(this); 160 } 161 162 public Byte getOwnScaleImage() 163 { 164 return scaleImage; 165 } 166 167 170 public void setScaleImage(byte scaleImage) 171 { 172 this.scaleImage = new Byte (scaleImage); 173 } 174 175 178 public void setScaleImage(Byte scaleImage) 179 { 180 this.scaleImage = scaleImage; 181 } 182 183 186 public byte getHorizontalAlignment() 187 { 188 return JRStyleResolver.getHorizontalAlignment(this); 189 } 190 191 public Byte getOwnHorizontalAlignment() 192 { 193 return horizontalAlignment; 194 } 195 196 199 public void setHorizontalAlignment(byte horizontalAlignment) 200 { 201 this.horizontalAlignment = new Byte (horizontalAlignment); 202 } 203 204 207 public void setHorizontalAlignment(Byte horizontalAlignment) 208 { 209 this.horizontalAlignment = horizontalAlignment; 210 } 211 212 215 public byte getVerticalAlignment() 216 { 217 return JRStyleResolver.getVerticalAlignment(this); 218 } 219 220 public Byte getOwnVerticalAlignment() 221 { 222 return verticalAlignment; 223 } 224 225 228 public void setVerticalAlignment(byte verticalAlignment) 229 { 230 this.verticalAlignment = new Byte (verticalAlignment); 231 } 232 233 236 public void setVerticalAlignment(Byte verticalAlignment) 237 { 238 this.verticalAlignment = verticalAlignment; 239 } 240 241 244 public boolean isUsingCache() 245 { 246 if (isUsingCache == null) 247 { 248 if (getExpression() != null) 249 { 250 return String .class.getName().equals(getExpression().getValueClassName()); 251 } 252 return true; 253 } 254 return isUsingCache.booleanValue(); 255 } 256 257 260 public Boolean isOwnUsingCache() 261 { 262 return isUsingCache; 263 } 264 265 268 public byte getEvaluationTime() 269 { 270 return evaluationTime; 271 } 272 273 276 public JRBox getBox() 277 { 278 return this; 279 } 280 281 284 public byte getHyperlinkType() 285 { 286 return JRHyperlinkHelper.getHyperlinkType(this); 287 } 288 289 292 public byte getHyperlinkTarget() 293 { 294 return hyperlinkTarget; 295 } 296 297 300 public JRGroup getEvaluationGroup() 301 { 302 return evaluationGroup; 303 } 304 305 308 public JRExpression getExpression() 309 { 310 return expression; 311 } 312 313 316 public JRExpression getAnchorNameExpression() 317 { 318 return anchorNameExpression; 319 } 320 321 324 public JRExpression getHyperlinkReferenceExpression() 325 { 326 return hyperlinkReferenceExpression; 327 } 328 329 332 public JRExpression getHyperlinkAnchorExpression() 333 { 334 return hyperlinkAnchorExpression; 335 } 336 337 340 public JRExpression getHyperlinkPageExpression() 341 { 342 return hyperlinkPageExpression; 343 } 344 345 346 349 public void setUsingCache(boolean isUsingCache) 350 { 351 setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE); 352 } 353 354 357 public void setUsingCache(Boolean isUsingCache) 358 { 359 this.isUsingCache = isUsingCache; 360 } 361 362 365 public boolean isLazy() 366 { 367 return isLazy; 368 } 369 370 373 public void setLazy(boolean isLazy) 374 { 375 this.isLazy = isLazy; 376 } 377 378 381 public byte getOnErrorType() 382 { 383 return onErrorType; 384 } 385 386 389 public void setOnErrorType(byte onErrorType) 390 { 391 this.onErrorType = onErrorType; 392 } 393 394 398 public void setEvaluationTime(byte evaluationTime) 399 { 400 this.evaluationTime = evaluationTime; 401 } 402 403 406 public void setBox(JRBox box) 407 { 408 border = box.getOwnBorder(); 409 topBorder = box.getOwnTopBorder(); 410 leftBorder = box.getOwnLeftBorder(); 411 bottomBorder = box.getOwnBottomBorder(); 412 rightBorder = box.getOwnRightBorder(); 413 borderColor = box.getOwnBorderColor(); 414 topBorderColor = box.getOwnTopBorderColor(); 415 leftBorderColor = box.getOwnLeftBorderColor(); 416 bottomBorderColor = box.getOwnBottomBorderColor(); 417 rightBorderColor = box.getOwnRightBorderColor(); 418 padding = box.getOwnPadding(); 419 topPadding = box.getOwnTopPadding(); 420 leftPadding = box.getOwnLeftPadding(); 421 bottomPadding = box.getOwnBottomPadding(); 422 rightPadding = box.getOwnRightPadding(); 423 } 424 425 426 432 public void setHyperlinkType(byte hyperlinkType) 433 { 434 setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType)); 435 } 436 437 440 public void setHyperlinkTarget(byte hyperlinkTarget) 441 { 442 this.hyperlinkTarget = hyperlinkTarget; 443 } 444 445 448 public void setEvaluationGroup(JRGroup evaluationGroup) 449 { 450 this.evaluationGroup = evaluationGroup; 451 } 452 453 456 public void setExpression(JRExpression expression) 457 { 458 this.expression = expression; 459 } 460 461 464 public void setAnchorNameExpression(JRExpression anchorNameExpression) 465 { 466 this.anchorNameExpression = anchorNameExpression; 467 } 468 469 472 public void setHyperlinkReferenceExpression(JRExpression hyperlinkReferenceExpression) 473 { 474 this.hyperlinkReferenceExpression = hyperlinkReferenceExpression; 475 } 476 477 480 public void setHyperlinkAnchorExpression(JRExpression hyperlinkAnchorExpression) 481 { 482 this.hyperlinkAnchorExpression = hyperlinkAnchorExpression; 483 } 484 485 488 public void setHyperlinkPageExpression(JRExpression hyperlinkPageExpression) 489 { 490 this.hyperlinkPageExpression = hyperlinkPageExpression; 491 } 492 493 496 public JRChild getCopy(JRAbstractObjectFactory factory) 497 { 498 return factory.getImage(this); 499 } 500 501 504 public void collectExpressions(JRExpressionCollector collector) 505 { 506 collector.collect(this); 507 } 508 509 512 public void writeXml(JRXmlWriter xmlWriter) throws IOException 513 { 514 xmlWriter.writeImage(this); 515 } 516 517 518 public int getBookmarkLevel() 519 { 520 return bookmarkLevel; 521 } 522 523 524 530 public void setBookmarkLevel(int bookmarkLevel) 531 { 532 this.bookmarkLevel = bookmarkLevel; 533 } 534 535 538 public byte getBorder() 539 { 540 return JRStyleResolver.getBorder(this); 541 } 542 543 public Byte getOwnBorder() 544 { 545 return border; 546 } 547 548 551 public void setBorder(byte border) 552 { 553 this.border = new Byte (border); 554 } 555 556 559 public Color getBorderColor() 560 { 561 return JRStyleResolver.getBorderColor(this, getForecolor()); 562 } 563 564 public Color getOwnBorderColor() 565 { 566 return borderColor; 567 } 568 569 572 public void setBorderColor(Color borderColor) 573 { 574 this.borderColor = borderColor; 575 } 576 577 580 public int getPadding() 581 { 582 return JRStyleResolver.getPadding(this); 583 } 584 585 public Integer getOwnPadding() 586 { 587 return padding; 588 } 589 590 593 public void setPadding(int padding) 594 { 595 this.padding = new Integer (padding); 596 } 597 598 601 public byte getTopBorder() 602 { 603 return JRStyleResolver.getTopBorder(this); 604 } 605 606 609 public Byte getOwnTopBorder() 610 { 611 return topBorder; 612 } 613 614 617 public void setTopBorder(byte topBorder) 618 { 619 this.topBorder = new Byte (topBorder); 620 } 621 622 625 public Color getTopBorderColor() 626 { 627 return JRStyleResolver.getTopBorderColor(this, getForecolor()); 628 } 629 630 633 public Color getOwnTopBorderColor() 634 { 635 return topBorderColor; 636 } 637 638 641 public void setTopBorderColor(Color topBorderColor) 642 { 643 this.topBorderColor = topBorderColor; 644 } 645 646 649 public int getTopPadding() 650 { 651 return JRStyleResolver.getTopPadding(this); 652 } 653 654 657 public Integer getOwnTopPadding() 658 { 659 return topPadding; 660 } 661 662 665 public void setTopPadding(int topPadding) 666 { 667 this.topPadding = new Integer (topPadding); 668 } 669 670 673 public byte getLeftBorder() 674 { 675 return JRStyleResolver.getLeftBorder(this); 676 } 677 678 681 public Byte getOwnLeftBorder() 682 { 683 return leftBorder; 684 } 685 686 689 public void setLeftBorder(byte leftBorder) 690 { 691 this.leftBorder = new Byte (leftBorder); 692 } 693 694 697 public Color getLeftBorderColor() 698 { 699 return JRStyleResolver.getLeftBorderColor(this, getForecolor()); 700 } 701 702 705 public Color getOwnLeftBorderColor() 706 { 707 return leftBorderColor; 708 } 709 710 713 public void setLeftBorderColor(Color leftBorderColor) 714 { 715 this.leftBorderColor = leftBorderColor; 716 } 717 718 721 public int getLeftPadding() 722 { 723 return JRStyleResolver.getLeftPadding(this); 724 } 725 726 729 public Integer getOwnLeftPadding() 730 { 731 return leftPadding; 732 } 733 734 737 public void setLeftPadding(int leftPadding) 738 { 739 this.leftPadding = new Integer (leftPadding); 740 } 741 742 745 public byte getBottomBorder() 746 { 747 return JRStyleResolver.getBottomBorder(this); 748 } 749 750 753 public Byte getOwnBottomBorder() 754 { 755 return bottomBorder; 756 } 757 758 761 public void setBottomBorder(byte bottomBorder) 762 { 763 this.bottomBorder = new Byte (bottomBorder); 764 } 765 766 769 public Color getBottomBorderColor() 770 { 771 return JRStyleResolver.getBottomBorderColor(this, getForecolor()); 772 } 773 774 777 public Color getOwnBottomBorderColor() 778 { 779 return bottomBorderColor; 780 } 781 782 785 public void setBottomBorderColor(Color bottomBorderColor) 786 { 787 this.bottomBorderColor = bottomBorderColor; 788 } 789 790 793 public int getBottomPadding() 794 { 795 return JRStyleResolver.getBottomPadding(this); 796 } 797 798 801 public Integer getOwnBottomPadding() 802 { 803 return bottomPadding; 804 } 805 806 809 public void setBottomPadding(int bottomPadding) 810 { 811 this.bottomPadding = new Integer (bottomPadding); 812 } 813 814 817 public byte getRightBorder() 818 { 819 return JRStyleResolver.getRightBorder(this); 820 } 821 822 825 public Byte getOwnRightBorder() 826 { 827 return rightBorder; 828 } 829 830 833 public void setRightBorder(byte rightBorder) 834 { 835 this.rightBorder = new Byte (rightBorder); 836 } 837 838 841 public Color getRightBorderColor() 842 { 843 return JRStyleResolver.getRightBorderColor(this, getForecolor()); 844 } 845 846 849 public Color getOwnRightBorderColor() 850 { 851 return rightBorderColor; 852 } 853 854 857 public void setRightBorderColor(Color rightBorderColor) 858 { 859 this.rightBorderColor = rightBorderColor; 860 } 861 862 865 public int getRightPadding() 866 { 867 return JRStyleResolver.getRightPadding(this); 868 } 869 870 873 public Integer getOwnRightPadding() 874 { 875 return rightPadding; 876 } 877 878 881 public void setRightPadding(int rightPadding) 882 { 883 this.rightPadding = new Integer (rightPadding); 884 } 885 886 887 890 public void setBorder(Byte border) 891 { 892 this.border = border; 893 } 894 895 898 public void setPadding(Integer padding) 899 { 900 this.padding = padding; 901 } 902 903 906 public void setTopBorder(Byte topBorder) 907 { 908 this.topBorder = topBorder; 909 } 910 911 914 public void setTopPadding(Integer topPadding) 915 { 916 this.topPadding = topPadding; 917 } 918 919 922 public void setLeftBorder(Byte leftBorder) 923 { 924 this.leftBorder = leftBorder; 925 } 926 927 930 public void setLeftPadding(Integer leftPadding) 931 { 932 this.leftPadding = leftPadding; 933 } 934 935 938 public void setBottomBorder(Byte bottomBorder) 939 { 940 this.bottomBorder = bottomBorder; 941 } 942 943 946 public void setBottomPadding(Integer bottomPadding) 947 { 948 this.bottomPadding = bottomPadding; 949 } 950 951 954 public void setRightBorder(Byte rightBorder) 955 { 956 this.rightBorder = rightBorder; 957 } 958 959 962 public void setRightPadding(Integer rightPadding) 963 { 964 this.rightPadding = rightPadding; 965 } 966 967 968 public String getLinkType() 969 { 970 return linkType; 971 } 972 973 974 983 public void setLinkType(String type) 984 { 985 this.linkType = type; 986 } 987 988 989 public JRHyperlinkParameter[] getHyperlinkParameters() 990 { 991 JRHyperlinkParameter[] parameters; 992 if (hyperlinkParameters.isEmpty()) 993 { 994 parameters = null; 995 } 996 else 997 { 998 parameters = new JRHyperlinkParameter[hyperlinkParameters.size()]; 999 hyperlinkParameters.toArray(parameters); 1000 } 1001 return parameters; 1002 } 1003 1004 1005 1010 public List getHyperlinkParametersList() 1011 { 1012 return hyperlinkParameters; 1013 } 1014 1015 1016 1021 public void addHyperlinkParameter(JRHyperlinkParameter parameter) 1022 { 1023 hyperlinkParameters.add(parameter); 1024 } 1025 1026 1027 1032 public void removeHyperlinkParameter(JRHyperlinkParameter parameter) 1033 { 1034 hyperlinkParameters.remove(parameter); 1035 } 1036 1037 1038 1047 public void removeHyperlinkParameter(String parameterName) 1048 { 1049 for (Iterator it = hyperlinkParameters.iterator(); it.hasNext();) 1050 { 1051 JRHyperlinkParameter parameter = (JRHyperlinkParameter) it.next(); 1052 if (parameter.getName() != null && parameter.getName().equals(parameterName)) 1053 { 1054 it.remove(); 1055 } 1056 } 1057 } 1058 1059 1060 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException 1061 { 1062 in.defaultReadObject(); 1063 normalizeLinkType(); 1064 } 1065 1066 1067 protected void normalizeLinkType() 1068 { 1069 if (linkType == null) 1070 { 1071 linkType = JRHyperlinkHelper.getLinkType(hyperlinkType); 1072 } 1073 hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL; 1074 } 1075 1076 1077 public JRExpression getHyperlinkTooltipExpression() 1078 { 1079 return hyperlinkTooltipExpression; 1080 } 1081 1082 1083 1089 public void setHyperlinkTooltipExpression(JRExpression hyperlinkTooltipExpression) 1090 { 1091 this.hyperlinkTooltipExpression = hyperlinkTooltipExpression; 1092 } 1093 1094} 1095 | Popular Tags |