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