KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > base > JRBaseFont


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.base;
29
30 import java.awt.font.TextAttribute JavaDoc;
31 import java.io.Serializable JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import net.sf.jasperreports.engine.JRConstants;
35 import net.sf.jasperreports.engine.JRDefaultFontProvider;
36 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
37 import net.sf.jasperreports.engine.JRFont;
38 import net.sf.jasperreports.engine.JRReportFont;
39 import net.sf.jasperreports.engine.JRStyle;
40 import net.sf.jasperreports.engine.util.JRStyleResolver;
41 import net.sf.jasperreports.engine.util.JRTextAttribute;
42
43
44 /**
45  * @author Teodor Danciu (teodord@users.sourceforge.net)
46  * @version $Id: JRBaseFont.java 1229 2006-04-19 13:27:35 +0300 (Wed, 19 Apr 2006) teodord $
47  */

48 public class JRBaseFont implements JRFont, Serializable JavaDoc
49 {
50
51
52     /**
53      *
54      */

55     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
56
57     /**
58      *
59      */

60     protected JRDefaultFontProvider defaultFontProvider = null;
61
62     /**
63      *
64      */

65     protected JRReportFont reportFont = null;
66
67     protected String JavaDoc fontName = null;
68     protected Boolean JavaDoc isBold = null;
69     protected Boolean JavaDoc isItalic = null;
70     protected Boolean JavaDoc isUnderline = null;
71     protected Boolean JavaDoc isStrikeThrough = null;
72     protected Integer JavaDoc fontSize = null;
73     protected String JavaDoc pdfFontName = null;
74     protected String JavaDoc pdfEncoding = null;
75     protected Boolean JavaDoc isPdfEmbedded = null;
76
77
78     /**
79      *
80      */

81     public JRBaseFont()
82     {
83     }
84         
85
86     /**
87      *
88      */

89     public JRBaseFont(Map JavaDoc attributes)
90     {
91         String JavaDoc fontNameAttr = (String JavaDoc)attributes.get(TextAttribute.FAMILY);
92         if (fontNameAttr != null)
93         {
94             setFontName(fontNameAttr);
95         }
96         
97         Object JavaDoc bold = attributes.get(TextAttribute.WEIGHT);
98         if (bold != null)
99         {
100             setBold(TextAttribute.WEIGHT_BOLD.equals(bold));
101         }
102
103         Object JavaDoc italic = attributes.get(TextAttribute.POSTURE);
104         if (italic != null)
105         {
106             setItalic(TextAttribute.POSTURE_OBLIQUE.equals(italic));
107         }
108
109         Float JavaDoc sizeAttr = (Float JavaDoc)attributes.get(TextAttribute.SIZE);
110         if (sizeAttr != null)
111         {
112             setFontSize(sizeAttr.intValue());
113         }
114         
115         Object JavaDoc underline = attributes.get(TextAttribute.UNDERLINE);
116         if (underline != null)
117         {
118             setUnderline(TextAttribute.UNDERLINE_ON.equals(underline));
119         }
120
121         Object JavaDoc strikeThrough = attributes.get(TextAttribute.STRIKETHROUGH);
122         if (strikeThrough != null)
123         {
124             setStrikeThrough(TextAttribute.STRIKETHROUGH_ON.equals(strikeThrough));
125         }
126
127         String JavaDoc pdfFontNameAttr = (String JavaDoc)attributes.get(JRTextAttribute.PDF_FONT_NAME);
128         if (pdfFontNameAttr != null)
129         {
130             setPdfFontName(pdfFontNameAttr);
131         }
132         
133         String JavaDoc pdfEncodingAttr = (String JavaDoc)attributes.get(JRTextAttribute.PDF_ENCODING);
134         if (pdfEncodingAttr != null)
135         {
136             setPdfEncoding(pdfEncodingAttr);
137         }
138         
139         Boolean JavaDoc isPdfEmbeddedAttr = (Boolean JavaDoc)attributes.get(JRTextAttribute.IS_PDF_EMBEDDED);
140         if (isPdfEmbeddedAttr != null)
141         {
142             setPdfEmbedded(isPdfEmbeddedAttr);
143         }
144     }
145         
146
147     /**
148      *
149      */

150     protected JRBaseFont(JRDefaultFontProvider defaultFontProvider)
151     {
152         this.defaultFontProvider = defaultFontProvider;
153     }
154         
155
156     /**
157      *
158      */

159     public JRBaseFont(
160         JRDefaultFontProvider defaultFontProvider,
161         JRReportFont reportFont,
162         JRFont font
163         )
164     {
165         this.defaultFontProvider = defaultFontProvider;
166         
167         this.reportFont = reportFont;
168         
169         fontName = font.getOwnFontName();
170         isBold = font.isOwnBold();
171         isItalic = font.isOwnItalic();
172         isUnderline = font.isOwnUnderline();
173         isStrikeThrough = font.isOwnStrikeThrough();
174         fontSize = font.getOwnFontSize();
175         pdfFontName = font.getOwnPdfFontName();
176         pdfEncoding = font.getOwnPdfEncoding();
177         isPdfEmbedded = font.isOwnPdfEmbedded();
178     }
179         
180
181     /**
182      *
183      */

184     public JRDefaultFontProvider getDefaultFontProvider()
185     {
186         return defaultFontProvider;
187     }
188
189     /**
190      *
191      */

192     public JRDefaultStyleProvider getDefaultStyleProvider()
193     {
194         return null;
195     }
196
197     /**
198      *
199      */

200     public JRStyle getStyle()
201     {
202         return null;
203     }
204
205     /**
206      *
207      */

208     public JRReportFont getReportFont()
209     {
210         return reportFont;
211     }
212     
213     /**
214      *
215      */

216     public void setReportFont(JRReportFont reportFont)
217     {
218         this.reportFont = reportFont;
219     }
220
221     /**
222      *
223      */

224     public String JavaDoc getFontName()
225     {
226         return JRStyleResolver.getFontName(this);
227     }
228     
229     /**
230      *
231      */

232     public String JavaDoc getOwnFontName()
233     {
234         return fontName;
235     }
236     
237     /**
238      *
239      */

240     public void setFontName(String JavaDoc fontName)
241     {
242         this.fontName = fontName;
243     }
244     
245
246     /**
247      *
248      */

249     public boolean isBold()
250     {
251         return JRStyleResolver.isBold(this);
252     }
253     
254     /**
255      *
256      */

257     public Boolean JavaDoc isOwnBold()
258     {
259         return isBold;
260     }
261     
262     /**
263      *
264      */

265     public void setBold(boolean isBold)
266     {
267         setBold(isBold ? Boolean.TRUE : Boolean.FALSE);
268     }
269
270     /**
271      * Alternative setBold method which allows also to reset
272      * the "own" isBold property.
273      */

274     public void setBold(Boolean JavaDoc isBold)
275     {
276         this.isBold = isBold;
277     }
278
279     
280     /**
281      *
282      */

283     public boolean isItalic()
284     {
285         return JRStyleResolver.isItalic(this);
286     }
287     
288     /**
289      *
290      */

291     public Boolean JavaDoc isOwnItalic()
292     {
293         return isItalic;
294     }
295     
296     /**
297      *
298      */

299     public void setItalic(boolean isItalic)
300     {
301         setItalic(isItalic ? Boolean.TRUE : Boolean.FALSE);
302     }
303     
304     /**
305      * Alternative setItalic method which allows also to reset
306      * the "own" isItalic property.
307      */

308     public void setItalic(Boolean JavaDoc isItalic)
309     {
310         this.isItalic = isItalic;
311     }
312     
313     /**
314      *
315      */

316     public boolean isUnderline()
317     {
318         return JRStyleResolver.isUnderline(this);
319     }
320     
321     /**
322      *
323      */

324     public Boolean JavaDoc isOwnUnderline()
325     {
326         return isUnderline;
327     }
328     
329     /**
330      *
331      */

332     public void setUnderline(boolean isUnderline)
333     {
334         setUnderline(isUnderline ? Boolean.TRUE : Boolean.FALSE);
335     }
336     
337     /**
338      * Alternative setUnderline method which allows also to reset
339      * the "own" isUnderline property.
340      */

341     public void setUnderline(Boolean JavaDoc isUnderline)
342     {
343         this.isUnderline = isUnderline;
344     }
345
346     /**
347      *
348      */

349     public boolean isStrikeThrough()
350     {
351         return JRStyleResolver.isStrikeThrough(this);
352     }
353     
354     /**
355      *
356      */

357     public Boolean JavaDoc isOwnStrikeThrough()
358     {
359         return isStrikeThrough;
360     }
361     
362     /**
363      *
364      */

365     public void setStrikeThrough(boolean isStrikeThrough)
366     {
367         setStrikeThrough(isStrikeThrough ? Boolean.TRUE : Boolean.FALSE);
368     }
369
370     /**
371      * Alternative setStrikeThrough method which allows also to reset
372      * the "own" isStrikeThrough property.
373      */

374     public void setStrikeThrough(Boolean JavaDoc isStrikeThrough)
375     {
376         this.isStrikeThrough = isStrikeThrough;
377     }
378
379     /**
380      *
381      */

382     public int getFontSize()
383     {
384         return JRStyleResolver.getFontSize(this);
385     }
386     
387     /**
388      *
389      */

390     public Integer JavaDoc getOwnFontSize()
391     {
392         return fontSize;
393     }
394     
395     /**
396      *
397      */

398     public void setFontSize(int fontSize)
399     {
400         setFontSize(new Integer JavaDoc(fontSize));
401     }
402
403     /**
404      * Alternative setSize method which allows also to reset
405      * the "own" size property.
406      */

407     public void setFontSize(Integer JavaDoc fontSize)
408     {
409         this.fontSize = fontSize;
410     }
411
412     /**
413      * @deprecated Replaced by {@link #getFontSize()}.
414      */

415     public int getSize()
416     {
417         return getFontSize();
418     }
419     
420     /**
421      * @deprecated Replaced by {@link #getOwnFontSize()}.
422      */

423     public Integer JavaDoc getOwnSize()
424     {
425         return getOwnFontSize();
426     }
427     
428     /**
429      * @deprecated Replaced by {@link #setFontSize(int)}.
430      */

431     public void setSize(int size)
432     {
433         setFontSize(size);
434     }
435
436     /**
437      * @deprecated Replaced by {@link #setFontSize(Integer)}.
438      */

439     public void setSize(Integer JavaDoc size)
440     {
441         setFontSize(size)
442 ; }
443
444     /**
445      *
446      */

447     public String JavaDoc getPdfFontName()
448     {
449         return JRStyleResolver.getPdfFontName(this);
450     }
451
452     /**
453      *
454      */

455     public String JavaDoc getOwnPdfFontName()
456     {
457         return pdfFontName;
458     }
459     
460     /**
461      *
462      */

463     public void setPdfFontName(String JavaDoc pdfFontName)
464     {
465         this.pdfFontName = pdfFontName;
466     }
467
468     
469     /**
470      *
471      */

472     public String JavaDoc getPdfEncoding()
473     {
474         return JRStyleResolver.getPdfEncoding(this);
475     }
476     
477     /**
478      *
479      */

480     public String JavaDoc getOwnPdfEncoding()
481     {
482         return pdfEncoding;
483     }
484     
485     /**
486      *
487      */

488     public void setPdfEncoding(String JavaDoc pdfEncoding)
489     {
490         this.pdfEncoding = pdfEncoding;
491     }
492
493
494     /**
495      *
496      */

497     public boolean isPdfEmbedded()
498     {
499         return JRStyleResolver.isPdfEmbedded(this);
500     }
501
502     /**
503      *
504      */

505     public Boolean JavaDoc isOwnPdfEmbedded()
506     {
507         return isPdfEmbedded;
508     }
509     
510     /**
511      *
512      */

513     public void setPdfEmbedded(boolean isPdfEmbedded)
514     {
515         setPdfEmbedded(isPdfEmbedded ? Boolean.TRUE : Boolean.FALSE);
516     }
517     
518     /**
519      * Alternative setPdfEmbedded method which allows also to reset
520      * the "own" isPdfEmbedded property.
521      */

522     public void setPdfEmbedded(Boolean JavaDoc isPdfEmbedded)
523     {
524         this.isPdfEmbedded = isPdfEmbedded;
525     }
526
527     
528 }
529
Popular Tags