001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Mikael MARCHE, Fayçal SOUGRATI, Vincent PAUTRET
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.models;
025:
026: import java.io.File;
027:
028: import javax.swing.filechooser.FileFilter;
029:
030: /**
031:
032: * @author teaml039
033:
034: */
035:
036: /** Cette classe permet d'ajouter un filtre bas? sur l'extension des fichiers. */
037:
038: public class ScriptFileFilter extends FileFilter {
039:
040: /** Le texte qui sera affich? dans le comboBox du JFileChooser. */
041:
042: private String description;
043:
044: /** Extension de notre fichier (inclus le '.') */
045:
046: private String[] extensions;
047:
048: /**
049:
050: * Constructeur.
051:
052: * @param description, le texte de description pour l'utilisateur.
053:
054: * @param extentions, les extension du fichier
055:
056: */
057:
058: public ScriptFileFilter(String description, String[] extensions) {
059:
060: super ();
061:
062: this .description = description;
063:
064: this .extensions = extensions;
065:
066: }
067:
068: /**
069:
070: * Constructeur.
071:
072: * @param description, le texte de description pour l'utilisateur.
073:
074: * @param extention, l'extention du fichier (commencant par '.')
075:
076: */
077:
078: public ScriptFileFilter(String description, String extension) {
079:
080: this (description, new String[] { extension });
081:
082: }
083:
084: /**
085:
086: * Indique si le fichier est accept? par le filtre.
087:
088: * @return vrai si le fichier est accept?.
089:
090: */
091:
092: public boolean accept(File file) {
093:
094: if (file.isDirectory()) {
095:
096: return true;
097:
098: }
099:
100: String nomFichier = file.getPath().toLowerCase();
101:
102: int n = extensions.length;
103:
104: for (int i = 0; i < n; i++) {
105:
106: if (nomFichier.endsWith(extensions[i])) {
107:
108: return true;
109:
110: }
111:
112: }
113:
114: return false;
115:
116: }
117:
118: public String getDescription() {
119:
120: return (this.description);
121:
122: }
123:
124: }
|