KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > JRAbstractSvgRenderer


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;
29
30 import java.awt.Color JavaDoc;
31 import java.awt.Graphics2D JavaDoc;
32 import java.awt.Rectangle JavaDoc;
33 import java.awt.geom.Dimension2D JavaDoc;
34 import java.awt.image.BufferedImage JavaDoc;
35
36 import net.sf.jasperreports.engine.util.JRImageLoader;
37
38
39 /**
40  * @author Teodor Danciu (teodord@users.sourceforge.net)
41  * @version $Id: JRAbstractSvgRenderer.java 1508 2006-11-28 19:09:17 +0200 (Tue, 28 Nov 2006) teodord $
42  */

43 public abstract class JRAbstractSvgRenderer extends JRAbstractRenderer
44 {
45
46     /**
47      *
48      */

49     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
50
51     
52     /**
53      *
54      */

55     public byte getType()
56     {
57         return TYPE_SVG;
58     }
59
60
61     /**
62      *
63      */

64     public byte getImageType()
65     {
66         return IMAGE_TYPE_PNG;
67     }
68
69
70     /**
71      *
72      */

73     public Dimension2D JavaDoc getDimension()
74     {
75         return null;
76     }
77
78
79     /**
80      *
81      */

82     public Color JavaDoc getBackcolor()
83     {
84         return null;
85     }
86
87
88     /**
89      *
90      */

91     public byte[] getImageData() throws JRException
92     {
93         Dimension2D JavaDoc dimension = getDimension();
94         if (dimension != null)
95         {
96             byte imageType = getImageType();
97             BufferedImage JavaDoc bi =
98                 new BufferedImage JavaDoc(
99                     (int)dimension.getWidth(),
100                     (int)dimension.getHeight(),
101                     // avoid creating JPEG images with transparency that would result
102
// in invalid image files for some viewers (browsers)
103
(imageType == JRRenderable.IMAGE_TYPE_GIF || imageType == JRRenderable.IMAGE_TYPE_PNG)
104                         ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB
105                     );
106
107             Graphics2D JavaDoc g = bi.createGraphics();
108             Color JavaDoc backcolor = getBackcolor();
109             if (backcolor != null)
110             {
111                 g.setColor(backcolor);
112                 g.fillRect(0, 0, (int)dimension.getWidth(), (int)dimension.getHeight());
113             }
114             render(g, new Rectangle JavaDoc((int)dimension.getWidth(), (int)dimension.getHeight()));
115             g.dispose();
116             
117             return JRImageLoader.loadImageDataFromAWTImage(bi, getImageType());
118         }
119         return null;
120     }
121
122
123 }
124
Popular Tags