1
24 package net.sf.jasperreports.engine.fill;
25
26 import net.sf.jasperreports.engine.JRException;
27 import net.sf.jasperreports.engine.JRExpressionCollector;
28 import net.sf.jasperreports.engine.JRPrintElement;
29 import net.sf.jasperreports.engine.JRStaticText;
30 import net.sf.jasperreports.engine.JRVisitor;
31
32
33
36 public class JRFillStaticText extends JRFillTextElement implements JRStaticText
37 {
38
39 private final String text;
40
41
44 protected JRFillStaticText(
45 JRBaseFiller filler,
46 JRStaticText staticText,
47 JRFillObjectFactory factory
48 )
49 {
50 super(filler, staticText, factory);
51
52 String text = processMarkupText(staticText.getText());
53 if (text == null)
54 {
55 text = "";
56 }
57 this.text = text;
58 }
59
60
61 protected JRFillStaticText(JRFillStaticText staticText, JRFillCloneFactory factory)
62 {
63 super(staticText, factory);
64
65 this.text = staticText.text;
66 }
67
68
69 @Override
70 public void setText(String text)
71 {
72 }
73
74
75
78 protected JRTemplateText getJRTemplateText()
79 {
80 return (JRTemplateText) getElementTemplate();
81 }
82
83
84 @Override
85 protected JRTemplateElement createElementTemplate()
86 {
87 JRTemplateText template = new JRTemplateText(
88 getElementOrigin(),
89 filler.getJasperPrint().getDefaultStyleProvider(),
90 this
91 );
92 template.copyParagraph(getPrintParagraph());
93 template.copyLineBox(getPrintLineBox());
94 return template;
95 }
96
97
98 @Override
99 protected void evaluate(
100 byte evaluation
101 ) throws JRException
102 {
103 reset();
104
105 evaluatePrintWhenExpression(evaluation);
106 evaluateProperties(evaluation);
107 evaluateStyle(evaluation);
108
109
110 setRawText(this.text);
111 resetTextChunk();
112
113 setValueRepeating(true);
114 }
115
116
117 @Override
118 protected boolean prepare(
119 int availableHeight,
120 boolean isOverflow
121 ) throws JRException
122 {
123 boolean willOverflow = false;
124
125 super.prepare(availableHeight, isOverflow);
126
127 if (!isToPrint())
128 {
129 return willOverflow;
130 }
131
132 boolean isToPrint = true;
133 boolean isReprinted = false;
134
135 if (isOverflow && isAlreadyPrinted() && !isPrintWhenDetailOverflows())
136 {
137 isToPrint = false;
138 }
139
140 if (
141 isToPrint &&
142 isPrintWhenExpressionNull() &&
143 !isPrintRepeatedValues()
144 )
145 {
146 if (
147 ( !isPrintInFirstWholeBand() || !getBand().isFirstWholeOnPageColumn()) &&
148 ( getPrintWhenGroupChanges() == null || !getBand().isNewGroup(getPrintWhenGroupChanges()) ) &&
149 ( !isOverflow || !isPrintWhenDetailOverflows() )
150 )
151 {
152 isToPrint = false;
153 }
154 }
155
156 if (
157 isToPrint &&
158 availableHeight < getRelativeY() + getHeight()
159 )
160 {
161 isToPrint = false;
162 willOverflow = true;
163 }
164
165 if (
166 isToPrint &&
167 isOverflow &&
168
169 (isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues())))
170 )
171 {
172 isReprinted = true;
173 }
174
175 resetTextChunk();
176
177 if (isToPrint)
178 {
179 chopTextElement(0);
180 }
181
182 setToPrint(isToPrint);
183 setReprinted(isReprinted);
184
185 return willOverflow;
186 }
187
188
189 @Override
190 protected JRPrintElement fill()
191 {
192 JRTemplatePrintText text = new JRTemplatePrintText(getJRTemplateText(), printElementOriginator);
193 text.setUUID(getUUID());
194 text.setX(getX());
195 text.setY(getRelativeY());
196 text.setWidth(getWidth());
197
198
199
200 text.setHeight(getStretchHeight());
201
202
203
204
205
206 text.setRunDirection(getRunDirectionValue());
207 text.setLineSpacingFactor(getLineSpacingFactor());
208 text.setLeadingOffset(getLeadingOffset());
209 text.setTextHeight(getTextHeight());
210 transferProperties(text);
211
212
213 setPrintText(text);
214
215 return text;
216 }
217
218
219 @Override
220 public void collectExpressions(JRExpressionCollector collector)
221 {
222 collector.collect(this);
223 }
224
225 @Override
226 public void visit(JRVisitor visitor)
227 {
228 visitor.visitStaticText(this);
229 }
230
231
232 @Override
233 protected void resolveElement (JRPrintElement element, byte evaluation)
234 {
235
236 }
237
238
239 @Override
240 public JRFillCloneable createClone(JRFillCloneFactory factory)
241 {
242 return new JRFillStaticText(this, factory);
243 }
244
245
246 @Override
247 protected boolean canOverflow()
248 {
249 return false;
250 }
251
252
253 @Override
254 protected boolean scaleFontToFit()
255 {
256 return false;
257 }
258
259
260 @Override
261 public String getText()
262 {
263 return ((JRStaticText) parent).getText();
264 }
265
266 }
267