/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Mar 14, 2007 */ package ml.core.helper; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; /** * This represents the information associated with a file type * that is displayed in a dialog to open and save files. * * @author gregor */ public class FileType { private final String name; private final List patterns; public FileType(String name, ArrayList patterns) { this.name=name; this.patterns=(List) patterns.clone(); } /** * @return a short, descriptive of the file format for display in the file dialog */ public String getName() { return name; } /** * @return a list of patterns (e.g. *.jpg for JPEGs) that the file names of files of this type usually obey. */ public List getPatterns() { return patterns; } /** * This function checks if the given file name matches any of the patterns * listed for this file type. * * @param filename the filename to check * @return true if the file matches, otherwise false */ public boolean matches(String filename) { for(String pattern : patterns) { String regex=""; for(int i=0;i