KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > adwt > FileUtil


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.adwt;
8
9 import java.io.File JavaDoc;
10 import java.net.URL JavaDoc;
11 import java.util.ResourceBundle JavaDoc;
12
13 import javax.swing.JFileChooser JavaDoc;
14 import javax.swing.filechooser.FileFilter JavaDoc;
15
16 import org.apache.log4j.Logger;
17
18 /**
19  * Description of the Class
20  *
21  * @author Laurent Etiemble
22  * @version $Revision: 1.1 $
23  * @todo Javadoc to complete
24  */

25 public class FileUtil
26 {
27    /** Description of the Field */
28    public static FileFilter JavaDoc WORKSPACE_FILE_FILTER =
29       new FileFilter JavaDoc()
30       {
31          public boolean accept(File JavaDoc file)
32          {
33             return file.getName().endsWith(".xml");
34          }
35
36
37          public String JavaDoc getDescription()
38          {
39             return resources.getString("workspace.file.dialog.extension.description");
40          }
41       };
42    /** Default logger */
43    private static Logger logger = Logger.getLogger(FileUtil.class);
44    /** Bundle for I18N */
45    private static ResourceBundle JavaDoc resources = ResourceBundle.getBundle("org.ejtools.adwt.Resources");
46
47
48    /**Constructor for the FileUtil object */
49    private FileUtil() { }
50
51
52    /**
53     * Description of the Method
54     *
55     * @param title Description of the Parameter
56     * @param type Description of the Parameter
57     * @return Description of the Return Value
58     * @exception Exception Description of the Exception
59     */

60    public static URL JavaDoc selectWorkspaceFile(String JavaDoc title, int type)
61       throws Exception JavaDoc
62    {
63       // Fix for JFileChooser/SecurityManager bug (#4264750)
64
SecurityManager JavaDoc s = System.getSecurityManager();
65       System.setSecurityManager(null);
66
67       // Choose file
68
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(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