01: /*
02: * The contents of this file are subject to the
03: * Mozilla Public License Version 1.1 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
09: * 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;
22: import java.util.ArrayList;
23: import java.util.Iterator;
24:
25: import javax.swing.filechooser.FileFilter;
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 {
35:
36: ArrayList m_aExts = new ArrayList();
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 file) {
55: if (file.isDirectory()) {
56: return true;
57: }
58:
59: String sFilename = file.getName();
60: if (sFilename.indexOf(".") > 0) {
61: String sExt = sFilename
62: .substring(sFilename.indexOf(".") + 1);
63: if (sExt.length() > 0) {
64: boolean bFound = false;
65: Iterator itor = this .m_aExts.iterator();
66: while (itor.hasNext()) {
67: String element = (String) itor.next();
68: if (element.equalsIgnoreCase(sExt)) {
69: bFound = true;
70: }
71: }
72: if (bFound) {
73: return true;
74: }
75: }
76: }
77: return false;
78: }
79:
80: /* (non-Javadoc)
81: * @see javax.swing.filechooser.FileFilter#getDescription()
82: */
83: public String getDescription() {
84: return "Images";
85: }
86:
87: }
|