KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > cbutil > CBFileFilter


1 package com.ca.commons.cbutil;
2
3 import java.io.File JavaDoc;
4 import java.io.FileFilter JavaDoc;
5
6 /**
7  * Quick Hack to cover up yet another
8  * Swing inadequacy.
9  */

10
11 public class CBFileFilter extends javax.swing.filechooser.FileFilter JavaDoc
12         implements FileFilter JavaDoc
13 {
14     protected String JavaDoc[] extensions; // make it possible to extend this class
15
String JavaDoc description;
16
17     public CBFileFilter(String JavaDoc[] exts)
18     {
19         this(exts, "no description given");
20     }
21
22     public CBFileFilter(String JavaDoc[] exts, String JavaDoc desc)
23     {
24         extensions = new String JavaDoc[exts.length];
25         for (int i = 0; i < exts.length; i++)
26         {
27             extensions[i] = exts[i].toLowerCase();
28         }
29
30         description = desc;
31     }
32
33     public boolean accept(File JavaDoc f)
34     {
35         if (f.isDirectory()) return true;
36
37         for (int i = 0; i < extensions.length; i++)
38             if (f.getName().toLowerCase().endsWith(extensions[i]))
39                 return true;
40
41         return false;
42     }
43
44     public String JavaDoc getDescription()
45     {
46         return description;
47     }
48
49 }
Popular Tags