1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

24 package net.sf.jasperreports.engine.fill;
25
26 import net.sf.jasperreports.engine.JRBand;
27 import net.sf.jasperreports.engine.JRGroup;
28 import net.sf.jasperreports.engine.JROrigin;
29 import net.sf.jasperreports.engine.JRPart;
30 import net.sf.jasperreports.engine.JRSection;
31
32
33 /**
34  * @author Teodor Danciu (teodord@users.sourceforge.net)
35  */

36 public class JRFillSection implements JRSection, JROriginProvider
37 {
38
39     /**
40      *
41      */

42     protected JRBaseFiller filler;
43
44     protected JRFillBand[] bands;
45
46     protected JROrigin origin;
47
48     private boolean isEmpty = true;
49     private boolean areAllPrintWhenExprNull = true;
50
51     
52     /**
53      *
54      */

55     protected JRFillSection(
56         JRBaseFiller filler,
57         JRSection section,
58         JRFillObjectFactory factory
59         )
60     {
61         if (section != null)
62         {
63             factory.put(section, this);
64
65             isEmpty = true;
66             areAllPrintWhenExprNull = true;
67             
68             JRBand[] jrBands = section.getBands();
69             if (jrBands != null && jrBands.length > 0)
70             {
71                 bands = new JRFillBand[jrBands.length];
72                 for (int i = 0; i < jrBands.length; i++)
73                 {
74                     bands[i] = factory.getBand(jrBands[i]);
75                     isEmpty = isEmpty && bands[i].isEmpty();
76                     areAllPrintWhenExprNull = areAllPrintWhenExprNull && bands[i].isPrintWhenExpressionNull();
77                 }
78             }
79             else
80             {
81                 // use a single missing band for empty sections
82                 bands = new JRFillBand[]{filler.missingFillBand};
83             }
84         }
85         else
86         {
87             // use a single missing band for null/missing sections
88             bands = new JRFillBand[]{filler.missingFillBand};
89         }
90
91         this.filler = filler;
92     }
93
94     
95     @Override
96     public JROrigin getOrigin()
97     {
98         return origin;
99     }
100
101     
102     /**
103      *
104      */

105     protected void setOrigin(JROrigin origin)
106     {
107         this.origin = origin;
108
109         if (bands.length > 0)
110         {
111             for (int i = 0; i < bands.length; i++)
112             {
113                 bands[i].setOrigin(origin);
114             }
115         }
116         
117         this.filler.getJasperPrint().addOrigin(origin);//FIXMESECTION detail origin appears even if empty
118     }
119
120
121     public JRFillBand[] getFillBands()
122     {
123         return bands;
124     }
125     
126     @Override
127     public JRBand[] getBands() 
128     {
129         return bands;
130     }
131     
132     @Override
133     public JRPart[] getParts() 
134     {
135         return null;
136     }
137
138
139     @Override
140     public Object clone() 
141     {
142         throw new UnsupportedOperationException();
143     }
144
145
146     protected boolean isEmpty()
147     {
148         return isEmpty;
149     }
150
151
152     protected boolean areAllPrintWhenExpressionsNull()
153     {
154         return areAllPrintWhenExprNull;
155     }
156
157
158     protected void setNewPageColumn(boolean isNew)
159     {
160         for(int i = 0; i < bands.length; i++)
161         {
162             bands[i].setNewPageColumn(isNew);
163         }
164     }
165
166
167     protected void setNewGroup(JRGroup group, boolean isNew)
168     {
169         for(int i = 0; i < bands.length; i++)
170         {
171             bands[i].setNewGroup(group, isNew);
172         }
173     }
174
175
176     protected void addNowEvaluationTime(JREvaluationTime evaluationTime)
177     {
178         for(int i = 0; i < bands.length; i++)
179         {
180             bands[i].addNowEvaluationTime(evaluationTime);
181         }
182     }
183
184 }
185