KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > fractal > gui > menu > control > SimpleFileFilter


1 /***
2  * FractalGUI: a graphical tool to edit Fractal component configurations.
3  * Copyright (C) 2003 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Contact: fractal@objectweb.org
20  *
21  * Authors: Eric Bruneton, Patrice Fauvel
22  */

23
24 package org.objectweb.fractal.gui.menu.control;
25
26 import java.io.File JavaDoc;
27 import javax.swing.filechooser.FileFilter JavaDoc;
28
29 /**
30  * Simple {@link FileFilter} implementation.
31  */

32
33 public class SimpleFileFilter extends FileFilter JavaDoc {
34
35   /**
36    * The extension that files must have in order to be accepted by this filter.
37    */

38
39   private String JavaDoc extension;
40
41   /**
42    * Short description ot this file filter.
43    */

44
45   private String JavaDoc description;
46
47   /**
48    * Constructs a new {@link SimpleFileFilter} object.
49    *
50    * @param extension the extension that files must have in order to be accepted
51    * by this filter.
52    * @param description a short description ot this file filter.
53    */

54
55     public SimpleFileFilter (final String JavaDoc extension, final String JavaDoc description) {
56     this.extension = extension;
57     this.description = description;
58   }
59
60   public boolean accept (final File JavaDoc f) {
61     if (f.isDirectory()) {
62       return true;
63     } else {
64       String JavaDoc name = f.getName();
65       int i = name.lastIndexOf('.');
66       if (i > 0 && i < name.length() - 1) {
67         return name.substring(i + 1).toLowerCase().equals(extension);
68       } else {
69         return false;
70       }
71     }
72     }
73
74     public String JavaDoc getDescription () {
75     return description;
76     }
77 }
78
Popular Tags