KickJava   Java API By Example, From Geeks To Geeks.

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


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.Locale JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.TimeZone JavaDoc;
34
35 import net.sf.jasperreports.engine.JRException;
36 import net.sf.jasperreports.engine.JRPrintImage;
37 import net.sf.jasperreports.engine.JRPrintPage;
38 import net.sf.jasperreports.engine.query.JRQueryExecuter;
39 import net.sf.jasperreports.engine.util.FormatFactory;
40
41 /**
42  * Context class shared by all the fillers involved in a report (master and subfillers).
43  * <p>
44  * The context is created by the master filler and inherited by the subfillers.
45  *
46  * @author Lucian Chirita (lucianc@users.sourceforge.net)
47  * @version $Id: JRFillContext.java 1485 2006-11-14 20:23:17 +0200 (Tue, 14 Nov 2006) teodord $
48  * @see net.sf.jasperreports.engine.fill.JRBaseFiller
49  */

50 public class JRFillContext
51 {
52     private Map JavaDoc loadedImages;
53     private boolean usingVirtualizer = false;
54     private boolean perPageBoundElements = false;
55     private JRPrintPage printPage = null;
56     private boolean ignorePagination = false;
57     private JRQueryExecuter queryExecuter;
58
59     private JRVirtualizationContext virtualizationContext;
60     
61     private FormatFactory masterFormatFactory;
62     private Locale JavaDoc masterLocale;
63     private TimeZone JavaDoc masterTimeZone;
64
65     
66     /**
67      * Constructs a fill context.
68      */

69     public JRFillContext()
70     {
71         loadedImages = new HashMap JavaDoc();
72     }
73     
74     
75     /**
76      * Checks whether an image given by source has already been loaded and cached.
77      *
78      * @param source the source of the image
79      * @return whether the image has been cached
80      * @see #getLoadedImage(Object)
81      * @see #registerLoadedImage(Object, JRPrintImage)
82      */

83     public boolean hasLoadedImage(Object JavaDoc source)
84     {
85         return loadedImages.containsKey(source);
86     }
87     
88     
89     /**
90      * Gets a cached image.
91      *
92      * @param source the source of the image
93      * @return the cached image
94      * @see #registerLoadedImage(Object, JRPrintImage)
95      */

96     public JRPrintImage getLoadedImage(Object JavaDoc source)
97     {
98         return (JRPrintImage) loadedImages.get(source);
99     }
100     
101     
102     /**
103      * Registers an image loaded from a source.
104      * <p>
105      * The image is cached for further use.
106      *
107      * @param source the source that was used to load the image
108      * @param image the loaded image
109      * @see #getLoadedImage(Object)
110      */

111     public void registerLoadedImage(Object JavaDoc source, JRPrintImage image)
112     {
113         loadedImages.put(source, image);
114         if (usingVirtualizer)
115         {
116             virtualizationContext.cacheRenderer(image);
117         }
118     }
119
120     
121     /**
122      * Sets the flag indicating whether a virtualizer is used by the filling process.
123      *
124      * @param usingVirtualizer whether virtualization is used
125      * @see #isUsingVirtualizer()
126      */

127     public void setUsingVirtualizer(boolean usingVirtualizer)
128     {
129         this.usingVirtualizer = usingVirtualizer;
130         if (usingVirtualizer && virtualizationContext == null)
131         {
132             virtualizationContext = new JRVirtualizationContext();
133         }
134     }
135     
136     
137     /**
138      * Decides whether virtualization is used by the filling process.
139      *
140      * @return <code>true</code> iff a virtualizer is used
141      * @see #setUsingVirtualizer(boolean)
142      * @see net.sf.jasperreports.engine.JRParameter#REPORT_VIRTUALIZER
143      */

144     public boolean isUsingVirtualizer()
145     {
146         return usingVirtualizer;
147     }
148
149     
150     /**
151      * Sets the flag indicating whether fillers should keep per page bound
152      * element maps.
153      *
154      * @param perPageBoundElements the value of the flag
155      * @see #isPerPageBoundElements()
156      */

157     public void setPerPageBoundElements(boolean perPageBoundElements)
158     {
159         this.perPageBoundElements = perPageBoundElements;
160     }
161
162     
163     /**
164      * Decides whether fillers should keep per page bound element maps.
165      *
166      * @return <code>true</code> iff fillers should keep per page bound element maps
167      * @see #setPerPageBoundElements(boolean)
168      */

169     public boolean isPerPageBoundElements()
170     {
171         return perPageBoundElements;
172     }
173     
174     
175     /**
176      * Sets the current master print page.
177      *
178      * @param page the master print page
179      * @see #getPrintPage()
180      */

181     public void setPrintPage(JRPrintPage page)
182     {
183         printPage = page;
184     }
185     
186     
187     /**
188      * Returns the current master print page.
189      *
190      * @return the current master print page
191      * @see #setPrintPage(JRPrintPage)
192      */

193     public JRPrintPage getPrintPage()
194     {
195         return printPage;
196     }
197     
198     
199     /**
200      * Sets the flag that decides whether pagination should be ignored during filling.
201      *
202      * @param ignorePagination
203      * @see #isIgnorePagination()
204      */

205     public void setIgnorePagination(boolean ignorePagination)
206     {
207         this.ignorePagination = ignorePagination;
208     }
209     
210     
211     /**
212      * Decides whether the filling should ignore pagination.
213      *
214      * @return whether the filling should ignore pagination
215      * @see #setIgnorePagination(boolean)
216      * @see net.sf.jasperreports.engine.JRParameter#IS_IGNORE_PAGINATION
217      */

218     public boolean isIgnorePagination()
219     {
220         return ignorePagination;
221     }
222     
223     
224     /**
225      * Sets the running query executer.
226      * <p>
227      * This method is called before firing the query.
228      *
229      * @param queryExecuter the running query executer
230      */

231     public synchronized void setRunningQueryExecuter(JRQueryExecuter queryExecuter)
232     {
233         this.queryExecuter = queryExecuter;
234     }
235     
236     
237     /**
238      * Clears the running query executer.
239      * <p>
240      * This method is called after the query has ended.
241      *
242      */

243     public synchronized void clearRunningQueryExecuter()
244     {
245         this.queryExecuter = null;
246     }
247     
248     
249     /**
250      * Cancels the running query.
251      *
252      * @return <code>true</code> iff there is a running query and it has been cancelled.
253      * @throws JRException
254      */

255     public synchronized boolean cancelRunningQuery() throws JRException
256     {
257         if (queryExecuter != null)
258         {
259             return queryExecuter.cancelQuery();
260         }
261         
262         return false;
263     }
264
265
266     /**
267      * Ensures that the master page is available when virtualization is used.
268      */

269     public void ensureMasterPageAvailable()
270     {
271         if (usingVirtualizer)
272         {
273             printPage.getElements();
274         }
275     }
276     
277     
278     /**
279      * Returns the virtualization context.
280      *
281      * @return the virtualization context
282      */

283     public JRVirtualizationContext getVirtualizationContext()
284     {
285         return virtualizationContext;
286     }
287
288     
289     public FormatFactory getMasterFormatFactory()
290     {
291         return masterFormatFactory;
292     }
293
294     
295     public void setMasterFormatFactory(FormatFactory masterFormatFactory)
296     {
297         this.masterFormatFactory = masterFormatFactory;
298     }
299
300     
301     public Locale JavaDoc getMasterLocale()
302     {
303         return masterLocale;
304     }
305
306     
307     public void setMasterLocale(Locale JavaDoc masterLocale)
308     {
309         this.masterLocale = masterLocale;
310     }
311
312     
313     public TimeZone JavaDoc getMasterTimeZone()
314     {
315         return masterTimeZone;
316     }
317
318     
319     public void setMasterTimeZone(TimeZone JavaDoc masterTimeZone)
320     {
321         this.masterTimeZone = masterTimeZone;
322     }
323 }
324
Popular Tags