1 28 package net.sf.jasperreports.engine.base; 29 30 import java.awt.Color ; 31 import java.io.IOException ; 32 import java.io.ObjectInputStream ; 33 34 import net.sf.jasperreports.charts.JRAreaPlot; 35 import net.sf.jasperreports.charts.JRBar3DPlot; 36 import net.sf.jasperreports.charts.JRBarPlot; 37 import net.sf.jasperreports.charts.JRBubblePlot; 38 import net.sf.jasperreports.charts.JRCandlestickPlot; 39 import net.sf.jasperreports.charts.JRCategoryDataset; 40 import net.sf.jasperreports.charts.JRHighLowDataset; 41 import net.sf.jasperreports.charts.JRHighLowPlot; 42 import net.sf.jasperreports.charts.JRLinePlot; 43 import net.sf.jasperreports.charts.JRMeterPlot; 44 import net.sf.jasperreports.charts.JRMultiAxisPlot; 45 import net.sf.jasperreports.charts.JRPie3DPlot; 46 import net.sf.jasperreports.charts.JRPieDataset; 47 import net.sf.jasperreports.charts.JRPiePlot; 48 import net.sf.jasperreports.charts.JRScatterPlot; 49 import net.sf.jasperreports.charts.JRThermometerPlot; 50 import net.sf.jasperreports.charts.JRTimePeriodDataset; 51 import net.sf.jasperreports.charts.JRTimeSeriesDataset; 52 import net.sf.jasperreports.charts.JRTimeSeriesPlot; 53 import net.sf.jasperreports.charts.JRValueDataset; 54 import net.sf.jasperreports.charts.JRXyDataset; 55 import net.sf.jasperreports.charts.JRXyzDataset; 56 import net.sf.jasperreports.engine.JRAbstractObjectFactory; 57 import net.sf.jasperreports.engine.JRAnchor; 58 import net.sf.jasperreports.engine.JRBox; 59 import net.sf.jasperreports.engine.JRChart; 60 import net.sf.jasperreports.engine.JRChartDataset; 61 import net.sf.jasperreports.engine.JRChartPlot; 62 import net.sf.jasperreports.engine.JRChild; 63 import net.sf.jasperreports.engine.JRConstants; 64 import net.sf.jasperreports.engine.JRExpression; 65 import net.sf.jasperreports.engine.JRExpressionCollector; 66 import net.sf.jasperreports.engine.JRFont; 67 import net.sf.jasperreports.engine.JRGroup; 68 import net.sf.jasperreports.engine.JRHyperlink; 69 import net.sf.jasperreports.engine.JRHyperlinkHelper; 70 import net.sf.jasperreports.engine.JRHyperlinkParameter; 71 import net.sf.jasperreports.engine.JRRuntimeException; 72 import net.sf.jasperreports.engine.util.JRStyleResolver; 73 import net.sf.jasperreports.engine.xml.JRXmlWriter; 74 75 76 80 public class JRBaseChart extends JRBaseElement implements JRChart 81 { 82 83 84 87 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 88 89 92 protected byte chartType = 0; 93 94 97 protected boolean isShowLegend = false; 98 protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW; 99 protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL; 100 protected String linkType; 101 protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF; 102 private JRHyperlinkParameter[] hyperlinkParameters; 103 104 protected byte titlePosition = JRChart.TITLE_POSITION_TOP; 105 protected Color titleColor = Color.black; 106 protected Color subtitleColor = Color.black; 107 protected Color legendColor = null; 108 protected Color legendBackgroundColor = null; 109 110 113 protected JRBox box = null; 114 protected JRFont titleFont = null; 115 protected JRFont subtitleFont = null; 116 protected JRFont legendFont = null; 117 118 protected String customizerClass; 119 120 123 protected JRGroup evaluationGroup = null; 124 protected JRExpression titleExpression = null; 125 protected JRExpression subtitleExpression = null; 126 protected JRExpression anchorNameExpression = null; 127 protected JRExpression hyperlinkReferenceExpression = null; 128 protected JRExpression hyperlinkAnchorExpression = null; 129 protected JRExpression hyperlinkPageExpression = null; 130 private JRExpression hyperlinkTooltipExpression; 131 132 protected JRChartDataset dataset = null; 133 protected JRChartPlot plot = null; 134 135 136 139 protected Byte border; 140 protected Byte topBorder = null; 141 protected Byte leftBorder = null; 142 protected Byte bottomBorder = null; 143 protected Byte rightBorder = null; 144 protected Color borderColor = null; 145 protected Color topBorderColor = null; 146 protected Color leftBorderColor = null; 147 protected Color bottomBorderColor = null; 148 protected Color rightBorderColor = null; 149 protected Integer padding; 150 protected Integer topPadding = null; 151 protected Integer leftPadding = null; 152 protected Integer bottomPadding = null; 153 protected Integer rightPadding = null; 154 155 156 160 protected int bookmarkLevel = JRAnchor.NO_BOOKMARK; 161 162 165 protected JRBaseChart(JRChart chart, JRBaseObjectFactory factory) 166 { 167 super(chart, factory); 168 169 chartType = chart.getChartType(); 170 171 switch(chartType) { 172 case CHART_TYPE_AREA: 173 dataset = factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 174 plot = factory.getAreaPlot((JRAreaPlot) chart.getPlot()); 175 break; 176 case CHART_TYPE_BAR: 177 dataset = factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 178 plot = factory.getBarPlot((JRBarPlot) chart.getPlot()); 179 break; 180 case CHART_TYPE_BAR3D: 181 dataset = factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 182 plot = factory.getBar3DPlot((JRBar3DPlot) chart.getPlot()); 183 break; 184 case CHART_TYPE_BUBBLE: 185 dataset = factory.getXyzDataset((JRXyzDataset) chart.getDataset()); 186 plot = factory.getBubblePlot((JRBubblePlot) chart.getPlot()); 187 break; 188 case CHART_TYPE_CANDLESTICK: 189 dataset = factory.getHighLowDataset((JRHighLowDataset) chart.getDataset()); 190 plot = factory.getCandlestickPlot((JRCandlestickPlot) chart.getPlot()); 191 break; 192 case CHART_TYPE_HIGHLOW: 193 dataset = factory.getHighLowDataset((JRHighLowDataset) chart.getDataset()); 194 plot = factory.getHighLowPlot((JRHighLowPlot) chart.getPlot()); 195 break; 196 case CHART_TYPE_LINE: 197 dataset = factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 198 plot = factory.getLinePlot((JRLinePlot) chart.getPlot()); 199 break; 200 case CHART_TYPE_METER: 201 dataset = factory.getValueDataset((JRValueDataset) chart.getDataset()); 202 plot = factory.getMeterPlot((JRMeterPlot) chart.getPlot()); 203 break; 204 case CHART_TYPE_MULTI_AXIS: 205 dataset = null; 206 plot = factory.getMultiAxisPlot((JRMultiAxisPlot) chart.getPlot()); 207 break; 208 case CHART_TYPE_PIE: 209 dataset = factory.getPieDataset((JRPieDataset) chart.getDataset()); 210 plot = factory.getPiePlot((JRPiePlot) chart.getPlot()); 211 break; 212 case CHART_TYPE_PIE3D: 213 dataset = factory.getPieDataset((JRPieDataset) chart.getDataset()); 214 plot = factory.getPie3DPlot((JRPie3DPlot) chart.getPlot()); 215 break; 216 case CHART_TYPE_SCATTER: 217 dataset = factory.getXyDataset((JRXyDataset) chart.getDataset()); 218 plot = factory.getScatterPlot((JRScatterPlot) chart.getPlot()); 219 break; 220 case CHART_TYPE_STACKEDBAR: 221 dataset = factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 222 plot = factory.getBarPlot((JRBarPlot) chart.getPlot()); 223 break; 224 case CHART_TYPE_STACKEDBAR3D: 225 dataset = factory.getCategoryDataset((JRCategoryDataset) chart.getDataset()); 226 plot = factory.getBar3DPlot((JRBar3DPlot) chart.getPlot()); 227 break; 228 case CHART_TYPE_THERMOMETER: 229 dataset = factory.getValueDataset((JRValueDataset) chart.getDataset()); 230 plot = factory.getThermometerPlot((JRThermometerPlot) chart.getPlot()); 231 break; 232 case CHART_TYPE_TIMESERIES: 233 dataset = factory.getTimeSeriesDataset((JRTimeSeriesDataset)chart.getDataset()); 234 plot = factory.getTimeSeriesPlot( (JRTimeSeriesPlot)chart.getPlot() ); 235 break; 236 case CHART_TYPE_XYAREA: 237 dataset = factory.getXyDataset((JRXyDataset) chart.getDataset()); 238 plot = factory.getAreaPlot((JRAreaPlot) chart.getPlot()); 239 break; 240 case CHART_TYPE_XYBAR: 241 242 switch (chart.getDataset().getDatasetType()){ 243 case JRChartDataset.TIMESERIES_DATASET: 244 dataset = factory.getTimeSeriesDataset((JRTimeSeriesDataset) chart.getDataset()); 245 break; 246 case JRChartDataset.TIMEPERIOD_DATASET: 247 dataset = factory.getTimePeriodDataset((JRTimePeriodDataset) chart.getDataset() ); 248 break; 249 case JRChartDataset.XY_DATASET: 250 dataset = factory.getXyDataset( (JRXyDataset)chart.getDataset() ); 251 break; 252 } 253 plot = factory.getBarPlot((JRBarPlot)chart.getPlot()); 254 break; 255 case CHART_TYPE_XYLINE: 256 dataset = factory.getXyDataset((JRXyDataset) chart.getDataset()); 257 plot = factory.getLinePlot((JRLinePlot) chart.getPlot()); 258 break; 259 default: 260 throw new JRRuntimeException("Chart type not supported."); 261 } 262 263 isShowLegend = chart.isShowLegend(); 264 evaluationTime = chart.getEvaluationTime(); 265 linkType = chart.getLinkType(); 266 hyperlinkTarget = chart.getHyperlinkTarget(); 267 titlePosition = chart.getTitlePosition(); 268 titleColor = chart.getTitleColor(); 269 subtitleColor = chart.getSubtitleColor(); 270 legendColor = chart.getLegendColor(); 271 legendBackgroundColor = chart.getLegendBackgroundColor(); 272 273 titleFont = factory.getFont(chart.getTitleFont()); 274 subtitleFont = factory.getFont(chart.getSubtitleFont()); 275 legendFont = factory.getFont(chart.getLegendFont()); 276 277 evaluationGroup = factory.getGroup(chart.getEvaluationGroup()); 278 titleExpression = factory.getExpression(chart.getTitleExpression()); 279 subtitleExpression = factory.getExpression(chart.getSubtitleExpression()); 280 anchorNameExpression = factory.getExpression(chart.getAnchorNameExpression()); 281 hyperlinkReferenceExpression = factory.getExpression(chart.getHyperlinkReferenceExpression()); 282 hyperlinkAnchorExpression = factory.getExpression(chart.getHyperlinkAnchorExpression()); 283 hyperlinkPageExpression = factory.getExpression(chart.getHyperlinkPageExpression()); 284 hyperlinkTooltipExpression = factory.getExpression(chart.getHyperlinkTooltipExpression()); 285 bookmarkLevel = chart.getBookmarkLevel(); 286 hyperlinkParameters = JRBaseHyperlink.copyHyperlinkParameters(chart, factory); 287 288 customizerClass = chart.getCustomizerClass(); 289 290 border = chart.getOwnBorder(); 291 topBorder = chart.getOwnTopBorder(); 292 leftBorder = chart.getOwnLeftBorder(); 293 bottomBorder = chart.getOwnBottomBorder(); 294 rightBorder = chart.getOwnRightBorder(); 295 borderColor = chart.getOwnBorderColor(); 296 topBorderColor = chart.getOwnTopBorderColor(); 297 leftBorderColor = chart.getOwnLeftBorderColor(); 298 bottomBorderColor = chart.getOwnBottomBorderColor(); 299 rightBorderColor = chart.getOwnRightBorderColor(); 300 padding = chart.getOwnPadding(); 301 topPadding = chart.getOwnTopPadding(); 302 leftPadding = chart.getOwnLeftPadding(); 303 bottomPadding = chart.getOwnBottomPadding(); 304 rightPadding = chart.getOwnRightPadding(); 305 306 } 307 308 309 312 public boolean isShowLegend() 313 { 314 return this.isShowLegend; 315 } 316 317 320 public void setShowLegend(boolean isShowLegend) 321 { 322 this.isShowLegend = isShowLegend; 323 } 324 325 328 public byte getEvaluationTime() 329 { 330 return evaluationTime; 331 } 332 333 336 public JRGroup getEvaluationGroup() 337 { 338 return evaluationGroup; 339 } 340 341 344 public JRBox getBox() 345 { 346 return this; 347 } 348 349 352 public JRFont getTitleFont() 353 { 354 return titleFont; 355 } 356 357 360 public byte getTitlePosition() 361 { 362 return titlePosition; 363 } 364 365 368 public void setTitlePosition(byte titlePosition) 369 { 370 this.titlePosition = titlePosition; 371 } 372 373 376 public Color getTitleColor() 377 { 378 return titleColor; 379 } 380 381 384 public void setTitleColor(Color titleColor) 385 { 386 this.titleColor = titleColor; 387 } 388 389 392 public JRFont getSubtitleFont() 393 { 394 return subtitleFont; 395 } 396 397 400 public Color getSubtitleColor() 401 { 402 return subtitleColor; 403 } 404 405 408 public void setSubtitleColor(Color subtitleColor) 409 { 410 this.subtitleColor = subtitleColor; 411 } 412 413 414 public Color getLegendBackgroundColor() { 415 return legendBackgroundColor; 416 } 417 418 419 public Color getLegendColor() { 420 return legendColor; 421 } 422 423 424 public JRFont getLegendFont() { 425 return legendFont; 426 } 427 428 429 public void setLegendBackgroundColor(Color legendBackgroundColor) { 430 this.legendBackgroundColor = legendBackgroundColor; 431 } 432 433 434 public void setLegendColor(Color legendColor) { 435 this.legendColor = legendColor; 436 } 437 438 441 public byte getHyperlinkType() 442 { 443 return JRHyperlinkHelper.getHyperlinkType(this); 444 } 445 446 449 public byte getHyperlinkTarget() 450 { 451 return hyperlinkTarget; 452 } 453 454 457 public JRExpression getTitleExpression() 458 { 459 return titleExpression; 460 } 461 462 465 public JRExpression getSubtitleExpression() 466 { 467 return subtitleExpression; 468 } 469 470 473 public JRExpression getAnchorNameExpression() 474 { 475 return anchorNameExpression; 476 } 477 478 481 public JRExpression getHyperlinkReferenceExpression() 482 { 483 return hyperlinkReferenceExpression; 484 } 485 486 489 public JRExpression getHyperlinkAnchorExpression() 490 { 491 return hyperlinkAnchorExpression; 492 } 493 494 497 public JRExpression getHyperlinkPageExpression() 498 { 499 return hyperlinkPageExpression; 500 } 501 502 505 public JRChartDataset getDataset() 506 { 507 return dataset; 508 } 509 510 513 public JRChartPlot getPlot() 514 { 515 return plot; 516 } 517 518 public byte getChartType() 519 { 520 return chartType; 521 } 522 523 524 public JRChild getCopy(JRAbstractObjectFactory factory) 525 { 526 return factory.getChart(this); 527 } 528 529 530 public void collectExpressions(JRExpressionCollector collector) 531 { 532 collector.collect(this); 533 } 534 535 536 public void writeXml(JRXmlWriter xmlWriter) throws IOException 537 { 538 xmlWriter.writeChartTag(this); 539 } 540 541 542 public int getBookmarkLevel() 543 { 544 return bookmarkLevel; 545 } 546 547 548 551 public String getCustomizerClass() 552 { 553 return customizerClass; 554 } 555 556 559 public byte getMode() 560 { 561 return JRStyleResolver.getMode(this, MODE_TRANSPARENT); 562 } 563 564 567 public byte getBorder() 568 { 569 return JRStyleResolver.getBorder(this); 570 } 571 572 public Byte getOwnBorder() 573 { 574 return border; 575 } 576 577 580 public void setBorder(byte border) 581 { 582 this.border = new Byte (border); 583 } 584 585 588 public void setBorder(Byte border) 589 { 590 this.border = border; 591 } 592 593 596 public Color getBorderColor() 597 { 598 return JRStyleResolver.getBorderColor(this, getForecolor()); 599 } 600 601 public Color getOwnBorderColor() 602 { 603 return borderColor; 604 } 605 606 609 public void setBorderColor(Color borderColor) 610 { 611 this.borderColor = borderColor; 612 } 613 614 617 public int getPadding() 618 { 619 return JRStyleResolver.getPadding(this); 620 } 621 622 public Integer getOwnPadding() 623 { 624 return padding; 625 } 626 627 630 public void setPadding(int padding) 631 { 632 this.padding = new Integer (padding); 633 } 634 635 638 public void setPadding(Integer padding) 639 { 640 this.padding = padding; 641 } 642 643 646 public byte getTopBorder() 647 { 648 return JRStyleResolver.getTopBorder(this); 649 } 650 651 654 public Byte getOwnTopBorder() 655 { 656 return topBorder; 657 } 658 659 662 public void setTopBorder(byte topBorder) 663 { 664 this.topBorder = new Byte (topBorder); 665 } 666 667 670 public void setTopBorder(Byte topBorder) 671 { 672 this.topBorder = topBorder; 673 } 674 675 678 public Color getTopBorderColor() 679 { 680 return JRStyleResolver.getTopBorderColor(this, getForecolor()); 681 } 682 683 686 public Color getOwnTopBorderColor() 687 { 688 return topBorderColor; 689 } 690 691 694 public void setTopBorderColor(Color topBorderColor) 695 { 696 this.topBorderColor = topBorderColor; 697 } 698 699 702 public int getTopPadding() 703 { 704 return JRStyleResolver.getTopPadding(this); 705 } 706 707 710 public Integer getOwnTopPadding() 711 { 712 return topPadding; 713 } 714 715 718 public void setTopPadding(int topPadding) 719 { 720 this.topPadding = new Integer (topPadding); 721 } 722 723 726 public void setTopPadding(Integer topPadding) 727 { 728 this.topPadding = topPadding; 729 } 730 731 734 public byte getLeftBorder() 735 { 736 return JRStyleResolver.getLeftBorder(this); 737 } 738 739 742 public Byte getOwnLeftBorder() 743 { 744 return leftBorder; 745 } 746 747 750 public void setLeftBorder(byte leftBorder) 751 { 752 this.leftBorder = new Byte (leftBorder); 753 } 754 755 758 public void setLeftBorder(Byte leftBorder) 759 { 760 this.leftBorder = leftBorder; 761 } 762 763 766 public Color getLeftBorderColor() 767 { 768 return JRStyleResolver.getLeftBorderColor(this, getForecolor()); 769 } 770 771 774 public Color getOwnLeftBorderColor() 775 { 776 return leftBorderColor; 777 } 778 779 782 public void setLeftBorderColor(Color leftBorderColor) 783 { 784 this.leftBorderColor = leftBorderColor; 785 } 786 787 790 public int getLeftPadding() 791 { 792 return JRStyleResolver.getLeftPadding(this); 793 } 794 795 798 public Integer getOwnLeftPadding() 799 { 800 return leftPadding; 801 } 802 803 806 public void setLeftPadding(int leftPadding) 807 { 808 this.leftPadding = new Integer (leftPadding); 809 } 810 811 814 public void setLeftPadding(Integer leftPadding) 815 { 816 this.leftPadding = leftPadding; 817 } 818 819 822 public byte getBottomBorder() 823 { 824 return JRStyleResolver.getBottomBorder(this); 825 } 826 827 830 public Byte getOwnBottomBorder() 831 { 832 return bottomBorder; 833 } 834 835 838 public void setBottomBorder(byte bottomBorder) 839 { 840 this.bottomBorder = new Byte (bottomBorder); 841 } 842 843 846 public void setBottomBorder(Byte bottomBorder) 847 { 848 this.bottomBorder = bottomBorder; 849 } 850 851 854 public Color getBottomBorderColor() 855 { 856 return JRStyleResolver.getBottomBorderColor(this, getForecolor()); 857 } 858 859 862 public Color getOwnBottomBorderColor() 863 { 864 return bottomBorderColor; 865 } 866 867 870 public void setBottomBorderColor(Color bottomBorderColor) 871 { 872 this.bottomBorderColor = bottomBorderColor; 873 } 874 875 878 public int getBottomPadding() 879 { 880 return JRStyleResolver.getBottomPadding(this); 881 } 882 883 886 public Integer getOwnBottomPadding() 887 { 888 return bottomPadding; 889 } 890 891 894 public void setBottomPadding(int bottomPadding) 895 { 896 this.bottomPadding = new Integer (bottomPadding); 897 } 898 899 902 public void setBottomPadding(Integer bottomPadding) 903 { 904 this.bottomPadding = bottomPadding; 905 } 906 907 910 public byte getRightBorder() 911 { 912 return JRStyleResolver.getRightBorder(this); 913 } 914 915 918 public Byte getOwnRightBorder() 919 { 920 return rightBorder; 921 } 922 923 926 public void setRightBorder(byte rightBorder) 927 { 928 this.rightBorder = new Byte (rightBorder); 929 } 930 931 934 public void setRightBorder(Byte rightBorder) 935 { 936 this.rightBorder = rightBorder; 937 } 938 939 942 public Color getRightBorderColor() 943 { 944 return JRStyleResolver.getRightBorderColor(this, getForecolor()); 945 } 946 947 950 public Color getOwnRightBorderColor() 951 { 952 return rightBorderColor; 953 } 954 955 958 public void setRightBorderColor(Color rightBorderColor) 959 { 960 this.rightBorderColor = rightBorderColor; 961 } 962 963 966 public int getRightPadding() 967 { 968 return JRStyleResolver.getRightPadding(this); 969 } 970 971 974 public Integer getOwnRightPadding() 975 { 976 return rightPadding; 977 } 978 979 982 public void setRightPadding(int rightPadding) 983 { 984 this.rightPadding = new Integer (rightPadding); 985 } 986 987 990 public void setRightPadding(Integer rightPadding) 991 { 992 this.rightPadding = rightPadding; 993 } 994 995 996 public String getLinkType() 997 { 998 return linkType; 999 } 1000 1001 1002 public JRHyperlinkParameter[] getHyperlinkParameters() 1003 { 1004 return hyperlinkParameters; 1005 } 1006 1007 1008 private void readObject(ObjectInputStream in) throws IOException , ClassNotFoundException 1009 { 1010 in.defaultReadObject(); 1011 normalizeLinkType(); 1012 } 1013 1014 1015 protected void normalizeLinkType() 1016 { 1017 if (linkType == null) 1018 { 1019 linkType = JRHyperlinkHelper.getLinkType(hyperlinkType); 1020 } 1021 hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL; 1022 } 1023 1024 1025 public JRExpression getHyperlinkTooltipExpression() 1026 { 1027 return hyperlinkTooltipExpression; 1028 } 1029 1030} 1031 | Popular Tags |