1 28 package net.sf.jasperreports.engine.design; 29 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.HashMap ; 33 import java.util.HashSet ; 34 import java.util.Iterator ; 35 import java.util.List ; 36 import java.util.Map ; 37 38 import net.sf.jasperreports.crosstabs.JRCrosstab; 39 import net.sf.jasperreports.crosstabs.design.JRDesignCrosstab; 40 import net.sf.jasperreports.engine.JRBand; 41 import net.sf.jasperreports.engine.JRConstants; 42 import net.sf.jasperreports.engine.JRDataset; 43 import net.sf.jasperreports.engine.JRElement; 44 import net.sf.jasperreports.engine.JRException; 45 import net.sf.jasperreports.engine.JRExpression; 46 import net.sf.jasperreports.engine.JRExpressionCollector; 47 import net.sf.jasperreports.engine.JRField; 48 import net.sf.jasperreports.engine.JRFrame; 49 import net.sf.jasperreports.engine.JRGroup; 50 import net.sf.jasperreports.engine.JRParameter; 51 import net.sf.jasperreports.engine.JRReportFont; 52 import net.sf.jasperreports.engine.JRSortField; 53 import net.sf.jasperreports.engine.JRStyle; 54 import net.sf.jasperreports.engine.JRVariable; 55 import net.sf.jasperreports.engine.base.JRBaseReport; 56 57 58 70 public class JasperDesign extends JRBaseReport 71 { 72 75 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 76 77 private Map fontsMap = new HashMap (); 78 private List fontsList = new ArrayList (); 79 private Map stylesMap = new HashMap (); 80 private List stylesList = new ArrayList (); 81 82 85 private JRDesignDataset mainDesignDataset; 86 87 90 private Map datasetMap = new HashMap (); 91 private List datasetList = new ArrayList (); 92 93 private transient List crosstabs; 94 95 98 public JasperDesign() 99 { 100 setMainDataset(new JRDesignDataset(true)); 101 } 102 103 104 108 public void setName(String name) 109 { 110 this.name = name; 111 this.mainDesignDataset.setName(name); 112 } 113 114 115 118 public void setLanguage(String language) 119 { 120 this.language = language; 121 } 122 123 124 127 public void setColumnCount(int columnCount) 128 { 129 this.columnCount = columnCount; 130 } 131 132 133 138 public void setPrintOrder(byte printOrder) 139 { 140 this.printOrder = printOrder; 141 } 142 143 144 147 public void setPageWidth(int pageWidth) 148 { 149 this.pageWidth = pageWidth; 150 } 151 152 153 156 public void setPageHeight(int pageHeight) 157 { 158 this.pageHeight = pageHeight; 159 } 160 161 162 167 public void setOrientation(byte orientation) 168 { 169 this.orientation = orientation; 170 } 171 172 173 176 public void setColumnWidth(int columnWidth) 177 { 178 this.columnWidth = columnWidth; 179 } 180 181 182 185 public void setColumnSpacing(int columnSpacing) 186 { 187 this.columnSpacing = columnSpacing; 188 } 189 190 191 194 public void setLeftMargin(int leftMargin) 195 { 196 this.leftMargin = leftMargin; 197 } 198 199 200 203 public void setRightMargin(int rightMargin) 204 { 205 this.rightMargin = rightMargin; 206 } 207 208 209 212 public void setTopMargin(int topMargin) 213 { 214 this.topMargin = topMargin; 215 } 216 217 218 221 public void setBottomMargin(int bottomMargin) 222 { 223 this.bottomMargin = bottomMargin; 224 } 225 226 227 230 public void setBackground(JRBand background) 231 { 232 this.background = background; 233 } 234 235 236 239 public void setTitle(JRBand title) 240 { 241 this.title = title; 242 } 243 244 245 251 public void setTitleNewPage(boolean isTitleNewPage) 252 { 253 this.isTitleNewPage = isTitleNewPage; 254 } 255 256 257 260 public void setSummary(JRBand summary) 261 { 262 this.summary = summary; 263 } 264 265 266 272 public void setSummaryNewPage(boolean isSummaryNewPage) 273 { 274 this.isSummaryNewPage = isSummaryNewPage; 275 } 276 277 278 282 public void setFloatColumnFooter(boolean isFloatColumnFooter) 283 { 284 this.isFloatColumnFooter = isFloatColumnFooter; 285 } 286 287 288 291 public void setPageHeader(JRBand pageHeader) 292 { 293 this.pageHeader = pageHeader; 294 } 295 296 297 300 public void setPageFooter(JRBand pageFooter) 301 { 302 this.pageFooter = pageFooter; 303 } 304 305 306 309 public void setLastPageFooter(JRBand lastPageFooter) 310 { 311 this.lastPageFooter = lastPageFooter; 312 } 313 314 315 318 public void setColumnHeader(JRBand columnHeader) 319 { 320 this.columnHeader = columnHeader; 321 } 322 323 324 327 public void setColumnFooter(JRBand columnFooter) 328 { 329 this.columnFooter = columnFooter; 330 } 331 332 333 336 public void setDetail(JRBand detail) 337 { 338 this.detail = detail; 339 } 340 341 342 345 public void setScriptletClass(String scriptletClass) 346 { 347 mainDesignDataset.setScriptletClass(scriptletClass); 348 } 349 350 351 354 public void setFormatFactoryClass(String formatFactoryClass) 355 { 356 this.formatFactoryClass = formatFactoryClass; 357 } 358 359 360 363 public void setResourceBundle(String resourceBundle) 364 { 365 mainDesignDataset.setResourceBundle(resourceBundle); 366 } 367 368 369 372 public void addImport(String value) 373 { 374 if (importsSet == null) 375 { 376 importsSet = new HashSet (); 377 } 378 importsSet.add(value); 379 } 380 381 382 385 public void removeImport(String value) 386 { 387 if (importsSet != null) 388 { 389 importsSet.remove(value); 390 } 391 } 392 393 394 397 public void setDefaultFont(JRReportFont font) 398 { 399 this.defaultFont = font; 400 } 401 402 403 407 public JRReportFont[] getFonts() 408 { 409 JRReportFont[] fontsArray = new JRReportFont[fontsList.size()]; 410 411 fontsList.toArray(fontsArray); 412 413 return fontsArray; 414 } 415 416 417 421 public List getFontsList() 422 { 423 return fontsList; 424 } 425 426 427 430 public Map getFontsMap() 431 { 432 return fontsMap; 433 } 434 435 436 440 public void addFont(JRReportFont reportFont) throws JRException 441 { 442 if (fontsMap.containsKey(reportFont.getName())) 443 { 444 throw new JRException("Duplicate declaration of report font : " + reportFont.getName()); 445 } 446 447 fontsList.add(reportFont); 448 fontsMap.put(reportFont.getName(), reportFont); 449 450 if (reportFont.isDefault()) 451 { 452 setDefaultFont(reportFont); 453 } 454 } 455 456 457 461 public JRReportFont removeFont(String propName) 462 { 463 return removeFont( 464 (JRReportFont)fontsMap.get(propName) 465 ); 466 } 467 468 469 473 public JRReportFont removeFont(JRReportFont reportFont) 474 { 475 if (reportFont != null) 476 { 477 if (reportFont.isDefault()) 478 { 479 setDefaultFont(null); 480 } 481 482 fontsList.remove(reportFont); 483 fontsMap.remove(reportFont.getName()); 484 } 485 486 return reportFont; 487 } 488 489 490 493 public void setDefaultStyle(JRStyle style) 494 { 495 this.defaultStyle = style; 496 } 497 498 499 502 public JRStyle[] getStyles() 503 { 504 JRStyle[] stylesArray = new JRStyle[stylesList.size()]; 505 506 stylesList.toArray(stylesArray); 507 508 return stylesArray; 509 } 510 511 512 515 public List getStylesList() 516 { 517 return stylesList; 518 } 519 520 521 524 public Map getStylesMap() 525 { 526 return stylesMap; 527 } 528 529 530 533 public void addStyle(JRStyle style) throws JRException 534 { 535 if (stylesMap.containsKey(style.getName())) 536 { 537 throw new JRException("Duplicate declaration of report style : " + style.getName()); 538 } 539 540 stylesList.add(style); 541 stylesMap.put(style.getName(), style); 542 543 if (style.isDefault()) 544 { 545 setDefaultStyle(style); 546 } 547 } 548 549 550 553 public JRStyle removeStyle(String styleName) 554 { 555 return removeStyle( 556 (JRStyle)stylesMap.get(styleName) 557 ); 558 } 559 560 561 564 public JRStyle removeStyle(JRStyle style) 565 { 566 if (style != null) 567 { 568 if (style.isDefault()) 569 { 570 setDefaultStyle(null); 571 } 572 573 stylesList.remove(style); 574 stylesMap.remove(style.getName()); 575 } 576 577 return style; 578 } 579 580 581 584 public List getParametersList() 585 { 586 return mainDesignDataset.getParametersList(); 587 } 588 589 590 593 public Map getParametersMap() 594 { 595 return mainDesignDataset.getParametersMap(); 596 } 597 598 599 602 public void addParameter(JRParameter parameter) throws JRException 603 { 604 mainDesignDataset.addParameter(parameter); 605 } 606 607 608 611 public JRParameter removeParameter(String parameterName) 612 { 613 return mainDesignDataset.removeParameter(parameterName); 614 } 615 616 617 620 public JRParameter removeParameter(JRParameter parameter) 621 { 622 return mainDesignDataset.removeParameter(parameter); 623 } 624 625 626 629 public void setQuery(JRDesignQuery query) 630 { 631 mainDesignDataset.setQuery(query); 632 } 633 634 635 638 public List getFieldsList() 639 { 640 return mainDesignDataset.getFieldsList(); 641 } 642 643 644 647 public Map getFieldsMap() 648 { 649 return mainDesignDataset.getFieldsMap(); 650 } 651 652 653 656 public void addField(JRField field) throws JRException 657 { 658 mainDesignDataset.addField(field); 659 } 660 661 662 665 public JRField removeField(String fieldName) 666 { 667 return mainDesignDataset.removeField(fieldName); 668 } 669 670 671 674 public JRField removeField(JRField field) 675 { 676 return mainDesignDataset.removeField(field); 677 } 678 679 680 683 public List getSortFieldsList() 684 { 685 return mainDesignDataset.getSortFieldsList(); 686 } 687 688 689 692 public void addSortField(JRSortField sortField) throws JRException 693 { 694 mainDesignDataset.addSortField(sortField); 695 } 696 697 698 701 public JRSortField removeSortField(String fieldName) 702 { 703 return mainDesignDataset.removeSortField(fieldName); 704 } 705 706 707 710 public JRSortField removeSortField(JRSortField sortField) 711 { 712 return mainDesignDataset.removeSortField(sortField); 713 } 714 715 716 719 public List getVariablesList() 720 { 721 return mainDesignDataset.getVariablesList(); 722 } 723 724 725 728 public Map getVariablesMap() 729 { 730 return mainDesignDataset.getVariablesMap(); 731 } 732 733 734 737 public void addVariable(JRDesignVariable variable) throws JRException 738 { 739 mainDesignDataset.addVariable(variable); 740 } 741 742 743 746 public JRVariable removeVariable(String variableName) 747 { 748 return mainDesignDataset.removeVariable(variableName); 749 } 750 751 752 755 public JRVariable removeVariable(JRVariable variable) 756 { 757 return mainDesignDataset.removeVariable(variable); 758 } 759 760 761 764 public List getGroupsList() 765 { 766 return mainDesignDataset.getGroupsList(); 767 } 768 769 770 773 public Map getGroupsMap() 774 { 775 return mainDesignDataset.getGroupsMap(); 776 } 777 778 779 782 public void addGroup(JRDesignGroup group) throws JRException 783 { 784 mainDesignDataset.addGroup(group); 785 } 786 787 788 791 public JRGroup removeGroup(String groupName) 792 { 793 return mainDesignDataset.removeGroup(groupName); 794 } 795 796 797 800 public JRGroup removeGroup(JRGroup group) 801 { 802 return mainDesignDataset.removeGroup(group); 803 } 804 805 806 809 public Collection getExpressions() 810 { 811 return JRExpressionCollector.collectExpressions(this); 812 } 813 814 815 public JRDataset[] getDatasets() 816 { 817 JRDataset[] datasetArray = new JRDataset[datasetList.size()]; 818 datasetList.toArray(datasetArray); 819 return datasetArray; 820 } 821 822 823 824 829 public List getDatasetsList() 830 { 831 return datasetList; 832 } 833 834 835 840 public Map getDatasetMap() 841 { 842 return datasetMap; 843 } 844 845 846 852 public void addDataset(JRDesignDataset dataset) throws JRException 853 { 854 if (datasetMap.containsKey(dataset.getName())) 855 { 856 throw new JRException("Duplicate declaration of dataset : " + dataset.getName()); 857 } 858 859 datasetList.add(dataset); 860 datasetMap.put(dataset.getName(), dataset); 861 } 862 863 864 870 public JRDataset removeDataset(String datasetName) 871 { 872 return removeDataset( 873 (JRDataset)datasetMap.get(datasetName) 874 ); 875 } 876 877 878 884 public JRDataset removeDataset(JRDataset dataset) 885 { 886 if (dataset != null) 887 { 888 datasetList.remove(dataset); 889 datasetMap.remove(dataset.getName()); 890 } 891 892 return dataset; 893 } 894 895 896 901 public JRDesignDataset getMainDesignDataset() 902 { 903 return mainDesignDataset; 904 } 905 906 907 914 public void setMainDataset(JRDesignDataset dataset) 915 { 916 this.mainDataset = this.mainDesignDataset = dataset; 917 this.mainDesignDataset.setName(getName()); 918 } 919 920 921 924 public void preprocess() 925 { 926 collectCrosstabs(); 927 928 for (Iterator it = crosstabs.iterator(); it.hasNext();) 929 { 930 JRDesignCrosstab crosstab = (JRDesignCrosstab) it.next(); 931 crosstab.preprocess(); 932 } 933 } 934 935 protected List getCrosstabs() 936 { 937 if (crosstabs == null) 938 { 939 collectCrosstabs(); 940 } 941 942 return crosstabs; 943 } 944 945 protected List collectCrosstabs() 946 { 947 crosstabs = new ArrayList (); 948 collectCrosstabs(background); 949 collectCrosstabs(title); 950 collectCrosstabs(pageHeader); 951 collectCrosstabs(columnHeader); 952 collectCrosstabs(detail); 953 collectCrosstabs(columnFooter); 954 collectCrosstabs(pageFooter); 955 collectCrosstabs(lastPageFooter); 956 collectCrosstabs(summary); 957 958 JRGroup[] groups = getGroups(); 959 if (groups != null) 960 { 961 for (int i = 0; i < groups.length; i++) 962 { 963 collectCrosstabs(groups[i].getGroupHeader()); 964 collectCrosstabs(groups[i].getGroupFooter()); 965 } 966 } 967 968 return crosstabs; 969 } 970 971 protected void collectCrosstabs(JRBand band) 972 { 973 if (band != null) 974 { 975 collectCrosstabs(band.getElements()); 976 } 977 } 978 979 980 protected void collectCrosstabs(JRElement[] elements) 981 { 982 if (elements != null) 983 { 984 for (int i = 0; i < elements.length; i++) 985 { 986 JRElement element = elements[i]; 987 if (element instanceof JRCrosstab) 988 { 989 crosstabs.add(element); 990 } 991 else if (element instanceof JRFrame) 992 { 993 JRFrame frame = (JRFrame) element; 994 collectCrosstabs(frame.getElements()); 995 } 996 } 997 } 998 } 999 1000 1001 1007 public void setIgnorePagination(boolean ignorePagination) 1008 { 1009 this.ignorePagination = ignorePagination; 1010 } 1011 1012 1013 1019 public JRExpression getFilterExpression() 1020 { 1021 return mainDesignDataset.getFilterExpression(); 1022 } 1023 1024 1025 1032 public void setFilterExpression(JRExpression expression) 1033 { 1034 mainDesignDataset.setFilterExpression(expression); 1035 } 1036} 1037 | Popular Tags |