KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > base > JRBaseElement


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.base;
29
30 import java.awt.Color JavaDoc;
31 import java.io.Serializable JavaDoc;
32
33 import net.sf.jasperreports.engine.JRConstants;
34 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
35 import net.sf.jasperreports.engine.JRElement;
36 import net.sf.jasperreports.engine.JRElementGroup;
37 import net.sf.jasperreports.engine.JRExpression;
38 import net.sf.jasperreports.engine.JRGroup;
39 import net.sf.jasperreports.engine.JRStyle;
40 import net.sf.jasperreports.engine.util.JRStyleResolver;
41
42
43 /**
44  * This class provides a skeleton implementation for a report element. It mostly provides internal variables, representing
45  * the most common element properties, and their getter/setter methods. It also has a constructor for initializing
46  * these properties.
47  * @author Teodor Danciu (teodord@users.sourceforge.net)
48  * @version $Id: JRBaseElement.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
49  */

50 public abstract class JRBaseElement implements JRElement, Serializable JavaDoc
51 {
52
53
54     /**
55      *
56      */

57     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
58
59     /**
60      *
61      */

62     protected String JavaDoc key = null;
63     protected byte positionType;
64     protected byte stretchType;
65     protected boolean isPrintRepeatedValues = true;
66     protected Byte JavaDoc mode;
67     protected int x = 0;
68     protected int y = 0;
69     protected int width = 0;
70     protected int height = 0;
71     protected boolean isRemoveLineWhenBlank = false;
72     protected boolean isPrintInFirstWholeBand = false;
73     protected boolean isPrintWhenDetailOverflows = false;
74     protected Color JavaDoc forecolor = null;
75     protected Color JavaDoc backcolor = null;
76
77     /**
78      *
79      */

80     protected JRExpression printWhenExpression = null;
81     protected JRGroup printWhenGroupChanges = null;
82     protected JRElementGroup elementGroup = null;
83
84     protected JRDefaultStyleProvider defaultStyleProvider;
85     protected JRStyle parentStyle;
86
87
88     /**
89      *
90      */

91     protected JRBaseElement(JRDefaultStyleProvider defaultStyleProvider)
92     {
93         this.defaultStyleProvider = defaultStyleProvider;
94     }
95
96
97     /**
98      * Initializes basic properties of the element.
99      * @param element an element whose properties are copied to this element. Usually it is a
100      * {@link net.sf.jasperreports.engine.design.JRDesignElement} that must be transformed into an
101      * <tt>JRBaseElement</tt> at compile time.
102      * @param factory a factory used in the compile process
103      */

104     protected JRBaseElement(JRElement element, JRBaseObjectFactory factory)
105     {
106         factory.put(element, this);
107
108         defaultStyleProvider = factory.getDefaultStyleProvider();
109
110         parentStyle = factory.getStyle(element.getStyle());
111
112         key = element.getKey();
113         positionType = element.getPositionType();
114         stretchType = element.getStretchType();
115         isPrintRepeatedValues = element.isPrintRepeatedValues();
116         mode = element.getOwnMode();
117         x = element.getX();
118         y = element.getY();
119         width = element.getWidth();
120         height = element.getHeight();
121         isRemoveLineWhenBlank = element.isRemoveLineWhenBlank();
122         isPrintInFirstWholeBand = element.isPrintInFirstWholeBand();
123         isPrintWhenDetailOverflows = element.isPrintWhenDetailOverflows();
124         forecolor = element.getOwnForecolor();
125         backcolor = element.getOwnBackcolor();
126
127         printWhenExpression = factory.getExpression(element.getPrintWhenExpression());
128         printWhenGroupChanges = factory.getGroup(element.getPrintWhenGroupChanges());
129         elementGroup = factory.getElementGroup(element.getElementGroup());
130     }
131
132
133     /**
134      *
135      */

136     public JRDefaultStyleProvider getDefaultStyleProvider()
137     {
138         return defaultStyleProvider;
139     }
140
141     /**
142      *
143      */

144     protected JRStyle getBaseStyle()
145     {
146         if (parentStyle != null)
147             return parentStyle;
148         if (defaultStyleProvider != null)
149             return defaultStyleProvider.getDefaultStyle();
150         return null;
151     }
152
153     /**
154      *
155      */

156     public String JavaDoc getKey()
157     {
158         return this.key;
159     }
160
161     /**
162      *
163      */

164     public byte getPositionType()
165     {
166         return positionType;
167     }
168
169     /**
170      *
171      */

172     public void setPositionType(byte positionType)
173     {
174         this.positionType = positionType;
175     }
176
177     /**
178      *
179      */

180     public byte getStretchType()
181     {
182         return stretchType;
183     }
184
185     /**
186      *
187      */

188     public void setStretchType(byte stretchType)
189     {
190         this.stretchType = stretchType;
191     }
192
193     /**
194      *
195      */

196     public boolean isPrintRepeatedValues()
197     {
198         return this.isPrintRepeatedValues;
199     }
200
201     /**
202      *
203      */

204     public void setPrintRepeatedValues(boolean isPrintRepeatedValues)
205     {
206         this.isPrintRepeatedValues = isPrintRepeatedValues;
207     }
208
209     /**
210      *
211      */

212     public byte getMode()
213     {
214         return JRStyleResolver.getMode(this, MODE_OPAQUE);
215     }
216
217     /**
218      *
219      */

220     public Byte JavaDoc getOwnMode()
221     {
222         return mode;
223     }
224
225     /**
226      *
227      */

228     public void setMode(byte mode)
229     {
230         this.mode = new Byte JavaDoc(mode);
231     }
232
233     /**
234      *
235      */

236     public void setMode(Byte JavaDoc mode)
237     {
238         this.mode = mode;
239     }
240
241     /**
242      *
243      */

244     public int getX()
245     {
246         return this.x;
247     }
248
249     /**
250      *
251      */

252     public void setX(int x)
253     {
254         this.x = x;
255     }
256
257     /**
258      *
259      */

260     public int getY()
261     {
262         return this.y;
263     }
264
265     /**
266      *
267      */

268     public int getWidth()
269     {
270         return this.width;
271     }
272
273     /**
274      *
275      */

276     public void setWidth(int width)
277     {
278         this.width = width;
279     }
280
281     /**
282      *
283      */

284     public int getHeight()
285     {
286         return this.height;
287     }
288
289     /**
290      *
291      */

292     public boolean isRemoveLineWhenBlank()
293     {
294         return this.isRemoveLineWhenBlank;
295     }
296
297     /**
298      *
299      */

300     public void setRemoveLineWhenBlank(boolean isRemoveLine)
301     {
302         this.isRemoveLineWhenBlank = isRemoveLine;
303     }
304
305     /**
306      *
307      */

308     public boolean isPrintInFirstWholeBand()
309     {
310         return this.isPrintInFirstWholeBand;
311     }
312
313     /**
314      *
315      */

316     public void setPrintInFirstWholeBand(boolean isPrint)
317     {
318         this.isPrintInFirstWholeBand = isPrint;
319     }
320
321     /**
322      *
323      */

324     public boolean isPrintWhenDetailOverflows()
325     {
326         return this.isPrintWhenDetailOverflows;
327     }
328
329     /**
330      *
331      */

332     public void setPrintWhenDetailOverflows(boolean isPrint)
333     {
334         this.isPrintWhenDetailOverflows = isPrint;
335     }
336
337     /**
338      *
339      */

340     public Color JavaDoc getForecolor()
341     {
342         return JRStyleResolver.getForecolor(this);
343     }
344
345     /**
346      *
347      */

348     public Color JavaDoc getOwnForecolor()
349     {
350         return forecolor;
351     }
352
353     /**
354      *
355      */

356     public void setForecolor(Color JavaDoc forecolor)
357     {
358         this.forecolor = forecolor;
359     }
360
361     /**
362      *
363      */

364     public Color JavaDoc getBackcolor()
365     {
366         return JRStyleResolver.getBackcolor(this);
367     }
368
369     /**
370      *
371      */

372     public Color JavaDoc getOwnBackcolor()
373     {
374         return backcolor;
375     }
376
377     /**
378      *
379      */

380     public void setBackcolor(Color JavaDoc backcolor)
381     {
382         this.backcolor = backcolor;
383     }
384
385     /**
386      *
387      */

388     public JRExpression getPrintWhenExpression()
389     {
390         return this.printWhenExpression;
391     }
392
393     /**
394      *
395      */

396     public JRGroup getPrintWhenGroupChanges()
397     {
398         return this.printWhenGroupChanges;
399     }
400
401     /**
402      *
403      */

404     public JRElementGroup getElementGroup()
405     {
406         return this.elementGroup;
407     }
408
409     public JRStyle getStyle()
410     {
411         return parentStyle;
412     }
413 }
414
Popular Tags