KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
31
32 import net.sf.jasperreports.engine.JRAbstractObjectFactory;
33 import net.sf.jasperreports.engine.JRChild;
34 import net.sf.jasperreports.engine.JRException;
35 import net.sf.jasperreports.engine.JRExpressionCollector;
36 import net.sf.jasperreports.engine.JRPrintElement;
37 import net.sf.jasperreports.engine.JRPrintText;
38 import net.sf.jasperreports.engine.JRStaticText;
39 import net.sf.jasperreports.engine.JRStyle;
40 import net.sf.jasperreports.engine.xml.JRXmlWriter;
41
42
43 /**
44  * @author Teodor Danciu (teodord@users.sourceforge.net)
45  * @version $Id: JRFillStaticText.java 1357 2006-08-10 12:36:24 +0300 (Thu, 10 Aug 2006) lucianc $
46  */

47 public class JRFillStaticText extends JRFillTextElement implements JRStaticText
48 {
49
50
51     /**
52      *
53      */

54     protected JRFillStaticText(
55             JRBaseFiller filler,
56             JRStaticText staticText,
57             JRFillObjectFactory factory
58             )
59         {
60             super(filler, staticText, factory);
61             
62             //setRawText(JRStringUtil.treatNewLineChars(staticText.getText()));
63
String JavaDoc text = staticText.getText();
64             if (text == null)
65             {
66                 text = "";
67             }
68             setRawText(text);
69         }
70
71
72     protected JRFillStaticText(JRFillStaticText staticText, JRFillCloneFactory factory)
73     {
74         super(staticText, factory);
75
76         // setRawText(JRStringUtil.treatNewLineChars(staticText.getText()));
77
String JavaDoc text = staticText.getText();
78         if (text == null)
79         {
80             text = "";
81         }
82         setRawText(text);
83     }
84
85
86     /**
87      *
88      */

89     public void setText(String JavaDoc text)
90     {
91     }
92
93
94     /**
95      *
96      */

97     protected JRTemplateText getJRTemplateText()
98     {
99         JRStyle style = getStyle();
100         JRTemplateText template = (JRTemplateText) getTemplate(style);
101         if (template == null)
102         {
103             template = new JRTemplateText(filler.getJasperPrint().getDefaultStyleProvider(), this);
104             registerTemplate(style, template);
105         }
106         return template;
107     }
108
109
110     /**
111      *
112      */

113     protected void evaluate(
114         byte evaluation
115         ) throws JRException
116     {
117         reset();
118         
119         evaluatePrintWhenExpression(evaluation);
120         
121         setTextStart(0);
122         setTextEnd(0);
123         
124         setValueRepeating(true);
125     }
126
127
128     /**
129      *
130      */

131     protected boolean prepare(
132         int availableStretchHeight,
133         boolean isOverflow
134         ) throws JRException
135     {
136         boolean willOverflow = false;
137
138         super.prepare(availableStretchHeight, isOverflow);
139         
140         if (!isToPrint())
141         {
142             return willOverflow;
143         }
144         
145         boolean isToPrint = true;
146         boolean isReprinted = false;
147
148         if (isOverflow && isAlreadyPrinted() && !isPrintWhenDetailOverflows())
149         {
150             isToPrint = false;
151         }
152
153         if (
154             isToPrint &&
155             isPrintWhenExpressionNull() &&
156             !isPrintRepeatedValues()
157             )
158         {
159             if (
160                 ( !isPrintInFirstWholeBand() || !getBand().isFirstWholeOnPageColumn()) &&
161                 ( getPrintWhenGroupChanges() == null || !getBand().isNewGroup(getPrintWhenGroupChanges()) ) &&
162                 ( !isOverflow || !isPrintWhenDetailOverflows() )
163                 )
164             {
165                 isToPrint = false;
166             }
167         }
168
169         if (
170             isToPrint &&
171             availableStretchHeight < getRelativeY() - getY() - getBandBottomY()
172             )
173         {
174             isToPrint = false;
175             willOverflow = true;
176         }
177         
178         if (
179             isToPrint &&
180             isOverflow &&
181             //(isAlreadyPrinted() || !isPrintRepeatedValues())
182
(isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues())))
183             )
184         {
185             isReprinted = true;
186         }
187
188         setTextStart(0);
189         setTextEnd(0);
190
191         if (isToPrint)
192         {
193             chopTextElement(0);
194         }
195         
196         setToPrint(isToPrint);
197         setReprinted(isReprinted);
198         
199         return willOverflow;
200     }
201
202
203     /**
204      *
205      */

206     protected JRPrintElement fill()
207     {
208         JRPrintText text = null;
209
210         text = new JRTemplatePrintText(getJRTemplateText());
211         text.setX(getX());
212         text.setY(getRelativeY());
213         text.setWidth(getWidth());
214         if (getRotation() == ROTATION_NONE)
215         {
216             text.setHeight(getStretchHeight());
217         }
218         else
219         {
220             text.setHeight(getHeight());
221         }
222         text.setRunDirection(getRunDirection());
223         text.setLineSpacingFactor(getLineSpacingFactor());
224         text.setLeadingOffset(getLeadingOffset());
225         text.setTextHeight(getTextHeight());
226
227         //text.setText(getRawText());
228
text.setText(textChopper.chop(this, getTextStart(), getTextEnd()));
229         
230         return text;
231     }
232
233
234     /**
235      *
236      */

237     public JRChild getCopy(JRAbstractObjectFactory factory)
238     {
239         return factory.getStaticText(this);
240     }
241
242     /**
243      *
244      */

245     public void collectExpressions(JRExpressionCollector collector)
246     {
247         collector.collect(this);
248     }
249
250     /**
251      *
252      */

253     public void writeXml(JRXmlWriter xmlWriter) throws IOException JavaDoc
254     {
255         xmlWriter.writeStaticText(this);
256     }
257
258         
259     protected void resolveElement (JRPrintElement element, byte evaluation)
260     {
261         // nothing
262
}
263
264
265     public JRCloneable createClone(JRFillCloneFactory factory)
266     {
267         return new JRFillStaticText(this, factory);
268     }
269
270 }
271
Popular Tags