KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.Set JavaDoc;
34
35 import net.sf.jasperreports.engine.JRBand;
36 import net.sf.jasperreports.engine.JRElement;
37 import net.sf.jasperreports.engine.JRException;
38 import net.sf.jasperreports.engine.JRExpression;
39 import net.sf.jasperreports.engine.JRGroup;
40 import net.sf.jasperreports.engine.JRSubreport;
41 import net.sf.jasperreports.engine.JRSubreportReturnValue;
42
43
44 /**
45  * @author Teodor Danciu (teodord@users.sourceforge.net)
46  * @version $Id: JRFillBand.java 1485 2006-11-14 20:23:17 +0200 (Tue, 14 Nov 2006) teodord $
47  */

48 public class JRFillBand extends JRFillElementContainer implements JRBand
49 {
50
51
52     /**
53      *
54      */

55     private JRBand parent = null;
56
57     private boolean isPrintWhenTrue = true;
58
59     /**
60      *
61      */

62     private boolean isNewPageColumn = false;
63     private boolean isFirstWholeOnPageColumn = false;
64     private Map JavaDoc isNewGroupMap = new HashMap JavaDoc();
65
66     private Set JavaDoc nowEvaluationTimes;
67
68     /**
69      *
70      */

71     protected JRFillBand(
72         JRBaseFiller filler,
73         JRBand band,
74         JRFillObjectFactory factory
75         )
76     {
77         super(filler, band, factory);
78
79         parent = band;
80
81         if (deepElements.length > 0)
82         {
83             for(int i = 0; i < deepElements.length; i++)
84             {
85                 deepElements[i].setBand(this);
86             }
87         }
88
89         initElements();
90
91         initConditionalStyles();
92
93         nowEvaluationTimes = new HashSet JavaDoc();
94     }
95
96
97     /**
98      *
99      */

100     protected void setNewPageColumn(boolean isNew)
101     {
102         this.isNewPageColumn = isNew;
103     }
104
105
106     /**
107      *
108      */

109     protected boolean isNewPageColumn()
110     {
111         return isNewPageColumn;
112     }
113
114
115     /**
116      * Decides whether this band is the for whole band on the page/column.
117      *
118      * @return whether this band is the for whole band on the page/column
119      */

120     protected boolean isFirstWholeOnPageColumn()
121     {
122         return isFirstWholeOnPageColumn;
123     }
124
125
126     /**
127      *
128      */

129     protected void setNewGroup(JRGroup group, boolean isNew)
130     {
131         isNewGroupMap.put(group, isNew ? Boolean.TRUE : Boolean.FALSE);
132     }
133
134
135     /**
136      *
137      */

138     protected boolean isNewGroup(JRGroup group)
139     {
140         Boolean JavaDoc value = (Boolean JavaDoc)isNewGroupMap.get(group);
141
142         if (value == null)
143         {
144             value = Boolean.FALSE;
145         }
146
147         return value.booleanValue();
148     }
149
150
151     /**
152      *
153      */

154     public int getHeight()
155     {
156         return (parent != null ? parent.getHeight() : 0);
157     }
158
159     /**
160      *
161      */

162     public boolean isSplitAllowed()
163     {
164         return parent.isSplitAllowed();
165     }
166
167     /**
168      *
169      */

170     public void setSplitAllowed(boolean isSplitAllowed)
171     {
172     }
173
174     /**
175      *
176      */

177     public JRExpression getPrintWhenExpression()
178     {
179         return (parent != null ? parent.getPrintWhenExpression() : null);
180     }
181
182     /**
183      *
184      */

185     protected boolean isPrintWhenExpressionNull()
186     {
187         return (getPrintWhenExpression() == null);
188     }
189
190     /**
191      *
192      */

193     protected boolean isPrintWhenTrue()
194     {
195         return isPrintWhenTrue;
196     }
197
198     /**
199      *
200      */

201     protected void setPrintWhenTrue(boolean isPrintWhenTrue)
202     {
203         this.isPrintWhenTrue = isPrintWhenTrue;
204     }
205
206     /**
207      *
208      */

209     protected boolean isToPrint()
210     {
211         return
212             (isPrintWhenExpressionNull() ||
213              (!isPrintWhenExpressionNull() &&
214               isPrintWhenTrue()));
215     }
216
217
218     /**
219      *
220      */

221     protected void evaluatePrintWhenExpression(
222         byte evaluation
223         ) throws JRException
224     {
225         boolean isPrintTrue = false;
226
227         JRExpression expression = getPrintWhenExpression();
228         if (expression != null)
229         {
230             Boolean JavaDoc printWhenExpressionValue = (Boolean JavaDoc)filler.evaluateExpression(expression, evaluation);
231             if (printWhenExpressionValue == null)
232             {
233                 isPrintTrue = false;
234             }
235             else
236             {
237                 isPrintTrue = printWhenExpressionValue.booleanValue();
238             }
239         }
240
241         setPrintWhenTrue(isPrintTrue);
242     }
243
244
245
246     /**
247      *
248      */

249     protected JRPrintBand refill(
250         int availableStretchHeight
251         ) throws JRException
252     {
253         rewind();
254
255         return fill(availableStretchHeight);
256     }
257
258
259     /**
260      *
261      */

262     protected JRPrintBand fill() throws JRException
263     {
264         return fill(0, false);
265     }
266
267
268     /**
269      *
270      */

271     protected JRPrintBand fill(
272         int availableStretchHeight
273         ) throws JRException
274     {
275         return fill(availableStretchHeight, true);
276     }
277
278
279     /**
280      *
281      */

282     protected JRPrintBand fill(
283         int availableStretchHeight,
284         boolean isOverflowAllowed
285         ) throws JRException
286     {
287         filler.fillContext.ensureMasterPageAvailable();
288
289         if (
290             Thread.currentThread().isInterrupted()
291             || filler.isInterrupted()
292             )
293         {
294             // child fillers will stop if this parent filler was marked as interrupted
295
filler.setInterrupted(true);
296
297             throw new JRFillInterruptedException();
298         }
299
300         filler.setBandOverFlowAllowed(isOverflowAllowed);
301
302         initFill();
303
304         if (isNewPageColumn && !isOverflow)
305         {
306             isFirstWholeOnPageColumn = true;
307         }
308         
309         resetElements();
310
311         prepareElements(availableStretchHeight, isOverflowAllowed);
312
313         stretchElements();
314
315         moveBandBottomElements();
316
317         removeBlankElements();
318
319         isFirstWholeOnPageColumn = isNewPageColumn && isOverflow;
320         isNewPageColumn = false;
321         isNewGroupMap = new HashMap JavaDoc();
322
323         JRPrintBand printBand = new JRPrintBand();
324         fillElements(printBand);
325
326         return printBand;
327     }
328
329
330     protected int getContainerHeight()
331     {
332         return getHeight();
333     }
334
335
336     protected boolean isVariableUsedInSubreportReturns(String JavaDoc variableName)
337     {
338         boolean used = false;
339         JRElement[] bandElements = getElements();
340         if (bandElements != null)
341         {
342             elementsLoop:
343             for (int i = 0; i < bandElements.length; i++)
344             {
345                 JRElement element = bandElements[i];
346                 if (element instanceof JRSubreport)
347                 {
348                     JRSubreport subreport = (JRSubreport) element;
349                     JRSubreportReturnValue[] returnValues = subreport.getReturnValues();
350                     if (returnValues != null)
351                     {
352                         for (int j = 0; j < returnValues.length; j++)
353                         {
354                             JRSubreportReturnValue returnValue = returnValues[j];
355                             if (returnValue.getToVariable().equals(variableName))
356                             {
357                                 used = true;
358                                 break elementsLoop;
359                             }
360                         }
361                     }
362                 }
363             }
364         }
365
366         return used;
367     }
368
369
370     protected void addNowEvaluationTime(JREvaluationTime evaluationTime)
371     {
372         nowEvaluationTimes.add(evaluationTime);
373     }
374
375
376     protected void addNowEvaluationTimes(JREvaluationTime[] evaluationTimes)
377     {
378         for (int i = 0; i < evaluationTimes.length; i++)
379         {
380             nowEvaluationTimes.add(evaluationTimes[i]);
381         }
382     }
383
384
385     protected boolean isNowEvaluationTime(JREvaluationTime evaluationTime)
386     {
387         return nowEvaluationTimes.contains(evaluationTime);
388     }
389
390
391     protected int getId()
392     {
393         return System.identityHashCode(this);
394     }
395
396
397     protected void evaluate(byte evaluation) throws JRException
398     {
399         evaluateConditionalStyles(evaluation);
400         super.evaluate(evaluation);
401     }
402
403 }
404
Popular Tags