1 26 package org.objectweb.openccm.explorer.menu; 27 28 29 import java.io.File ; 30 import javax.swing.JFileChooser ; 31 import javax.swing.filechooser.FileFilter ; 32 33 39 public class JFileChooserSingleton { 40 41 42 protected static JFileChooser instance_ = null; 43 44 45 protected static FileFilter jarFileFilter = new JarFileFilter(); 46 47 48 protected static FileFilter xmlFileFilter = new XMLFileFilter(); 49 50 51 protected static FileFilter iorFileFilter = new IORFileFilter(); 52 53 54 protected static FileFilter zipFileFilter = new ZipFileFilter(); 55 56 57 protected static FileFilter aarFileFilter = new AARFileFilter(); 58 59 60 protected static FileFilter assemblyArchiveFileFilter = new AssemblyArchiveFileFilter(); 61 62 63 protected static FileFilter componentArchiveFileFilter = new ComponentArchiveFileFilter(); 64 65 68 protected static void init() { 69 instance_ = new JFileChooser (); 70 } 71 72 88 public static JFileChooser getInstance(int fileFilterType) { 89 return getInstance(fileFilterType, "Open", JFileChooser.FILES_ONLY); 90 } 91 92 114 public static JFileChooser getInstance(int fileFilterType, int fileSelectionMode) { 115 return getInstance(fileFilterType, "Open", fileSelectionMode); 116 } 117 118 140 public static JFileChooser getInstance(int fileFilterType, String dialogTitle, int fileSelectionMode) { 141 File f = null; 142 if (instance_ != null) 143 f = instance_.getCurrentDirectory(); 144 else 145 f = new File (System.getProperty("user.dir")); 146 init(); 147 instance_.setCurrentDirectory(f); 148 instance_.setDialogTitle(dialogTitle); 149 try{ 150 instance_.setFileSelectionMode(fileSelectionMode); 151 }catch(IllegalArgumentException e){} 152 if (fileFilterType == OpenCCMBrowserConstants.JAR_FILE_CHOOSER) 153 instance_.setFileFilter(jarFileFilter); 154 else if (fileFilterType == OpenCCMBrowserConstants.XML_FILE_CHOOSER) 155 instance_.setFileFilter(xmlFileFilter); 156 else if (fileFilterType == OpenCCMBrowserConstants.IOR_FILE_CHOOSER) 157 instance_.setFileFilter(iorFileFilter); 158 else if (fileFilterType == OpenCCMBrowserConstants.ZIP_FILE_CHOOSER) 159 instance_.setFileFilter(zipFileFilter); 160 else if (fileFilterType == OpenCCMBrowserConstants.AAR_FILE_CHOOSER) 161 instance_.setFileFilter(aarFileFilter); 162 else if (fileFilterType == OpenCCMBrowserConstants.ASSEMBLY_ARCHIVE_FILE_CHOOSER) 163 instance_.setFileFilter(assemblyArchiveFileFilter); 164 else if (fileFilterType == OpenCCMBrowserConstants.COMPONENT_ARCHIVE_FILE_CHOOSER) 165 instance_.setFileFilter(componentArchiveFileFilter); 166 else if (fileFilterType == OpenCCMBrowserConstants.DIRECTORY_FILE_CHOOSER) 167 instance_.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); 168 return instance_; 169 } 170 171 } 172 | Popular Tags |