KickJava   Java API By Example, From Geeks To Geeks.

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


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.Color JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.io.ObjectInputStream JavaDoc;
33
34 import net.sf.jasperreports.engine.JRAbstractObjectFactory;
35 import net.sf.jasperreports.engine.JRAnchor;
36 import net.sf.jasperreports.engine.JRBox;
37 import net.sf.jasperreports.engine.JRChild;
38 import net.sf.jasperreports.engine.JRConstants;
39 import net.sf.jasperreports.engine.JRExpression;
40 import net.sf.jasperreports.engine.JRExpressionCollector;
41 import net.sf.jasperreports.engine.JRGroup;
42 import net.sf.jasperreports.engine.JRHyperlink;
43 import net.sf.jasperreports.engine.JRHyperlinkHelper;
44 import net.sf.jasperreports.engine.JRHyperlinkParameter;
45 import net.sf.jasperreports.engine.JRImage;
46 import net.sf.jasperreports.engine.util.JRStyleResolver;
47 import net.sf.jasperreports.engine.xml.JRXmlWriter;
48
49
50 /**
51  * The actual implementation of a graphic element representing an image.
52  * @author Teodor Danciu (teodord@users.sourceforge.net)
53  * @version $Id: JRBaseImage.java 1364 2006-08-31 18:13:20 +0300 (Thu, 31 Aug 2006) lucianc $
54  */

55 public class JRBaseImage extends JRBaseGraphicElement implements JRImage
56 {
57
58
59     /**
60      *
61      */

62     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
63
64     /**
65      *
66      */

67     protected Byte JavaDoc scaleImage;
68     protected Byte JavaDoc horizontalAlignment;
69     protected Byte JavaDoc verticalAlignment;
70     protected Boolean JavaDoc isUsingCache = null;
71     protected boolean isLazy = false;
72     protected byte onErrorType = ON_ERROR_TYPE_ERROR;
73     protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW;
74     protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
75     protected String JavaDoc linkType;
76     protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
77     private JRHyperlinkParameter[] hyperlinkParameters;
78
79     /**
80      *
81      */

82     protected Byte JavaDoc border;
83     protected Byte JavaDoc topBorder = null;
84     protected Byte JavaDoc leftBorder = null;
85     protected Byte JavaDoc bottomBorder = null;
86     protected Byte JavaDoc rightBorder = null;
87     protected Color JavaDoc borderColor = null;
88     protected Color JavaDoc topBorderColor = null;
89     protected Color JavaDoc leftBorderColor = null;
90     protected Color JavaDoc bottomBorderColor = null;
91     protected Color JavaDoc rightBorderColor = null;
92     protected Integer JavaDoc padding;
93     protected Integer JavaDoc topPadding = null;
94     protected Integer JavaDoc leftPadding = null;
95     protected Integer JavaDoc bottomPadding = null;
96     protected Integer JavaDoc rightPadding = null;
97
98     /**
99      *
100      */

101 // protected JRBox box = null;
102

103     /**
104      *
105      */

106     protected JRGroup evaluationGroup = null;
107     protected JRExpression expression = null;
108     protected JRExpression anchorNameExpression = null;
109     protected JRExpression hyperlinkReferenceExpression = null;
110     protected JRExpression hyperlinkAnchorExpression = null;
111     protected JRExpression hyperlinkPageExpression = null;
112     private JRExpression hyperlinkTooltipExpression;
113
114     /**
115      * The bookmark level for the anchor associated with this image.
116      * @see JRAnchor#getBookmarkLevel()
117      */

118     protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
119
120     /**
121      *
122      *
123     protected JRBaseImage()
124     {
125         super();
126     }
127         
128
129     /**
130      * Initializes properties that are specific to images. Common properties are initialized by its
131      * parent constructors.
132      * @param image an element whose properties are copied to this element. Usually it is a
133      * {@link net.sf.jasperreports.engine.design.JRDesignImage} that must be transformed into an
134      * <tt>JRBaseImage</tt> at compile time.
135      * @param factory a factory used in the compile process
136      */

137     protected JRBaseImage(JRImage image, JRBaseObjectFactory factory)
138     {
139         super(image, factory);
140         
141         scaleImage = image.getOwnScaleImage();
142         horizontalAlignment = image.getOwnHorizontalAlignment();
143         verticalAlignment = image.getOwnVerticalAlignment();
144         isUsingCache = image.isOwnUsingCache();
145         isLazy = image.isLazy();
146         onErrorType = image.getOnErrorType();
147         evaluationTime = image.getEvaluationTime();
148         linkType = image.getLinkType();
149         hyperlinkTarget = image.getHyperlinkTarget();
150         hyperlinkParameters = JRBaseHyperlink.copyHyperlinkParameters(image, factory);
151
152 // box = image.getBox();
153

154         border = image.getOwnBorder();
155         topBorder = image.getOwnTopBorder();
156         leftBorder = image.getOwnLeftBorder();
157         bottomBorder = image.getOwnBottomBorder();
158         rightBorder = image.getOwnRightBorder();
159         borderColor = image.getOwnBorderColor();
160         topBorderColor = image.getOwnTopBorderColor();
161         leftBorderColor = image.getOwnLeftBorderColor();
162         bottomBorderColor = image.getOwnBottomBorderColor();
163         rightBorderColor = image.getOwnRightBorderColor();
164         padding = image.getOwnPadding();
165         topPadding = image.getOwnTopPadding();
166         leftPadding = image.getOwnLeftPadding();
167         bottomPadding = image.getOwnBottomPadding();
168         rightPadding = image.getOwnRightPadding();
169
170         evaluationGroup = factory.getGroup(image.getEvaluationGroup());
171         expression = factory.getExpression(image.getExpression());
172         anchorNameExpression = factory.getExpression(image.getAnchorNameExpression());
173         hyperlinkReferenceExpression = factory.getExpression(image.getHyperlinkReferenceExpression());
174         hyperlinkAnchorExpression = factory.getExpression(image.getHyperlinkAnchorExpression());
175         hyperlinkPageExpression = factory.getExpression(image.getHyperlinkPageExpression());
176         hyperlinkTooltipExpression = factory.getExpression(image.getHyperlinkTooltipExpression());
177         bookmarkLevel = image.getBookmarkLevel();
178     }
179
180
181     /**
182      *
183      */

184     public byte getMode()
185     {
186         return JRStyleResolver.getMode(this, MODE_TRANSPARENT);
187     }
188
189     /**
190      *
191      */

192     public byte getPen()
193     {
194         return JRStyleResolver.getPen(this, PEN_NONE);
195     }
196
197     /**
198      *
199      */

200     public byte getScaleImage()
201     {
202         return JRStyleResolver.getScaleImage(this);
203     }
204
205     public Byte JavaDoc getOwnScaleImage()
206     {
207         return scaleImage;
208     }
209
210     /**
211      *
212      */

213     public void setScaleImage(byte scaleImage)
214     {
215         this.scaleImage = new Byte JavaDoc(scaleImage);
216     }
217
218     /**
219      *
220      */

221     public void setScaleImage(Byte JavaDoc scaleImage)
222     {
223         this.scaleImage = scaleImage;
224     }
225
226     /**
227      *
228      */

229     public byte getHorizontalAlignment()
230     {
231         return JRStyleResolver.getHorizontalAlignment(this);
232     }
233
234     public Byte JavaDoc getOwnHorizontalAlignment()
235     {
236         return horizontalAlignment;
237     }
238
239     /**
240      *
241      */

242     public void setHorizontalAlignment(byte horizontalAlignment)
243     {
244         this.horizontalAlignment = new Byte JavaDoc(horizontalAlignment);
245     }
246         
247     /**
248      *
249      */

250     public void setHorizontalAlignment(Byte JavaDoc horizontalAlignment)
251     {
252         this.horizontalAlignment = horizontalAlignment;
253     }
254         
255     /**
256      *
257      */

258     public byte getVerticalAlignment()
259     {
260         return JRStyleResolver.getVerticalAlignment(this);
261     }
262
263     public Byte JavaDoc getOwnVerticalAlignment()
264     {
265         return verticalAlignment;
266     }
267
268     /**
269      *
270      */

271     public void setVerticalAlignment(byte verticalAlignment)
272     {
273         this.verticalAlignment = new Byte JavaDoc(verticalAlignment);
274     }
275         
276     /**
277      *
278      */

279     public void setVerticalAlignment(Byte JavaDoc verticalAlignment)
280     {
281         this.verticalAlignment = verticalAlignment;
282     }
283         
284     /**
285      *
286      */

287     public boolean isUsingCache()
288     {
289         if (isUsingCache == null)
290         {
291             if (getExpression() != null)
292             {
293                 return String JavaDoc.class.getName().equals(getExpression().getValueClassName());
294             }
295             return true;
296         }
297         return isUsingCache.booleanValue();
298     }
299
300     /**
301      *
302      */

303     public Boolean JavaDoc isOwnUsingCache()
304     {
305         return isUsingCache;
306     }
307
308     /**
309      *
310      */

311     public void setUsingCache(boolean isUsingCache)
312     {
313         setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
314     }
315
316     /**
317      *
318      */

319     public void setUsingCache(Boolean JavaDoc isUsingCache)
320     {
321         this.isUsingCache = isUsingCache;
322     }
323
324     /**
325      *
326      */

327     public boolean isLazy()
328     {
329         return isLazy;
330     }
331
332     /**
333      *
334      */

335     public void setLazy(boolean isLazy)
336     {
337         this.isLazy = isLazy;
338     }
339
340     /**
341      *
342      */

343     public byte getOnErrorType()
344     {
345         return onErrorType;
346     }
347
348     /**
349      *
350      */

351     public void setOnErrorType(byte onErrorType)
352     {
353         this.onErrorType = onErrorType;
354     }
355
356     /**
357      *
358      */

359     public byte getEvaluationTime()
360     {
361         return evaluationTime;
362     }
363         
364     /**
365      * @deprecated
366      */

367     public JRBox getBox()
368     {
369         return this;
370     }
371
372     /**
373      *
374      */

375     public byte getHyperlinkType()
376     {
377         return JRHyperlinkHelper.getHyperlinkType(this);
378     }
379         
380     /**
381      *
382      */

383     public byte getHyperlinkTarget()
384     {
385         return hyperlinkTarget;
386     }
387         
388     /**
389      *
390      */

391     public JRGroup getEvaluationGroup()
392     {
393         return evaluationGroup;
394     }
395         
396     /**
397      *
398      */

399     public JRExpression getExpression()
400     {
401         return expression;
402     }
403
404     /**
405      *
406      */

407     public JRExpression getAnchorNameExpression()
408     {
409         return anchorNameExpression;
410     }
411
412     /**
413      *
414      */

415     public JRExpression getHyperlinkReferenceExpression()
416     {
417         return hyperlinkReferenceExpression;
418     }
419
420     /**
421      *
422      */

423     public JRExpression getHyperlinkAnchorExpression()
424     {
425         return hyperlinkAnchorExpression;
426     }
427
428     /**
429      *
430      */

431     public JRExpression getHyperlinkPageExpression()
432     {
433         return hyperlinkPageExpression;
434     }
435     
436     /**
437      *
438      */

439     public JRChild getCopy(JRAbstractObjectFactory factory)
440     {
441         return factory.getImage(this);
442     }
443
444     /**
445      *
446      */

447     public void collectExpressions(JRExpressionCollector collector)
448     {
449         collector.collect(this);
450     }
451
452     /**
453      *
454      */

455     public void writeXml(JRXmlWriter xmlWriter) throws IOException JavaDoc
456     {
457         xmlWriter.writeImage(this);
458     }
459
460
461     public int getBookmarkLevel()
462     {
463         return bookmarkLevel;
464     }
465
466     /**
467      *
468      */

469     public byte getBorder()
470     {
471         return JRStyleResolver.getBorder(this);
472     }
473
474     public Byte JavaDoc getOwnBorder()
475     {
476         return border;
477     }
478
479     /**
480      *
481      */

482     public void setBorder(byte border)
483     {
484         this.border = new Byte JavaDoc(border);
485     }
486
487     /**
488      *
489      */

490     public Color JavaDoc getBorderColor()
491     {
492         return JRStyleResolver.getBorderColor(this, getForecolor());
493     }
494
495     public Color JavaDoc getOwnBorderColor()
496     {
497         return borderColor;
498     }
499
500     /**
501      *
502      */

503     public void setBorderColor(Color JavaDoc borderColor)
504     {
505         this.borderColor = borderColor;
506     }
507
508     /**
509      *
510      */

511     public int getPadding()
512     {
513         return JRStyleResolver.getPadding(this);
514     }
515
516     public Integer JavaDoc getOwnPadding()
517     {
518         return padding;
519     }
520
521     /**
522      *
523      */

524     public void setPadding(int padding)
525     {
526         this.padding = new Integer JavaDoc(padding);
527     }
528
529     /**
530      *
531      */

532     public byte getTopBorder()
533     {
534         return JRStyleResolver.getTopBorder(this);
535     }
536
537     /**
538      *
539      */

540     public Byte JavaDoc getOwnTopBorder()
541     {
542         return topBorder;
543     }
544
545     /**
546      *
547      */

548     public void setTopBorder(byte topBorder)
549     {
550         this.topBorder = new Byte JavaDoc(topBorder);
551     }
552
553     /**
554      *
555      */

556     public Color JavaDoc getTopBorderColor()
557     {
558         return JRStyleResolver.getTopBorderColor(this, getForecolor());
559     }
560
561     /**
562      *
563      */

564     public Color JavaDoc getOwnTopBorderColor()
565     {
566         return topBorderColor;
567     }
568
569     /**
570      *
571      */

572     public void setTopBorderColor(Color JavaDoc topBorderColor)
573     {
574         this.topBorderColor = topBorderColor;
575     }
576
577     /**
578      *
579      */

580     public int getTopPadding()
581     {
582         return JRStyleResolver.getTopPadding(this);
583     }
584
585     /**
586      *
587      */

588     public Integer JavaDoc getOwnTopPadding()
589     {
590         return topPadding;
591     }
592
593     /**
594      *
595      */

596     public void setTopPadding(int topPadding)
597     {
598         this.topPadding = new Integer JavaDoc(topPadding);
599     }
600
601     /**
602      *
603      */

604     public byte getLeftBorder()
605     {
606         return JRStyleResolver.getLeftBorder(this);
607     }
608
609     /**
610      *
611      */

612     public Byte JavaDoc getOwnLeftBorder()
613     {
614         return leftBorder;
615     }
616
617     /**
618      *
619      */

620     public void setLeftBorder(byte leftBorder)
621     {
622         this.leftBorder = new Byte JavaDoc(leftBorder);
623     }
624
625     /**
626      *
627      */

628     public Color JavaDoc getLeftBorderColor()
629     {
630         return JRStyleResolver.getLeftBorderColor(this, getForecolor());
631     }
632
633     /**
634      *
635      */

636     public Color JavaDoc getOwnLeftBorderColor()
637     {
638         return leftBorderColor;
639     }
640
641     /**
642      *
643      */

644     public void setLeftBorderColor(Color JavaDoc leftBorderColor)
645     {
646         this.leftBorderColor = leftBorderColor;
647     }
648
649     /**
650      *
651      */

652     public int getLeftPadding()
653     {
654         return JRStyleResolver.getLeftPadding(this);
655     }
656
657     /**
658      *
659      */

660     public Integer JavaDoc getOwnLeftPadding()
661     {
662         return leftPadding;
663     }
664
665     /**
666      *
667      */

668     public void setLeftPadding(int leftPadding)
669     {
670         this.leftPadding = new Integer JavaDoc(leftPadding);
671     }
672
673     /**
674      *
675      */

676     public byte getBottomBorder()
677     {
678         return JRStyleResolver.getBottomBorder(this);
679     }
680
681     /**
682      *
683      */

684     public Byte JavaDoc getOwnBottomBorder()
685     {
686         return bottomBorder;
687     }
688
689     /**
690      *
691      */

692     public void setBottomBorder(byte bottomBorder)
693     {
694         this.bottomBorder = new Byte JavaDoc(bottomBorder);
695     }
696
697     /**
698      *
699      */

700     public Color JavaDoc getBottomBorderColor()
701     {
702         return JRStyleResolver.getBottomBorderColor(this, getForecolor());
703     }
704
705     /**
706      *
707      */

708     public Color JavaDoc getOwnBottomBorderColor()
709     {
710         return bottomBorderColor;
711     }
712
713     /**
714      *
715      */

716     public void setBottomBorderColor(Color JavaDoc bottomBorderColor)
717     {
718         this.bottomBorderColor = bottomBorderColor;
719     }
720
721     /**
722      *
723      */

724     public int getBottomPadding()
725     {
726         return JRStyleResolver.getBottomPadding(this);
727     }
728
729     /**
730      *
731      */

732     public Integer JavaDoc getOwnBottomPadding()
733     {
734         return bottomPadding;
735     }
736
737     /**
738      *
739      */

740     public void setBottomPadding(int bottomPadding)
741     {
742         this.bottomPadding = new Integer JavaDoc(bottomPadding);
743     }
744
745     /**
746      *
747      */

748     public byte getRightBorder()
749     {
750         return JRStyleResolver.getRightBorder(this);
751     }
752
753     /**
754      *
755      */

756     public Byte JavaDoc getOwnRightBorder()
757     {
758         return rightBorder;
759     }
760
761     /**
762      *
763      */

764     public void setRightBorder(byte rightBorder)
765     {
766         this.rightBorder = new Byte JavaDoc(rightBorder);
767     }
768
769     /**
770      *
771      */

772     public Color JavaDoc getRightBorderColor()
773     {
774         return JRStyleResolver.getRightBorderColor(this, getForecolor());
775     }
776
777     /**
778      *
779      */

780     public Color JavaDoc getOwnRightBorderColor()
781     {
782         return rightBorderColor;
783     }
784
785     /**
786      *
787      */

788     public void setRightBorderColor(Color JavaDoc rightBorderColor)
789     {
790         this.rightBorderColor = rightBorderColor;
791     }
792
793     /**
794      *
795      */

796     public int getRightPadding()
797     {
798         return JRStyleResolver.getRightPadding(this);
799     }
800
801     /**
802      *
803      */

804     public Integer JavaDoc getOwnRightPadding()
805     {
806         return rightPadding;
807     }
808
809     /**
810      *
811      */

812     public void setRightPadding(int rightPadding)
813     {
814         this.rightPadding = new Integer JavaDoc(rightPadding);
815     }
816
817
818     /**
819      *
820      */

821     public void setBorder(Byte JavaDoc border)
822     {
823         this.border = border;
824     }
825
826     /**
827      *
828      */

829     public void setPadding(Integer JavaDoc padding)
830     {
831         this.padding = padding;
832     }
833
834     /**
835      *
836      */

837     public void setTopBorder(Byte JavaDoc topBorder)
838     {
839         this.topBorder = topBorder;
840     }
841
842     /**
843      *
844      */

845     public void setTopPadding(Integer JavaDoc topPadding)
846     {
847         this.topPadding = topPadding;
848     }
849
850     /**
851      *
852      */

853     public void setLeftBorder(Byte JavaDoc leftBorder)
854     {
855         this.leftBorder = leftBorder;
856     }
857
858     /**
859      *
860      */

861     public void setLeftPadding(Integer JavaDoc leftPadding)
862     {
863         this.leftPadding = leftPadding;
864     }
865
866     /**
867      *
868      */

869     public void setBottomBorder(Byte JavaDoc bottomBorder)
870     {
871         this.bottomBorder = bottomBorder;
872     }
873
874     /**
875      *
876      */

877     public void setBottomPadding(Integer JavaDoc bottomPadding)
878     {
879         this.bottomPadding = bottomPadding;
880     }
881
882     /**
883      *
884      */

885     public void setRightBorder(Byte JavaDoc rightBorder)
886     {
887         this.rightBorder = rightBorder;
888     }
889
890     /**
891      *
892      */

893     public void setRightPadding(Integer JavaDoc rightPadding)
894     {
895         this.rightPadding = rightPadding;
896     }
897
898
899     public String JavaDoc getLinkType()
900     {
901         return linkType;
902     }
903
904
905     public JRHyperlinkParameter[] getHyperlinkParameters()
906     {
907         return hyperlinkParameters;
908     }
909     
910     
911     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
912     {
913         in.defaultReadObject();
914         normalizeLinkType();
915     }
916
917
918     protected void normalizeLinkType()
919     {
920         if (linkType == null)
921         {
922              linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
923         }
924         hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
925     }
926
927     
928     public JRExpression getHyperlinkTooltipExpression()
929     {
930         return hyperlinkTooltipExpression;
931     }
932
933 }
934
Popular Tags