01: /*
02: * SalomeTMF is a Test Management Framework
03: * Copyright (C) 2005 France Telecom R&D
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2 of the License, or (at your option) any later version.
09: *
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: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
20: *
21: * Contact: mikael.marche@rd.francetelecom.com
22: */
23:
24: package salomeTMF_plug.beanshell;
25:
26: import java.io.File;
27:
28: import javax.swing.filechooser.FileFilter;
29:
30: /** Cette classe permet d'ajouter un filtre basé sur l'extension des fichiers. */
31: public class BeanShellFileFilter extends FileFilter {
32:
33: /** Le texte qui sera affiché dans le comboBox du JFileChooser. */
34: private String description;
35: /** Extension de notre fichier (inclus le '.') */
36: private String[] extensions;
37:
38: /**
39: * Constructeur.
40: * @param description, le texte de description pour l'utilisateur.
41: * @param extentions, les extension du fichier
42: */
43: public BeanShellFileFilter(String description, String[] extensions) {
44: super ();
45: this .description = description;
46: this .extensions = extensions;
47: }
48:
49: /**
50: * Constructeur.
51: * @param description, le texte de description pour l'utilisateur.
52: * @param extention, l'extention du fichier (commencant par '.')
53: */
54: public BeanShellFileFilter(String description, String extension) {
55: this (description, new String[] { extension });
56: }
57:
58: /**
59: * Indique si le fichier est accepté par le filtre.
60: * @return vrai si le fichier est accepté.
61: */
62: public boolean accept(File file) {
63: if (file.isDirectory()) {
64: return true;
65: }
66:
67: String nomFichier = file.getPath().toLowerCase();
68: int n = extensions.length;
69: for (int i = 0; i < n; i++) {
70: if (nomFichier.endsWith(extensions[i])) {
71: return true;
72: }
73: }
74: return false;
75: }
76:
77: public String getDescription() {
78: return (this.description);
79: }
80: }
|