1
24 package net.sf.jasperreports.engine.base;
25
26 import java.io.IOException;
27 import java.io.ObjectInputStream;
28
29 import net.sf.jasperreports.engine.JRAnchor;
30 import net.sf.jasperreports.engine.JRConstants;
31 import net.sf.jasperreports.engine.JRExpression;
32 import net.sf.jasperreports.engine.JRExpressionCollector;
33 import net.sf.jasperreports.engine.JRGroup;
34 import net.sf.jasperreports.engine.JRHyperlinkHelper;
35 import net.sf.jasperreports.engine.JRHyperlinkParameter;
36 import net.sf.jasperreports.engine.JRTextField;
37 import net.sf.jasperreports.engine.JRVisitor;
38 import net.sf.jasperreports.engine.type.EvaluationTimeEnum;
39 import net.sf.jasperreports.engine.type.HyperlinkTargetEnum;
40 import net.sf.jasperreports.engine.type.HyperlinkTypeEnum;
41 import net.sf.jasperreports.engine.type.TextAdjustEnum;
42 import net.sf.jasperreports.engine.util.JRCloneUtils;
43
44
45
50 public class JRBaseTextField extends JRBaseTextElement implements JRTextField
51 {
52
53
54
57 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
58
59 public static final String PROPERTY_STRETCH_WITH_OVERFLOW = "isStretchWithOverflow";
60 public static final String PROPERTY_TEXT_ADJUST = "textAdjust";
61
62
65 protected TextAdjustEnum textAdjust = TextAdjustEnum.CUT_TEXT;
66 protected EvaluationTimeEnum evaluationTimeValue = EvaluationTimeEnum.NOW;
67 protected String pattern;
68 protected Boolean isBlankWhenNull;
69 protected String linkType;
70 protected String linkTarget;
71 private JRHyperlinkParameter[] hyperlinkParameters;
72
73
76 protected JRGroup evaluationGroup;
77 protected JRExpression expression;
78 protected JRExpression patternExpression;
79 protected JRExpression anchorNameExpression;
80 protected JRExpression bookmarkLevelExpression;
81 protected JRExpression hyperlinkReferenceExpression;
82 protected JRExpression hyperlinkWhenExpression;
83 protected JRExpression hyperlinkAnchorExpression;
84 protected JRExpression hyperlinkPageExpression;
85 private JRExpression hyperlinkTooltipExpression;
86
87
91 protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
92
93
96 protected JRBaseTextField(JRTextField textField, JRBaseObjectFactory factory)
97 {
98 super(textField, factory);
99
100 textAdjust = textField.getTextAdjust();
101 evaluationTimeValue = textField.getEvaluationTimeValue();
102 pattern = textField.getOwnPattern();
103 isBlankWhenNull = textField.isOwnBlankWhenNull();
104 linkType = textField.getLinkType();
105 linkTarget = textField.getLinkTarget();
106 hyperlinkParameters = JRBaseHyperlink.copyHyperlinkParameters(textField, factory);
107
108 evaluationGroup = factory.getGroup(textField.getEvaluationGroup());
109 expression = factory.getExpression(textField.getExpression());
110 patternExpression = factory.getExpression(textField.getPatternExpression());
111 anchorNameExpression = factory.getExpression(textField.getAnchorNameExpression());
112 bookmarkLevelExpression = factory.getExpression(textField.getBookmarkLevelExpression());
113 hyperlinkReferenceExpression = factory.getExpression(textField.getHyperlinkReferenceExpression());
114 hyperlinkWhenExpression = factory.getExpression(textField.getHyperlinkWhenExpression());
115 hyperlinkAnchorExpression = factory.getExpression(textField.getHyperlinkAnchorExpression());
116 hyperlinkPageExpression = factory.getExpression(textField.getHyperlinkPageExpression());
117 hyperlinkTooltipExpression = factory.getExpression(textField.getHyperlinkTooltipExpression());
118 bookmarkLevel = textField.getBookmarkLevel();
119 }
120
121
122
125 @Override
126 public boolean isStretchWithOverflow()
127 {
128 return getTextAdjust() == TextAdjustEnum.STRETCH_HEIGHT;
129 }
130
131
134 @Override
135 public void setStretchWithOverflow(boolean isStretchWithOverflow)
136 {
137 boolean old = this.textAdjust == TextAdjustEnum.STRETCH_HEIGHT;
138
139 setTextAdjust(isStretchWithOverflow ? TextAdjustEnum.STRETCH_HEIGHT : TextAdjustEnum.CUT_TEXT);
140
141 getEventSupport().firePropertyChange(PROPERTY_STRETCH_WITH_OVERFLOW, old, isStretchWithOverflow);
142 }
143
144 @Override
145 public TextAdjustEnum getTextAdjust()
146 {
147 return this.textAdjust;
148 }
149
150 @Override
151 public void setTextAdjust(TextAdjustEnum textAdjust)
152 {
153 TextAdjustEnum old = this.textAdjust;
154 this.textAdjust = textAdjust;
155 getEventSupport().firePropertyChange(PROPERTY_TEXT_ADJUST, old, this.textAdjust);
156 }
157
158 @Override
159 public EvaluationTimeEnum getEvaluationTimeValue()
160 {
161 return this.evaluationTimeValue;
162 }
163
164 @Override
165 public String getPattern()
166 {
167 return getStyleResolver().getPattern(this);
168 }
169
170 @Override
171 public String getOwnPattern()
172 {
173 return this.pattern;
174 }
175
176 @Override
177 public void setPattern(String pattern)
178 {
179 Object old = this.pattern;
180 this.pattern = pattern;
181 getEventSupport().firePropertyChange(JRBaseStyle.PROPERTY_PATTERN, old, this.pattern);
182 }
183
184 @Override
185 public boolean isBlankWhenNull()
186 {
187 return getStyleResolver().isBlankWhenNull(this);
188 }
189
190 @Override
191 public Boolean isOwnBlankWhenNull()
192 {
193 return isBlankWhenNull;
194 }
195
196 @Override
197 public void setBlankWhenNull(Boolean isBlank)
198 {
199 Object old = this.isBlankWhenNull;
200 this.isBlankWhenNull = isBlank;
201 getEventSupport().firePropertyChange(JRBaseStyle.PROPERTY_BLANK_WHEN_NULL, old, this.isBlankWhenNull);
202 }
203
204 @Override
205 public void setBlankWhenNull(boolean isBlank)
206 {
207 setBlankWhenNull((Boolean)isBlank);
208 }
209
210
213 public byte getHyperlinkType()
214 {
215 return getHyperlinkTypeValue().getValue();
216 }
217
218 @Override
219 public HyperlinkTypeEnum getHyperlinkTypeValue()
220 {
221 return JRHyperlinkHelper.getHyperlinkTypeValue(this);
222 }
223
224 @Override
225 public byte getHyperlinkTarget()
226 {
227 return JRHyperlinkHelper.getHyperlinkTarget(this);
228 }
229
230 @Override
231 public JRGroup getEvaluationGroup()
232 {
233 return this.evaluationGroup;
234 }
235
236 @Override
237 public JRExpression getExpression()
238 {
239 return this.expression;
240 }
241
242 @Override
243 public JRExpression getPatternExpression()
244 {
245 return this.patternExpression;
246 }
247
248 @Override
249 public JRExpression getAnchorNameExpression()
250 {
251 return this.anchorNameExpression;
252 }
253
254 @Override
255 public JRExpression getBookmarkLevelExpression()
256 {
257 return this.bookmarkLevelExpression;
258 }
259
260 @Override
261 public JRExpression getHyperlinkReferenceExpression()
262 {
263 return this.hyperlinkReferenceExpression;
264 }
265
266 @Override
267 public JRExpression getHyperlinkWhenExpression()
268 {
269 return this.hyperlinkWhenExpression;
270 }
271
272 @Override
273 public JRExpression getHyperlinkAnchorExpression()
274 {
275 return this.hyperlinkAnchorExpression;
276 }
277
278 @Override
279 public JRExpression getHyperlinkPageExpression()
280 {
281 return this.hyperlinkPageExpression;
282 }
283
284 @Override
285 public void collectExpressions(JRExpressionCollector collector)
286 {
287 collector.collect(this);
288 }
289
290 @Override
291 public void visit(JRVisitor visitor)
292 {
293 visitor.visitTextField(this);
294 }
295
296
297 @Override
298 public int getBookmarkLevel()
299 {
300 return bookmarkLevel;
301 }
302
303
304 @Override
305 public String getLinkType()
306 {
307 return linkType;
308 }
309
310 @Override
311 public String getLinkTarget()
312 {
313 return linkTarget;
314 }
315
316
317 @Override
318 public JRHyperlinkParameter[] getHyperlinkParameters()
319 {
320 return hyperlinkParameters;
321 }
322
323
324 @Override
325 public JRExpression getHyperlinkTooltipExpression()
326 {
327 return hyperlinkTooltipExpression;
328 }
329
330 @Override
331 public Object clone()
332 {
333 JRBaseTextField clone = (JRBaseTextField)super.clone();
334 clone.hyperlinkParameters = JRCloneUtils.cloneArray(hyperlinkParameters);
335 clone.expression = JRCloneUtils.nullSafeClone(expression);
336 clone.patternExpression = JRCloneUtils.nullSafeClone(patternExpression);
337 clone.anchorNameExpression = JRCloneUtils.nullSafeClone(anchorNameExpression);
338 clone.bookmarkLevelExpression = JRCloneUtils.nullSafeClone(bookmarkLevelExpression);
339 clone.hyperlinkReferenceExpression = JRCloneUtils.nullSafeClone(hyperlinkReferenceExpression);
340 clone.hyperlinkWhenExpression = JRCloneUtils.nullSafeClone(hyperlinkWhenExpression);
341 clone.hyperlinkAnchorExpression = JRCloneUtils.nullSafeClone(hyperlinkAnchorExpression);
342 clone.hyperlinkPageExpression = JRCloneUtils.nullSafeClone(hyperlinkPageExpression);
343 clone.hyperlinkTooltipExpression = JRCloneUtils.nullSafeClone(hyperlinkTooltipExpression);
344 return clone;
345 }
346
347
350 private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID;
351
354 private byte hyperlinkType;
355
358 private byte hyperlinkTarget;
359
362 private byte evaluationTime;
363
366 private boolean isStretchWithOverflow;
367
368 @SuppressWarnings("deprecation")
369 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
370 {
371 in.defaultReadObject();
372
373 if (linkType == null)
374 {
375 linkType = JRHyperlinkHelper.getLinkType(HyperlinkTypeEnum.getByValue(hyperlinkType));
376 }
377
378 if (linkTarget == null)
379 {
380 linkTarget = JRHyperlinkHelper.getLinkTarget(HyperlinkTargetEnum.getByValue(hyperlinkTarget));
381 }
382
383 if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_7_2)
384 {
385 evaluationTimeValue = EvaluationTimeEnum.getByValue(evaluationTime);
386 }
387
388 if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_6_11_0)
389 {
390 textAdjust = isStretchWithOverflow ? TextAdjustEnum.STRETCH_HEIGHT : TextAdjustEnum.CUT_TEXT;
391 }
392 }
393 }
394