001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * TextElementFactory.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.elementfactory;
030:
031: import org.jfree.report.style.ElementStyleKeys;
032: import org.jfree.report.style.ElementStyleSheet;
033: import org.jfree.report.style.TextStyleKeys;
034: import org.jfree.report.style.TextWrap;
035: import org.jfree.report.style.VerticalTextAlign;
036: import org.jfree.report.style.WhitespaceCollapse;
037:
038: /**
039: * The text element factory is the abstract base class for all text element factory implementations. It provides common
040: * properties shared among all text elements.
041: *
042: * @author Thomas Morgner
043: */
044: public abstract class TextElementFactory extends ElementFactory {
045: /**
046: * The name of the font used to print the text.
047: */
048: private String fontName;
049: /**
050: * A flag defining whether to use the bold font style.
051: */
052: private Boolean bold;
053: /**
054: * A flag defining whether to use the italic font style.
055: */
056: private Boolean italic;
057: /**
058: * A flag defining whether to use the underline font style.
059: */
060: private Boolean underline;
061: /**
062: * A flag defining whether to use the strikethough font style.
063: */
064: private Boolean strikethrough;
065: /**
066: * A flag defining whether to embed the font used for the element in the target document.
067: */
068: private Boolean embedFont;
069: /**
070: * Defines the font size of the used font.
071: */
072: private Integer fontSize;
073: /**
074: * Defines the lineheight. The lineheight must be >= the font size, or it is ignored.
075: */
076: private Float lineHeight;
077:
078: /**
079: * Defines the font encoding used when writing the text.
080: */
081: private String encoding;
082:
083: /**
084: * Defines the vertical text alignment. The vertical text alignment controls how inline elements are positioned
085: * relative to each other.
086: *
087: * @see TextWrap
088: */
089: private VerticalTextAlign verticalTextAlignment;
090:
091: /**
092: * The reserved literal.
093: */
094: private String reservedLiteral;
095: /**
096: * A flag defining whether to remove leading and trailing whitespaces from text lines.
097: */
098: private Boolean trimTextContent;
099: /**
100: * A flag defining, whether the text should be autmaticly wrapped in Excel.
101: */
102: private Boolean wrapText;
103:
104: /**
105: * Defines how and when text-wrapping should occur inside a text element.
106: *
107: * @see TextWrap
108: */
109: private TextWrap wrap;
110:
111: /**
112: * Defines how to treat whitespaces in the text of a text-element.
113: *
114: * @see WhitespaceCollapse
115: */
116: private WhitespaceCollapse whitespaceCollapse;
117: /**
118: * Defines the maximum letter spacing for a text element. This property controls how the justify-alignment distributes
119: * extra space on a line.
120: */
121: private Float maximumLetterSpacing;
122: /**
123: * Defines the minimum letter spacing for a text element. This property controls how the justify-alignment distributes
124: * extra space on a line and controls how much extra space is applied between the characters of a text.
125: */
126: private Float minimumLetterSpacing;
127: /**
128: * Defines the optimum letter spacing for a text element. This property controls how the justify-alignment distributes
129: * extra space on a line.
130: */
131: private Float optimumLetterSpacing;
132:
133: /**
134: * Default Constructor.
135: */
136: protected TextElementFactory() {
137: }
138:
139: /**
140: * Returns the defined vertical text alignment for this element.
141: *
142: * @return the vertical text alignment property or null, if the property is not defined.
143: */
144: public VerticalTextAlign getVerticalTextAlignment() {
145: return verticalTextAlignment;
146: }
147:
148: /**
149: * Defines the vertical text alignment for this element.
150: *
151: * @param verticalTextAlignment the vertical text alignment property or null, if the property should not be defined.
152: */
153: public void setVerticalTextAlignment(
154: final VerticalTextAlign verticalTextAlignment) {
155: this .verticalTextAlignment = verticalTextAlignment;
156: }
157:
158: /**
159: * Returns how and when text-wrapping should occur inside a text element.
160: *
161: * @return the defined text-wrap property.
162: * @see TextWrap
163: */
164: public TextWrap getWrap() {
165: return wrap;
166: }
167:
168: /**
169: * Defines how and when text-wrapping should occur inside a text element.
170: *
171: * @param wrap the defined text-wrap property.
172: * @see TextWrap
173: */
174: public void setWrap(final TextWrap wrap) {
175: this .wrap = wrap;
176: }
177:
178: /**
179: * Returns how the layouter treats whitespaces in the text of a text-element.
180: *
181: * @return the white space collapse constant or null, if undefined.
182: * @see WhitespaceCollapse
183: */
184: public WhitespaceCollapse getWhitespaceCollapse() {
185: return whitespaceCollapse;
186: }
187:
188: /**
189: * Defines how to treat whitespaces in the text of a text-element.
190: *
191: * @param whitespaceCollapse the white space collapse constant or null, if undefined.
192: * @see WhitespaceCollapse
193: */
194: public void setWhitespaceCollapse(
195: final WhitespaceCollapse whitespaceCollapse) {
196: this .whitespaceCollapse = whitespaceCollapse;
197: }
198:
199: /**
200: * Returns the defined maximum letter spacing for a text element. This property controls how the justify-alignment
201: * distributes extra space on a line.
202: *
203: * @return the maximum letter spacing or null, if undefined.
204: */
205: public Float getMaximumLetterSpacing() {
206: return maximumLetterSpacing;
207: }
208:
209: /**
210: * Defines the maximum letter spacing for a text element. This property controls how the justify-alignment distributes
211: * extra space on a line.
212: *
213: * @param maximumLetterSpacing the maximum letter spacing.
214: */
215: public void setMaximumLetterSpacing(final Float maximumLetterSpacing) {
216: this .maximumLetterSpacing = maximumLetterSpacing;
217: }
218:
219: /**
220: * Returns the defined minimum letter spacing for a text element. This property controls how the justify-alignment
221: * distributes extra space on a line and controls how much extra space is applied between the characters of a text.
222: *
223: * @return the minimum letter spacing or null, if undefined.
224: */
225: public Float getMinimumLetterSpacing() {
226: return minimumLetterSpacing;
227: }
228:
229: /**
230: * Defines the minimum letter spacing for a text element. This property controls how the justify-alignment distributes
231: * extra space on a line and controls how much extra space is applied between the characters of a text.
232: *
233: * @param minimumLetterSpacing the minimum letter spacing or null, if undefined.
234: */
235: public void setMinimumLetterSpacing(final Float minimumLetterSpacing) {
236: this .minimumLetterSpacing = minimumLetterSpacing;
237: }
238:
239: /**
240: * Return optimum letter spacing for a text element. This property controls how the justify-alignment distributes
241: * extra space on a line.
242: *
243: * @return the optimum letter spacing or null, if undefined.
244: */
245: public Float getOptimumLetterSpacing() {
246: return optimumLetterSpacing;
247: }
248:
249: /**
250: * Defines the optimum letter spacing for a text element. This property controls how the justify-alignment distributes
251: * extra space on a line.
252: *
253: * @param optimumLetterSpacing the optimum letter spacing or null, if undefined.
254: */
255: public void setOptimumLetterSpacing(final Float optimumLetterSpacing) {
256: this .optimumLetterSpacing = optimumLetterSpacing;
257: }
258:
259: /**
260: * Returns the font embedding flag for the new text elements. Font embedding is only used in some output targets.
261: *
262: * @return the font embedding flag.
263: */
264: public Boolean getEmbedFont() {
265: return embedFont;
266: }
267:
268: /**
269: * Defines that the font should be embedded if possible.
270: *
271: * @param embedFont embedds the font if possible.
272: */
273: public void setEmbedFont(final Boolean embedFont) {
274: this .embedFont = embedFont;
275: }
276:
277: /**
278: * Returns the name of the font that should be used to print the text.
279: *
280: * @return the font name.
281: */
282: public String getFontName() {
283: return fontName;
284: }
285:
286: /**
287: * Defines the name of the font that should be used to print the text.
288: *
289: * @param fontName the name of the font.
290: */
291: public void setFontName(final String fontName) {
292: this .fontName = fontName;
293: }
294:
295: /**
296: * Returns the state of the bold flag for the font. This method may return null to indicate that that value should be
297: * inherited from the parents.
298: *
299: * @return the bold-flag.
300: */
301: public Boolean getBold() {
302: return bold;
303: }
304:
305: /**
306: * Defines the state of the bold flag for the font. This value may be set to null to indicate that that value should
307: * be inherited from the parents.
308: *
309: * @param bold the bold-flag.
310: */
311: public void setBold(final Boolean bold) {
312: this .bold = bold;
313: }
314:
315: /**
316: * Returns the state of the italic flag for the font. This method may return null to indicate that that value should
317: * be inherited from the parents.
318: *
319: * @return the italic-flag.
320: */
321: public Boolean getItalic() {
322: return italic;
323: }
324:
325: /**
326: * Defines the state of the italic flag for the font. This value may be set to null to indicate that that value should
327: * be inherited from the parents.
328: *
329: * @param italic the italic-flag.
330: */
331: public void setItalic(final Boolean italic) {
332: this .italic = italic;
333: }
334:
335: /**
336: * Returns the state of the underline flag for the font. This method may return null to indicate that that value
337: * should be inherited from the parents.
338: *
339: * @return the underline-flag.
340: */
341: public Boolean getUnderline() {
342: return underline;
343: }
344:
345: /**
346: * Defines the state of the underline flag for the font. This value may be set to null to indicate that that value
347: * should be inherited from the parents.
348: *
349: * @param underline the underline-flag.
350: */
351: public void setUnderline(final Boolean underline) {
352: this .underline = underline;
353: }
354:
355: /**
356: * Returns the state of the strike through flag for the font. This method may return null to indicate that that value
357: * should be inherited from the parents.
358: *
359: * @return the strike-through-flag.
360: */
361: public Boolean getStrikethrough() {
362: return strikethrough;
363: }
364:
365: /**
366: * Defines the state of the strike through flag for the font. This value may be set to null to indicate that that
367: * value should be inherited from the parents.
368: *
369: * @param strikethrough the strikethrough-flag.
370: */
371: public void setStrikethrough(final Boolean strikethrough) {
372: this .strikethrough = strikethrough;
373: }
374:
375: /**
376: * Returns the font size in points.
377: *
378: * @return the font size.
379: */
380: public Integer getFontSize() {
381: return fontSize;
382: }
383:
384: /**
385: * Returns the font size in points.
386: *
387: * @param fontSize the font size.
388: */
389: public void setFontSize(final Integer fontSize) {
390: this .fontSize = fontSize;
391: }
392:
393: /**
394: * Returns the lineheight defined for the text element. The lineheight must be greater than the font size, or this
395: * value will be ignored.
396: *
397: * @return the line height.
398: */
399: public Float getLineHeight() {
400: return lineHeight;
401: }
402:
403: /**
404: * Defines the lineheight defined for the text element. The lineheight must be greater than the font size, or this
405: * value will be ignored.
406: *
407: * @param lineHeight the line height.
408: */
409: public void setLineHeight(final Float lineHeight) {
410: this .lineHeight = lineHeight;
411: }
412:
413: /**
414: * Returns the font encoding used to write the text. This parameter is only used by some output targets and will be
415: * ignored otherwise.
416: *
417: * @return the font encoding.
418: */
419: public String getEncoding() {
420: return encoding;
421: }
422:
423: /**
424: * Defines the font encoding used to write the text. This parameter is only used by some output targets and will be
425: * ignored otherwise.
426: *
427: * @param encoding the font encoding.
428: */
429: public void setEncoding(final String encoding) {
430: this .encoding = encoding;
431: }
432:
433: /**
434: * Returns the defined reserved literal, which should be appended to the text to signal text, which was not completly
435: * printed.
436: *
437: * @return the reserved literal.
438: */
439: public String getReservedLiteral() {
440: return reservedLiteral;
441: }
442:
443: /**
444: * Defines the defined reserved literal, which should be appended to the text to signal text, which was not completly
445: * printed.
446: *
447: * @param reservedLiteral the reserved literal.
448: */
449: public void setReservedLiteral(final String reservedLiteral) {
450: this .reservedLiteral = reservedLiteral;
451: }
452:
453: /**
454: * Returns, whether the text lines should be trimmed.
455: *
456: * @return Boolean.TRUE, if the text should be trimmed, Boolean.FALSE if the text should never be trimmed or null, if
457: * the default should be applied.
458: */
459: public Boolean getTrimTextContent() {
460: return trimTextContent;
461: }
462:
463: /**
464: * Defines, whether the text lines should be trimmed.
465: *
466: * @param trimTextContent Boolean.TRUE, if the text should be trimmed, Boolean.FALSE if the text should never be
467: * trimmed or null, if the default should be applied.
468: */
469: public void setTrimTextContent(final Boolean trimTextContent) {
470: this .trimTextContent = trimTextContent;
471: }
472:
473: /**
474: * Returns, whether the text should be wrapped in Excel-cells.
475: *
476: * @return the wrap text flag.
477: */
478: public Boolean getWrapText() {
479: return wrapText;
480: }
481:
482: /**
483: * Defines, whether the text should be wrapped in excel cells.
484: *
485: * @param wrapText the wrap text flag.
486: */
487: public void setWrapText(final Boolean wrapText) {
488: this .wrapText = wrapText;
489: }
490:
491: /**
492: * Applies the defined element style to the given stylesheet. This is a helper function to reduce the code size of the
493: * implementors.
494: *
495: * @param style the stlyesheet.
496: */
497: protected void applyStyle(final ElementStyleSheet style) {
498: super.applyStyle(style);
499: style.setStyleProperty(TextStyleKeys.BOLD, getBold());
500: style.setStyleProperty(TextStyleKeys.EMBEDDED_FONT,
501: getEmbedFont());
502: style.setStyleProperty(TextStyleKeys.FONT, getFontName());
503: style.setStyleProperty(TextStyleKeys.FONTENCODING,
504: getEncoding());
505: style.setStyleProperty(TextStyleKeys.FONTSIZE, getFontSize());
506: style.setStyleProperty(TextStyleKeys.ITALIC, getItalic());
507: style.setStyleProperty(TextStyleKeys.LINEHEIGHT,
508: getLineHeight());
509: style.setStyleProperty(TextStyleKeys.STRIKETHROUGH,
510: getStrikethrough());
511: style
512: .setStyleProperty(TextStyleKeys.UNDERLINED,
513: getUnderline());
514: style.setStyleProperty(TextStyleKeys.RESERVED_LITERAL,
515: getReservedLiteral());
516: style.setStyleProperty(TextStyleKeys.TRIM_TEXT_CONTENT,
517: getTrimTextContent());
518:
519: style.setStyleProperty(TextStyleKeys.FONT_SMOOTH,
520: getFontSmooth());
521: style.setStyleProperty(TextStyleKeys.TEXT_WRAP, getWrap());
522: style.setStyleProperty(TextStyleKeys.X_MAX_LETTER_SPACING,
523: getMaximumLetterSpacing());
524: style.setStyleProperty(TextStyleKeys.X_MIN_LETTER_SPACING,
525: getMinimumLetterSpacing());
526: style.setStyleProperty(TextStyleKeys.X_OPTIMUM_LETTER_SPACING,
527: getOptimumLetterSpacing());
528: style.setStyleProperty(TextStyleKeys.VERTICAL_TEXT_ALIGNMENT,
529: getVerticalTextAlignment());
530: style.setStyleProperty(TextStyleKeys.WHITE_SPACE_COLLAPSE,
531: getWhitespaceCollapse());
532:
533: style.setStyleProperty(ElementStyleKeys.EXCEL_WRAP_TEXT,
534: getWrapText());
535: }
536: }
|