Source Code Cross Referenced for ExampleFileFilter.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dfly » utils » loadercontrol » 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 » 6.0 JDK Modules » java 3d » org.jdesktop.j3dfly.utils.loadercontrol 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/utils/loadercontrol/ExampleFileFilter.java,v 1.1 2005/04/20 21:05:06 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is Java 3D(tm) Fly Through.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dfly.utils.loadercontrol;
019:
020:        import java.io.File;
021:        import java.util.Hashtable;
022:        import java.util.Enumeration;
023:        import javax.swing.*;
024:        import javax.swing.filechooser.*;
025:
026:        /**
027:         * A convenience implementation of FileFilter that filters out
028:         * all files except for those type extensions that it knows about.
029:         *
030:         * Extensions are of the type ".foo", which is typically found on
031:         * Windows and Unix boxes, but not on Macinthosh. Case is ignored.
032:         *
033:         * Example - create a new filter that filerts out all files
034:         * but gif and jpg image files:
035:         *
036:         *     JFileChooser chooser = new JFileChooser();
037:         *     ExampleFileFilter filter = new ExampleFileFilter(
038:         *                   new String{"gif", "jpg"}, "JPEG & GIF Images")
039:         *     chooser.addChoosableFileFilter(filter);
040:         *     chooser.showOpenDialog(this);
041:         *
042:         * @version 1.9 04/23/99
043:         * @author Jeff Dinkins
044:         */
045:        public class ExampleFileFilter extends FileFilter {
046:
047:            private static String TYPE_UNKNOWN = "Type Unknown";
048:            private static String HIDDEN_FILE = "Hidden File";
049:
050:            private Hashtable filters = null;
051:            private String description = null;
052:            private String fullDescription = null;
053:            private boolean useExtensionsInDescription = true;
054:
055:            /**
056:             * Creates a file filter. If no filters are added, then all
057:             * files are accepted.
058:             *
059:             * @see #addExtension
060:             */
061:            public ExampleFileFilter() {
062:                this .filters = new Hashtable();
063:            }
064:
065:            /**
066:             * Creates a file filter that accepts files with the given extension.
067:             * Example: new ExampleFileFilter("jpg");
068:             *
069:             * @see #addExtension
070:             */
071:            public ExampleFileFilter(String extension) {
072:                this (extension, null);
073:            }
074:
075:            /**
076:             * Creates a file filter that accepts the given file type.
077:             * Example: new ExampleFileFilter("jpg", "JPEG Image Images");
078:             *
079:             * Note that the "." before the extension is not needed. If
080:             * provided, it will be ignored.
081:             *
082:             * @see #addExtension
083:             */
084:            public ExampleFileFilter(String extension, String description) {
085:                this ();
086:                if (extension != null)
087:                    addExtension(extension);
088:                if (description != null)
089:                    setDescription(description);
090:            }
091:
092:            /**
093:             * Creates a file filter from the given string array.
094:             * Example: new ExampleFileFilter(String {"gif", "jpg"});
095:             *
096:             * Note that the "." before the extension is not needed adn
097:             * will be ignored.
098:             *
099:             * @see #addExtension
100:             */
101:            public ExampleFileFilter(String[] filters) {
102:                this (filters, null);
103:            }
104:
105:            /**
106:             * Creates a file filter from the given string array and description.
107:             * Example: new ExampleFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
108:             *
109:             * Note that the "." before the extension is not needed and will be ignored.
110:             *
111:             * @see #addExtension
112:             */
113:            public ExampleFileFilter(String[] filters, String description) {
114:                this ();
115:                for (int i = 0; i < filters.length; i++) {
116:                    // add filters one by one
117:                    addExtension(filters[i]);
118:                }
119:                if (description != null)
120:                    setDescription(description);
121:            }
122:
123:            /**
124:             * Return true if this file should be shown in the directory pane,
125:             * false if it shouldn't.
126:             *
127:             * Files that begin with "." are ignored.
128:             *
129:             * @see #getExtension
130:             * @see FileFilter#accepts
131:             */
132:            public boolean accept(File f) {
133:                if (f != null) {
134:                    if (f.isDirectory()) {
135:                        return true;
136:                    }
137:                    String extension = getExtension(f);
138:                    if (extension != null
139:                            && filters.get(getExtension(f)) != null) {
140:                        return true;
141:                    }
142:                    ;
143:                }
144:                return false;
145:            }
146:
147:            /**
148:             * Return the extension portion of the file's name .
149:             *
150:             * @see #getExtension
151:             * @see FileFilter#accept
152:             */
153:            public String getExtension(File f) {
154:                if (f != null) {
155:                    String filename = f.getName();
156:                    int i = filename.lastIndexOf('.');
157:                    if (i > 0 && i < filename.length() - 1) {
158:                        return filename.substring(i + 1).toLowerCase();
159:                    }
160:                    ;
161:                }
162:                return null;
163:            }
164:
165:            /**
166:             * Adds a filetype "dot" extension to filter against.
167:             *
168:             * For example: the following code will create a filter that filters
169:             * out all files except those that end in ".jpg" and ".tif":
170:             *
171:             *   ExampleFileFilter filter = new ExampleFileFilter();
172:             *   filter.addExtension("jpg");
173:             *   filter.addExtension("tif");
174:             *
175:             * Note that the "." before the extension is not needed and will be ignored.
176:             */
177:            public void addExtension(String extension) {
178:                if (filters == null) {
179:                    filters = new Hashtable(5);
180:                }
181:                filters.put(extension.toLowerCase(), this );
182:                fullDescription = null;
183:            }
184:
185:            /**
186:             * Returns the human readable description of this filter. For
187:             * example: "JPEG and GIF Image Files (*.jpg, *.gif)"
188:             *
189:             * @see setDescription
190:             * @see setExtensionListInDescription
191:             * @see isExtensionListInDescription
192:             * @see FileFilter#getDescription
193:             */
194:            public String getDescription() {
195:                if (fullDescription == null) {
196:                    if (description == null || isExtensionListInDescription()) {
197:                        fullDescription = description == null ? "("
198:                                : description + " (";
199:                        // build the description from the extension list
200:                        Enumeration extensions = filters.keys();
201:                        if (extensions != null) {
202:                            fullDescription += "."
203:                                    + (String) extensions.nextElement();
204:                            while (extensions.hasMoreElements()) {
205:                                fullDescription += ", "
206:                                        + (String) extensions.nextElement();
207:                            }
208:                        }
209:                        fullDescription += ")";
210:                    } else {
211:                        fullDescription = description;
212:                    }
213:                }
214:                return fullDescription;
215:            }
216:
217:            /**
218:             * Sets the human readable description of this filter. For
219:             * example: filter.setDescription("Gif and JPG Images");
220:             *
221:             * @see setDescription
222:             * @see setExtensionListInDescription
223:             * @see isExtensionListInDescription
224:             */
225:            public void setDescription(String description) {
226:                this .description = description;
227:                fullDescription = null;
228:            }
229:
230:            /**
231:             * Determines whether the extension list (.jpg, .gif, etc) should
232:             * show up in the human readable description.
233:             *
234:             * Only relevent if a description was provided in the constructor
235:             * or using setDescription();
236:             *
237:             * @see getDescription
238:             * @see setDescription
239:             * @see isExtensionListInDescription
240:             */
241:            public void setExtensionListInDescription(boolean b) {
242:                useExtensionsInDescription = b;
243:                fullDescription = null;
244:            }
245:
246:            /**
247:             * Returns whether the extension list (.jpg, .gif, etc) should
248:             * show up in the human readable description.
249:             *
250:             * Only relevent if a description was provided in the constructor
251:             * or using setDescription();
252:             *
253:             * @see getDescription
254:             * @see setDescription
255:             * @see setExtensionListInDescription
256:             */
257:            public boolean isExtensionListInDescription() {
258:                return useExtensionsInDescription;
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.