KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > TextFieldReportElement


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * TextFieldReportElement.java
28  *
29  * Created on 24 maggio 2003, 10.22
30  *
31  */

32
33 package it.businesslogic.ireport;
34
35 import it.businesslogic.ireport.gui.MainFrame;
36
37 /**
38  *
39  * @author Administrator
40  */

41 public class TextFieldReportElement extends it.businesslogic.ireport.TextReportElement implements HyperLinkableReportElement {
42     
43     
44     public final static String JavaDoc PATTERN = "PATTERN";
45     public final static String JavaDoc DEFAULT_PATTERN = "";
46     
47     private String JavaDoc classExpression;
48     
49     private String JavaDoc group;
50     
51     private String JavaDoc evaluationTime;
52     
53     private boolean blankWhenNull;
54     
55     private boolean stretchWithOverflow;
56     
57     //private String pattern;
58

59     private String JavaDoc anchorNameExpression = "";
60     
61     private String JavaDoc hyperlinkAnchorExpression = "";
62     
63     private String JavaDoc hyperlinkPageExpression = "";
64     
65     private String JavaDoc hyperlinkReferenceExpression = "";
66     
67     private String JavaDoc hyperlinkType = "None";
68     
69     private int bookmarkLevel = 0;
70     
71     private java.util.List JavaDoc linkParameters = new java.util.ArrayList JavaDoc();
72     
73     static private java.util.List JavaDoc acceptedTextfieldClasses = null;
74     static {
75         acceptedTextfieldClasses = new java.util.ArrayList JavaDoc();
76
77         acceptedTextfieldClasses.add("java.lang.Boolean");
78         acceptedTextfieldClasses.add("java.lang.Byte");
79         acceptedTextfieldClasses.add("java.util.Date");
80         acceptedTextfieldClasses.add("java.sql.Timestamp");
81         acceptedTextfieldClasses.add("java.sql.Time");
82         acceptedTextfieldClasses.add("java.lang.Double");
83         acceptedTextfieldClasses.add("java.lang.Float");
84         acceptedTextfieldClasses.add("java.lang.Integer");
85         acceptedTextfieldClasses.add("java.lang.Long");
86         acceptedTextfieldClasses.add("java.lang.Short");
87         acceptedTextfieldClasses.add("java.math.BigDecimal");
88         acceptedTextfieldClasses.add("java.lang.Number");
89         acceptedTextfieldClasses.add("java.lang.String");
90     }
91     
92     
93     /** Creates a new instance of TextFieldReportElement */
94     public TextFieldReportElement(int x, int y, int width, int height)
95     {
96         super(x,y,width,height);
97                 this.setText("$F{Field}");
98                 //this.pattern = "";
99
this.stretchWithOverflow = false;
100                 this.blankWhenNull = false;
101                 this.group = "";
102                 this.evaluationTime = "Now";
103                 this.classExpression = "java.lang.String";
104                 this.hyperlinkType = "None";
105                 this.anchorNameExpression = "";
106                 
107                 setKey("textField");
108     }
109     
110     /** Getter for property blankWhenNull.
111      * @return Value of property blankWhenNull.
112      *
113      */

114     public boolean isBlankWhenNull() {
115         return blankWhenNull;
116     }
117     
118     /** Setter for property blankWhenNull.
119      * @param blankWhenNull New value of property blankWhenNull.
120      *
121      */

122     public void setBlankWhenNull(boolean blankWhenNull) {
123         this.blankWhenNull = blankWhenNull;
124     }
125     
126     /** Getter for property classExpression.
127      * @return Value of property classExpression.
128      *
129      */

130     public java.lang.String JavaDoc getClassExpression() {
131         return classExpression;
132     }
133     
134     /** Setter for property classExpression.
135      * @param classExpression New value of property classExpression.
136      *
137      */

138     public void setClassExpression(java.lang.String JavaDoc classExpression) {
139         this.classExpression = classExpression;
140     }
141     
142     
143     /** Setter for property classExpression.
144      * If newClass is not in
145      * java.lang.Boolean
146      * java.lang.Byte
147      * java.util.Date
148      * java.sql.Timestamp
149      * java.sql.Time
150      * java.lang.Double
151      * java.lang.Float
152      * java.lang.Integer
153      * java.lang.Long
154      * java.lang.Short
155      * java.math.BigDecimal
156      * java.lang.Number
157      * java.lang.String
158      * the method trys to find something of similar using getSuperClass
159      * it is used.
160      *
161      * In no solution is find, the type is set to java.lang.String an optionally is possible
162      * change the expression with something like ""+<exp>. This should be very rare...
163      * @param classExpression New value of property classExpression.
164      *
165      */

166     public void setMatchingClassExpression(java.lang.String JavaDoc newClassName, boolean adjustExpression) {
167         
168         if (!acceptedTextfieldClasses.contains(newClassName))
169         {
170             try {
171                 Class JavaDoc newClass = MainFrame.getMainInstance().getReportClassLoader().loadClass( newClassName );
172                 setMatchingClassExpression(newClass, adjustExpression);
173             } catch (Exception JavaDoc ex)
174             {
175                 ex.printStackTrace();
176             }
177         }
178         else
179         {
180             setClassExpression(newClassName);
181         }
182     }
183     
184     private void setMatchingClassExpression(Class JavaDoc newClass, boolean adjustExpression) {
185         
186         // try with the superclasss..
187
Class JavaDoc superClass = newClass.getSuperclass();
188
189         if (superClass == null)
190         {
191             this.classExpression = classExpression;
192             if (adjustExpression)
193             {
194                 this.setText("\"\"+" + getText());
195             }
196         }
197         else
198         {
199             setMatchingClassExpression(superClass.getName(), adjustExpression);
200         }
201     }
202     
203     
204     /** Getter for property evaluationTime.
205      * @return Value of property evaluationTime.
206      *
207      */

208     public java.lang.String JavaDoc getEvaluationTime() {
209         return evaluationTime;
210     }
211     
212     /** Setter for property evaluationTime.
213      * @param evaluationTime New value of property evaluationTime.
214      *
215      */

216     public void setEvaluationTime(java.lang.String JavaDoc evaluationTime) {
217         this.evaluationTime = evaluationTime;
218     }
219     
220     /** Getter for property group.
221      * @return Value of property group.
222      *
223      */

224     public java.lang.String JavaDoc getGroup() {
225         return group;
226     }
227     
228     /** Setter for property group.
229      * @param group New value of property group.
230      *
231      */

232     public void setGroup(java.lang.String JavaDoc group) {
233         this.group = group;
234     }
235     
236     /** Getter for property pattern.
237      * @return Value of property pattern.
238      *
239      */

240     public java.lang.String JavaDoc getPattern() {
241         if (getPropertyValue( PATTERN) == null)
242        {
243             // Look for a fgcolor in the stylesheet...
244
if (getStyle() != null)
245             {
246                return getStyle().getAttributeString( getStyle().ATTRIBUTE_pattern, DEFAULT_PATTERN, true);
247             }
248         }
249         return getStringValue( PATTERN, DEFAULT_PATTERN );
250     }
251     
252     /** Setter for property pattern.
253      * @param pattern New value of property pattern.
254      *
255      */

256     public void setPattern(java.lang.String JavaDoc pattern) {
257         setPropertyValue(PATTERN, pattern);
258     }
259     
260     /** Getter for property stretchWithOverflow.
261      * @return Value of property stretchWithOverflow.
262      *
263      */

264     public boolean isStretchWithOverflow() {
265         return stretchWithOverflow;
266     }
267     
268     /** Setter for property stretchWithOverflow.
269      * @param stretchWithOverflow New value of property stretchWithOverflow.
270      *
271      */

272     public void setStretchWithOverflow(boolean stretchWithOverflow) {
273         this.stretchWithOverflow = stretchWithOverflow;
274     }
275     
276     /** Getter for property anchorNameExpression.
277      * @return Value of property anchorNameExpression.
278      *
279      */

280     public java.lang.String JavaDoc getAnchorNameExpression() {
281         return anchorNameExpression;
282     }
283     
284     /** Setter for property anchorNameExpression.
285      * @param anchorNameExpression New value of property anchorNameExpression.
286      *
287      */

288     public void setAnchorNameExpression(java.lang.String JavaDoc anchorNameExpression) {
289         this.anchorNameExpression = anchorNameExpression;
290     }
291     
292     /** Getter for property hyperlinkAnchorExpression.
293      * @return Value of property hyperlinkAnchorExpression.
294      *
295      */

296     public java.lang.String JavaDoc getHyperlinkAnchorExpression() {
297         return hyperlinkAnchorExpression;
298     }
299     
300     /** Setter for property hyperlinkAnchorExpression.
301      * @param hyperlinkAnchorExpression New value of property hyperlinkAnchorExpression.
302      *
303      */

304     public void setHyperlinkAnchorExpression(java.lang.String JavaDoc hyperlinkAnchorExpression) {
305         this.hyperlinkAnchorExpression = hyperlinkAnchorExpression;
306     }
307     
308     /** Getter for property hyperlinkPageExpression.
309      * @return Value of property hyperlinkPageExpression.
310      *
311      */

312     public java.lang.String JavaDoc getHyperlinkPageExpression() {
313         return hyperlinkPageExpression;
314     }
315     
316     /** Setter for property hyperlinkPageExpression.
317      * @param hyperlinkPageExpression New value of property hyperlinkPageExpression.
318      *
319      */

320     public void setHyperlinkPageExpression(java.lang.String JavaDoc hyperlinkPageExpression) {
321         this.hyperlinkPageExpression = hyperlinkPageExpression;
322     }
323     
324     /** Getter for property hyperlinkReferenceExpression.
325      * @return Value of property hyperlinkReferenceExpression.
326      *
327      */

328     public java.lang.String JavaDoc getHyperlinkReferenceExpression() {
329         return hyperlinkReferenceExpression;
330     }
331     
332     /** Setter for property hyperlinkReferenceExpression.
333      * @param hyperlinkReferenceExpression New value of property hyperlinkReferenceExpression.
334      *
335      */

336     public void setHyperlinkReferenceExpression(java.lang.String JavaDoc hyperlinkReferenceExpression) {
337         this.hyperlinkReferenceExpression = hyperlinkReferenceExpression;
338     }
339     
340     /** Getter for property hyperlinkType.
341      * @return Value of property hyperlinkType.
342      *
343      */

344     public java.lang.String JavaDoc getHyperlinkType() {
345         return hyperlinkType;
346     }
347     
348     /** Setter for property hyperlinkType.
349      * @param hyperlinkType New value of property hyperlinkType.
350      *
351      */

352     public void setHyperlinkType(java.lang.String JavaDoc hyperlinkType) {
353         this.hyperlinkType = hyperlinkType;
354     }
355     
356     public ReportElement cloneMe()
357     {
358     TextFieldReportElement newReportElement = new TextFieldReportElement(position.x, position.y, width, height);
359     copyBaseReportElement(newReportElement, this);
360     return newReportElement;
361     }
362         
363     public void copyBaseReportElement(ReportElement destination, ReportElement source)
364         {
365                 super.copyBaseReportElement(destination, source);
366                 
367                 if (destination instanceof TextFieldReportElement &&
368                     source instanceof TextFieldReportElement )
369                 {
370                     destination.setPropertyValue(PATTERN, source.getPropertyValue(PATTERN));
371                     ((TextFieldReportElement)destination).setBlankWhenNull( ((TextFieldReportElement)source).isBlankWhenNull());
372                     ((TextFieldReportElement)destination).setClassExpression(new String JavaDoc( ((TextFieldReportElement)source).getClassExpression() ));
373                     ((TextFieldReportElement)destination).setEvaluationTime(new String JavaDoc( ((TextFieldReportElement)source).getEvaluationTime() ));
374                     ((TextFieldReportElement)destination).setGroup(new String JavaDoc( ((TextFieldReportElement)source).getGroup()));
375                     //((TextFieldReportElement)destination).setPattern(new String( ((TextFieldReportElement)source).getPattern() ));
376
((TextFieldReportElement)destination).setStretchWithOverflow( ((TextFieldReportElement)source).isStretchWithOverflow() );
377                     
378                     
379                     ((HyperLinkableReportElement)destination).setAnchorNameExpression(new String JavaDoc( ((HyperLinkableReportElement)source).getAnchorNameExpression() ));
380                     ((HyperLinkableReportElement)destination).setHyperlinkAnchorExpression(new String JavaDoc( ((HyperLinkableReportElement)source).getHyperlinkAnchorExpression() ));
381                     ((HyperLinkableReportElement)destination).setHyperlinkPageExpression(new String JavaDoc( ((HyperLinkableReportElement)source).getHyperlinkPageExpression() ));
382                     ((HyperLinkableReportElement)destination).setHyperlinkReferenceExpression(new String JavaDoc( ((HyperLinkableReportElement)source).getHyperlinkReferenceExpression() ));
383                     ((HyperLinkableReportElement)destination).setHyperlinkType(new String JavaDoc( ((HyperLinkableReportElement)source).getHyperlinkType() ));
384                 }
385         }
386     
387     protected String JavaDoc hyperlinkTarget = "Self";
388     /** Getter for property hyperlinkTarget.
389          * @return Value of property hyperlinkTarget.
390          *
391          */

392         public java.lang.String JavaDoc getHyperlinkTarget(){ return hyperlinkTarget; }
393         
394         /** Setter for property hyperlinkTarget.
395          * @param hyperlinkTarget New value of property hyperlinkTarget.
396          *
397          */

398         public void setHyperlinkTarget(java.lang.String JavaDoc hyperlinkTarget) { this.hyperlinkTarget = hyperlinkTarget; }
399
400     public int getBookmarkLevel() {
401         return bookmarkLevel;
402     }
403
404     public void setBookmarkLevel(int bookmarkLevel) {
405         this.bookmarkLevel = bookmarkLevel;
406     }
407
408     public void setStyle(Style style) {
409      
410         super.setStyle(style);
411         
412         if (style != null)
413         {
414             //this.setIsStyledText( style.getAttributeBoolean( style.ATTRIBUTE_isStyledText, isIsStyledText(), true));
415
this.setBlankWhenNull( style.getAttributeBoolean( style.ATTRIBUTE_isBlankWhenNull, isBlankWhenNull(), true));
416             //this.setPattern( style.getAttributeString( style.ATTRIBUTE_pattern, getPattern(), true));
417
}
418      }
419
420     public java.util.List JavaDoc getLinkParameters() {
421         return linkParameters;
422     }
423
424     public void setLinkParameters(java.util.List JavaDoc linkParameters) {
425         this.linkParameters = linkParameters;
426     }
427 }
428
Popular Tags