Update of /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/export
In directory sc8-pr-cvs1:/tmp/cvs-serv20661/common/src/main/org/ejtools/util/export
Added Files:
PNGTools.java
Log Message:
Adjust Eclipse build files
Adjust some Javadoc
Integrate Persistence framework
Integrate Image export as PNG
--- NEW FILE: PNGTools.java ---
/*
* EJTools, the Enterprise Java Tools
*
* Distributable under LGPL license.
* See terms of license at www.gnu.org.
*/
package org.ejtools.util.export;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import org.apache.log4j.Logger;
import org.ejtools.util.Platform;
/**
* Description of the Class
*
* @author Laurent Etiemble
* @version $Revision: 1.1 $
*/
public class PNGTools
{
/** Description of the Field */
private static FileFilter PNG_FILE_FILTER =
new FileFilter()
{
public boolean accept(File file)
{
return file.getName().endsWith(".png");
}
public String getDescription()
{
return "PNG image (*.png)";
}
};
/** Description of the Field */
private static Logger logger = Logger.getLogger(PNGTools.class);
/**Constructor for the PNGCreator object */
private PNGTools()
{
super();
}
/**
* Description of the Method
*
* @param image Description of the Parameter
* @param output Description of the Parameter
*/
public static void exportAsPNG(RenderedImage image, File output)
{
if (Platform.isJavaVersionCompatible(Platform.JAVA_1_4))
{
try
{
// Qualified name is mandatory
javax.imageio.ImageIO.write(image, "PNG", output);
}
catch (IOException ioe)
{
logger.error("Can't export image as PNG", ioe);
}
}
}
/**
* Description of the Method
*
* @param component Description of the Parameter
* @param output Description of the Parameter
*/
public static void exportAsPNG(Component component, File output)
{
if (Platform.isJavaVersionCompatible(Platform.JAVA_1_4))
{
try
{
BufferedImage image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB);
component.paint(image.getGraphics());
// Qualified name is mandatory
javax.imageio.ImageIO.write(image, "PNG", output);
}
catch (IOException ioe)
{
logger.error("Can't export image as PNG", ioe);
}
}
}
/**
* Description of the Method
*
* @return Description of the Return Value
*/
public static File selectPNGFile()
{
// Fix for JFileChooser/SecurityManager bug (#4264750)
SecurityManager s = System.getSecurityManager();
System.setSecurityManager(null);
// Choose file
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir"));
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
chooser.setFileFilter(PNG_FILE_FILTER);
int returnVal = chooser.showSaveDialog(null);
System.setSecurityManager(s);
if (returnVal != JFileChooser.APPROVE_OPTION)
{
return null;
}
return chooser.getSelectedFile();
}
}
|