KickJava   Java API By Example, From Geeks To Geeks.

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


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.JRAnchor;
35 import net.sf.jasperreports.engine.JRBox;
36 import net.sf.jasperreports.engine.JRConstants;
37 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
38 import net.sf.jasperreports.engine.JRElement;
39 import net.sf.jasperreports.engine.JRGraphicElement;
40 import net.sf.jasperreports.engine.JRHyperlink;
41 import net.sf.jasperreports.engine.JRHyperlinkHelper;
42 import net.sf.jasperreports.engine.JRImage;
43 import net.sf.jasperreports.engine.JRPrintHyperlinkParameter;
44 import net.sf.jasperreports.engine.JRPrintHyperlinkParameters;
45 import net.sf.jasperreports.engine.JRPrintImage;
46 import net.sf.jasperreports.engine.JRRenderable;
47 import net.sf.jasperreports.engine.util.JRStyleResolver;
48
49
50 /**
51  * @author Teodor Danciu (teodord@users.sourceforge.net)
52  * @version $Id: JRBasePrintImage.java 1364 2006-08-31 18:13:20 +0300 (Thu, 31 Aug 2006) lucianc $
53  */

54 public class JRBasePrintImage extends JRBasePrintGraphicElement implements JRPrintImage
55 {
56
57
58     /**
59      *
60      */

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

66     protected JRRenderable renderer = null;
67     protected Byte JavaDoc scaleImage = null;
68     protected Byte JavaDoc horizontalAlignment = null;
69     protected Byte JavaDoc verticalAlignment = null;
70     protected boolean isLazy = false;
71     protected byte onErrorType = JRImage.ON_ERROR_TYPE_ERROR;
72     //protected JRBox box = null;
73
protected String JavaDoc anchorName = null;
74     protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
75     private String JavaDoc linkType;
76     protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
77     protected String JavaDoc hyperlinkReference = null;
78     protected String JavaDoc hyperlinkAnchor = null;
79     protected Integer JavaDoc hyperlinkPage = null;
80     protected String JavaDoc hyperlinkTooltip;
81     protected JRPrintHyperlinkParameters hyperlinkParameters;
82
83     /**
84      * The bookmark level for the anchor associated with this field.
85      * @see JRAnchor#getBookmarkLevel()
86      */

87     protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
88
89     /**
90      *
91      */

92     protected Byte JavaDoc border;
93     protected Byte JavaDoc topBorder = null;
94     protected Byte JavaDoc leftBorder = null;
95     protected Byte JavaDoc bottomBorder = null;
96     protected Byte JavaDoc rightBorder = null;
97     protected Color JavaDoc borderColor = null;
98     protected Color JavaDoc topBorderColor = null;
99     protected Color JavaDoc leftBorderColor = null;
100     protected Color JavaDoc bottomBorderColor = null;
101     protected Color JavaDoc rightBorderColor = null;
102     protected Integer JavaDoc padding;
103     protected Integer JavaDoc topPadding = null;
104     protected Integer JavaDoc leftPadding = null;
105     protected Integer JavaDoc bottomPadding = null;
106     protected Integer JavaDoc rightPadding = null;
107
108     
109     /**
110      *
111      */

112     public JRBasePrintImage(JRDefaultStyleProvider defaultStyleProvider)
113     {
114         super(defaultStyleProvider);
115     }
116
117
118     /**
119      *
120      */

121     public byte getMode()
122     {
123         return JRStyleResolver.getMode(this, JRElement.MODE_TRANSPARENT);
124     }
125         
126     /**
127      *
128      */

129     public byte getPen()
130     {
131         return JRStyleResolver.getPen(this, JRGraphicElement.PEN_NONE);
132     }
133         
134     /**
135      *
136      */

137     public JRRenderable getRenderer()
138     {
139         return renderer;
140     }
141         
142     /**
143      *
144      */

145     public void setRenderer(JRRenderable renderer)
146     {
147         this.renderer = renderer;
148     }
149         
150     /**
151      *
152      */

153     public byte getScaleImage()
154     {
155         return JRStyleResolver.getScaleImage(this);
156     }
157
158     /**
159      *
160      */

161     public Byte JavaDoc getOwnScaleImage()
162     {
163         return scaleImage;
164     }
165
166     /**
167      *
168      */

169     public void setScaleImage(byte scaleImage)
170     {
171         this.scaleImage = new Byte JavaDoc(scaleImage);
172     }
173
174     /**
175      *
176      */

177     public void setScaleImage(Byte JavaDoc scaleImage)
178     {
179         this.scaleImage = scaleImage;
180     }
181
182     /**
183      *
184      */

185     public byte getHorizontalAlignment()
186     {
187         return JRStyleResolver.getHorizontalAlignment(this);
188     }
189         
190     /**
191      *
192      */

193     public Byte JavaDoc getOwnHorizontalAlignment()
194     {
195         return horizontalAlignment;
196     }
197         
198     /**
199      *
200      */

201     public void setHorizontalAlignment(byte horizontalAlignment)
202     {
203         this.horizontalAlignment = new Byte JavaDoc(horizontalAlignment);
204     }
205
206     /**
207      *
208      */

209     public void setHorizontalAlignment(Byte JavaDoc horizontalAlignment)
210     {
211         this.horizontalAlignment = horizontalAlignment;
212     }
213
214     /**
215      *
216      */

217     public byte getVerticalAlignment()
218     {
219         return JRStyleResolver.getVerticalAlignment(this);
220     }
221         
222     /**
223      *
224      */

225     public Byte JavaDoc getOwnVerticalAlignment()
226     {
227         return verticalAlignment;
228     }
229         
230     /**
231      *
232      */

233     public void setVerticalAlignment(byte verticalAlignment)
234     {
235         this.verticalAlignment = new Byte JavaDoc(verticalAlignment);
236     }
237
238     /**
239      *
240      */

241     public void setVerticalAlignment(Byte JavaDoc verticalAlignment)
242     {
243         this.verticalAlignment = verticalAlignment;
244     }
245
246     /**
247      *
248      */

249     public boolean isLazy()
250     {
251         return isLazy;
252     }
253
254     /**
255      *
256      */

257     public void setLazy(boolean isLazy)
258     {
259         this.isLazy = isLazy;
260     }
261
262     /**
263      *
264      */

265     public byte getOnErrorType()
266     {
267         return onErrorType;
268     }
269
270     /**
271      *
272      */

273     public void setOnErrorType(byte onErrorType)
274     {
275         this.onErrorType = onErrorType;
276     }
277
278     /**
279      * @deprecated
280      */

281     public JRBox getBox()
282     {
283         return this;
284     }
285
286     /**
287      * @deprecated
288      */

289     public void setBox(JRBox box)
290     {
291         border = box.getOwnBorder();
292         topBorder = box.getOwnTopBorder();
293         leftBorder = box.getOwnLeftBorder();
294         bottomBorder = box.getOwnBottomBorder();
295         rightBorder = box.getOwnRightBorder();
296         borderColor = box.getOwnBorderColor();
297         topBorderColor = box.getOwnTopBorderColor();
298         leftBorderColor = box.getOwnLeftBorderColor();
299         bottomBorderColor = box.getOwnBottomBorderColor();
300         rightBorderColor = box.getOwnRightBorderColor();
301         padding = box.getOwnPadding();
302         topPadding = box.getOwnTopPadding();
303         leftPadding = box.getOwnLeftPadding();
304         bottomPadding = box.getOwnBottomPadding();
305         rightPadding = box.getOwnRightPadding();
306     }
307
308     /**
309      *
310      */

311     public String JavaDoc getAnchorName()
312     {
313         return anchorName;
314     }
315         
316     /**
317      *
318      */

319     public void setAnchorName(String JavaDoc anchorName)
320     {
321         this.anchorName = anchorName;
322     }
323         
324     /**
325      *
326      */

327     public byte getHyperlinkType()
328     {
329         return JRHyperlinkHelper.getHyperlinkType(getLinkType());
330     }
331         
332     /**
333      *
334      */

335     public void setHyperlinkType(byte hyperlinkType)
336     {
337         setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
338     }
339
340     /**
341      *
342      */

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

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

359     public String JavaDoc getHyperlinkReference()
360     {
361         return hyperlinkReference;
362     }
363         
364     /**
365      *
366      */

367     public void setHyperlinkReference(String JavaDoc hyperlinkReference)
368     {
369         this.hyperlinkReference = hyperlinkReference;
370     }
371         
372     /**
373      *
374      */

375     public String JavaDoc getHyperlinkAnchor()
376     {
377         return hyperlinkAnchor;
378     }
379         
380     /**
381      *
382      */

383     public void setHyperlinkAnchor(String JavaDoc hyperlinkAnchor)
384     {
385         this.hyperlinkAnchor = hyperlinkAnchor;
386     }
387         
388     /**
389      *
390      */

391     public Integer JavaDoc getHyperlinkPage()
392     {
393         return hyperlinkPage;
394     }
395         
396     /**
397      *
398      */

399     public void setHyperlinkPage(Integer JavaDoc hyperlinkPage)
400     {
401         this.hyperlinkPage = hyperlinkPage;
402     }
403         
404     /**
405      *
406      */

407     public void setHyperlinkPage(String JavaDoc hyperlinkPage)
408     {
409         this.hyperlinkPage = new Integer JavaDoc(hyperlinkPage);
410     }
411
412
413     public int getBookmarkLevel()
414     {
415         return bookmarkLevel;
416     }
417
418
419     public void setBookmarkLevel(int bookmarkLevel)
420     {
421         this.bookmarkLevel = bookmarkLevel;
422     }
423     
424
425     /**
426      *
427      */

428     public byte getBorder()
429     {
430         return JRStyleResolver.getBorder(this);
431     }
432
433     public Byte JavaDoc getOwnBorder()
434     {
435         return border;
436     }
437
438     /**
439      *
440      */

441     public void setBorder(byte border)
442     {
443         this.border = new Byte JavaDoc(border);
444     }
445
446     /**
447      *
448      */

449     public Color JavaDoc getBorderColor()
450     {
451         return JRStyleResolver.getBorderColor(this, getForecolor());
452     }
453
454     public Color JavaDoc getOwnBorderColor()
455     {
456         return borderColor;
457     }
458
459     /**
460      *
461      */

462     public void setBorderColor(Color JavaDoc borderColor)
463     {
464         this.borderColor = borderColor;
465     }
466
467     /**
468      *
469      */

470     public int getPadding()
471     {
472         return JRStyleResolver.getPadding(this);
473     }
474
475     public Integer JavaDoc getOwnPadding()
476     {
477         return padding;
478     }
479
480     /**
481      *
482      */

483     public void setPadding(int padding)
484     {
485         this.padding = new Integer JavaDoc(padding);
486     }
487
488     /**
489      *
490      */

491     public byte getTopBorder()
492     {
493         return JRStyleResolver.getTopBorder(this);
494     }
495
496     /**
497      *
498      */

499     public Byte JavaDoc getOwnTopBorder()
500     {
501         return topBorder;
502     }
503
504     /**
505      *
506      */

507     public void setTopBorder(byte topBorder)
508     {
509         this.topBorder = new Byte JavaDoc(topBorder);
510     }
511
512     /**
513      *
514      */

515     public Color JavaDoc getTopBorderColor()
516     {
517         return JRStyleResolver.getTopBorderColor(this, getForecolor());
518     }
519
520     /**
521      *
522      */

523     public Color JavaDoc getOwnTopBorderColor()
524     {
525         return topBorderColor;
526     }
527
528     /**
529      *
530      */

531     public void setTopBorderColor(Color JavaDoc topBorderColor)
532     {
533         this.topBorderColor = topBorderColor;
534     }
535
536     /**
537      *
538      */

539     public int getTopPadding()
540     {
541         return JRStyleResolver.getTopPadding(this);
542     }
543
544     /**
545      *
546      */

547     public Integer JavaDoc getOwnTopPadding()
548     {
549         return topPadding;
550     }
551
552     /**
553      *
554      */

555     public void setTopPadding(int topPadding)
556     {
557         this.topPadding = new Integer JavaDoc(topPadding);
558     }
559
560     /**
561      *
562      */

563     public byte getLeftBorder()
564     {
565         return JRStyleResolver.getLeftBorder(this);
566     }
567
568     /**
569      *
570      */

571     public Byte JavaDoc getOwnLeftBorder()
572     {
573         return leftBorder;
574     }
575
576     /**
577      *
578      */

579     public void setLeftBorder(byte leftBorder)
580     {
581         this.leftBorder = new Byte JavaDoc(leftBorder);
582     }
583
584     /**
585      *
586      */

587     public Color JavaDoc getLeftBorderColor()
588     {
589         return JRStyleResolver.getLeftBorderColor(this, getForecolor());
590     }
591
592     /**
593      *
594      */

595     public Color JavaDoc getOwnLeftBorderColor()
596     {
597         return leftBorderColor;
598     }
599
600     /**
601      *
602      */

603     public void setLeftBorderColor(Color JavaDoc leftBorderColor)
604     {
605         this.leftBorderColor = leftBorderColor;
606     }
607
608     /**
609      *
610      */

611     public int getLeftPadding()
612     {
613         return JRStyleResolver.getLeftPadding(this);
614     }
615
616     /**
617      *
618      */

619     public Integer JavaDoc getOwnLeftPadding()
620     {
621         return leftPadding;
622     }
623
624     /**
625      *
626      */

627     public void setLeftPadding(int leftPadding)
628     {
629         this.leftPadding = new Integer JavaDoc(leftPadding);
630     }
631
632     /**
633      *
634      */

635     public byte getBottomBorder()
636     {
637         return JRStyleResolver.getBottomBorder(this);
638     }
639
640     /**
641      *
642      */

643     public Byte JavaDoc getOwnBottomBorder()
644     {
645         return bottomBorder;
646     }
647
648     /**
649      *
650      */

651     public void setBottomBorder(byte bottomBorder)
652     {
653         this.bottomBorder = new Byte JavaDoc(bottomBorder);
654     }
655
656     /**
657      *
658      */

659     public Color JavaDoc getBottomBorderColor()
660     {
661         return JRStyleResolver.getBottomBorderColor(this, getForecolor());
662     }
663
664     /**
665      *
666      */

667     public Color JavaDoc getOwnBottomBorderColor()
668     {
669         return bottomBorderColor;
670     }
671
672     /**
673      *
674      */

675     public void setBottomBorderColor(Color JavaDoc bottomBorderColor)
676     {
677         this.bottomBorderColor = bottomBorderColor;
678     }
679
680     /**
681      *
682      */

683     public int getBottomPadding()
684     {
685         return JRStyleResolver.getBottomPadding(this);
686     }
687
688     /**
689      *
690      */

691     public Integer JavaDoc getOwnBottomPadding()
692     {
693         return bottomPadding;
694     }
695
696     /**
697      *
698      */

699     public void setBottomPadding(int bottomPadding)
700     {
701         this.bottomPadding = new Integer JavaDoc(bottomPadding);
702     }
703
704     /**
705      *
706      */

707     public byte getRightBorder()
708     {
709         return JRStyleResolver.getRightBorder(this);
710     }
711
712     /**
713      *
714      */

715     public Byte JavaDoc getOwnRightBorder()
716     {
717         return rightBorder;
718     }
719
720     /**
721      *
722      */

723     public void setRightBorder(byte rightBorder)
724     {
725         this.rightBorder = new Byte JavaDoc(rightBorder);
726     }
727
728     /**
729      *
730      */

731     public Color JavaDoc getRightBorderColor()
732     {
733         return JRStyleResolver.getRightBorderColor(this, getForecolor());
734     }
735
736     /**
737      *
738      */

739     public Color JavaDoc getOwnRightBorderColor()
740     {
741         return rightBorderColor;
742     }
743
744     /**
745      *
746      */

747     public void setRightBorderColor(Color JavaDoc rightBorderColor)
748     {
749         this.rightBorderColor = rightBorderColor;
750     }
751
752     /**
753      *
754      */

755     public int getRightPadding()
756     {
757         return JRStyleResolver.getRightPadding(this);
758     }
759
760     /**
761      *
762      */

763     public Integer JavaDoc getOwnRightPadding()
764     {
765         return rightPadding;
766     }
767
768     /**
769      *
770      */

771     public void setRightPadding(int rightPadding)
772     {
773         this.rightPadding = new Integer JavaDoc(rightPadding);
774     }
775
776     /**
777      *
778      */

779     public void setBorder(Byte JavaDoc border)
780     {
781         this.border = border;
782     }
783
784     /**
785      *
786      */

787     public void setPadding(Integer JavaDoc padding)
788     {
789         this.padding = padding;
790     }
791
792     /**
793      *
794      */

795     public void setTopBorder(Byte JavaDoc topBorder)
796     {
797         this.topBorder = topBorder;
798     }
799
800     /**
801      *
802      */

803     public void setTopPadding(Integer JavaDoc topPadding)
804     {
805         this.topPadding = topPadding;
806     }
807
808     /**
809      *
810      */

811     public void setLeftBorder(Byte JavaDoc leftBorder)
812     {
813         this.leftBorder = leftBorder;
814     }
815
816     /**
817      *
818      */

819     public void setLeftPadding(Integer JavaDoc leftPadding)
820     {
821         this.leftPadding = leftPadding;
822     }
823
824     /**
825      *
826      */

827     public void setBottomBorder(Byte JavaDoc bottomBorder)
828     {
829         this.bottomBorder = bottomBorder;
830     }
831
832     /**
833      *
834      */

835     public void setBottomPadding(Integer JavaDoc bottomPadding)
836     {
837         this.bottomPadding = bottomPadding;
838     }
839
840     /**
841      *
842      */

843     public void setRightBorder(Byte JavaDoc rightBorder)
844     {
845         this.rightBorder = rightBorder;
846     }
847
848     /**
849      *
850      */

851     public void setRightPadding(Integer JavaDoc rightPadding)
852     {
853         this.rightPadding = rightPadding;
854     }
855
856     
857     public JRPrintHyperlinkParameters getHyperlinkParameters()
858     {
859         return hyperlinkParameters;
860     }
861
862     
863     public void setHyperlinkParameters(JRPrintHyperlinkParameters hyperlinkParameters)
864     {
865         this.hyperlinkParameters = hyperlinkParameters;
866     }
867
868     
869     /**
870      * Adds a custom hyperlink parameter.
871      *
872      * @param parameter the parameter to add
873      * @see #getHyperlinkParameters()
874      * @see JRPrintHyperlinkParameters#addParameter(JRPrintHyperlinkParameter)
875      */

876     public void addHyperlinkParameter(JRPrintHyperlinkParameter parameter)
877     {
878         if (hyperlinkParameters == null)
879         {
880             hyperlinkParameters = new JRPrintHyperlinkParameters();
881         }
882         hyperlinkParameters.addParameter(parameter);
883     }
884
885     
886     public String JavaDoc getLinkType()
887     {
888         return linkType;
889     }
890
891     
892     public void setLinkType(String JavaDoc linkType)
893     {
894         this.linkType = linkType;
895     }
896     
897     
898     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
899     {
900         in.defaultReadObject();
901         normalizeLinkType();
902     }
903
904
905     protected void normalizeLinkType()
906     {
907         if (linkType == null)
908         {
909              linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
910         }
911         hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
912     }
913
914
915     
916     public String JavaDoc getHyperlinkTooltip()
917     {
918         return hyperlinkTooltip;
919     }
920
921
922     
923     public void setHyperlinkTooltip(String JavaDoc hyperlinkTooltip)
924     {
925         this.hyperlinkTooltip = hyperlinkTooltip;
926     }
927
928 }
929
Popular Tags