001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.toolkit.swing;
025:
026: import jacareto.toolkit.io.FileUtilities;
027:
028: import java.io.File;
029:
030: import javax.swing.filechooser.FileFilter;
031:
032: /**
033: * A FileFilter for audio files.
034: *
035: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
036: * @version 0.9
037: */
038: public class AudioClipFileFilter extends FileFilter {
039: /** The description of this FileFilter. */
040: private String description;
041:
042: /**
043: * Creates an audio clip FileFilter with the default description. The default description is
044: * ".WAV".
045: */
046: public AudioClipFileFilter() {
047: this ("*.WAV");
048: }
049:
050: /**
051: * Creates an audio clip FileFilter with the specified description.
052: *
053: * @param description The description for this filter
054: */
055: public AudioClipFileFilter(String description) {
056: super ();
057: setDescription(description);
058: }
059:
060: /**
061: * Returns the description of this filter.
062: *
063: * @return The description
064: *
065: * @see #setDescription(String)
066: */
067: public String getDescription() {
068: return description;
069: }
070:
071: /**
072: * Sets the description of this filter. The default is ".XML"
073: *
074: * @param description The new description
075: *
076: * @see #getDescription()
077: */
078: public void setDescription(String description) {
079: this .description = description;
080: }
081:
082: /**
083: * Whether or not the given File is an audio ile. Directories are accepted, too.
084: *
085: * @param file The file to be tested
086: *
087: * @return Returns true when the given File is accepted
088: */
089: public boolean accept(File file) {
090: try {
091: if (file.isDirectory()) {
092: return true;
093: } else {
094: String extension = FileUtilities.getExtension(file);
095:
096: return extension.equals("wav");
097: }
098: } catch (Exception e) {
099: // just for mysterious InterruptedExceptions
100: return false;
101: }
102: }
103: }
|