Source Code Cross Referenced for FileSelector.java in  » Database-Client » executequery » org » underworldlabs » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » executequery » org.underworldlabs.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * FileSelector.java
003:         *
004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005:         *
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License
008:         * as published by the Free Software Foundation; either version 2
009:         * of the License, or any later version.
010:         *
011:         * This program is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014:         * GNU General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU General Public License
017:         * along with this program; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
019:         *
020:         */
021:
022:        package org.underworldlabs.swing;
023:
024:        import java.io.File;
025:
026:        import java.util.Enumeration;
027:        import java.util.Hashtable;
028:
029:        import javax.swing.filechooser.FileFilter;
030:
031:        /* ----------------------------------------------------------
032:         * CVS NOTE: Changes to the CVS repository prior to the 
033:         *           release of version 3.0.0beta1 has meant a 
034:         *           resetting of CVS revision numbers.
035:         * ----------------------------------------------------------
036:         */
037:
038:        /**
039:         * A convenience implementation of FileFilter that filters out
040:         * all files except for those type extensions that it knows about.
041:         *
042:         * Extensions are of the type ".foo", which is typically found on
043:         * Windows and Unix boxes, but not on Macinthosh. Case is ignored.
044:         *
045:         * Example - create a new filter that filters out all files
046:         * but gif and jpg image files:
047:         *
048:         *     JFileChooser chooser = new JFileChooser();
049:         *     ExampleFileFilter filter = new ExampleFileFilter(
050:         *                   new String{"gif", "jpg"}, "JPEG & GIF Images")
051:         *     chooser.addChoosableFileFilter(filter);
052:         *     chooser.showOpenDialog(this);
053:         *
054:         * @version 1.9 04/23/99
055:         * @author Jeff Dinkins
056:         */
057:        public class FileSelector extends FileFilter {
058:
059:            private static String TYPE_UNKNOWN = "Type Unknown";
060:            private static String HIDDEN_FILE = "Hidden File";
061:
062:            private Hashtable filters = null;
063:            private String description = null;
064:            private String fullDescription = null;
065:            private boolean useExtensionsInDescription = true;
066:
067:            /**
068:             * Creates a file filter. If no filters are added, then all
069:             * files are accepted.
070:             *
071:             * @see #addExtension
072:             */
073:            public FileSelector() {
074:                this .filters = new Hashtable();
075:            }
076:
077:            /**
078:             * Creates a file filter that accepts files with the given extension.
079:             * Example: new ExampleFileFilter("jpg");
080:             *
081:             * @see #addExtension
082:             */
083:            public FileSelector(String extension) {
084:                this (extension, null);
085:            }
086:
087:            /**
088:             * Creates a file filter that accepts the given file type.
089:             * Example: new ExampleFileFilter("jpg", "JPEG Image Images");
090:             *
091:             * Note that the "." before the extension is not needed. If
092:             * provided, it will be ignored.
093:             *
094:             * @see #addExtension
095:             */
096:            public FileSelector(String extension, String description) {
097:                this ();
098:                if (extension != null)
099:                    addExtension(extension);
100:                if (description != null)
101:                    setDescription(description);
102:            }
103:
104:            /**
105:             * Creates a file filter from the given string array.
106:             * Example: new ExampleFileFilter(String {"gif", "jpg"});
107:             *
108:             * Note that the "." before the extension is not needed and
109:             * will be ignored.
110:             *
111:             * @see #addExtension
112:             */
113:            public FileSelector(String[] filters) {
114:                this (filters, null);
115:            }
116:
117:            /**
118:             * Creates a file filter from the given string array and description.
119:             * Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
120:             *
121:             * Note that the "." before the extension is not needed and will be ignored.
122:             *
123:             * @see #addExtension
124:             */
125:            public FileSelector(String[] filters, String description) {
126:                this ();
127:                for (int i = 0; i < filters.length; i++) {
128:                    // add filters one by one
129:                    addExtension(filters[i]);
130:                }
131:                if (description != null)
132:                    setDescription(description);
133:            }
134:
135:            /**
136:             * Return true if this file should be shown in the directory pane,
137:             * false if it shouldn't.
138:             *
139:             * Files that begin with "." are ignored.
140:             *
141:             * @see #getExtension
142:             * @see FileFilter#accepts
143:             */
144:            public boolean accept(File f) {
145:                if (f != null) {
146:                    if (f.isDirectory()) {
147:                        return true;
148:                    }
149:                    String extension = getExtension(f);
150:                    if (extension != null
151:                            && filters.get(getExtension(f)) != null) {
152:                        return true;
153:                    }
154:                    ;
155:                }
156:                return false;
157:            }
158:
159:            /**
160:             * Return the extension portion of the file's name .
161:             *
162:             * @see #getExtension
163:             * @see FileFilter#accept
164:             */
165:            public String getExtension(File f) {
166:                if (f != null) {
167:                    String filename = f.getName();
168:                    int i = filename.lastIndexOf('.');
169:                    if (i > 0 && i < filename.length() - 1) {
170:                        return filename.substring(i + 1).toLowerCase();
171:                    }
172:                    ;
173:                }
174:                return null;
175:            }
176:
177:            /**
178:             * Adds a filetype "dot" extension to filter against.
179:             *
180:             * For example: the following code will create a filter that filters
181:             * out all files except those that end in ".jpg" and ".tif":
182:             *
183:             *   ExampleFileFilter filter = new ExampleFileFilter();
184:             *   filter.addExtension("jpg");
185:             *   filter.addExtension("tif");
186:             *
187:             * Note that the "." before the extension is not needed and will be ignored.
188:             */
189:            public void addExtension(String extension) {
190:                if (filters == null) {
191:                    filters = new Hashtable(5);
192:                }
193:                filters.put(extension.toLowerCase(), this );
194:                fullDescription = null;
195:            }
196:
197:            /**
198:             * Returns the human readable description of this filter. For
199:             * example: "JPEG and GIF Image Files (*.jpg, *.gif)"
200:             *
201:             * @see setDescription
202:             * @see setExtensionListInDescription
203:             * @see isExtensionListInDescription
204:             * @see FileFilter#getDescription
205:             */
206:            public String getDescription() {
207:                if (fullDescription == null) {
208:                    if (description == null || isExtensionListInDescription()) {
209:                        fullDescription = description == null ? "("
210:                                : description + " (";
211:                        // build the description from the extension list
212:                        Enumeration extensions = filters.keys();
213:                        if (extensions != null) {
214:                            fullDescription += "."
215:                                    + (String) extensions.nextElement();
216:                            while (extensions.hasMoreElements()) {
217:                                fullDescription += ", "
218:                                        + (String) extensions.nextElement();
219:                            }
220:                        }
221:                        fullDescription += ")";
222:                    } else {
223:                        fullDescription = description;
224:                    }
225:                }
226:                return fullDescription;
227:            }
228:
229:            /**
230:             * Sets the human readable description of this filter. For
231:             * example: filter.setDescription("Gif and JPG Images");
232:             *
233:             * @see setDescription
234:             * @see setExtensionListInDescription
235:             * @see isExtensionListInDescription
236:             */
237:            public void setDescription(String description) {
238:                this .description = description;
239:                fullDescription = null;
240:            }
241:
242:            /**
243:             * Determines whether the extension list (.jpg, .gif, etc) should
244:             * show up in the human readable description.
245:             *
246:             * Only relevent if a description was provided in the constructor
247:             * or using setDescription();
248:             *
249:             * @see getDescription
250:             * @see setDescription
251:             * @see isExtensionListInDescription
252:             */
253:            public void setExtensionListInDescription(boolean b) {
254:                useExtensionsInDescription = b;
255:                fullDescription = null;
256:            }
257:
258:            /**
259:             * Returns whether the extension list (.jpg, .gif, etc) should
260:             * show up in the human readable description.
261:             *
262:             * Only relevent if a description was provided in the constructor
263:             * or using setDescription();
264:             *
265:             * @see getDescription
266:             * @see setDescription
267:             * @see setExtensionListInDescription
268:             */
269:            public boolean isExtensionListInDescription() {
270:                return useExtensionsInDescription;
271:            }
272:
273:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.