Source Code Cross Referenced for JRImageRenderer.java in  » Report » jasperreports-2.0.1 » net » sf » jasperreports » engine » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » jasperreports 2.0.1 » net.sf.jasperreports.engine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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;
029:
030:        import java.awt.Dimension;
031:        import java.awt.Graphics2D;
032:        import java.awt.Image;
033:        import java.awt.geom.Dimension2D;
034:        import java.awt.geom.Rectangle2D;
035:        import java.io.File;
036:        import java.io.InputStream;
037:        import java.lang.ref.SoftReference;
038:        import java.net.URL;
039:        import java.net.URLStreamHandlerFactory;
040:
041:        import net.sf.jasperreports.engine.util.JRImageLoader;
042:        import net.sf.jasperreports.engine.util.JRLoader;
043:        import net.sf.jasperreports.engine.util.JRResourcesUtil;
044:        import net.sf.jasperreports.engine.util.JRTypeSniffer;
045:
046:        /**
047:         * @author Teodor Danciu (teodord@users.sourceforge.net)
048:         * @version $Id: JRImageRenderer.java 1811 2007-08-13 19:52:07Z teodord $
049:         */
050:        public class JRImageRenderer extends JRAbstractRenderer {
051:
052:            /**
053:             *
054:             */
055:            private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
056:
057:            /**
058:             *
059:             */
060:            private byte[] imageData = null;
061:            private String imageLocation = null;
062:            private byte imageType = IMAGE_TYPE_UNKNOWN;
063:
064:            /**
065:             *
066:             */
067:            private transient SoftReference awtImageRef = null;
068:
069:            /**
070:             *
071:             */
072:            private JRImageRenderer(byte[] imageData) {
073:                this .imageData = imageData;
074:
075:                if (imageData != null) {
076:                    imageType = JRTypeSniffer.getImageType(imageData);
077:                }
078:
079:            }
080:
081:            /**
082:             *
083:             */
084:            private JRImageRenderer(String imageLocation) {
085:                this .imageLocation = imageLocation;
086:            }
087:
088:            /**
089:             * @deprecated replaced by
090:             * {@link JRResourcesUtil#getThreadClassLoader() JRResourcesUtil.getThreadClassLoader()}
091:             */
092:            public static ClassLoader getClassLoader() {
093:                return JRResourcesUtil.getThreadClassLoader();
094:            }
095:
096:            /**
097:             * @deprecated replace by
098:             * {@link JRResourcesUtil#setThreadClassLoader(ClassLoader) JRResourcesUtil.setThreadClassLoader(ClassLoader)}
099:             */
100:            public static void setClassLoader(ClassLoader classLoader) {
101:                JRResourcesUtil.setThreadClassLoader(classLoader);
102:            }
103:
104:            /**
105:             *
106:             */
107:            public static JRImageRenderer getInstance(byte[] imageData) {
108:                return new JRImageRenderer(imageData);
109:            }
110:
111:            /**
112:             *
113:             */
114:            public static JRRenderable getInstance(String imageLocation)
115:                    throws JRException {
116:                return getInstance(imageLocation, JRImage.ON_ERROR_TYPE_ERROR,
117:                        true);
118:            }
119:
120:            /**
121:             *
122:             */
123:            public static JRRenderable getInstance(String imageLocation,
124:                    byte onErrorType) throws JRException {
125:                return getInstance(imageLocation, onErrorType, true);
126:            }
127:
128:            /**
129:             *
130:             */
131:            public static JRRenderable getInstance(String imageLocation,
132:                    byte onErrorType, boolean isLazy) throws JRException {
133:                return getInstance(imageLocation, onErrorType, isLazy, null,
134:                        null);
135:            }
136:
137:            /**
138:             *
139:             */
140:            public static JRRenderable getInstance(String imageLocation,
141:                    byte onErrorType, boolean isLazy, ClassLoader classLoader,
142:                    URLStreamHandlerFactory urlHandlerFactory)
143:                    throws JRException {
144:                if (imageLocation == null) {
145:                    return null;
146:                }
147:
148:                if (isLazy) {
149:                    return new JRImageRenderer(imageLocation);
150:                }
151:
152:                try {
153:                    byte[] data = JRLoader.loadBytesFromLocation(imageLocation,
154:                            classLoader, urlHandlerFactory);
155:                    return new JRImageRenderer(data);
156:                } catch (JRException e) {
157:                    return getOnErrorRenderer(onErrorType, e);
158:                }
159:            }
160:
161:            /**
162:             *
163:             */
164:            public static JRRenderable getInstance(Image img, byte onErrorType)
165:                    throws JRException {
166:                return getInstance(img, JRRenderable.IMAGE_TYPE_JPEG,
167:                        onErrorType);
168:            }
169:
170:            /**
171:             * Creates and returns an instance of the JRImageRenderer class after encoding the image object using an image
172:             * encoder that supports the supplied image type.
173:             * 
174:             * @param image the java.awt.Image object to wrap into a JRImageRenderer instance
175:             * @param imageType the type of the image as specified by one of the constants defined in the JRRenderable interface
176:             * @param onErrorType one of the error type constants defined in the JRImage interface
177:             * @return the image renderer instance
178:             */
179:            public static JRRenderable getInstance(Image image, byte imageType,
180:                    byte onErrorType) throws JRException {
181:                try {
182:                    return new JRImageRenderer(JRImageLoader
183:                            .loadImageDataFromAWTImage(image, imageType));
184:                } catch (JRException e) {
185:                    return getOnErrorRenderer(onErrorType, e);
186:                }
187:            }
188:
189:            /**
190:             *
191:             */
192:            public static JRRenderable getInstance(InputStream is,
193:                    byte onErrorType) throws JRException {
194:                try {
195:                    return new JRImageRenderer(JRLoader.loadBytes(is));
196:                } catch (JRException e) {
197:                    return getOnErrorRenderer(onErrorType, e);
198:                }
199:            }
200:
201:            /**
202:             *
203:             */
204:            public static JRRenderable getInstance(URL url, byte onErrorType)
205:                    throws JRException {
206:                try {
207:                    return new JRImageRenderer(JRLoader.loadBytes(url));
208:                } catch (JRException e) {
209:                    return getOnErrorRenderer(onErrorType, e);
210:                }
211:            }
212:
213:            /**
214:             *
215:             */
216:            public static JRRenderable getInstance(File file, byte onErrorType)
217:                    throws JRException {
218:                try {
219:                    return new JRImageRenderer(JRLoader.loadBytes(file));
220:                } catch (JRException e) {
221:                    return getOnErrorRenderer(onErrorType, e);
222:                }
223:            }
224:
225:            /**
226:             *
227:             */
228:            public static JRRenderable getOnErrorRendererForDimension(
229:                    JRRenderable renderer, byte onErrorType) throws JRException {
230:                try {
231:                    renderer.getDimension();
232:                    return renderer;
233:                } catch (JRException e) {
234:                    return getOnErrorRenderer(onErrorType, e);
235:                }
236:            }
237:
238:            /**
239:             *
240:             */
241:            public static JRRenderable getOnErrorRendererForImageData(
242:                    JRRenderable renderer, byte onErrorType) throws JRException {
243:                try {
244:                    renderer.getImageData();
245:                    return renderer;
246:                } catch (JRException e) {
247:                    return getOnErrorRenderer(onErrorType, e);
248:                }
249:            }
250:
251:            /**
252:             *
253:             */
254:            public static JRImageRenderer getOnErrorRendererForImage(
255:                    JRImageRenderer renderer, byte onErrorType)
256:                    throws JRException {
257:                try {
258:                    renderer.getImage();
259:                    return renderer;
260:                } catch (JRException e) {
261:                    return getOnErrorRenderer(onErrorType, e);
262:                }
263:            }
264:
265:            /**
266:             *
267:             */
268:            private static JRImageRenderer getOnErrorRenderer(byte onErrorType,
269:                    JRException e) throws JRException {
270:                JRImageRenderer renderer = null;
271:
272:                switch (onErrorType) {
273:                case JRImage.ON_ERROR_TYPE_ICON: {
274:                    renderer = new JRImageRenderer(
275:                            "net/sf/jasperreports/engine/images/noimage.GIF");
276:                    //FIXME cache these renderers
277:                    break;
278:                }
279:                case JRImage.ON_ERROR_TYPE_BLANK: {
280:                    break;
281:                }
282:                case JRImage.ON_ERROR_TYPE_ERROR:
283:                default: {
284:                    throw e;
285:                }
286:                }
287:
288:                return renderer;
289:            }
290:
291:            /**
292:             *
293:             */
294:            public Image getImage() throws JRException {
295:                if (awtImageRef == null || awtImageRef.get() == null) {
296:                    Image awtImage = JRImageLoader.loadImage(getImageData());
297:                    awtImageRef = new SoftReference(awtImage);
298:                }
299:                return (Image) awtImageRef.get();
300:            }
301:
302:            /**
303:             *
304:             */
305:            public String getImageLocation() {
306:                return imageLocation;
307:            }
308:
309:            /**
310:             *
311:             */
312:            public byte getType() {
313:                return TYPE_IMAGE;
314:            }
315:
316:            public byte getImageType() {
317:                return imageType;
318:            }
319:
320:            /**
321:             *
322:             */
323:            public Dimension2D getDimension() throws JRException {
324:                Image img = getImage();
325:                return new Dimension(img.getWidth(null), img.getHeight(null));
326:            }
327:
328:            /**
329:             *
330:             */
331:            public byte[] getImageData() throws JRException {
332:                if (imageData == null) {
333:                    imageData = JRLoader.loadBytesFromLocation(imageLocation);
334:                }
335:
336:                return imageData;
337:            }
338:
339:            /**
340:             *
341:             */
342:            public void render(Graphics2D grx, Rectangle2D rectanle)
343:                    throws JRException {
344:                Image img = getImage();
345:
346:                grx.drawImage(img, (int) rectanle.getX(),
347:                        (int) rectanle.getY(), (int) rectanle.getWidth(),
348:                        (int) rectanle.getHeight(), null);
349:            }
350:
351:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.