KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > util > export > PNGFileTools


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.util.export;
8
9 import java.awt.Component JavaDoc;
10 import java.awt.image.BufferedImage JavaDoc;
11 import java.awt.image.RenderedImage JavaDoc;
12 import java.io.File JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.util.ResourceBundle JavaDoc;
15
16 import org.apache.log4j.Logger;
17 import org.ejtools.util.FileTools;
18 import org.ejtools.util.Platform;
19
20 /**
21  * Description of the Class
22  *
23  * @author Laurent Etiemble
24  * @version $Revision: 1.2 $
25  */

26 public class PNGFileTools extends FileTools
27 {
28    /** Description of the Field */
29    private static Logger logger = Logger.getLogger(PNGFileTools.class);
30    /** Description of the Field */
31    private static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.util.Resources");
32    /** Description of the Field */
33    public final static SimpleFileFilter PNG_FILE_FILTER = new FileTools.SimpleFileFilter(".png", resources.getString("png.file.dialog.extension.description"));
34
35
36    /** Constructor for the FileUtil object */
37    protected PNGFileTools() { }
38
39
40    /**
41     * Description of the Method
42     *
43     * @param image Description of the Parameter
44     * @param output Description of the Parameter
45     */

46    public static void exportAsPNG(RenderedImage JavaDoc image, File JavaDoc output)
47    {
48       if (Platform.isJavaVersionCompatible(Platform.JAVA_1_4))
49       {
50          try
51          {
52             // Qualified name is mandatory
53
javax.imageio.ImageIO.write(image, "PNG", output);
54          }
55          catch (IOException JavaDoc ioe)
56          {
57             logger.error("Can't export image as PNG", ioe);
58          }
59       }
60    }
61
62
63    /**
64     * Description of the Method
65     *
66     * @param component Description of the Parameter
67     * @param output Description of the Parameter
68     */

69    public static void exportAsPNG(Component JavaDoc component, File JavaDoc output)
70    {
71       if (Platform.isJavaVersionCompatible(Platform.JAVA_1_4))
72       {
73          try
74          {
75             BufferedImage JavaDoc image = paintAsPNG(component);
76             // Qualified name is mandatory
77
javax.imageio.ImageIO.write(image, "PNG", output);
78          }
79          catch (IOException JavaDoc ioe)
80          {
81             logger.error("Can't export image as PNG", ioe);
82          }
83       }
84    }
85
86
87    /**
88     * Description of the Method
89     *
90     * @param component Description of the Parameter
91     * @return Description of the Return Value
92     */

93    public static BufferedImage JavaDoc paintAsPNG(Component JavaDoc component)
94    {
95       BufferedImage JavaDoc image = null;
96
97       image = new BufferedImage JavaDoc(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB);
98       component.paint(image.getGraphics());
99
100       return image;
101    }
102 }
103
Popular Tags