KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > design > JRDesignTextField


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.design;
29
30 import java.io.IOException JavaDoc;
31 import java.io.ObjectInputStream JavaDoc;
32 import java.util.ArrayList JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35
36 import net.sf.jasperreports.engine.JRAbstractObjectFactory;
37 import net.sf.jasperreports.engine.JRAnchor;
38 import net.sf.jasperreports.engine.JRChild;
39 import net.sf.jasperreports.engine.JRConstants;
40 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
41 import net.sf.jasperreports.engine.JRExpression;
42 import net.sf.jasperreports.engine.JRExpressionCollector;
43 import net.sf.jasperreports.engine.JRGroup;
44 import net.sf.jasperreports.engine.JRHyperlink;
45 import net.sf.jasperreports.engine.JRHyperlinkHelper;
46 import net.sf.jasperreports.engine.JRHyperlinkParameter;
47 import net.sf.jasperreports.engine.JRTextField;
48 import net.sf.jasperreports.engine.util.JRStyleResolver;
49 import net.sf.jasperreports.engine.xml.JRXmlWriter;
50
51 //import java.text.Format;
52

53
54 /**
55  * @author Teodor Danciu (teodord@users.sourceforge.net)
56  * @version $Id: JRDesignTextField.java 1364 2006-08-31 18:13:20 +0300 (Thu, 31 Aug 2006) lucianc $
57  */

58 public class JRDesignTextField extends JRDesignTextElement implements JRTextField
59 {
60
61
62     /**
63      *
64      */

65     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
66
67     /**
68      *
69      */

70     protected boolean isStretchWithOverflow = false;
71     protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW;
72     protected String JavaDoc pattern = null;
73     protected Boolean JavaDoc isBlankWhenNull = null;
74     protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
75     protected String JavaDoc linkType;
76     protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
77     private List JavaDoc hyperlinkParameters;
78
79     /**
80      *
81      */

82     protected JRGroup evaluationGroup = null;
83     protected JRExpression expression = null;
84     protected JRExpression anchorNameExpression = null;
85     protected JRExpression hyperlinkReferenceExpression = null;
86     protected JRExpression hyperlinkAnchorExpression = null;
87     protected JRExpression hyperlinkPageExpression = null;
88     private JRExpression hyperlinkTooltipExpression;
89
90     /**
91      * The bookmark level for the anchor associated with this field.
92      * @see JRAnchor#getBookmarkLevel()
93      */

94     protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
95
96
97     /**
98      *
99      */

100     public JRDesignTextField()
101     {
102         super(null);
103         
104         hyperlinkParameters = new ArrayList JavaDoc();
105     }
106         
107     /**
108      *
109      */

110     public JRDesignTextField(JRDefaultStyleProvider defaultStyleProvider)
111     {
112         super(defaultStyleProvider);
113         
114         hyperlinkParameters = new ArrayList JavaDoc();
115     }
116         
117
118     /**
119      *
120      */

121     public boolean isStretchWithOverflow()
122     {
123         return this.isStretchWithOverflow;
124     }
125         
126     /**
127      *
128      */

129     public byte getEvaluationTime()
130     {
131         return this.evaluationTime;
132     }
133         
134     /**
135      *
136      */

137     public String JavaDoc getPattern()
138     {
139         return JRStyleResolver.getPattern(this);
140     }
141
142     public String JavaDoc getOwnPattern()
143     {
144         return this.pattern;
145     }
146         
147     /**
148      *
149      */

150     public boolean isBlankWhenNull()
151     {
152         return JRStyleResolver.isBlankWhenNull(this);
153     }
154
155     /**
156      *
157      */

158     public Boolean JavaDoc isOwnBlankWhenNull()
159     {
160         return isBlankWhenNull;
161     }
162
163     /**
164      *
165      */

166     public byte getHyperlinkType()
167     {
168         return JRHyperlinkHelper.getHyperlinkType(this);
169     }
170         
171     /**
172      *
173      */

174     public byte getHyperlinkTarget()
175     {
176         return this.hyperlinkTarget;
177     }
178         
179     /**
180      *
181      */

182     public JRGroup getEvaluationGroup()
183     {
184         return this.evaluationGroup;
185     }
186         
187     /**
188      *
189      */

190     public JRExpression getExpression()
191     {
192         return this.expression;
193     }
194
195     /**
196      *
197      */

198     public JRExpression getAnchorNameExpression()
199     {
200         return this.anchorNameExpression;
201     }
202
203     /**
204      *
205      */

206     public JRExpression getHyperlinkReferenceExpression()
207     {
208         return this.hyperlinkReferenceExpression;
209     }
210
211     /**
212      *
213      */

214     public JRExpression getHyperlinkAnchorExpression()
215     {
216         return this.hyperlinkAnchorExpression;
217     }
218
219     /**
220      *
221      */

222     public JRExpression getHyperlinkPageExpression()
223     {
224         return this.hyperlinkPageExpression;
225     }
226
227     /**
228      *
229      */

230     public void setStretchWithOverflow(boolean isStretch)
231     {
232         this.isStretchWithOverflow = isStretch;
233     }
234         
235     /**
236      *
237      */

238     public void setEvaluationTime(byte evaluationTime)
239     {
240         this.evaluationTime = evaluationTime;
241     }
242         
243     /**
244      *
245      */

246     public void setPattern(String JavaDoc pattern)
247     {
248         this.pattern = pattern;
249     }
250
251     /**
252      *
253      */

254     public void setBlankWhenNull(boolean isBlank)
255     {
256         this.isBlankWhenNull = isBlank ? Boolean.TRUE : Boolean.FALSE;
257     }
258
259     /**
260      *
261      */

262     public void setBlankWhenNull(Boolean JavaDoc isBlank)
263     {
264         this.isBlankWhenNull = isBlank;
265     }
266
267     /**
268      * Sets the link type as a built-in hyperlink type.
269      *
270      * @param hyperlinkType the built-in hyperlink type
271      * @see #getLinkType()
272      */

273     public void setHyperlinkType(byte hyperlinkType)
274     {
275         setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
276     }
277         
278     /**
279      *
280      */

281     public void setHyperlinkTarget(byte hyperlinkTarget)
282     {
283         this.hyperlinkTarget = hyperlinkTarget;
284     }
285         
286     /**
287      *
288      */

289     public void setEvaluationGroup(JRGroup evaluationGroup)
290     {
291         this.evaluationGroup = evaluationGroup;
292     }
293         
294     /**
295      *
296      */

297     public void setExpression(JRExpression expression)
298     {
299         this.expression = expression;
300     }
301
302     /**
303      *
304      */

305     public void setAnchorNameExpression(JRExpression anchorNameExpression)
306     {
307         this.anchorNameExpression = anchorNameExpression;
308     }
309
310     /**
311      *
312      */

313     public void setHyperlinkReferenceExpression(JRExpression hyperlinkReferenceExpression)
314     {
315         this.hyperlinkReferenceExpression = hyperlinkReferenceExpression;
316     }
317
318     /**
319      *
320      */

321     public void setHyperlinkAnchorExpression(JRExpression hyperlinkAnchorExpression)
322     {
323         this.hyperlinkAnchorExpression = hyperlinkAnchorExpression;
324     }
325
326     /**
327      *
328      */

329     public void setHyperlinkPageExpression(JRExpression hyperlinkPageExpression)
330     {
331         this.hyperlinkPageExpression = hyperlinkPageExpression;
332     }
333
334     /**
335      *
336      */

337     public JRChild getCopy(JRAbstractObjectFactory factory)
338     {
339         return factory.getTextField(this);
340     }
341
342     /**
343      *
344      */

345     public void collectExpressions(JRExpressionCollector collector)
346     {
347         collector.collect(this);
348     }
349
350     /**
351      *
352      */

353     public void writeXml(JRXmlWriter xmlWriter) throws IOException JavaDoc
354     {
355         xmlWriter.writeTextField(this);
356     }
357
358
359     public int getBookmarkLevel()
360     {
361         return bookmarkLevel;
362     }
363
364
365     /**
366      * Sets the boomark level for the anchor associated with this field.
367      *
368      * @param bookmarkLevel the bookmark level (starting from 1)
369      * or {@link JRAnchor#NO_BOOKMARK NO_BOOKMARK} if no bookmark should be created
370      */

371     public void setBookmarkLevel(int bookmarkLevel)
372     {
373         this.bookmarkLevel = bookmarkLevel;
374     }
375
376
377     public String JavaDoc getLinkType()
378     {
379         return linkType;
380     }
381
382
383     /**
384      * Sets the hyperlink type.
385      * <p>
386      * The type can be one of the built-in types
387      * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
388      * or can be an arbitrary type.
389      * </p>
390      * @param type the hyperlink type
391      */

392     public void setLinkType(String JavaDoc type)
393     {
394         this.linkType = type;
395     }
396
397
398     public JRHyperlinkParameter[] getHyperlinkParameters()
399     {
400         JRHyperlinkParameter[] parameters;
401         if (hyperlinkParameters.isEmpty())
402         {
403             parameters = null;
404         }
405         else
406         {
407             parameters = new JRHyperlinkParameter[hyperlinkParameters.size()];
408             hyperlinkParameters.toArray(parameters);
409         }
410         return parameters;
411     }
412     
413     
414     /**
415      * Returns the list of custom hyperlink parameters.
416      *
417      * @return the list of custom hyperlink parameters
418      */

419     public List JavaDoc getHyperlinkParametersList()
420     {
421         return hyperlinkParameters;
422     }
423     
424     
425     /**
426      * Adds a custom hyperlink parameter.
427      *
428      * @param parameter the parameter to add
429      */

430     public void addHyperlinkParameter(JRHyperlinkParameter parameter)
431     {
432         hyperlinkParameters.add(parameter);
433     }
434     
435
436     /**
437      * Removes a custom hyperlink parameter.
438      *
439      * @param parameter the parameter to remove
440      */

441     public void removeHyperlinkParameter(JRHyperlinkParameter parameter)
442     {
443         hyperlinkParameters.remove(parameter);
444     }
445     
446     
447     /**
448      * Removes a custom hyperlink parameter.
449      * <p>
450      * If multiple parameters having the specified name exist, all of them
451      * will be removed
452      * </p>
453      *
454      * @param parameterName the parameter name
455      */

456     public void removeHyperlinkParameter(String JavaDoc parameterName)
457     {
458         for (Iterator JavaDoc it = hyperlinkParameters.iterator(); it.hasNext();)
459         {
460             JRHyperlinkParameter parameter = (JRHyperlinkParameter) it.next();
461             if (parameter.getName() != null && parameter.getName().equals(parameterName))
462             {
463                 it.remove();
464             }
465         }
466     }
467     
468     
469     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
470     {
471         in.defaultReadObject();
472         normalizeLinkType();
473     }
474
475
476     protected void normalizeLinkType()
477     {
478         if (linkType == null)
479         {
480              linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
481         }
482         hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
483     }
484
485     
486     public JRExpression getHyperlinkTooltipExpression()
487     {
488         return hyperlinkTooltipExpression;
489     }
490
491     
492     /**
493      * Sets the expression which will be used to generate the hyperlink tooltip.
494      *
495      * @param hyperlinkTooltipExpression the expression which will be used to generate the hyperlink tooltip
496      * @see #getHyperlinkTooltipExpression()
497      */

498     public void setHyperlinkTooltipExpression(JRExpression hyperlinkTooltipExpression)
499     {
500         this.hyperlinkTooltipExpression = hyperlinkTooltipExpression;
501     }
502     
503 }
504
Popular Tags