KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > explorer > menu > JFileChooserSingleton


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 package org.objectweb.openccm.explorer.menu;
27
28 /** The Java API's imports */
29 import java.io.File JavaDoc;
30 import javax.swing.JFileChooser JavaDoc;
31 import javax.swing.filechooser.FileFilter JavaDoc;
32
33 /**
34  * This class provides a JFileChooser.
35  *
36  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
37  * @version 0.1
38  */

39 public class JFileChooserSingleton {
40
41     /** The JFileChooser instance */
42     protected static JFileChooser JavaDoc instance_ = null;
43
44     /** The JarFileFilter instance */
45     protected static FileFilter JavaDoc jarFileFilter = new JarFileFilter();
46
47     /** The JarFileFilter instance */
48     protected static FileFilter JavaDoc xmlFileFilter = new XMLFileFilter();
49
50     /** The IORFileFilter instance */
51     protected static FileFilter JavaDoc iorFileFilter = new IORFileFilter();
52
53     /** The ZipFileFilter instance */
54     protected static FileFilter JavaDoc zipFileFilter = new ZipFileFilter();
55     
56     /** The AarFileFilter instance */
57     protected static FileFilter JavaDoc aarFileFilter = new AARFileFilter();
58
59     /** The AssemblyArchiveFileFilter instance */
60     protected static FileFilter JavaDoc assemblyArchiveFileFilter = new AssemblyArchiveFileFilter();
61
62     /** The AssemblyArchiveFileFilter instance */
63     protected static FileFilter JavaDoc componentArchiveFileFilter = new ComponentArchiveFileFilter();
64
65     /**
66      * Initialize the instance
67      */

68     protected static void init() {
69         instance_ = new JFileChooser JavaDoc();
70     }
71
72     /**
73      * Provides a JFileChooser with a specific FileFilter
74      * The default dialogTitle is Open and the defaulf fileSelectionMode is JFileChooser.FILES_ONLY.
75      * @param fileFilterType The FileFilter type.
76      * <ul>
77      * <li>OpenCCMBrowserConstants.JAR_FILE_CHOOSER</li>
78      * <li>OpenCCMBrowserConstants.XML_FILE_CHOOSER</li>
79      * <li>OpenCCMBrowserConstants.IOR_FILE_CHOOSER</li>
80      * <li>OpenCCMBrowserConstants.DIRECTORY_FILE_CHOOSER</li>
81      * <li>OpenCCMBrowserConstants.ZIP_FILE_CHOOSER</li>
82      * <li>OpenCCMBrowserConstants.AAR_FILE_CHOOSER</li>
83      * <li>OpenCCMBrowserConstants.ASSEMBLY_ARCHIVE_FILE_CHOOSER</li>
84      * <li>OpenCCMBrowserConstants.COMPONENT_ARCHIVE_FILE_CHOOSER</li>
85      * </ul>
86      * @return The appropriate JFileChooser
87      */

88     public static JFileChooser JavaDoc getInstance(int fileFilterType) {
89         return getInstance(fileFilterType, "Open", JFileChooser.FILES_ONLY);
90     }
91
92     /**
93      * Provides a JFileChooser with a specific FileFilter
94      * The default dialogTitle is Open and the defaulf fileSelectionMode is JFileChooser.FILES_ONLY.
95      * @param fileFilterType The FileFilter type.
96      * <ul>
97      * <li>OpenCCMBrowserConstants.JAR_FILE_CHOOSER</li>
98      * <li>OpenCCMBrowserConstants.XML_FILE_CHOOSER</li>
99      * <li>OpenCCMBrowserConstants.IOR_FILE_CHOOSER</li>
100      * <li>OpenCCMBrowserConstants.DIRECTORY_FILE_CHOOSER</li>
101      * <li>OpenCCMBrowserConstants.ZIP_FILE_CHOOSER</li>
102      * <li>OpenCCMBrowserConstants.AAR_FILE_CHOOSER</li>
103      * <li>OpenCCMBrowserConstants.ASSEMBLY_ARCHIVE_FILE_CHOOSER</li>
104      * <li>OpenCCMBrowserConstants.COMPONENT_ARCHIVE_FILE_CHOOSER</li>
105      * </ul>
106      * @param fileSelectionMode The file selection mode
107      * <ul>
108      * <li>JFileChooser.FILES_ONLY</li>
109      * <li>JFileChooser.DIRECTORIES_ONLY</li>
110      * <li>JFileChooser.FILES_AND_DIRECTORIES</li>
111      * </ul>
112      * @return The appropriate JFileChooser
113      */

114     public static JFileChooser JavaDoc getInstance(int fileFilterType, int fileSelectionMode) {
115         return getInstance(fileFilterType, "Open", fileSelectionMode);
116     }
117
118     /**
119      * Gives a JFileChooser with a specific FileFilter
120      * @param fileFilterType The FileFilter type.
121      * <ul>
122      * <li>OpenCCMBrowserConstants.JAR_FILE_CHOOSER</li>
123      * <li>OpenCCMBrowserConstants.XML_FILE_CHOOSER</li>
124      * <li>OpenCCMBrowserConstants.IOR_FILE_CHOOSER</li>
125      * <li>OpenCCMBrowserConstants.DIRECTORY_FILE_CHOOSER</li>
126      * <li>OpenCCMBrowserConstants.ZIP_FILE_CHOOSER</li>
127      * <li>OpenCCMBrowserConstants.AAR_FILE_CHOOSER</li>
128      * <li>OpenCCMBrowserConstants.ASSEMBLY_ARCHIVE_FILE_CHOOSER</li>
129      * <li>OpenCCMBrowserConstants.COMPONENT_ARCHIVE_FILE_CHOOSER</li>
130      * </ul>
131      * @param dialogTitle The title of the JFileChooser box.
132      * @param fileSelectionMode The file selection mode
133      * <ul>
134      * <li>JFileChooser.FILES_ONLY</li>
135      * <li>JFileChooser.DIRECTORIES_ONLY</li>
136      * <li>JFileChooser.FILES_AND_DIRECTORIES</li>
137      * </ul>
138      * @return The appropriate JFileChooser
139      */

140     public static JFileChooser JavaDoc getInstance(int fileFilterType, String JavaDoc dialogTitle, int fileSelectionMode) {
141         File JavaDoc f = null;
142         if (instance_ != null)
143             f = instance_.getCurrentDirectory();
144         else
145             f = new File JavaDoc(System.getProperty("user.dir"));
146         init();
147         instance_.setCurrentDirectory(f);
148         instance_.setDialogTitle(dialogTitle);
149         try{
150             instance_.setFileSelectionMode(fileSelectionMode);
151         }catch(IllegalArgumentException JavaDoc 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