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: import java.io.IOException;
032: import java.io.ObjectInputStream;
033:
034: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
035: import net.sf.jasperreports.engine.JRAnchor;
036: import net.sf.jasperreports.engine.JRBox;
037: import net.sf.jasperreports.engine.JRChild;
038: import net.sf.jasperreports.engine.JRConstants;
039: import net.sf.jasperreports.engine.JRExpression;
040: import net.sf.jasperreports.engine.JRExpressionCollector;
041: import net.sf.jasperreports.engine.JRGroup;
042: import net.sf.jasperreports.engine.JRHyperlink;
043: import net.sf.jasperreports.engine.JRHyperlinkHelper;
044: import net.sf.jasperreports.engine.JRHyperlinkParameter;
045: import net.sf.jasperreports.engine.JRImage;
046: import net.sf.jasperreports.engine.util.JRStyleResolver;
047: import net.sf.jasperreports.engine.xml.JRXmlWriter;
048:
049: /**
050: * The actual implementation of a graphic element representing an image.
051: * @author Teodor Danciu (teodord@users.sourceforge.net)
052: * @version $Id: JRBaseImage.java 1364 2006-08-31 15:13:20Z lucianc $
053: */
054: public class JRBaseImage extends JRBaseGraphicElement implements
055: JRImage {
056:
057: /**
058: *
059: */
060: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
061:
062: /**
063: *
064: */
065: protected Byte scaleImage;
066: protected Byte horizontalAlignment;
067: protected Byte verticalAlignment;
068: protected Boolean isUsingCache = null;
069: protected boolean isLazy = false;
070: protected byte onErrorType = ON_ERROR_TYPE_ERROR;
071: protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW;
072: protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
073: protected String linkType;
074: protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
075: private JRHyperlinkParameter[] hyperlinkParameters;
076:
077: /**
078: *
079: */
080: protected Byte border;
081: protected Byte topBorder = null;
082: protected Byte leftBorder = null;
083: protected Byte bottomBorder = null;
084: protected Byte rightBorder = null;
085: protected Color borderColor = null;
086: protected Color topBorderColor = null;
087: protected Color leftBorderColor = null;
088: protected Color bottomBorderColor = null;
089: protected Color rightBorderColor = null;
090: protected Integer padding;
091: protected Integer topPadding = null;
092: protected Integer leftPadding = null;
093: protected Integer bottomPadding = null;
094: protected Integer rightPadding = null;
095:
096: /**
097: *
098: */
099: // protected JRBox box = null;
100: /**
101: *
102: */
103: protected JRGroup evaluationGroup = null;
104: protected JRExpression expression = null;
105: protected JRExpression anchorNameExpression = null;
106: protected JRExpression hyperlinkReferenceExpression = null;
107: protected JRExpression hyperlinkAnchorExpression = null;
108: protected JRExpression hyperlinkPageExpression = null;
109: private JRExpression hyperlinkTooltipExpression;
110:
111: /**
112: * The bookmark level for the anchor associated with this image.
113: * @see JRAnchor#getBookmarkLevel()
114: */
115: protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
116:
117: /**
118: *
119: *
120: protected JRBaseImage()
121: {
122: super();
123: }
124:
125:
126: /**
127: * Initializes properties that are specific to images. Common properties are initialized by its
128: * parent constructors.
129: * @param image an element whose properties are copied to this element. Usually it is a
130: * {@link net.sf.jasperreports.engine.design.JRDesignImage} that must be transformed into an
131: * <tt>JRBaseImage</tt> at compile time.
132: * @param factory a factory used in the compile process
133: */
134: protected JRBaseImage(JRImage image, JRBaseObjectFactory factory) {
135: super (image, factory);
136:
137: scaleImage = image.getOwnScaleImage();
138: horizontalAlignment = image.getOwnHorizontalAlignment();
139: verticalAlignment = image.getOwnVerticalAlignment();
140: isUsingCache = image.isOwnUsingCache();
141: isLazy = image.isLazy();
142: onErrorType = image.getOnErrorType();
143: evaluationTime = image.getEvaluationTime();
144: linkType = image.getLinkType();
145: hyperlinkTarget = image.getHyperlinkTarget();
146: hyperlinkParameters = JRBaseHyperlink.copyHyperlinkParameters(
147: image, factory);
148:
149: // box = image.getBox();
150:
151: border = image.getOwnBorder();
152: topBorder = image.getOwnTopBorder();
153: leftBorder = image.getOwnLeftBorder();
154: bottomBorder = image.getOwnBottomBorder();
155: rightBorder = image.getOwnRightBorder();
156: borderColor = image.getOwnBorderColor();
157: topBorderColor = image.getOwnTopBorderColor();
158: leftBorderColor = image.getOwnLeftBorderColor();
159: bottomBorderColor = image.getOwnBottomBorderColor();
160: rightBorderColor = image.getOwnRightBorderColor();
161: padding = image.getOwnPadding();
162: topPadding = image.getOwnTopPadding();
163: leftPadding = image.getOwnLeftPadding();
164: bottomPadding = image.getOwnBottomPadding();
165: rightPadding = image.getOwnRightPadding();
166:
167: evaluationGroup = factory.getGroup(image.getEvaluationGroup());
168: expression = factory.getExpression(image.getExpression());
169: anchorNameExpression = factory.getExpression(image
170: .getAnchorNameExpression());
171: hyperlinkReferenceExpression = factory.getExpression(image
172: .getHyperlinkReferenceExpression());
173: hyperlinkAnchorExpression = factory.getExpression(image
174: .getHyperlinkAnchorExpression());
175: hyperlinkPageExpression = factory.getExpression(image
176: .getHyperlinkPageExpression());
177: hyperlinkTooltipExpression = factory.getExpression(image
178: .getHyperlinkTooltipExpression());
179: bookmarkLevel = image.getBookmarkLevel();
180: }
181:
182: /**
183: *
184: */
185: public byte getMode() {
186: return JRStyleResolver.getMode(this , MODE_TRANSPARENT);
187: }
188:
189: /**
190: *
191: */
192: public byte getPen() {
193: return JRStyleResolver.getPen(this , PEN_NONE);
194: }
195:
196: /**
197: *
198: */
199: public byte getScaleImage() {
200: return JRStyleResolver.getScaleImage(this );
201: }
202:
203: public Byte getOwnScaleImage() {
204: return scaleImage;
205: }
206:
207: /**
208: *
209: */
210: public void setScaleImage(byte scaleImage) {
211: this .scaleImage = new Byte(scaleImage);
212: }
213:
214: /**
215: *
216: */
217: public void setScaleImage(Byte scaleImage) {
218: this .scaleImage = scaleImage;
219: }
220:
221: /**
222: *
223: */
224: public byte getHorizontalAlignment() {
225: return JRStyleResolver.getHorizontalAlignment(this );
226: }
227:
228: public Byte getOwnHorizontalAlignment() {
229: return horizontalAlignment;
230: }
231:
232: /**
233: *
234: */
235: public void setHorizontalAlignment(byte horizontalAlignment) {
236: this .horizontalAlignment = new Byte(horizontalAlignment);
237: }
238:
239: /**
240: *
241: */
242: public void setHorizontalAlignment(Byte horizontalAlignment) {
243: this .horizontalAlignment = horizontalAlignment;
244: }
245:
246: /**
247: *
248: */
249: public byte getVerticalAlignment() {
250: return JRStyleResolver.getVerticalAlignment(this );
251: }
252:
253: public Byte getOwnVerticalAlignment() {
254: return verticalAlignment;
255: }
256:
257: /**
258: *
259: */
260: public void setVerticalAlignment(byte verticalAlignment) {
261: this .verticalAlignment = new Byte(verticalAlignment);
262: }
263:
264: /**
265: *
266: */
267: public void setVerticalAlignment(Byte verticalAlignment) {
268: this .verticalAlignment = verticalAlignment;
269: }
270:
271: /**
272: *
273: */
274: public boolean isUsingCache() {
275: if (isUsingCache == null) {
276: if (getExpression() != null) {
277: return String.class.getName().equals(
278: getExpression().getValueClassName());
279: }
280: return true;
281: }
282: return isUsingCache.booleanValue();
283: }
284:
285: /**
286: *
287: */
288: public Boolean isOwnUsingCache() {
289: return isUsingCache;
290: }
291:
292: /**
293: *
294: */
295: public void setUsingCache(boolean isUsingCache) {
296: setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
297: }
298:
299: /**
300: *
301: */
302: public void setUsingCache(Boolean isUsingCache) {
303: this .isUsingCache = isUsingCache;
304: }
305:
306: /**
307: *
308: */
309: public boolean isLazy() {
310: return isLazy;
311: }
312:
313: /**
314: *
315: */
316: public void setLazy(boolean isLazy) {
317: this .isLazy = isLazy;
318: }
319:
320: /**
321: *
322: */
323: public byte getOnErrorType() {
324: return onErrorType;
325: }
326:
327: /**
328: *
329: */
330: public void setOnErrorType(byte onErrorType) {
331: this .onErrorType = onErrorType;
332: }
333:
334: /**
335: *
336: */
337: public byte getEvaluationTime() {
338: return evaluationTime;
339: }
340:
341: /**
342: * @deprecated
343: */
344: public JRBox getBox() {
345: return this ;
346: }
347:
348: /**
349: *
350: */
351: public byte getHyperlinkType() {
352: return JRHyperlinkHelper.getHyperlinkType(this );
353: }
354:
355: /**
356: *
357: */
358: public byte getHyperlinkTarget() {
359: return hyperlinkTarget;
360: }
361:
362: /**
363: *
364: */
365: public JRGroup getEvaluationGroup() {
366: return evaluationGroup;
367: }
368:
369: /**
370: *
371: */
372: public JRExpression getExpression() {
373: return expression;
374: }
375:
376: /**
377: *
378: */
379: public JRExpression getAnchorNameExpression() {
380: return anchorNameExpression;
381: }
382:
383: /**
384: *
385: */
386: public JRExpression getHyperlinkReferenceExpression() {
387: return hyperlinkReferenceExpression;
388: }
389:
390: /**
391: *
392: */
393: public JRExpression getHyperlinkAnchorExpression() {
394: return hyperlinkAnchorExpression;
395: }
396:
397: /**
398: *
399: */
400: public JRExpression getHyperlinkPageExpression() {
401: return hyperlinkPageExpression;
402: }
403:
404: /**
405: *
406: */
407: public JRChild getCopy(JRAbstractObjectFactory factory) {
408: return factory.getImage(this );
409: }
410:
411: /**
412: *
413: */
414: public void collectExpressions(JRExpressionCollector collector) {
415: collector.collect(this );
416: }
417:
418: /**
419: *
420: */
421: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
422: xmlWriter.writeImage(this );
423: }
424:
425: public int getBookmarkLevel() {
426: return bookmarkLevel;
427: }
428:
429: /**
430: *
431: */
432: public byte getBorder() {
433: return JRStyleResolver.getBorder(this );
434: }
435:
436: public Byte getOwnBorder() {
437: return border;
438: }
439:
440: /**
441: *
442: */
443: public void setBorder(byte border) {
444: this .border = new Byte(border);
445: }
446:
447: /**
448: *
449: */
450: public Color getBorderColor() {
451: return JRStyleResolver.getBorderColor(this , getForecolor());
452: }
453:
454: public Color getOwnBorderColor() {
455: return borderColor;
456: }
457:
458: /**
459: *
460: */
461: public void setBorderColor(Color borderColor) {
462: this .borderColor = borderColor;
463: }
464:
465: /**
466: *
467: */
468: public int getPadding() {
469: return JRStyleResolver.getPadding(this );
470: }
471:
472: public Integer getOwnPadding() {
473: return padding;
474: }
475:
476: /**
477: *
478: */
479: public void setPadding(int padding) {
480: this .padding = new Integer(padding);
481: }
482:
483: /**
484: *
485: */
486: public byte getTopBorder() {
487: return JRStyleResolver.getTopBorder(this );
488: }
489:
490: /**
491: *
492: */
493: public Byte getOwnTopBorder() {
494: return topBorder;
495: }
496:
497: /**
498: *
499: */
500: public void setTopBorder(byte topBorder) {
501: this .topBorder = new Byte(topBorder);
502: }
503:
504: /**
505: *
506: */
507: public Color getTopBorderColor() {
508: return JRStyleResolver.getTopBorderColor(this , getForecolor());
509: }
510:
511: /**
512: *
513: */
514: public Color getOwnTopBorderColor() {
515: return topBorderColor;
516: }
517:
518: /**
519: *
520: */
521: public void setTopBorderColor(Color topBorderColor) {
522: this .topBorderColor = topBorderColor;
523: }
524:
525: /**
526: *
527: */
528: public int getTopPadding() {
529: return JRStyleResolver.getTopPadding(this );
530: }
531:
532: /**
533: *
534: */
535: public Integer getOwnTopPadding() {
536: return topPadding;
537: }
538:
539: /**
540: *
541: */
542: public void setTopPadding(int topPadding) {
543: this .topPadding = new Integer(topPadding);
544: }
545:
546: /**
547: *
548: */
549: public byte getLeftBorder() {
550: return JRStyleResolver.getLeftBorder(this );
551: }
552:
553: /**
554: *
555: */
556: public Byte getOwnLeftBorder() {
557: return leftBorder;
558: }
559:
560: /**
561: *
562: */
563: public void setLeftBorder(byte leftBorder) {
564: this .leftBorder = new Byte(leftBorder);
565: }
566:
567: /**
568: *
569: */
570: public Color getLeftBorderColor() {
571: return JRStyleResolver.getLeftBorderColor(this , getForecolor());
572: }
573:
574: /**
575: *
576: */
577: public Color getOwnLeftBorderColor() {
578: return leftBorderColor;
579: }
580:
581: /**
582: *
583: */
584: public void setLeftBorderColor(Color leftBorderColor) {
585: this .leftBorderColor = leftBorderColor;
586: }
587:
588: /**
589: *
590: */
591: public int getLeftPadding() {
592: return JRStyleResolver.getLeftPadding(this );
593: }
594:
595: /**
596: *
597: */
598: public Integer getOwnLeftPadding() {
599: return leftPadding;
600: }
601:
602: /**
603: *
604: */
605: public void setLeftPadding(int leftPadding) {
606: this .leftPadding = new Integer(leftPadding);
607: }
608:
609: /**
610: *
611: */
612: public byte getBottomBorder() {
613: return JRStyleResolver.getBottomBorder(this );
614: }
615:
616: /**
617: *
618: */
619: public Byte getOwnBottomBorder() {
620: return bottomBorder;
621: }
622:
623: /**
624: *
625: */
626: public void setBottomBorder(byte bottomBorder) {
627: this .bottomBorder = new Byte(bottomBorder);
628: }
629:
630: /**
631: *
632: */
633: public Color getBottomBorderColor() {
634: return JRStyleResolver.getBottomBorderColor(this ,
635: getForecolor());
636: }
637:
638: /**
639: *
640: */
641: public Color getOwnBottomBorderColor() {
642: return bottomBorderColor;
643: }
644:
645: /**
646: *
647: */
648: public void setBottomBorderColor(Color bottomBorderColor) {
649: this .bottomBorderColor = bottomBorderColor;
650: }
651:
652: /**
653: *
654: */
655: public int getBottomPadding() {
656: return JRStyleResolver.getBottomPadding(this );
657: }
658:
659: /**
660: *
661: */
662: public Integer getOwnBottomPadding() {
663: return bottomPadding;
664: }
665:
666: /**
667: *
668: */
669: public void setBottomPadding(int bottomPadding) {
670: this .bottomPadding = new Integer(bottomPadding);
671: }
672:
673: /**
674: *
675: */
676: public byte getRightBorder() {
677: return JRStyleResolver.getRightBorder(this );
678: }
679:
680: /**
681: *
682: */
683: public Byte getOwnRightBorder() {
684: return rightBorder;
685: }
686:
687: /**
688: *
689: */
690: public void setRightBorder(byte rightBorder) {
691: this .rightBorder = new Byte(rightBorder);
692: }
693:
694: /**
695: *
696: */
697: public Color getRightBorderColor() {
698: return JRStyleResolver
699: .getRightBorderColor(this , getForecolor());
700: }
701:
702: /**
703: *
704: */
705: public Color getOwnRightBorderColor() {
706: return rightBorderColor;
707: }
708:
709: /**
710: *
711: */
712: public void setRightBorderColor(Color rightBorderColor) {
713: this .rightBorderColor = rightBorderColor;
714: }
715:
716: /**
717: *
718: */
719: public int getRightPadding() {
720: return JRStyleResolver.getRightPadding(this );
721: }
722:
723: /**
724: *
725: */
726: public Integer getOwnRightPadding() {
727: return rightPadding;
728: }
729:
730: /**
731: *
732: */
733: public void setRightPadding(int rightPadding) {
734: this .rightPadding = new Integer(rightPadding);
735: }
736:
737: /**
738: *
739: */
740: public void setBorder(Byte border) {
741: this .border = border;
742: }
743:
744: /**
745: *
746: */
747: public void setPadding(Integer padding) {
748: this .padding = padding;
749: }
750:
751: /**
752: *
753: */
754: public void setTopBorder(Byte topBorder) {
755: this .topBorder = topBorder;
756: }
757:
758: /**
759: *
760: */
761: public void setTopPadding(Integer topPadding) {
762: this .topPadding = topPadding;
763: }
764:
765: /**
766: *
767: */
768: public void setLeftBorder(Byte leftBorder) {
769: this .leftBorder = leftBorder;
770: }
771:
772: /**
773: *
774: */
775: public void setLeftPadding(Integer leftPadding) {
776: this .leftPadding = leftPadding;
777: }
778:
779: /**
780: *
781: */
782: public void setBottomBorder(Byte bottomBorder) {
783: this .bottomBorder = bottomBorder;
784: }
785:
786: /**
787: *
788: */
789: public void setBottomPadding(Integer bottomPadding) {
790: this .bottomPadding = bottomPadding;
791: }
792:
793: /**
794: *
795: */
796: public void setRightBorder(Byte rightBorder) {
797: this .rightBorder = rightBorder;
798: }
799:
800: /**
801: *
802: */
803: public void setRightPadding(Integer rightPadding) {
804: this .rightPadding = rightPadding;
805: }
806:
807: public String getLinkType() {
808: return linkType;
809: }
810:
811: public JRHyperlinkParameter[] getHyperlinkParameters() {
812: return hyperlinkParameters;
813: }
814:
815: private void readObject(ObjectInputStream in) throws IOException,
816: ClassNotFoundException {
817: in.defaultReadObject();
818: normalizeLinkType();
819: }
820:
821: protected void normalizeLinkType() {
822: if (linkType == null) {
823: linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
824: }
825: hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
826: }
827:
828: public JRExpression getHyperlinkTooltipExpression() {
829: return hyperlinkTooltipExpression;
830: }
831:
832: }
|