Source Code Cross Referenced for JGraphpadFileFilter.java in  » Graphic-Library » jgraphpad » com » jgraph » pad » util » 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 » Graphic Library » jgraphpad » com.jgraph.pad.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * $Id: JGraphpadFileFilter.java,v 1.2 2005/10/09 12:00:04 gaudenz Exp $
003:         * Copyright (c) 2001-2005, Gaudenz Alder
004:         * 
005:         * All rights reserved.
006:         * 
007:         * See LICENSE file for license details. If you are unable to locate
008:         * this file please contact info (at) jgraph (dot) com.
009:         */
010:        package com.jgraph.pad.util;
011:
012:        import java.io.File;
013:
014:        import javax.imageio.ImageIO;
015:        import javax.swing.JFileChooser;
016:
017:        /**
018:         * Filter for use in a {@link JFileChooser}.
019:         */
020:        public class JGraphpadFileFilter extends
021:                javax.swing.filechooser.FileFilter {
022:
023:            /**
024:             * Extension of accepted files.
025:             */
026:            protected String ext;
027:
028:            /**
029:             * Description of accepted files.
030:             */
031:            protected String desc;
032:
033:            /**
034:             * Constructs a new filter for the specified extension and descpription.
035:             * 
036:             * @param extension
037:             *            The extension to accept files with.
038:             * @param description
039:             *            The description of the file format.
040:             */
041:            public JGraphpadFileFilter(String extension, String description) {
042:                ext = extension.toLowerCase();
043:                desc = description;
044:            }
045:
046:            /**
047:             * Returns true if <code>file</code> is a directory or ends with
048:             * {@link #ext}.
049:             * 
050:             * @param file
051:             *            The file to be checked.
052:             * @return Returns true if the file is accepted.
053:             */
054:            public boolean accept(File file) {
055:                return file.isDirectory()
056:                        || file.getName().toLowerCase().endsWith(ext);
057:            }
058:
059:            /**
060:             * Returns the description for accepted files.
061:             * 
062:             * @return Returns the description.
063:             */
064:            public String getDescription() {
065:                return desc;
066:            }
067:
068:            /**
069:             * Returns the extension for accepted files.
070:             * 
071:             * @return Returns the extension.
072:             */
073:            public String getExtension() {
074:                return ext;
075:            }
076:
077:            /**
078:             * Sets the extension for accepted files.
079:             * 
080:             * @param extension
081:             *            The extension to set.
082:             */
083:            public void setExtension(String extension) {
084:                this .ext = extension;
085:            }
086:
087:            /**
088:             * Utility file filter to accept all image formats supported by image io.
089:             * 
090:             * @see ImageIO#getReaderFormatNames()
091:             */
092:            public static class ImageFileFilter extends
093:                    javax.swing.filechooser.FileFilter {
094:
095:                /**
096:                 * Holds the accepted file format extensions for images.
097:                 */
098:                protected static String[] imageFormats = ImageIO
099:                        .getReaderFormatNames();
100:
101:                /**
102:                 * Description of the filter.
103:                 */
104:                protected String desc;
105:
106:                /**
107:                 * Constructs a new file filter for all supported image formats using
108:                 * the specified description.
109:                 * 
110:                 * @param description
111:                 *            The description to use for the file filter.
112:                 */
113:                public ImageFileFilter(String description) {
114:                    desc = description;
115:                }
116:
117:                /**
118:                 * Returns true if the file is a directory or ends with a known image
119:                 * extension.
120:                 * 
121:                 * @param file
122:                 *            The file to be checked.
123:                 * @return Returns true if the file is accepted.
124:                 */
125:                public boolean accept(File file) {
126:                    if (file.isDirectory())
127:                        return true;
128:                    String filename = file.toString().toLowerCase();
129:                    for (int j = 0; j < imageFormats.length; j++)
130:                        if (filename.endsWith("."
131:                                + imageFormats[j].toLowerCase()))
132:                            return true;
133:                    return false;
134:                }
135:
136:                /**
137:                 * Returns the description.
138:                 * 
139:                 * @return Returns the description.
140:                 */
141:                public String getDescription() {
142:                    return desc;
143:                }
144:
145:            }
146:
147:            /**
148:             * Utility file filter to accept editor files, namely .xml and .xml.gz
149:             * extensions.
150:             * 
151:             * @see ImageIO#getReaderFormatNames()
152:             */
153:            public static class EditorFileFilter extends
154:                    javax.swing.filechooser.FileFilter {
155:
156:                /**
157:                 * Description of the File format
158:                 */
159:                protected String desc;
160:
161:                /**
162:                 * Constructs a new editor file filter using the specified description.
163:                 * 
164:                 * @param description
165:                 *            The description to use for the filter.
166:                 */
167:                public EditorFileFilter(String description) {
168:                    desc = description;
169:                }
170:
171:                /**
172:                 * Returns true if the file is a directory or has a .xml or .xml.gz
173:                 * extension.
174:                 * 
175:                 * @return Returns true if the file is accepted.
176:                 */
177:                public boolean accept(File file) {
178:                    if (file.isDirectory())
179:                        return true;
180:                    String filename = file.getName().toLowerCase();
181:                    return filename.endsWith(".xml")
182:                            || filename.endsWith(".xml.gz");
183:                }
184:
185:                /**
186:                 * Returns the description.
187:                 * 
188:                 * @return Returns the description.
189:                 */
190:                public String getDescription() {
191:                    return desc;
192:                }
193:
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.