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 java.util.ArrayList;
031: import java.util.Iterator;
032: import java.util.List;
033:
034: import javax.swing.filechooser.FileFilter;
035:
036: /**
037: * FileFilter for video files
038: *
039: * @author Oliver Specht
040: * @version $revision$
041: */
042: public class VideoClipFileFilter extends FileFilter {
043: /** The description of this FileFilter. */
044: private String description;
045:
046: /** The listof extensions this filter accepts */
047: private List extensions = new ArrayList(2);
048:
049: /**
050: * Creates an video clip FileFilter with the default description. The default description is
051: * ".AVI and .MPG files".
052: */
053: public VideoClipFileFilter() {
054: this ("*.AVI and *.MPG files");
055: }
056:
057: /**
058: * Creates an video clip FileFilter with the specified description.
059: *
060: * @param description The description for this filter
061: */
062: public VideoClipFileFilter(String description) {
063: super ();
064: setDescription(description);
065: extensions.add("mov");
066: }
067:
068: /**
069: * Returns the description of this filter.
070: *
071: * @return String The description
072: *
073: * @see #setDescription(String)
074: */
075: public String getDescription() {
076: return description;
077: }
078:
079: /**
080: * Sets the description of this filter. The default is ".MOV files"
081: *
082: * @param description The new description
083: *
084: * @see #getDescription()
085: */
086: public void setDescription(String description) {
087: this .description = description;
088: }
089:
090: /**
091: * Whether or not the given {@link File} is an video file.
092: *
093: * @param file The file to be tested
094: *
095: * @return boolean true when the given {@link File} is accepted
096: */
097: public boolean accept(File file) {
098: if (file.isDirectory()) {
099: return true;
100: }
101:
102: String extension = FileUtilities.getExtension(file);
103: boolean accepts = false;
104:
105: Iterator iter = extensions.iterator();
106:
107: while (iter.hasNext()) {
108: if (extension.equals(iter.next())) {
109: accepts = true;
110: }
111: }
112:
113: return accepts;
114: }
115: }
|