[Ejtools-cvs] libraries/common/src/main/org/ejtools/util/export CSVTools.java,NONE,1.1 PNGTools.java
Brought to you by:
letiemble
|
From: <let...@us...> - 2003-11-27 00:40:27
|
Update of /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/export In directory sc8-pr-cvs1:/tmp/cvs-serv7476/common/src/main/org/ejtools/util/export Modified Files: PNGTools.java Added Files: CSVTools.java Log Message: Address Todo #800900 : PNG Export Address Bug #808973 : Sort MBean informations Address RFE #848285 : CSV Export Remove @created tags --- NEW FILE: CSVTools.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.io.File; import java.io.FileWriter; import java.io.IOException; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import org.apache.log4j.Logger; /** * Description of the Class * * @author Laurent Etiemble * @version $Revision: 1.1 $ */ public class CSVTools { /** Description of the Field */ private static FileFilter CSV_FILE_FILTER = new FileFilter() { public boolean accept(File file) { return file.getName().endsWith(".csv"); } public String getDescription() { return "Comma Separated Values file (*.csv)"; } }; /** Description of the Field */ private static Logger logger = Logger.getLogger(CSVTools.class); /**Constructor for the CSVTools object */ private CSVTools() { super(); } /** * Description of the Method * * @param output Description of the Parameter * @param content Description of the Parameter */ public static void exportAsCVS(StringBuffer content, File output) { try { FileWriter writer = new FileWriter(output); writer.write(content.toString()); writer.flush(); writer.close(); } catch (IOException ioe) { logger.error("Can't export content as CSV", ioe); } } /** * Description of the Method * * @return Description of the Return Value */ public static File selectCSVFile() { // 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(CSV_FILE_FILTER); int returnVal = chooser.showSaveDialog(null); System.setSecurityManager(s); if (returnVal != JFileChooser.APPROVE_OPTION) { return null; } return chooser.getSelectedFile(); } } Index: PNGTools.java =================================================================== RCS file: /cvsroot/ejtools/libraries/common/src/main/org/ejtools/util/export/PNGTools.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PNGTools.java 15 Sep 2003 22:23:45 -0000 1.1 --- PNGTools.java 27 Nov 2003 00:40:24 -0000 1.2 *************** *** 89,94 **** 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); --- 89,93 ---- try { ! BufferedImage image = paintAsPNG(component); // Qualified name is mandatory javax.imageio.ImageIO.write(image, "PNG", output); *************** *** 99,102 **** --- 98,118 ---- } } + } + + + /** + * Description of the Method + * + * @param component Description of the Parameter + * @return Description of the Return Value + */ + public static BufferedImage paintAsPNG(Component component) + { + BufferedImage image = null; + + image = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB); + component.paint(image.getGraphics()); + + return image; } |