KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRHorizontalFiller


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.fill;
29
30 import java.util.Iterator JavaDoc;
31
32 import net.sf.jasperreports.engine.JRException;
33 import net.sf.jasperreports.engine.JRExpression;
34 import net.sf.jasperreports.engine.JRGroup;
35 import net.sf.jasperreports.engine.JRPrintElement;
36 import net.sf.jasperreports.engine.JRReport;
37 import net.sf.jasperreports.engine.JRRuntimeException;
38 import net.sf.jasperreports.engine.JRVariable;
39 import net.sf.jasperreports.engine.JasperReport;
40
41
42 /**
43  * @author Teodor Danciu (teodord@users.sourceforge.net)
44  * @version $Id: JRHorizontalFiller.java 1500 2006-11-21 18:10:31 +0200 (Tue, 21 Nov 2006) teodord $
45  */

46 public class JRHorizontalFiller extends JRBaseFiller
47 {
48
49
50
51     private int lastDetailOffsetX = -1;
52     private int lastDetailOffsetY = -1;
53
54
55     /**
56      *
57      */

58     protected JRHorizontalFiller(JasperReport jasperReport) throws JRException
59     {
60         this(jasperReport, null, null);
61     }
62
63     /**
64      *
65      */

66     protected JRHorizontalFiller(JasperReport jasperReport, JRBaseFiller parentFiller) throws JRException
67     {
68         super(jasperReport, null, parentFiller);
69
70         setPageHeight(pageHeight);
71     }
72
73     /**
74      *
75      */

76     protected JRHorizontalFiller(JasperReport jasperReport, JREvaluator evaluator, JRBaseFiller parentFiller) throws JRException
77     {
78         super(jasperReport, evaluator, parentFiller);
79
80         setPageHeight(pageHeight);
81     }
82
83
84     /**
85      *
86      */

87     protected void setPageHeight(int pageHeight)
88     {
89         this.pageHeight = pageHeight;
90
91         columnFooterOffsetY = pageHeight - bottomMargin;
92         if (pageFooter != null)
93             columnFooterOffsetY -= pageFooter.getHeight();
94         if (columnFooter != null)
95             columnFooterOffsetY -= columnFooter.getHeight();
96
97         lastPageColumnFooterOffsetY = pageHeight - bottomMargin;
98         if (lastPageFooter != null)
99             lastPageColumnFooterOffsetY -= lastPageFooter.getHeight();
100         if (columnFooter != null)
101             lastPageColumnFooterOffsetY -= columnFooter.getHeight();
102     }
103
104
105     /**
106      *
107      */

108     protected synchronized void fillReport() throws JRException
109     {
110         setLastPageFooter(false);
111
112         if (next())
113         {
114             fillReportStart();
115
116             while (next())
117             {
118                 fillReportContent();
119             }
120             
121             fillReportEnd();
122         }
123         else
124         {
125             switch (whenNoDataType)
126             {
127                 case JRReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL :
128                 {
129                     scriptlet.callBeforeReportInit();
130                     calculator.initializeVariables(JRVariable.RESET_TYPE_REPORT);
131                     scriptlet.callAfterReportInit();
132             
133                     printPage = newPage();
134                     addPage(printPage);
135                     setFirstColumn();
136                     offsetY = topMargin;
137             
138                     fillBackground();
139                     
140                     fillTitle();
141                     
142                     fillPageHeader(JRExpression.EVALUATION_DEFAULT);
143             
144                     fillColumnHeaders(JRExpression.EVALUATION_DEFAULT);
145             
146                     fillGroupHeaders(true);
147             
148                     fillGroupFooters(true);
149             
150                     fillSummary();
151
152                     break;
153                 }
154                 case JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE :
155                 {
156                     printPage = newPage();
157                     addPage(printPage);
158                     break;
159                 }
160                 case JRReport.WHEN_NO_DATA_TYPE_NO_PAGES :
161                 default :
162                 {
163                 }
164             }
165         }
166
167         if (isSubreport())
168         {
169             //if (
170
// columnIndex == 0 ||
171
// (columnIndex > 0 && printPageStretchHeight < offsetY + bottomMargin)
172
// )
173
//{
174
printPageStretchHeight = offsetY + bottomMargin;
175             //}
176

177             if (fillContext.isUsingVirtualizer())
178             {
179                 removePageIdentityDataProvider();
180             }
181         }
182         
183         if (fillContext.isIgnorePagination())
184         {
185             jasperPrint.setPageHeight(offsetY + bottomMargin);
186         }
187     }
188
189
190     /**
191      *
192      */

193     private void fillReportStart() throws JRException
194     {
195         scriptlet.callBeforeReportInit();
196         calculator.initializeVariables(JRVariable.RESET_TYPE_REPORT);
197         scriptlet.callAfterReportInit();
198
199         printPage = newPage();
200         addPage(printPage);
201         setFirstColumn();
202         offsetY = topMargin;
203
204         fillBackground();
205
206         fillTitle();
207         
208         fillPageHeader(JRExpression.EVALUATION_DEFAULT);
209
210         fillColumnHeaders(JRExpression.EVALUATION_DEFAULT);
211
212         fillGroupHeaders(true);
213
214         fillDetail();
215     }
216
217     
218     private void setFirstColumn()
219     {
220         columnIndex = 0;
221         offsetX = leftMargin;
222         setColumnNumberVariable();
223     }
224
225     /**
226      *
227      */

228     private void fillReportContent() throws JRException
229     {
230         calculator.estimateGroupRuptures();
231
232         fillGroupFooters(false);
233
234         resolveGroupBoundElements(JRExpression.EVALUATION_OLD, false);
235         scriptlet.callBeforeGroupInit();
236         calculator.initializeVariables(JRVariable.RESET_TYPE_GROUP);
237         scriptlet.callAfterGroupInit();
238
239         fillGroupHeaders(false);
240
241         fillDetail();
242     }
243
244
245     /**
246      *
247      */

248     private void fillReportEnd() throws JRException
249     {
250         fillGroupFooters(true);
251
252         fillSummary();
253     }
254
255
256     /**
257      *
258      */

259      private void fillTitle() throws JRException
260      {
261         title.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
262
263         if (title.isToPrint())
264         {
265             while (
266                 title.getHeight() > pageHeight - bottomMargin - offsetY
267                 )
268             {
269                 addPage(false);
270             }
271     
272             title.evaluate(JRExpression.EVALUATION_DEFAULT);
273
274             JRPrintBand printBand = title.fill(pageHeight - bottomMargin - offsetY - title.getHeight());
275             
276             if (title.willOverflow() && !title.isSplitAllowed() && isSubreport())
277             {
278                 resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, false);
279                 resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
280                 resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
281                 scriptlet.callBeforePageInit();
282                 calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
283                 scriptlet.callAfterPageInit();
284     
285                 addPage(false);
286     
287                 printBand = title.refill(pageHeight - bottomMargin - offsetY - title.getHeight());
288             }
289
290             fillBand(printBand);
291             offsetY += printBand.getHeight();
292     
293             while (title.willOverflow())
294             {
295                 resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, false);
296                 resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
297                 resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
298                 scriptlet.callBeforePageInit();
299                 calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
300                 scriptlet.callAfterPageInit();
301     
302                 addPage(false);
303     
304                 printBand = title.fill(pageHeight - bottomMargin - offsetY - title.getHeight());
305     
306                 fillBand(printBand);
307                 offsetY += printBand.getHeight();
308             }
309
310             resolveBandBoundElements(title, JRExpression.EVALUATION_DEFAULT);
311             
312             if (isTitleNewPage)
313             {
314                 resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, false);
315                 resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
316                 resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
317                 scriptlet.callBeforePageInit();
318                 calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
319                 scriptlet.callAfterPageInit();
320     
321                 addPage(false);
322             }
323         }
324     }
325
326
327     /**
328      *
329      */

330     private void fillPageHeader(byte evaluation) throws JRException
331     {
332         setNewPageColumnInBands();
333
334         pageHeader.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
335
336         if (pageHeader.isToPrint())
337         {
338             int reattempts = getMasterColumnCount();
339             if (isCreatingNewPage)
340             {
341                 --reattempts;
342             }
343             
344             boolean filled = fillBandNoOverflow(pageHeader, evaluation);
345             
346             for (int i = 0; !filled && i < reattempts; ++i)
347             {
348                 resolveGroupBoundElements(evaluation, false);
349                 resolveColumnBoundElements(evaluation);
350                 resolvePageBoundElements(evaluation);
351                 scriptlet.callBeforePageInit();
352                 calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
353                 scriptlet.callAfterPageInit();
354         
355                 addPage(false);
356                 
357                 filled = fillBandNoOverflow(pageHeader, evaluation);
358             }
359             
360             if (!filled)
361             {
362                 throw new JRRuntimeException("Infinite loop creating new page due to page header overflow.");
363             }
364         }
365
366         columnHeaderOffsetY = offsetY;
367         
368         isNewPage = true;
369     }
370
371     
372     private boolean fillBandNoOverflow(JRFillBand band, byte evaluation) throws JRException
373     {
374         int availableStretch = columnFooterOffsetY - offsetY - band.getHeight();
375         boolean overflow = availableStretch < 0;
376         
377         if (!overflow)
378         {
379             band.evaluate(evaluation);
380             JRPrintBand printBand = band.fill(availableStretch);
381             
382             overflow = band.willOverflow();
383             if (overflow)
384             {
385                 band.rewind();
386             }
387             else
388             {
389                 fillBand(printBand);
390                 offsetY += printBand.getHeight();
391                 
392                 resolveBandBoundElements(band, evaluation);
393             }
394         }
395         
396         return !overflow;
397     }
398
399
400     /**
401      *
402      */

403     private void fillColumnHeaders(byte evaluation) throws JRException
404     {
405         setNewPageColumnInBands();
406
407         for(columnIndex = 0; columnIndex < columnCount; columnIndex++)
408         {
409             setColumnNumberVariable();
410             
411             columnHeader.evaluatePrintWhenExpression(evaluation);
412         
413             if (columnHeader.isToPrint())
414             {
415                 int reattempts = getMasterColumnCount();
416                 if (isCreatingNewPage)
417                 {
418                     --reattempts;
419                 }
420                 
421                 boolean fits = columnHeader.getHeight() <= columnFooterOffsetY - offsetY;
422                 for (int i = 0; !fits && i < reattempts; ++i)
423                 {
424                     fillPageFooter(evaluation);
425                 
426                     resolveGroupBoundElements(evaluation, false);
427                     resolveColumnBoundElements(evaluation);
428                     resolvePageBoundElements(evaluation);
429                     scriptlet.callBeforePageInit();
430                     calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
431                     scriptlet.callAfterPageInit();
432         
433                     addPage(false);
434         
435                     fillPageHeader(evaluation);
436                     
437                     fits = columnHeader.getHeight() <= columnFooterOffsetY - offsetY;
438                 }
439
440                 if (!fits)
441                 {
442                     throw new JRRuntimeException("Infinite loop creating new page due to column header size.");
443                 }
444                 
445                 offsetX = leftMargin + columnIndex * (columnSpacing + columnWidth);
446                 offsetY = columnHeaderOffsetY;
447
448                 fillFixedBand(columnHeader, evaluation, false);
449             }
450         }
451
452         setFirstColumn();
453
454         isNewColumn = true;
455     }
456
457
458     /**
459      *
460      */

461     private void fillGroupHeaders(boolean isFillAll) throws JRException
462     {
463         if (groups != null && groups.length > 0)
464         {
465             for(int i = 0; i < groups.length; i++)
466             {
467                 if(isFillAll)
468                 {
469                     fillGroupHeader(groups[i]);
470                 }
471                 else
472                 {
473                     if (groups[i].hasChanged())
474                     {
475                         fillGroupHeader(groups[i]);
476                     }
477                 }
478             }
479         }
480     }
481
482
483     /**
484      *
485      */

486     private void fillGroupHeader(JRFillGroup group) throws JRException
487     {
488         byte evalPrevPage = (group.isTopLevelChange()?JRExpression.EVALUATION_OLD:JRExpression.EVALUATION_DEFAULT);
489
490         if (
491             (group.isStartNewPage() || group.isResetPageNumber()) && !isNewPage
492             || ( group.isStartNewColumn() && !isNewColumn )
493             )
494         {
495             fillPageBreak(
496                 group.isResetPageNumber(),
497                 evalPrevPage,
498                 JRExpression.EVALUATION_DEFAULT,
499                 true
500                 );
501         }
502         
503         JRFillBand groupHeader = (JRFillBand)group.getGroupHeader();
504
505         groupHeader.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
506         
507         if (groupHeader.isToPrint())
508         {
509             while (
510                 groupHeader.getHeight() > columnFooterOffsetY - offsetY ||
511                 group.getMinHeightToStartNewPage() > columnFooterOffsetY - offsetY
512                 )
513             {
514                 fillPageBreak(
515                     false,
516                     evalPrevPage,
517                     JRExpression.EVALUATION_DEFAULT,
518                     true
519                     );
520             }
521         }
522
523         setNewGroupInBands(group);
524
525         group.setFooterPrinted(false);
526
527         if (groupHeader.isToPrint())
528         {
529             setFirstColumn();
530
531             fillColumnBand(groupHeader, JRExpression.EVALUATION_DEFAULT);
532         }
533
534         group.setHeaderPrinted(true);
535
536         isNewGroup = true;
537     }
538
539
540     /**
541      *
542      */

543     private void fillGroupHeadersReprint(byte evaluation) throws JRException
544     {
545         if (groups != null && groups.length > 0)
546         {
547             for(int i = 0; i < groups.length; i++)
548             {
549                 fillGroupHeaderReprint(groups[i], evaluation);
550             }
551         }
552     }
553
554
555     /**
556      *
557      */

558      private void fillGroupHeaderReprint(JRFillGroup group, byte evaluation) throws JRException
559      {
560         if (
561             group.isReprintHeaderOnEachPage() &&
562             (!group.hasChanged() || (group.hasChanged() && group.isHeaderPrinted()))
563             )
564         {
565             JRFillBand groupHeader = (JRFillBand)group.getGroupHeader();
566
567             groupHeader.evaluatePrintWhenExpression(evaluation);
568         
569             if (groupHeader.isToPrint())
570             {
571                 setFirstColumn();
572
573                 while (
574                     groupHeader.getHeight() > columnFooterOffsetY - offsetY ||
575                     group.getMinHeightToStartNewPage() > columnFooterOffsetY - offsetY
576                     )
577                 {
578                     fillPageBreak(false, evaluation, evaluation, true);
579                 }
580     
581                 fillColumnBand(groupHeader, evaluation);
582             }
583         }
584     }
585
586
587     /**
588      *
589      */

590     private void fillDetail() throws JRException
591     {
592         if (!detail.isPrintWhenExpressionNull())
593         {
594             calculator.estimateVariables();
595             detail.evaluatePrintWhenExpression(JRExpression.EVALUATION_ESTIMATED);
596         }
597     
598         if (detail.isToPrint())
599         {
600             while (
601                 (columnIndex == columnCount - 1 || isNewGroup)
602                 && detail.getHeight() > columnFooterOffsetY - offsetY
603                 )
604             {
605                 byte evalPrevPage = (isNewGroup?JRExpression.EVALUATION_DEFAULT:JRExpression.EVALUATION_OLD);
606                 
607                 fillPageBreak(
608                     false,
609                     evalPrevPage,
610                     JRExpression.EVALUATION_DEFAULT,
611                     true
612                     );
613             }
614         }
615
616         scriptlet.callBeforeDetailEval();
617         calculator.calculateVariables();
618         scriptlet.callAfterDetailEval();
619
620         if (!detail.isPrintWhenExpressionNull())
621         {
622             detail.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
623         }
624
625         if (detail.isToPrint())
626         {
627             if (
628                 offsetX == lastDetailOffsetX
629                 && offsetY == lastDetailOffsetY
630                 )
631             {
632                 if (columnIndex == columnCount - 1)
633                 {
634                     setFirstColumn();
635                 }
636                 else
637                 {
638                     columnIndex++;
639                     offsetX += columnWidth + columnSpacing;
640                     offsetY -= detail.getHeight();
641                     
642                     setColumnNumberVariable();
643                 }
644             }
645
646             fillFixedBand(detail, JRExpression.EVALUATION_DEFAULT, false);
647             
648             lastDetailOffsetX = offsetX;
649             lastDetailOffsetY = offsetY;
650         }
651
652         isNewPage = false;
653         isNewColumn = false;
654         isNewGroup = false;
655     }
656
657
658     /**
659      *
660      */

661     private void fillGroupFooters(boolean isFillAll) throws JRException
662     {
663         if (groups != null && groups.length > 0)
664         {
665             byte evaluation = (isFillAll)?JRExpression.EVALUATION_DEFAULT:JRExpression.EVALUATION_OLD;
666             
667             for(int i = groups.length - 1; i >= 0; i--)
668             {
669                 if (isFillAll)
670                 {
671                     fillGroupFooter(groups[i], evaluation);
672                 }
673                 else
674                 {
675                     if (groups[i].hasChanged())
676                     {
677                         fillGroupFooter(groups[i], evaluation);
678                     }
679                 }
680             }
681         }
682     }
683
684
685     /**
686      *
687      */

688     private void fillGroupFooter(JRFillGroup group, byte evaluation) throws JRException
689     {
690         JRFillBand groupFooter = (JRFillBand)group.getGroupFooter();
691         
692         groupFooter.evaluatePrintWhenExpression(evaluation);
693     
694         if (groupFooter.isToPrint())
695         {
696             setFirstColumn();
697
698             if (
699                 groupFooter.getHeight() > columnFooterOffsetY - offsetY
700                 )
701             {
702                 fillPageBreak(false, evaluation, evaluation, true);
703             }
704     
705             fillColumnBand(groupFooter, evaluation);
706         }
707
708         isNewPage = false;
709         isNewColumn = false;
710
711         group.setHeaderPrinted(false);
712         group.setFooterPrinted(true);
713     }
714
715
716     /**
717      *
718      */

719      private void fillColumnFooters(byte evaluation) throws JRException
720      {
721         /*
722         if (!isSubreport)
723         {
724             offsetY = columnFooterOffsetY;
725         }
726         */

727
728         if (isSubreport())
729         {
730             columnFooterOffsetY = offsetY;
731         }
732
733         int tmpColumnFooterOffsetY = columnFooterOffsetY;
734
735         if (isFloatColumnFooter || fillContext.isIgnorePagination())
736         {
737             tmpColumnFooterOffsetY = offsetY;
738         }
739
740         for(columnIndex = 0; columnIndex < columnCount; columnIndex++)
741         {
742             setColumnNumberVariable();
743             
744             offsetX = leftMargin + columnIndex * (columnSpacing + columnWidth);
745             offsetY = tmpColumnFooterOffsetY;
746         
747             columnFooter.evaluatePrintWhenExpression(evaluation);
748
749             if (columnFooter.isToPrint())
750             {
751                 fillFixedBand(columnFooter, evaluation, false);
752             }
753         }
754     }
755
756
757     /**
758      *
759      */

760     private void fillPageFooter(byte evaluation) throws JRException
761     {
762         JRFillBand crtPageFooter = getCurrentPageFooter();
763         
764         offsetX = leftMargin;
765
766         if (!isSubreport() && !fillContext.isIgnorePagination())
767         {
768             offsetY = pageHeight - crtPageFooter.getHeight() - bottomMargin;
769         }
770
771         crtPageFooter.evaluatePrintWhenExpression(evaluation);
772
773         if (crtPageFooter.isToPrint())
774         {
775             fillFixedBand(crtPageFooter, evaluation);
776         }
777     }
778
779
780     /**
781      *
782      */

783     private void fillSummary() throws JRException
784     {
785         offsetX = leftMargin;
786         
787         if (lastPageFooter == missingFillBand)
788         {
789             if (
790                 !isSummaryNewPage
791                 //&& columnIndex == 0
792
&& summary.getHeight() <= columnFooterOffsetY - offsetY
793                 )
794             {
795                 fillSummarySamePage();
796             }
797             else
798             {
799                 fillSummaryNewPage();
800             }
801         }
802         else
803         {
804             if (
805                 !isSummaryNewPage
806                 && summary.getHeight() <= lastPageColumnFooterOffsetY - offsetY
807                 )
808             {
809                 setLastPageFooter(true);
810
811                 fillSummarySamePage();
812             }
813             else if (
814                 !isSummaryNewPage
815                 && summary.getHeight() <= columnFooterOffsetY - offsetY
816                 )
817             {
818                 fillSummarySamePageMixedFooters();
819             }
820             else if (offsetY <= lastPageColumnFooterOffsetY)
821             {
822                 setLastPageFooter(true);
823
824                 fillSummaryNewPage();
825             }
826             else
827             {
828                 fillPageBreak(false, JRExpression.EVALUATION_DEFAULT, JRExpression.EVALUATION_DEFAULT, false);
829             
830                 setLastPageFooter(true);
831             
832                 if (isSummaryNewPage)
833                 {
834                     fillSummaryNewPage();
835                 }
836                 else
837                 {
838                     fillSummarySamePage();
839                 }
840             }
841         }
842
843         resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
844         resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
845         resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
846         resolveReportBoundElements();
847     }
848         
849         
850     /**
851      *
852      */

853     private void fillSummarySamePage() throws JRException
854     {
855         summary.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
856
857         if (summary != missingFillBand && summary.isToPrint())
858         {
859             summary.evaluate(JRExpression.EVALUATION_DEFAULT);
860         
861             JRPrintBand printBand = summary.fill(columnFooterOffsetY - offsetY - summary.getHeight());
862                 
863             if (summary.willOverflow() && !summary.isSplitAllowed())
864             {
865                 fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
866             
867                 fillPageFooter(JRExpression.EVALUATION_DEFAULT);
868         
869                 resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
870                 resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
871                 resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
872                 scriptlet.callBeforePageInit();
873                 calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
874                 scriptlet.callAfterPageInit();
875         
876                 addPage(false);
877         
878                 printBand = summary.refill(pageHeight - bottomMargin - offsetY - summary.getHeight());
879         
880                 fillBand(printBand);
881                 offsetY += printBand.getHeight();
882             }
883             else
884             {
885                 fillBand(printBand);
886                 offsetY += printBand.getHeight();
887             
888                 fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
889             
890                 fillPageFooter(JRExpression.EVALUATION_DEFAULT);
891             }
892     
893             while (summary.willOverflow())
894             {
895                 resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
896                 resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
897                 resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
898                 scriptlet.callBeforePageInit();
899                 calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
900                 scriptlet.callAfterPageInit();
901         
902                 addPage(false);
903         
904                 printBand = summary.fill(pageHeight - bottomMargin - offsetY - summary.getHeight());
905         
906                 fillBand(printBand);
907                 offsetY += printBand.getHeight();
908             }
909             
910             resolveBandBoundElements(summary, JRExpression.EVALUATION_DEFAULT);
911         }
912         else
913         {
914             fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
915         
916             fillPageFooter(JRExpression.EVALUATION_DEFAULT);
917         }
918     }
919
920
921     /**
922      *
923      */

924     private void fillSummarySamePageMixedFooters() throws JRException
925     {
926         summary.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
927
928         if (summary != missingFillBand && summary.isToPrint())
929         {
930             summary.evaluate(JRExpression.EVALUATION_DEFAULT);
931         
932             JRPrintBand printBand = summary.fill(columnFooterOffsetY - offsetY - summary.getHeight());
933                 
934             if (summary.willOverflow() && !summary.isSplitAllowed())
935             {
936                 if (offsetY <= lastPageColumnFooterOffsetY)
937                 {
938                     setLastPageFooter(true);
939
940                     fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
941         
942                     fillPageFooter(JRExpression.EVALUATION_DEFAULT);
943
944                     resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
945                     resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
946                     resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
947                     scriptlet.callBeforePageInit();
948                     calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
949                     scriptlet.callAfterPageInit();
950         
951                     addPage(false);
952         
953                     printBand = summary.refill(pageHeight - bottomMargin - offsetY - summary.getHeight());
954
955                     fillBand(printBand);
956                     offsetY += printBand.getHeight();
957                 }
958                 else
959                 {
960                     fillPageBreak(false, JRExpression.EVALUATION_DEFAULT, JRExpression.EVALUATION_DEFAULT, false);
961         
962                     setLastPageFooter(true);
963
964                     printBand = summary.refill(lastPageColumnFooterOffsetY - offsetY - summary.getHeight());
965                     //printBand = summary.refill(pageHeight - bottomMargin - offsetY - summary.getHeight());
966

967                     fillBand(printBand);
968                     offsetY += printBand.getHeight();
969
970                     fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
971         
972                     fillPageFooter(JRExpression.EVALUATION_DEFAULT);
973                 }
974             }
975             else
976             {
977                 fillBand(printBand);
978                 offsetY += printBand.getHeight();
979                 
980                 fillPageBreak(false, JRExpression.EVALUATION_DEFAULT, JRExpression.EVALUATION_DEFAULT, false);
981
982                 setLastPageFooter(true);
983                 
984                 if (summary.willOverflow())
985                 {
986                     printBand = summary.fill(lastPageColumnFooterOffsetY - offsetY - summary.getHeight());
987
988                     fillBand(printBand);
989                     offsetY += printBand.getHeight();
990                 }
991
992                 fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
993         
994                 fillPageFooter(JRExpression.EVALUATION_DEFAULT);
995             }
996
997             while (summary.willOverflow())
998             {
999                 resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
1000                resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
1001                resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
1002                scriptlet.callBeforePageInit();
1003                calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
1004                scriptlet.callAfterPageInit();
1005        
1006                addPage(false);
1007        
1008                printBand = summary.fill(pageHeight - bottomMargin - offsetY - summary.getHeight());
1009        
1010                fillBand(printBand);
1011                offsetY += printBand.getHeight();
1012            }
1013            
1014            resolveBandBoundElements(summary, JRExpression.EVALUATION_DEFAULT);
1015        }
1016        else
1017        {
1018            if(offsetY > lastPageColumnFooterOffsetY)
1019            {
1020                fillPageBreak(false, JRExpression.EVALUATION_DEFAULT, JRExpression.EVALUATION_DEFAULT, false);
1021            }
1022
1023            setLastPageFooter(true);
1024
1025            fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
1026        
1027            fillPageFooter(JRExpression.EVALUATION_DEFAULT);
1028        }
1029    }
1030
1031
1032    /**
1033     *
1034     */

1035    private void fillSummaryNewPage() throws JRException
1036    {
1037        fillColumnFooters(JRExpression.EVALUATION_DEFAULT);
1038    
1039        fillPageFooter(JRExpression.EVALUATION_DEFAULT);
1040
1041        summary.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
1042    
1043        if (summary != missingFillBand && summary.isToPrint())
1044        {
1045            resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
1046            resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
1047            resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
1048            scriptlet.callBeforePageInit();
1049            calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
1050            scriptlet.callAfterPageInit();
1051    
1052            addPage(false);
1053    
1054            columnIndex = -1;// FIXME why?
1055

1056            summary.evaluate(JRExpression.EVALUATION_DEFAULT);
1057                
1058            JRPrintBand printBand = summary.fill(pageHeight - bottomMargin - offsetY - summary.getHeight());
1059                
1060            if (summary.willOverflow() && !summary.isSplitAllowed() && isSubreport())
1061            {
1062                resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
1063                resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
1064                resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
1065                scriptlet.callBeforePageInit();
1066                calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
1067                scriptlet.callAfterPageInit();
1068        
1069                addPage(false);
1070        
1071                printBand = summary.refill(pageHeight - bottomMargin - offsetY - summary.getHeight());
1072            }
1073
1074            fillBand(printBand);
1075            offsetY += printBand.getHeight();
1076        
1077            while (summary.willOverflow())
1078            {
1079                resolveGroupBoundElements(JRExpression.EVALUATION_DEFAULT, true);
1080                resolveColumnBoundElements(JRExpression.EVALUATION_DEFAULT);
1081                resolvePageBoundElements(JRExpression.EVALUATION_DEFAULT);
1082                scriptlet.callBeforePageInit();
1083                calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
1084                scriptlet.callAfterPageInit();
1085        
1086                addPage(false);
1087        
1088                printBand = summary.fill(pageHeight - bottomMargin - offsetY - summary.getHeight());
1089        
1090                fillBand(printBand);
1091                offsetY += printBand.getHeight();
1092            }
1093            
1094            resolveBandBoundElements(summary, JRExpression.EVALUATION_DEFAULT);
1095        }
1096    }
1097
1098
1099    /**
1100     *
1101     */

1102    private void fillBackground() throws JRException
1103    {
1104        //offsetX = leftMargin;
1105

1106        //if (!isSubreport)
1107
//{
1108
// offsetY = pageHeight - pageFooter.getHeight() - bottomMargin;
1109
//}
1110

1111        if (background.getHeight() <= pageHeight - bottomMargin - offsetY)
1112        {
1113            background.evaluatePrintWhenExpression(JRExpression.EVALUATION_DEFAULT);
1114    
1115            if (background.isToPrint())
1116            {
1117                    background.evaluate(JRExpression.EVALUATION_DEFAULT);
1118    
1119                    JRPrintBand printBand = background.fill(pageHeight - bottomMargin - offsetY - background.getHeight());
1120    
1121                    fillBand(printBand);
1122                    //offsetY += printBand.getHeight();
1123
}
1124        }
1125    }
1126
1127
1128    /**
1129     *
1130     */

1131    private void addPage(boolean isResetPageNumber) throws JRException
1132    {
1133        if (isSubreport())
1134        {
1135            if (!parentFiller.isBandOverFlowAllowed())
1136            {
1137                throw new JRRuntimeException("Subreport overflowed on a band that does not support overflow.");
1138            }
1139            
1140            //if (
1141
// columnIndex == 0 ||
1142
// (columnIndex > 0 && printPageStretchHeight < offsetY + bottomMargin)
1143
// )
1144
//{
1145
printPageStretchHeight = offsetY + bottomMargin;
1146            //}
1147

1148            if (fillContext.isUsingVirtualizer())
1149            {
1150                removePageIdentityDataProvider();
1151            }
1152            
1153            suspendSubreportRunner();
1154        }
1155        
1156        printPage = newPage();
1157        
1158        if (isSubreport() && fillContext.isUsingVirtualizer())
1159        {
1160            addPageIdentityDataProvider();
1161        }
1162        
1163        if (isResetPageNumber)
1164        {
1165            calculator.getPageNumber().setValue(new Integer JavaDoc(1));
1166        }
1167        else
1168        {
1169            calculator.getPageNumber().setValue(
1170                new Integer JavaDoc(((Number JavaDoc)calculator.getPageNumber().getValue()).intValue() + 1)
1171                );
1172        }
1173
1174        calculator.getPageNumber().setOldValue(
1175            calculator.getPageNumber().getValue()
1176            );
1177
1178        addPage(printPage);
1179        setFirstColumn();
1180        offsetY = topMargin;
1181
1182        lastDetailOffsetX = -1;
1183        lastDetailOffsetY = -1;
1184
1185        fillBackground();
1186    }
1187
1188    /**
1189     * Sets the column number value computed based on {@link #columnIndex columnIndex}
1190     */

1191    private void setColumnNumberVariable()
1192    {
1193        JRFillVariable columnNumberVar = calculator.getColumnNumber();
1194        columnNumberVar.setValue(new Integer JavaDoc(columnIndex + 1));
1195        columnNumberVar.setOldValue(columnNumberVar.getValue());
1196    }
1197
1198    /**
1199     *
1200     */

1201    private void fillPageBreak(
1202        boolean isResetPageNumber,
1203        byte evalPrevPage,
1204        byte evalNextPage,
1205        boolean isReprintGroupHeaders
1206        ) throws JRException
1207    {
1208        if (isCreatingNewPage)
1209        {
1210            throw new JRException("Infinite loop creating new page.");
1211        }
1212        
1213        isCreatingNewPage = true;
1214        
1215        fillColumnFooters(evalPrevPage);
1216
1217        fillPageFooter(evalPrevPage);
1218        
1219        resolveGroupBoundElements(evalPrevPage, false);
1220        resolveColumnBoundElements(evalPrevPage);
1221        resolvePageBoundElements(evalPrevPage);
1222        scriptlet.callBeforePageInit();
1223        calculator.initializeVariables(JRVariable.RESET_TYPE_PAGE);
1224        scriptlet.callAfterPageInit();
1225
1226        addPage(isResetPageNumber);
1227
1228        fillPageHeader(evalNextPage);
1229
1230        fillColumnHeaders(evalNextPage);
1231
1232        if (isReprintGroupHeaders)
1233        {
1234            fillGroupHeadersReprint(evalNextPage);
1235        }
1236
1237        isCreatingNewPage = false;
1238    }
1239
1240
1241    /**
1242     *
1243     *
1244    private void fillColumnBreak(
1245        byte evalPrevPage,
1246        byte evalNextPage
1247        ) throws JRException
1248    {
1249        if (columnIndex == columnCount - 1)
1250        {
1251            fillPageBreak(false, evalPrevPage, evalNextPage);
1252        }
1253        else
1254        {
1255            fillColumnFooter(evalPrevPage);
1256
1257            resolveGroupBoundImages(evalPrevPage, false);
1258            resolveColumnBoundImages(evalPrevPage);
1259            resolveGroupBoundTexts(evalPrevPage, false);
1260            resolveColumnBoundTexts(evalPrevPage);
1261            scriptlet.callBeforeColumnInit();
1262            calculator.initializeVariables(JRVariable.RESET_TYPE_COLUMN);
1263            scriptlet.callAfterColumnInit();
1264
1265            columnIndex += 1;
1266            offsetX = leftMargin + columnIndex * (columnSpacing + columnWidth);
1267            offsetY = columnHeaderOffsetY;
1268
1269            calculator.getColumnNumber().setValue(
1270                new Integer(((Number)calculator.getColumnNumber().getValue()).intValue() + 1)
1271                );
1272            calculator.getColumnNumber().setOldValue(
1273                calculator.getColumnNumber().getValue()
1274                );
1275    
1276            fillColumnHeader(evalNextPage);
1277        }
1278    }
1279
1280
1281    /**
1282     *
1283     */

1284    protected void fillPageBand(JRFillBand band, byte evaluation) throws JRException
1285    {
1286        band.evaluate(evaluation);
1287
1288        JRPrintBand printBand = band.fill(columnFooterOffsetY - offsetY - band.getHeight());
1289        
1290        if (band.willOverflow() && !band.isSplitAllowed())
1291        {
1292            fillPageBreak(false, evaluation, evaluation, true);
1293
1294            printBand = band.refill(columnFooterOffsetY - offsetY - band.getHeight());
1295        }
1296        
1297        fillBand(printBand);
1298        offsetY += printBand.getHeight();
1299
1300        while (band.willOverflow())
1301        {
1302            fillPageBreak(false, evaluation, evaluation, true);
1303
1304            printBand = band.fill(columnFooterOffsetY - offsetY - band.getHeight());
1305
1306            fillBand(printBand);
1307            offsetY += printBand.getHeight();
1308        }
1309        
1310        resolveBandBoundElements(band, evaluation);
1311    }
1312
1313
1314    /**
1315     *
1316     */

1317    protected void fillColumnBand(JRFillBand band, byte evaluation) throws JRException
1318    {
1319        band.evaluate(evaluation);
1320        
1321        JRPrintBand printBand = band.fill(columnFooterOffsetY - offsetY - band.getHeight());
1322        
1323        if (band.willOverflow() && !band.isSplitAllowed())
1324        {
1325            fillPageBreak(false, evaluation, evaluation, true);
1326
1327            printBand = band.refill(columnFooterOffsetY - offsetY - band.getHeight());
1328        }
1329        
1330        fillBand(printBand);
1331        offsetY += printBand.getHeight();
1332
1333        while (band.willOverflow())
1334        {
1335            fillPageBreak(false, evaluation, evaluation, true);
1336
1337            printBand = band.fill(columnFooterOffsetY - offsetY - band.getHeight());
1338
1339            fillBand(printBand);
1340            offsetY += printBand.getHeight();
1341        }
1342        
1343        resolveBandBoundElements(band, evaluation);
1344    }
1345
1346
1347    /**
1348     *
1349     */

1350    protected void fillFixedBand(JRFillBand band, byte evaluation) throws JRException
1351    {
1352        fillFixedBand(band, evaluation, true);
1353    }
1354
1355
1356    protected void fillFixedBand(JRFillBand band, byte evaluation, boolean allowShrinking) throws JRException
1357    {
1358        band.evaluate(evaluation);
1359
1360        JRPrintBand printBand = band.fill();
1361
1362        fillBand(printBand);
1363        offsetY += allowShrinking ? printBand.getHeight() : band.getHeight();
1364        
1365        resolveBandBoundElements(band, evaluation);
1366    }
1367
1368
1369    /**
1370     *
1371     */

1372    protected void fillBand(JRPrintBand band)
1373    {
1374        java.util.List JavaDoc elements = band.getElements();
1375        
1376        if (elements != null && elements.size() > 0)
1377        {
1378            JRPrintElement element = null;
1379            for(Iterator JavaDoc it = elements.iterator(); it.hasNext();)
1380            {
1381                element = (JRPrintElement)it.next();
1382                element.setX(element.getX() + offsetX);
1383                element.setY(element.getY() + offsetY);
1384                printPage.addElement(element);
1385            }
1386        }
1387    }
1388
1389
1390    /**
1391     *
1392     */

1393    private void setNewPageColumnInBands()
1394    {
1395        title.setNewPageColumn(true);
1396        pageHeader.setNewPageColumn(true);
1397        columnHeader.setNewPageColumn(true);
1398        detail.setNewPageColumn(true);
1399        columnFooter.setNewPageColumn(true);
1400        pageFooter.setNewPageColumn(true);
1401        lastPageFooter.setNewPageColumn(true);
1402        summary.setNewPageColumn(true);
1403        
1404        if (groups != null && groups.length > 0)
1405        {
1406            for(int i = 0; i < groups.length; i++)
1407            {
1408                ((JRFillBand)groups[i].getGroupHeader()).setNewPageColumn(true);
1409                ((JRFillBand)groups[i].getGroupFooter()).setNewPageColumn(true);
1410            }
1411        }
1412    }
1413
1414
1415    /**
1416     *
1417     */

1418    private void setNewGroupInBands(JRGroup group)
1419    {
1420        title.setNewGroup(group, true);
1421        pageHeader.setNewGroup(group, true);
1422        columnHeader.setNewGroup(group, true);
1423        detail.setNewGroup(group, true);
1424        columnFooter.setNewGroup(group, true);
1425        pageFooter.setNewGroup(group, true);
1426        lastPageFooter.setNewGroup(group, true);
1427        summary.setNewGroup(group, true);
1428        
1429        if (groups != null && groups.length > 0)
1430        {
1431            for(int i = 0; i < groups.length; i++)
1432            {
1433                ((JRFillBand)groups[i].getGroupHeader()).setNewGroup(group, true);
1434                ((JRFillBand)groups[i].getGroupFooter()).setNewGroup(group, true);
1435            }
1436        }
1437    }
1438
1439    
1440    /**
1441     *
1442     */

1443    private JRFillBand getCurrentPageFooter()
1444    {
1445        return isLastPageFooter ? lastPageFooter : pageFooter;
1446    }
1447
1448
1449    /**
1450     *
1451     */

1452    private void setLastPageFooter(boolean isLastPageFooter)
1453    {
1454        this.isLastPageFooter = isLastPageFooter;
1455        
1456        if (isLastPageFooter)
1457        {
1458            columnFooterOffsetY = lastPageColumnFooterOffsetY;
1459        }
1460    }
1461
1462
1463}
1464
Popular Tags