1 7 package org.ejtools.adwt; 8 9 import java.io.File ; 10 import java.net.URL ; 11 import java.util.ResourceBundle ; 12 13 import javax.swing.JFileChooser ; 14 import javax.swing.filechooser.FileFilter ; 15 16 import org.apache.log4j.Logger; 17 18 25 public class FileUtil 26 { 27 28 public static FileFilter WORKSPACE_FILE_FILTER = 29 new FileFilter () 30 { 31 public boolean accept(File file) 32 { 33 return file.getName().endsWith(".xml"); 34 } 35 36 37 public String getDescription() 38 { 39 return resources.getString("workspace.file.dialog.extension.description"); 40 } 41 }; 42 43 private static Logger logger = Logger.getLogger(FileUtil.class); 44 45 private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.adwt.Resources"); 46 47 48 49 private FileUtil() { } 50 51 52 60 public static URL selectWorkspaceFile(String title, int type) 61 throws Exception 62 { 63 SecurityManager s = System.getSecurityManager(); 65 System.setSecurityManager(null); 66 67 JFileChooser chooser = new JFileChooser (System.getProperty("user.dir")); 69 chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); 70 chooser.setDialogTitle(title); 71 chooser.setDialogType(type); 72 chooser.setFileFilter(WORKSPACE_FILE_FILTER); 73 74 int returnVal = chooser.showDialog(null, title); 75 System.setSecurityManager(s); 76 if (returnVal != JFileChooser.APPROVE_OPTION) 77 { 78 return null; 79 } 80 81 return chooser.getSelectedFile().toURL(); 82 } 83 } 84 | Popular Tags |