Source Code Cross Referenced for ExtensionFileFilter.java in  » Science » Cougaar12_4 » org » cougaar » tools » csmart » ui » monitor » generic » 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 » Science » Cougaar12_4 » org.cougaar.tools.csmart.ui.monitor.generic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * <copyright>
003:         *  
004:         *  Copyright 2000-2004 BBNT Solutions, LLC
005:         *  under sponsorship of the Defense Advanced Research Projects
006:         *  Agency (DARPA).
007:         * 
008:         *  You can redistribute this software and/or modify it under the
009:         *  terms of the Cougaar Open Source License as published on the
010:         *  Cougaar Open Source Website (www.cougaar.org).
011:         * 
012:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023:         *  
024:         * </copyright>
025:         */
026:
027:        package org.cougaar.tools.csmart.ui.monitor.generic;
028:
029:        import javax.swing.filechooser.FileFilter;
030:        import java.io.File;
031:        import java.util.Enumeration;
032:        import java.util.Hashtable;
033:
034:        /**
035:         * A convenience implementation of FileFilter that filters out
036:         * all files except for those type extensions that it knows about.
037:         *
038:         * Extensions are of the type ".foo", which is typically found on
039:         * Windows and Unix boxes, but not on Macinthosh. Case is ignored.
040:         *
041:         * Example - create a new filter that filters out all files
042:         * but gif and jpg image files:
043:         *
044:         *     JFileChooser chooser = new JFileChooser();
045:         *     ExtensionFileFilter filter = new ExtensionFileFilter(
046:         *                   new String{"gif", "jpg"}, "JPEG & GIF Images")
047:         *     chooser.addChoosableFileFilter(filter);
048:         *     chooser.showOpenDialog(this);
049:         *
050:         * From JDK1.2.1 demo.
051:         */
052:
053:        public class ExtensionFileFilter extends FileFilter {
054:
055:            //     private static String TYPE_UNKNOWN = "Type Unknown";
056:            //     private static String HIDDEN_FILE = "Hidden File";
057:
058:            private Hashtable filters = null;
059:            private String description = null;
060:            private String fullDescription = null;
061:            private boolean useExtensionsInDescription = true;
062:
063:            /**
064:             * Creates a file filter. If no filters are added, then all
065:             * files are accepted.
066:             *
067:             * @see #addExtension
068:             */
069:            public ExtensionFileFilter() {
070:                this .filters = new Hashtable();
071:            }
072:
073:            /**
074:             * Creates a file filter that accepts files with the given extension.
075:             * Example: new ExtensionFileFilter("jpg");
076:             *
077:             * @see #addExtension
078:             */
079:            public ExtensionFileFilter(String extension) {
080:                this (extension, null);
081:            }
082:
083:            /**
084:             * Creates a file filter that accepts the given file type.
085:             * Example: new ExtensionFileFilter("jpg", "JPEG Image Images");
086:             *
087:             * Note that the "." before the extension is not needed. If
088:             * provided, it will be ignored.
089:             *
090:             * @see #addExtension
091:             */
092:            public ExtensionFileFilter(String extension, String description) {
093:                this ();
094:                if (extension != null)
095:                    addExtension(extension);
096:                if (description != null)
097:                    setDescription(description);
098:            }
099:
100:            /**
101:             * Creates a file filter from the given string array.
102:             * Example: new ExtensionFileFilter(String {"gif", "jpg"});
103:             *
104:             * Note that the "." before the extension is not needed and
105:             * will be ignored.
106:             *
107:             * @see #addExtension
108:             */
109:            public ExtensionFileFilter(String[] filters) {
110:                this (filters, null);
111:            }
112:
113:            /**
114:             * Creates a file filter from the given string array and description.
115:             * Example: new ExtensionFileFilter(String {"gif", "jpg"}, "Gif and JPG Images");
116:             *
117:             * Note that the "." before the extension is not needed and will be ignored.
118:             *
119:             * @see #addExtension
120:             */
121:            public ExtensionFileFilter(String[] filters, String description) {
122:                this ();
123:                for (int i = 0; i < filters.length; i++) {
124:                    // add filters one by one
125:                    addExtension(filters[i]);
126:                }
127:                if (description != null)
128:                    setDescription(description);
129:            }
130:
131:            /**
132:             * Return true if this file should be shown in the directory pane,
133:             * false if it shouldn't.
134:             *
135:             * Files that begin with "." are ignored.
136:             *
137:             * @see #getExtension
138:             * @see FileFilter#accept
139:             */
140:            public boolean accept(File f) {
141:                if (f != null) {
142:                    if (f.isDirectory()) {
143:                        return true;
144:                    }
145:                    String extension = getExtension(f);
146:                    if (extension != null
147:                            && filters.get(getExtension(f)) != null) {
148:                        return true;
149:                    }
150:                    ;
151:                }
152:                return false;
153:            }
154:
155:            /**
156:             * Return the extension portion of the file's name .
157:             *
158:             * @see #getExtension
159:             * @see FileFilter#accept
160:             */
161:            public String getExtension(File f) {
162:                if (f != null) {
163:                    String filename = f.getName();
164:                    int i = filename.lastIndexOf('.');
165:                    if (i > 0 && i < filename.length() - 1) {
166:                        return filename.substring(i + 1).toLowerCase();
167:                    }
168:                    ;
169:                }
170:                return null;
171:            }
172:
173:            /**
174:             * Adds a filetype "dot" extension to filter against.
175:             *
176:             * For example: the following code will create a filter that filters
177:             * out all files except those that end in ".jpg" and ".tif":
178:             *
179:             *   ExtensionFileFilter filter = new ExtensionFileFilter();
180:             *   filter.addExtension("jpg");
181:             *   filter.addExtension("tif");
182:             *
183:             * Note that the "." before the extension is not needed and will be ignored.
184:             */
185:            public void addExtension(String extension) {
186:                if (filters == null) {
187:                    filters = new Hashtable(5);
188:                }
189:                filters.put(extension.toLowerCase(), this );
190:                fullDescription = null;
191:            }
192:
193:            /**
194:             * Returns the human readable description of this filter. For
195:             * example: "JPEG and GIF Image Files (*.jpg, *.gif)"
196:             *
197:             * @see #setDescription
198:             * @see #setExtensionListInDescription
199:             * @see #isExtensionListInDescription
200:             * @see FileFilter#getDescription
201:             */
202:            public String getDescription() {
203:                if (fullDescription == null) {
204:                    if (description == null || isExtensionListInDescription()) {
205:                        fullDescription = description == null ? "("
206:                                : description + " (";
207:                        // build the description from the extension list
208:                        Enumeration extensions = filters.keys();
209:                        if (extensions != null) {
210:                            //		    fullDescription += "." + (String) extensions.nextElement();
211:                            fullDescription += (String) extensions
212:                                    .nextElement();
213:                            while (extensions.hasMoreElements()) {
214:                                fullDescription += ", "
215:                                        + (String) extensions.nextElement();
216:                            }
217:                        }
218:                        fullDescription += ")";
219:                    } else {
220:                        fullDescription = description;
221:                    }
222:                }
223:                return fullDescription;
224:            }
225:
226:            /**
227:             * Sets the human readable description of this filter. For
228:             * example: filter.setDescription("Gif and JPG Images");
229:             *
230:             * @see #setDescription
231:             * @see #setExtensionListInDescription
232:             * @see #isExtensionListInDescription
233:             */
234:            public void setDescription(String description) {
235:                this .description = description;
236:                fullDescription = null;
237:            }
238:
239:            /**
240:             * Determines whether the extension list (.jpg, .gif, etc) should
241:             * show up in the human readable description.
242:             *
243:             * Only relevent if a description was provided in the constructor
244:             * or using setDescription();
245:             *
246:             * @see #getDescription
247:             * @see #setDescription
248:             * @see #isExtensionListInDescription
249:             */
250:            public void setExtensionListInDescription(boolean b) {
251:                useExtensionsInDescription = b;
252:                fullDescription = null;
253:            }
254:
255:            /**
256:             * Returns whether the extension list (.jpg, .gif, etc) should
257:             * show up in the human readable description.
258:             *
259:             * Only relevent if a description was provided in the constructor
260:             * or using setDescription();
261:             *
262:             * @see #getDescription
263:             * @see #setDescription
264:             * @see #setExtensionListInDescription
265:             */
266:            public boolean isExtensionListInDescription() {
267:                return useExtensionsInDescription;
268:            }
269:        }
w___ww_.___j___a__va__2__s__._c_o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.