KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > editors > filefilters > ImageFilter


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.editors.filefilters;
20
21 import java.io.File JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24
25 import javax.swing.filechooser.FileFilter JavaDoc;
26
27 /**
28  * Image file type filter for the file chooser dialog.
29  *
30  * @author Matthew Large
31  * @version $Revision: 1.1 $
32  *
33  */

34 public class ImageFilter extends FileFilter JavaDoc {
35
36     ArrayList JavaDoc m_aExts = new ArrayList JavaDoc();
37
38     /**
39      *
40      */

41     public ImageFilter() {
42         super();
43         this.m_aExts.add("jpg");
44         this.m_aExts.add("jpeg");
45         this.m_aExts.add("gif");
46         this.m_aExts.add("tif");
47         this.m_aExts.add("tiff");
48         this.m_aExts.add("png");
49     }
50
51     /* (non-Javadoc)
52      * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
53      */

54     public boolean accept(File JavaDoc file) {
55         if (file.isDirectory()) {
56             return true;
57         }
58
59         String JavaDoc sFilename = file.getName();
60         if(sFilename.indexOf(".")>0) {
61             String JavaDoc sExt = sFilename.substring(sFilename.indexOf(".")+1);
62             if(sExt.length()>0) {
63                 boolean bFound = false;
64                 Iterator JavaDoc itor = this.m_aExts.iterator();
65                 while (itor.hasNext()) {
66                     String JavaDoc element = (String JavaDoc) itor.next();
67                     if(element.equalsIgnoreCase(sExt)) {
68                         bFound=true;
69                     }
70                 }
71                 if(bFound) {
72                     return true;
73                 }
74             }
75         }
76         return false;
77     }
78
79     /* (non-Javadoc)
80      * @see javax.swing.filechooser.FileFilter#getDescription()
81      */

82     public String JavaDoc getDescription() {
83         return "Images";
84     }
85
86 }
Popular Tags