001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * 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,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.base;
029:
030: import java.awt.Color;
031:
032: import net.sf.jasperreports.engine.JRBox;
033: import net.sf.jasperreports.engine.JRConstants;
034: import net.sf.jasperreports.engine.JRFont;
035: import net.sf.jasperreports.engine.JRReportFont;
036: import net.sf.jasperreports.engine.JRStyle;
037: import net.sf.jasperreports.engine.JRTextElement;
038: import net.sf.jasperreports.engine.util.JRStyleResolver;
039:
040: /**
041: * This class provides functionality common to text elements. It provides implementation for the methods described
042: * in <tt>JRTextElement</tt>.
043: * @author Teodor Danciu (teodord@users.sourceforge.net)
044: * @version $Id: JRBaseTextElement.java 1229 2006-04-19 10:27:35Z teodord $
045: */
046: public abstract class JRBaseTextElement extends JRBaseElement implements
047: JRTextElement {
048:
049: /**
050: *
051: */
052: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
053:
054: /**
055: *
056: */
057: protected Byte horizontalAlignment;
058: protected Byte verticalAlignment;
059: protected Byte rotation;
060: protected Byte lineSpacing;
061: protected Boolean isStyledText;
062:
063: /**
064: *
065: */
066: protected Byte border;
067: protected Byte topBorder = null;
068: protected Byte leftBorder = null;
069: protected Byte bottomBorder = null;
070: protected Byte rightBorder = null;
071: protected Color borderColor = null;
072: protected Color topBorderColor = null;
073: protected Color leftBorderColor = null;
074: protected Color bottomBorderColor = null;
075: protected Color rightBorderColor = null;
076: protected Integer padding;
077: protected Integer topPadding = null;
078: protected Integer leftPadding = null;
079: protected Integer bottomPadding = null;
080: protected Integer rightPadding = null;
081:
082: protected JRReportFont reportFont = null;
083: protected String fontName = null;
084: protected Boolean isBold = null;
085: protected Boolean isItalic = null;
086: protected Boolean isUnderline = null;
087: protected Boolean isStrikeThrough = null;
088: protected Integer fontSize = null;
089: protected String pdfFontName = null;
090: protected String pdfEncoding = null;
091: protected Boolean isPdfEmbedded = null;
092:
093: /**
094: * Initializes properties that are specific to text elements. Common properties are initialized by its
095: * parent constructor.
096: * @param textElement an element whose properties are copied to this element. Usually it is a
097: * {@link net.sf.jasperreports.engine.design.JRDesignTextElement} that must be transformed into an
098: * <tt>JRBaseTextElement</tt> at compile time.
099: * @param factory a factory used in the compile process
100: */
101: protected JRBaseTextElement(JRTextElement textElement,
102: JRBaseObjectFactory factory) {
103: super (textElement, factory);
104:
105: horizontalAlignment = textElement.getOwnHorizontalAlignment();
106: verticalAlignment = textElement.getOwnVerticalAlignment();
107: rotation = textElement.getOwnRotation();
108: lineSpacing = textElement.getOwnLineSpacing();
109: isStyledText = textElement.isOwnStyledText();
110:
111: border = textElement.getOwnBorder();
112: topBorder = textElement.getOwnTopBorder();
113: leftBorder = textElement.getOwnLeftBorder();
114: bottomBorder = textElement.getOwnBottomBorder();
115: rightBorder = textElement.getOwnRightBorder();
116: borderColor = textElement.getOwnBorderColor();
117: topBorderColor = textElement.getOwnTopBorderColor();
118: leftBorderColor = textElement.getOwnLeftBorderColor();
119: bottomBorderColor = textElement.getOwnBottomBorderColor();
120: rightBorderColor = textElement.getOwnRightBorderColor();
121: padding = textElement.getOwnPadding();
122: topPadding = textElement.getOwnTopPadding();
123: leftPadding = textElement.getOwnLeftPadding();
124: bottomPadding = textElement.getOwnBottomPadding();
125: rightPadding = textElement.getOwnRightPadding();
126:
127: reportFont = factory.getReportFont(textElement.getReportFont());
128:
129: fontName = textElement.getOwnFontName();
130: isBold = textElement.isOwnBold();
131: isItalic = textElement.isOwnItalic();
132: isUnderline = textElement.isOwnUnderline();
133: isStrikeThrough = textElement.isOwnStrikeThrough();
134: fontSize = textElement.getOwnFontSize();
135: pdfFontName = textElement.getOwnPdfFontName();
136: pdfEncoding = textElement.getOwnPdfEncoding();
137: isPdfEmbedded = textElement.isOwnPdfEmbedded();
138: }
139:
140: /**
141: *
142: */
143: protected JRFont getBaseFont() {
144: if (reportFont != null)
145: return reportFont;
146: if (defaultStyleProvider != null)
147: return defaultStyleProvider.getDefaultFont();
148: return null;
149: }
150:
151: /**
152: * @deprecated Replaced by {@link #getHorizontalAlignment()}.
153: */
154: public byte getTextAlignment() {
155: if (horizontalAlignment == null) {
156: JRStyle style = getBaseStyle();
157: if (style != null && style.getHorizontalAlignment() != null)
158: return style.getHorizontalAlignment().byteValue();
159: return HORIZONTAL_ALIGN_LEFT;
160: }
161: return horizontalAlignment.byteValue();
162: }
163:
164: /**
165: * @deprecated Replaced by {@link #setHorizontalAlignment(byte)}.
166: */
167: public void setTextAlignment(byte horizontalAlignment) {
168: this .horizontalAlignment = new Byte(horizontalAlignment);
169: }
170:
171: /**
172: *
173: */
174: public byte getHorizontalAlignment() {
175: return JRStyleResolver.getHorizontalAlignment(this );
176: }
177:
178: public Byte getOwnHorizontalAlignment() {
179: return horizontalAlignment;
180: }
181:
182: /**
183: *
184: */
185: public void setHorizontalAlignment(byte horizontalAlignment) {
186: this .horizontalAlignment = new Byte(horizontalAlignment);
187: }
188:
189: /**
190: *
191: */
192: public void setHorizontalAlignment(Byte horizontalAlignment) {
193: this .horizontalAlignment = horizontalAlignment;
194: }
195:
196: /**
197: *
198: */
199: public byte getVerticalAlignment() {
200: return JRStyleResolver.getVerticalAlignment(this );
201: }
202:
203: public Byte getOwnVerticalAlignment() {
204: return verticalAlignment;
205: }
206:
207: /**
208: *
209: */
210: public void setVerticalAlignment(byte verticalAlignment) {
211: this .verticalAlignment = new Byte(verticalAlignment);
212: }
213:
214: /**
215: *
216: */
217: public void setVerticalAlignment(Byte verticalAlignment) {
218: this .verticalAlignment = verticalAlignment;
219: }
220:
221: /**
222: *
223: */
224: public byte getRotation() {
225: return JRStyleResolver.getRotation(this );
226: }
227:
228: public Byte getOwnRotation() {
229: return rotation;
230: }
231:
232: /**
233: *
234: */
235: public void setRotation(byte rotation) {
236: this .rotation = new Byte(rotation);
237: }
238:
239: /**
240: *
241: */
242: public void setRotation(Byte rotation) {
243: this .rotation = rotation;
244: }
245:
246: /**
247: *
248: */
249: public byte getLineSpacing() {
250: return JRStyleResolver.getLineSpacing(this );
251: }
252:
253: public Byte getOwnLineSpacing() {
254: return lineSpacing;
255: }
256:
257: /**
258: *
259: */
260: public void setLineSpacing(byte lineSpacing) {
261: this .lineSpacing = new Byte(lineSpacing);
262: }
263:
264: /**
265: *
266: */
267: public void setLineSpacing(Byte lineSpacing) {
268: this .lineSpacing = lineSpacing;
269: }
270:
271: /**
272: *
273: */
274: public boolean isStyledText() {
275: return JRStyleResolver.isStyledText(this );
276: }
277:
278: public Boolean isOwnStyledText() {
279: return isStyledText;
280: }
281:
282: /**
283: *
284: */
285: public void setStyledText(boolean isStyledText) {
286: setStyledText(isStyledText ? Boolean.TRUE : Boolean.FALSE);
287: }
288:
289: /**
290: *
291: */
292: public void setStyledText(Boolean isStyledText) {
293: this .isStyledText = isStyledText;
294: }
295:
296: /**
297: * @deprecated
298: */
299: public JRBox getBox() {
300: return this ;
301: }
302:
303: /**
304: * @deprecated
305: */
306: public JRFont getFont() {
307: return this ;
308: }
309:
310: /**
311: *
312: */
313: public byte getMode() {
314: return JRStyleResolver.getMode(this , MODE_TRANSPARENT);
315: }
316:
317: /**
318: *
319: */
320: public byte getBorder() {
321: return JRStyleResolver.getBorder(this );
322: }
323:
324: /**
325: *
326: */
327: public Byte getOwnBorder() {
328: return border;
329: }
330:
331: /**
332: *
333: */
334: public void setBorder(byte border) {
335: this .border = new Byte(border);
336: }
337:
338: /**
339: *
340: */
341: public void setBorder(Byte border) {
342: this .border = border;
343: }
344:
345: /**
346: *
347: */
348: public Color getBorderColor() {
349: return JRStyleResolver.getBorderColor(this , getForecolor());
350: }
351:
352: public Color getOwnBorderColor() {
353: return borderColor;
354: }
355:
356: /**
357: *
358: */
359: public void setBorderColor(Color borderColor) {
360: this .borderColor = borderColor;
361: }
362:
363: /**
364: *
365: */
366: public int getPadding() {
367: return JRStyleResolver.getPadding(this );
368: }
369:
370: public Integer getOwnPadding() {
371: return padding;
372: }
373:
374: /**
375: *
376: */
377: public void setPadding(int padding) {
378: this .padding = new Integer(padding);
379: }
380:
381: /**
382: *
383: */
384: public void setPadding(Integer padding) {
385: this .padding = padding;
386: }
387:
388: /**
389: *
390: */
391: public byte getTopBorder() {
392: return JRStyleResolver.getTopBorder(this );
393: }
394:
395: /**
396: *
397: */
398: public Byte getOwnTopBorder() {
399: return topBorder;
400: }
401:
402: /**
403: *
404: */
405: public void setTopBorder(byte topBorder) {
406: this .topBorder = new Byte(topBorder);
407: }
408:
409: /**
410: *
411: */
412: public void setTopBorder(Byte topBorder) {
413: this .topBorder = topBorder;
414: }
415:
416: /**
417: *
418: */
419: public Color getTopBorderColor() {
420: return JRStyleResolver.getTopBorderColor(this , getForecolor());
421: }
422:
423: /**
424: *
425: */
426: public Color getOwnTopBorderColor() {
427: return topBorderColor;
428: }
429:
430: /**
431: *
432: */
433: public void setTopBorderColor(Color topBorderColor) {
434: this .topBorderColor = topBorderColor;
435: }
436:
437: /**
438: *
439: */
440: public int getTopPadding() {
441: return JRStyleResolver.getTopPadding(this );
442: }
443:
444: /**
445: *
446: */
447: public Integer getOwnTopPadding() {
448: return topPadding;
449: }
450:
451: /**
452: *
453: */
454: public void setTopPadding(int topPadding) {
455: this .topPadding = new Integer(topPadding);
456: }
457:
458: /**
459: *
460: */
461: public void setTopPadding(Integer topPadding) {
462: this .topPadding = topPadding;
463: }
464:
465: /**
466: *
467: */
468: public byte getLeftBorder() {
469: return JRStyleResolver.getLeftBorder(this );
470: }
471:
472: /**
473: *
474: */
475: public Byte getOwnLeftBorder() {
476: return leftBorder;
477: }
478:
479: /**
480: *
481: */
482: public void setLeftBorder(byte leftBorder) {
483: this .leftBorder = new Byte(leftBorder);
484: }
485:
486: /**
487: *
488: */
489: public void setLeftBorder(Byte leftBorder) {
490: this .leftBorder = leftBorder;
491: }
492:
493: /**
494: *
495: */
496: public Color getLeftBorderColor() {
497: return JRStyleResolver.getLeftBorderColor(this , getForecolor());
498: }
499:
500: /**
501: *
502: */
503: public Color getOwnLeftBorderColor() {
504: return leftBorderColor;
505: }
506:
507: /**
508: *
509: */
510: public void setLeftBorderColor(Color leftBorderColor) {
511: this .leftBorderColor = leftBorderColor;
512: }
513:
514: /**
515: *
516: */
517: public int getLeftPadding() {
518: return JRStyleResolver.getLeftPadding(this );
519: }
520:
521: /**
522: *
523: */
524: public Integer getOwnLeftPadding() {
525: return leftPadding;
526: }
527:
528: /**
529: *
530: */
531: public void setLeftPadding(int leftPadding) {
532: this .leftPadding = new Integer(leftPadding);
533: }
534:
535: /**
536: *
537: */
538: public void setLeftPadding(Integer leftPadding) {
539: this .leftPadding = leftPadding;
540: }
541:
542: /**
543: *
544: */
545: public byte getBottomBorder() {
546: return JRStyleResolver.getBottomBorder(this );
547: }
548:
549: /**
550: *
551: */
552: public Byte getOwnBottomBorder() {
553: return bottomBorder;
554: }
555:
556: /**
557: *
558: */
559: public void setBottomBorder(byte bottomBorder) {
560: this .bottomBorder = new Byte(bottomBorder);
561: }
562:
563: /**
564: *
565: */
566: public void setBottomBorder(Byte bottomBorder) {
567: this .bottomBorder = bottomBorder;
568: }
569:
570: /**
571: *
572: */
573: public Color getBottomBorderColor() {
574: return JRStyleResolver.getBottomBorderColor(this ,
575: getForecolor());
576: }
577:
578: /**
579: *
580: */
581: public Color getOwnBottomBorderColor() {
582: return bottomBorderColor;
583: }
584:
585: /**
586: *
587: */
588: public void setBottomBorderColor(Color bottomBorderColor) {
589: this .bottomBorderColor = bottomBorderColor;
590: }
591:
592: /**
593: *
594: */
595: public int getBottomPadding() {
596: return JRStyleResolver.getBottomPadding(this );
597: }
598:
599: /**
600: *
601: */
602: public Integer getOwnBottomPadding() {
603: return bottomPadding;
604: }
605:
606: /**
607: *
608: */
609: public void setBottomPadding(int bottomPadding) {
610: this .bottomPadding = new Integer(bottomPadding);
611: }
612:
613: /**
614: *
615: */
616: public void setBottomPadding(Integer bottomPadding) {
617: this .bottomPadding = bottomPadding;
618: }
619:
620: /**
621: *
622: */
623: public byte getRightBorder() {
624: return JRStyleResolver.getRightBorder(this );
625: }
626:
627: /**
628: *
629: */
630: public Byte getOwnRightBorder() {
631: return rightBorder;
632: }
633:
634: /**
635: *
636: */
637: public void setRightBorder(byte rightBorder) {
638: this .rightBorder = new Byte(rightBorder);
639: }
640:
641: /**
642: *
643: */
644: public void setRightBorder(Byte rightBorder) {
645: this .rightBorder = rightBorder;
646: }
647:
648: /**
649: *
650: */
651: public Color getRightBorderColor() {
652: return JRStyleResolver
653: .getRightBorderColor(this , getForecolor());
654: }
655:
656: /**
657: *
658: */
659: public Color getOwnRightBorderColor() {
660: return rightBorderColor;
661: }
662:
663: /**
664: *
665: */
666: public void setRightBorderColor(Color rightBorderColor) {
667: this .rightBorderColor = rightBorderColor;
668: }
669:
670: /**
671: *
672: */
673: public int getRightPadding() {
674: return JRStyleResolver.getRightPadding(this );
675: }
676:
677: /**
678: *
679: */
680: public Integer getOwnRightPadding() {
681: return rightPadding;
682: }
683:
684: /**
685: *
686: */
687: public void setRightPadding(int rightPadding) {
688: this .rightPadding = new Integer(rightPadding);
689: }
690:
691: /**
692: *
693: */
694: public void setRightPadding(Integer rightPadding) {
695: this .rightPadding = rightPadding;
696: }
697:
698: /**
699: *
700: */
701: public JRReportFont getReportFont() {
702: return reportFont;
703: }
704:
705: /**
706: *
707: */
708: public void setReportFont(JRReportFont reportFont) {
709: this .reportFont = reportFont;
710: }
711:
712: /**
713: *
714: */
715: public String getFontName() {
716: return JRStyleResolver.getFontName(this );
717: }
718:
719: /**
720: *
721: */
722: public String getOwnFontName() {
723: return fontName;
724: }
725:
726: /**
727: *
728: */
729: public void setFontName(String fontName) {
730: this .fontName = fontName;
731: }
732:
733: /**
734: *
735: */
736: public boolean isBold() {
737: return JRStyleResolver.isBold(this );
738: }
739:
740: /**
741: *
742: */
743: public Boolean isOwnBold() {
744: return isBold;
745: }
746:
747: /**
748: *
749: */
750: public void setBold(boolean isBold) {
751: setBold(isBold ? Boolean.TRUE : Boolean.FALSE);
752: }
753:
754: /**
755: * Alternative setBold method which allows also to reset
756: * the "own" isBold property.
757: */
758: public void setBold(Boolean isBold) {
759: this .isBold = isBold;
760: }
761:
762: /**
763: *
764: */
765: public boolean isItalic() {
766: return JRStyleResolver.isItalic(this );
767: }
768:
769: /**
770: *
771: */
772: public Boolean isOwnItalic() {
773: return isItalic;
774: }
775:
776: /**
777: *
778: */
779: public void setItalic(boolean isItalic) {
780: setItalic(isItalic ? Boolean.TRUE : Boolean.FALSE);
781: }
782:
783: /**
784: * Alternative setItalic method which allows also to reset
785: * the "own" isItalic property.
786: */
787: public void setItalic(Boolean isItalic) {
788: this .isItalic = isItalic;
789: }
790:
791: /**
792: *
793: */
794: public boolean isUnderline() {
795: return JRStyleResolver.isUnderline(this );
796: }
797:
798: /**
799: *
800: */
801: public Boolean isOwnUnderline() {
802: return isUnderline;
803: }
804:
805: /**
806: *
807: */
808: public void setUnderline(boolean isUnderline) {
809: setUnderline(isUnderline ? Boolean.TRUE : Boolean.FALSE);
810: }
811:
812: /**
813: * Alternative setUnderline method which allows also to reset
814: * the "own" isUnderline property.
815: */
816: public void setUnderline(Boolean isUnderline) {
817: this .isUnderline = isUnderline;
818: }
819:
820: /**
821: *
822: */
823: public boolean isStrikeThrough() {
824: return JRStyleResolver.isStrikeThrough(this );
825: }
826:
827: /**
828: *
829: */
830: public Boolean isOwnStrikeThrough() {
831: return isStrikeThrough;
832: }
833:
834: /**
835: *
836: */
837: public void setStrikeThrough(boolean isStrikeThrough) {
838: setStrikeThrough(isStrikeThrough ? Boolean.TRUE : Boolean.FALSE);
839: }
840:
841: /**
842: * Alternative setStrikeThrough method which allows also to reset
843: * the "own" isStrikeThrough property.
844: */
845: public void setStrikeThrough(Boolean isStrikeThrough) {
846: this .isStrikeThrough = isStrikeThrough;
847: }
848:
849: /**
850: *
851: */
852: public int getFontSize() {
853: return JRStyleResolver.getFontSize(this );
854: }
855:
856: /**
857: *
858: */
859: public Integer getOwnFontSize() {
860: return fontSize;
861: }
862:
863: /**
864: *
865: */
866: public void setFontSize(int fontSize) {
867: setFontSize(new Integer(fontSize));
868: }
869:
870: /**
871: * Alternative setSize method which allows also to reset
872: * the "own" size property.
873: */
874: public void setFontSize(Integer fontSize) {
875: this .fontSize = fontSize;
876: }
877:
878: /**
879: * @deprecated Replaced by {@link #getFontSize()}.
880: */
881: public int getSize() {
882: return getFontSize();
883: }
884:
885: /**
886: * @deprecated Replaced by {@link #getOwnFontSize()}.
887: */
888: public Integer getOwnSize() {
889: return getOwnFontSize();
890: }
891:
892: /**
893: * @deprecated Replaced by {@link #setFontSize(int)}.
894: */
895: public void setSize(int size) {
896: setFontSize(size);
897: }
898:
899: /**
900: * @deprecated Replaced by {@link #setFontSize(Integer)}.
901: */
902: public void setSize(Integer size) {
903: setFontSize(size);
904: }
905:
906: /**
907: *
908: */
909: public String getPdfFontName() {
910: return JRStyleResolver.getPdfFontName(this );
911: }
912:
913: /**
914: *
915: */
916: public String getOwnPdfFontName() {
917: return pdfFontName;
918: }
919:
920: /**
921: *
922: */
923: public void setPdfFontName(String pdfFontName) {
924: this .pdfFontName = pdfFontName;
925: }
926:
927: /**
928: *
929: */
930: public String getPdfEncoding() {
931: return JRStyleResolver.getPdfEncoding(this );
932: }
933:
934: /**
935: *
936: */
937: public String getOwnPdfEncoding() {
938: return pdfEncoding;
939: }
940:
941: /**
942: *
943: */
944: public void setPdfEncoding(String pdfEncoding) {
945: this .pdfEncoding = pdfEncoding;
946: }
947:
948: /**
949: *
950: */
951: public boolean isPdfEmbedded() {
952: return JRStyleResolver.isPdfEmbedded(this );
953: }
954:
955: /**
956: *
957: */
958: public Boolean isOwnPdfEmbedded() {
959: return isPdfEmbedded;
960: }
961:
962: /**
963: *
964: */
965: public void setPdfEmbedded(boolean isPdfEmbedded) {
966: setPdfEmbedded(isPdfEmbedded ? Boolean.TRUE : Boolean.FALSE);
967: }
968:
969: /**
970: * Alternative setPdfEmbedded method which allows also to reset
971: * the "own" isPdfEmbedded property.
972: */
973: public void setPdfEmbedded(Boolean isPdfEmbedded) {
974: this.isPdfEmbedded = isPdfEmbedded;
975: }
976:
977: }
|