KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRTemplateImage


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.fill;
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.JRAlignment;
35 import net.sf.jasperreports.engine.JRBox;
36 import net.sf.jasperreports.engine.JRChart;
37 import net.sf.jasperreports.engine.JRConstants;
38 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
39 import net.sf.jasperreports.engine.JRElement;
40 import net.sf.jasperreports.engine.JRGraphicElement;
41 import net.sf.jasperreports.engine.JRHyperlink;
42 import net.sf.jasperreports.engine.JRHyperlinkHelper;
43 import net.sf.jasperreports.engine.JRImage;
44 import net.sf.jasperreports.engine.util.JRStyleResolver;
45
46
47 /**
48  * @author Teodor Danciu (teodord@users.sourceforge.net)
49  * @version $Id: JRTemplateImage.java 1355 2006-08-04 17:31:54 +0300 (Fri, 04 Aug 2006) lucianc $
50  */

51 public class JRTemplateImage extends JRTemplateGraphicElement implements JRAlignment, JRBox
52 {
53
54
55     /**
56      *
57      */

58     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
59
60     /**
61      *
62      */

63     private Byte JavaDoc scaleImage = null;
64     private Byte JavaDoc horizontalAlignment = null;
65     private Byte JavaDoc verticalAlignment = null;
66     protected boolean isLazy = false;
67     private byte onErrorType = JRImage.ON_ERROR_TYPE_ERROR;
68     private byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
69     private String JavaDoc linkType;
70     private byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
71     //private JRBox box = null;
72

73     /**
74      *
75      */

76     protected Byte JavaDoc border;
77     protected Byte JavaDoc topBorder = null;
78     protected Byte JavaDoc leftBorder = null;
79     protected Byte JavaDoc bottomBorder = null;
80     protected Byte JavaDoc rightBorder = null;
81     protected Color JavaDoc borderColor = null;
82     protected Color JavaDoc topBorderColor = null;
83     protected Color JavaDoc leftBorderColor = null;
84     protected Color JavaDoc bottomBorderColor = null;
85     protected Color JavaDoc rightBorderColor = null;
86     protected Integer JavaDoc padding;
87     protected Integer JavaDoc topPadding = null;
88     protected Integer JavaDoc leftPadding = null;
89     protected Integer JavaDoc bottomPadding = null;
90     protected Integer JavaDoc rightPadding = null;
91     
92
93     /**
94      *
95      */

96     protected JRTemplateImage(JRDefaultStyleProvider defaultStyleProvider, JRImage image)
97     {
98         super(defaultStyleProvider);
99         
100         setImage(image);
101     }
102
103
104     /**
105      *
106      */

107     protected JRTemplateImage(JRDefaultStyleProvider defaultStyleProvider, JRChart chart)
108     {
109         super(defaultStyleProvider);
110         
111         setChart(chart);
112     }
113
114     /**
115      *
116      */

117     protected void setBox(JRBox box)
118     {
119         border = box.getOwnBorder();
120         topBorder = box.getOwnTopBorder();
121         leftBorder = box.getOwnLeftBorder();
122         bottomBorder = box.getOwnBottomBorder();
123         rightBorder = box.getOwnRightBorder();
124         borderColor = box.getOwnBorderColor();
125         topBorderColor = box.getOwnTopBorderColor();
126         leftBorderColor = box.getOwnLeftBorderColor();
127         bottomBorderColor = box.getOwnBottomBorderColor();
128         rightBorderColor = box.getOwnRightBorderColor();
129         padding = box.getOwnPadding();
130         topPadding = box.getOwnTopPadding();
131         leftPadding = box.getOwnLeftPadding();
132         bottomPadding = box.getOwnBottomPadding();
133         rightPadding = box.getOwnRightPadding();
134     }
135
136     /**
137      *
138      */

139     protected void setImage(JRImage image)
140     {
141         super.setGraphicElement(image);
142         
143         setBox(image);
144
145         setScaleImage(image.getScaleImage());
146         setHorizontalAlignment(image.getHorizontalAlignment());
147         setVerticalAlignment(image.getVerticalAlignment());
148         setLazy(image.isLazy());
149         setOnErrorType(image.getOnErrorType());
150         setLinkType(image.getLinkType());
151         setHyperlinkTarget(image.getHyperlinkTarget());
152     }
153
154     /**
155      *
156      */

157     protected void setChart(JRChart chart)
158     {
159         super.setElement(chart);
160         
161         setPen(JRGraphicElement.PEN_NONE);
162         setFill(JRGraphicElement.FILL_SOLID);
163         
164         setBox(chart);
165
166         setLinkType(chart.getLinkType());
167         setHyperlinkTarget(chart.getHyperlinkTarget());
168     }
169
170     /**
171      *
172      */

173     public byte getMode()
174     {
175         return JRStyleResolver.getMode(this, JRElement.MODE_TRANSPARENT);
176     }
177         
178     /**
179      *
180      */

181     public byte getPen()
182     {
183         return JRStyleResolver.getPen(this, JRGraphicElement.PEN_NONE);
184     }
185         
186     /**
187      *
188      */

189     public byte getScaleImage()
190     {
191         return JRStyleResolver.getScaleImage(this);
192     }
193         
194     /**
195      *
196      */

197     public Byte JavaDoc getOwnScaleImage()
198     {
199         return scaleImage;
200     }
201         
202     /**
203      *
204      */

205     protected void setScaleImage(byte scaleImage)
206     {
207         this.scaleImage = new Byte JavaDoc(scaleImage);
208     }
209
210     /**
211      *
212      */

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

221     public byte getHorizontalAlignment()
222     {
223         return JRStyleResolver.getHorizontalAlignment(this);
224     }
225         
226     /**
227      *
228      */

229     public Byte JavaDoc getOwnHorizontalAlignment()
230     {
231         return horizontalAlignment;
232     }
233         
234     /**
235      *
236      */

237     public void setHorizontalAlignment(byte horizontalAlignment)
238     {
239         this.horizontalAlignment = new Byte JavaDoc(horizontalAlignment);
240     }
241         
242     /**
243      *
244      */

245     public void setHorizontalAlignment(Byte JavaDoc horizontalAlignment)
246     {
247         this.horizontalAlignment = horizontalAlignment;
248     }
249         
250     /**
251      *
252      */

253     public byte getVerticalAlignment()
254     {
255         return JRStyleResolver.getVerticalAlignment(this);
256     }
257         
258     /**
259      *
260      */

261     public Byte JavaDoc getOwnVerticalAlignment()
262     {
263         return verticalAlignment;
264     }
265         
266     /**
267      *
268      */

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

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

285     public boolean isLazy()
286     {
287         return this.isLazy;
288     }
289
290     /**
291      *
292      */

293     public void setLazy(boolean isLazy)
294     {
295         this.isLazy = isLazy;
296     }
297
298     /**
299      *
300      */

301     public byte getOnErrorType()
302     {
303         return this.onErrorType;
304     }
305
306     /**
307      *
308      */

309     public void setOnErrorType(byte onErrorType)
310     {
311         this.onErrorType = onErrorType;
312     }
313
314     /**
315      * @deprecated
316      */

317     public JRBox getBox()
318     {
319         return this;
320     }
321
322     
323     /**
324      * Retrieves the hyperlink type for the element.
325      * <p>
326      * The actual hyperlink type is determined by {@link #getLinkType() getLinkType()}.
327      * This method can is used to determine whether the hyperlink type is one of the
328      * built-in types or a custom type.
329      * When hyperlink is of custom type, {@link JRHyperlink#HYPERLINK_TYPE_CUSTOM HYPERLINK_TYPE_CUSTOM} is returned.
330      * </p>
331      * @return one of the hyperlink type constants
332      * @see #getLinkType()
333      */

334     public byte getHyperlinkType()
335     {
336         return JRHyperlinkHelper.getHyperlinkType(getLinkType());
337     }
338
339     
340     /**
341      * Sets the link type as a built-in hyperlink type.
342      *
343      * @param hyperlinkType the built-in hyperlink type
344      * @see #getLinkType()
345      */

346     protected void setHyperlinkType(byte hyperlinkType)
347     {
348         setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
349     }
350         
351     /**
352      *
353      */

354     public byte getHyperlinkTarget()
355     {
356         return this.hyperlinkTarget;
357     }
358         
359     /**
360      *
361      */

362     protected void setHyperlinkTarget(byte hyperlinkTarget)
363     {
364         this.hyperlinkTarget = hyperlinkTarget;
365     }
366     
367     /**
368      *
369      */

370     public byte getBorder()
371     {
372         return JRStyleResolver.getBorder(this);
373     }
374
375     public Byte JavaDoc getOwnBorder()
376     {
377         return border;
378     }
379
380     /**
381      *
382      */

383     public void setBorder(byte border)
384     {
385         this.border = new Byte JavaDoc(border);
386     }
387
388     /**
389      *
390      */

391     public Color JavaDoc getBorderColor()
392     {
393         return JRStyleResolver.getBorderColor(this, getForecolor());
394     }
395
396     public Color JavaDoc getOwnBorderColor()
397     {
398         return borderColor;
399     }
400
401     /**
402      *
403      */

404     public void setBorderColor(Color JavaDoc borderColor)
405     {
406         this.borderColor = borderColor;
407     }
408
409     /**
410      *
411      */

412     public int getPadding()
413     {
414         return JRStyleResolver.getPadding(this);
415     }
416
417     public Integer JavaDoc getOwnPadding()
418     {
419         return padding;
420     }
421
422     /**
423      *
424      */

425     public void setPadding(int padding)
426     {
427         this.padding = new Integer JavaDoc(padding);
428     }
429
430     /**
431      *
432      */

433     public byte getTopBorder()
434     {
435         return JRStyleResolver.getTopBorder(this);
436     }
437
438     /**
439      *
440      */

441     public Byte JavaDoc getOwnTopBorder()
442     {
443         return topBorder;
444     }
445
446     /**
447      *
448      */

449     public void setTopBorder(byte topBorder)
450     {
451         this.topBorder = new Byte JavaDoc(topBorder);
452     }
453
454     /**
455      *
456      */

457     public Color JavaDoc getTopBorderColor()
458     {
459         return JRStyleResolver.getTopBorderColor(this, getForecolor());
460     }
461
462     /**
463      *
464      */

465     public Color JavaDoc getOwnTopBorderColor()
466     {
467         return topBorderColor;
468     }
469
470     /**
471      *
472      */

473     public void setTopBorderColor(Color JavaDoc topBorderColor)
474     {
475         this.topBorderColor = topBorderColor;
476     }
477
478     /**
479      *
480      */

481     public int getTopPadding()
482     {
483         return JRStyleResolver.getTopPadding(this);
484     }
485
486     /**
487      *
488      */

489     public Integer JavaDoc getOwnTopPadding()
490     {
491         return topPadding;
492     }
493
494     /**
495      *
496      */

497     public void setTopPadding(int topPadding)
498     {
499         this.topPadding = new Integer JavaDoc(topPadding);
500     }
501
502     /**
503      *
504      */

505     public byte getLeftBorder()
506     {
507         return JRStyleResolver.getLeftBorder(this);
508     }
509
510     /**
511      *
512      */

513     public Byte JavaDoc getOwnLeftBorder()
514     {
515         return leftBorder;
516     }
517
518     /**
519      *
520      */

521     public void setLeftBorder(byte leftBorder)
522     {
523         this.leftBorder = new Byte JavaDoc(leftBorder);
524     }
525
526     /**
527      *
528      */

529     public Color JavaDoc getLeftBorderColor()
530     {
531         return JRStyleResolver.getLeftBorderColor(this, getForecolor());
532     }
533
534     /**
535      *
536      */

537     public Color JavaDoc getOwnLeftBorderColor()
538     {
539         return leftBorderColor;
540     }
541
542     /**
543      *
544      */

545     public void setLeftBorderColor(Color JavaDoc leftBorderColor)
546     {
547         this.leftBorderColor = leftBorderColor;
548     }
549
550     /**
551      *
552      */

553     public int getLeftPadding()
554     {
555         return JRStyleResolver.getLeftPadding(this);
556     }
557
558     /**
559      *
560      */

561     public Integer JavaDoc getOwnLeftPadding()
562     {
563         return leftPadding;
564     }
565
566     /**
567      *
568      */

569     public void setLeftPadding(int leftPadding)
570     {
571         this.leftPadding = new Integer JavaDoc(leftPadding);
572     }
573
574     /**
575      *
576      */

577     public byte getBottomBorder()
578     {
579         return JRStyleResolver.getBottomBorder(this);
580     }
581
582     /**
583      *
584      */

585     public Byte JavaDoc getOwnBottomBorder()
586     {
587         return bottomBorder;
588     }
589
590     /**
591      *
592      */

593     public void setBottomBorder(byte bottomBorder)
594     {
595         this.bottomBorder = new Byte JavaDoc(bottomBorder);
596     }
597
598     /**
599      *
600      */

601     public Color JavaDoc getBottomBorderColor()
602     {
603         return JRStyleResolver.getBottomBorderColor(this, getForecolor());
604     }
605
606     /**
607      *
608      */

609     public Color JavaDoc getOwnBottomBorderColor()
610     {
611         return bottomBorderColor;
612     }
613
614     /**
615      *
616      */

617     public void setBottomBorderColor(Color JavaDoc bottomBorderColor)
618     {
619         this.bottomBorderColor = bottomBorderColor;
620     }
621
622     /**
623      *
624      */

625     public int getBottomPadding()
626     {
627         return JRStyleResolver.getBottomPadding(this);
628     }
629
630     /**
631      *
632      */

633     public Integer JavaDoc getOwnBottomPadding()
634     {
635         return bottomPadding;
636     }
637
638     /**
639      *
640      */

641     public void setBottomPadding(int bottomPadding)
642     {
643         this.bottomPadding = new Integer JavaDoc(bottomPadding);
644     }
645
646     /**
647      *
648      */

649     public byte getRightBorder()
650     {
651         return JRStyleResolver.getRightBorder(this);
652     }
653
654     /**
655      *
656      */

657     public Byte JavaDoc getOwnRightBorder()
658     {
659         return rightBorder;
660     }
661
662     /**
663      *
664      */

665     public void setRightBorder(byte rightBorder)
666     {
667         this.rightBorder = new Byte JavaDoc(rightBorder);
668     }
669
670     /**
671      *
672      */

673     public Color JavaDoc getRightBorderColor()
674     {
675         return JRStyleResolver.getRightBorderColor(this, getForecolor());
676     }
677
678     /**
679      *
680      */

681     public Color JavaDoc getOwnRightBorderColor()
682     {
683         return rightBorderColor;
684     }
685
686     /**
687      *
688      */

689     public void setRightBorderColor(Color JavaDoc rightBorderColor)
690     {
691         this.rightBorderColor = rightBorderColor;
692     }
693
694     /**
695      *
696      */

697     public int getRightPadding()
698     {
699         return JRStyleResolver.getRightPadding(this);
700     }
701
702     /**
703      *
704      */

705     public Integer JavaDoc getOwnRightPadding()
706     {
707         return rightPadding;
708     }
709
710     /**
711      *
712      */

713     public void setRightPadding(int rightPadding)
714     {
715         this.rightPadding = new Integer JavaDoc(rightPadding);
716     }
717
718     /**
719      *
720      */

721     public void setBorder(Byte JavaDoc border)
722     {
723         this.border = border;
724     }
725
726     /**
727      *
728      */

729     public void setPadding(Integer JavaDoc padding)
730     {
731         this.padding = padding;
732     }
733
734     /**
735      *
736      */

737     public void setTopBorder(Byte JavaDoc topBorder)
738     {
739         this.topBorder = topBorder;
740     }
741
742     /**
743      *
744      */

745     public void setTopPadding(Integer JavaDoc topPadding)
746     {
747         this.topPadding = topPadding;
748     }
749
750     /**
751      *
752      */

753     public void setLeftBorder(Byte JavaDoc leftBorder)
754     {
755         this.leftBorder = leftBorder;
756     }
757
758     /**
759      *
760      */

761     public void setLeftPadding(Integer JavaDoc leftPadding)
762     {
763         this.leftPadding = leftPadding;
764     }
765
766     /**
767      *
768      */

769     public void setBottomBorder(Byte JavaDoc bottomBorder)
770     {
771         this.bottomBorder = bottomBorder;
772     }
773
774     /**
775      *
776      */

777     public void setBottomPadding(Integer JavaDoc bottomPadding)
778     {
779         this.bottomPadding = bottomPadding;
780     }
781
782     /**
783      *
784      */

785     public void setRightBorder(Byte JavaDoc rightBorder)
786     {
787         this.rightBorder = rightBorder;
788     }
789
790     /**
791      *
792      */

793     public void setRightPadding(Integer JavaDoc rightPadding)
794     {
795         this.rightPadding = rightPadding;
796     }
797
798     
799     /**
800      * Returns the hyperlink type.
801      * <p>
802      * The type can be one of the built-in types
803      * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
804      * or can be an arbitrary type.
805      * </p>
806      * @return the hyperlink type
807      */

808     public String JavaDoc getLinkType()
809     {
810         return linkType;
811     }
812
813
814     /**
815      * Sets the hyperlink type.
816      * <p>
817      * The type can be one of the built-in types
818      * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
819      * or can be an arbitrary type.
820      * </p>
821      * @param linkType the hyperlink type
822      */

823     public void setLinkType(String JavaDoc linkType)
824     {
825         this.linkType = linkType;
826     }
827     
828     
829     private void readObject(ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
830     {
831         in.defaultReadObject();
832         normalizeLinkType();
833     }
834
835
836     protected void normalizeLinkType()
837     {
838         if (linkType == null)
839         {
840              linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
841         }
842         hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
843     }
844
845 }
846
Popular Tags