001 package helliker.id3;
002
003 /*
004 Copyright (C) 2002 Jonathan Hilliker & Andreas Grunewald
005 Copyright (C) 2001 Jonathan Hilliker<br/>
006
007 This library is free software; you can redistribute it and/or
008 modify it under the terms of the GNU Lesser General Public
009 License as published by the Free Software Foundation; either
010 version 2.1 of the License, or (at your option) any later version.
011
012 This library is distributed in the hope that it will be useful,
013 but WITHOUT ANY WARRANTY; without even the implied warranty of
014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 Lesser General Public License for more details.
016
017 You should have received a copy of the GNU Lesser General Public
018 License along with this library; if not, write to the Free Software
019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020 */
021 /**
022 * This <code>FileFilter</code> only accepts files with a ".mp3" extension.
023 */
024 public class MP3FileFilter extends javax.swing.filechooser.FileFilter
025 implements java.io.FileFilter {
026
027 /**allows Directories
028 */
029 private boolean allowDirectories;
030
031 /**
032 * Create a default MP3FileFilter. The allowDirectories field will
033 * default to false.
034 *
035 */
036 public MP3FileFilter () {
037 this(false);
038 }
039
040 /**
041 * Create an MP3FileFilter. If allowDirectories is true, then this filter
042 * will accept directories as well as mp3 files. If it is false then
043 * only mp3 files will be accepted.
044 *
045 * @param allowDirectories whether or not to accept directories
046 */
047 public MP3FileFilter (boolean allowDirectories) {
048 this.allowDirectories = allowDirectories;
049 }
050
051 /**
052 * Determines whether or not the file is an mp3 file. If the file is
053 * a directory, whether or not is accepted depends upon the
054 * allowDirectories flag passed to the constructor.
055 *
056 * @param file the file to test
057 * @return true if this file or directory should be accepted
058 */
059 public boolean accept(java.io.File file) {
060 return ((file.getName()).toLowerCase().endsWith(".mp3"))
061 || (file.isDirectory() && (this.allowDirectories == true));
062 }
063
064 /**
065 * Returns the Name of the Filter for use in the Chooser Dialog
066 *
067 * @return The Description of the Filter
068 */
069 public String getDescription() {
070 return new String(".mp3 Files");
071 }
072 }//MP3FileFilter