001 /* PAVLOV -- Multiple Choice Study System 002 * Copyright (C) 2000 - 2004 T.J. Willis 003 * 004 * This program is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU General Public License 006 * as published by the Free Software Foundation; either version 2 007 * of the License, or (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, write to the Free Software 016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. 017 * 018 * $Header: /cvsroot/pavlov/net/sourceforge/pavlov/zipUtilities/ImageFileFilter.java,v 1.1 2004/05/10 15:33:22 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.zipUtilities; 021 022 import java.util.zip.ZipEntry; 023 import java.io.File; 024 025 /** 026 * A FileFilter that accepts only Image files (JPEG, PNG, GIF) and 027 * zip/jar entries. 028 * 029 * @version $Revision: 1.1 $ 030 */ 031 public class ImageFileFilter extends ZipCapableFileFilter { 032 // FIXME: add to CVS 033 /** 034 * Returns true if f is an Image file. 035 * 036 * @param f a <code>File</code> value 037 * @return a <code>boolean</code> value 038 */ 039 public boolean accept (File f) { 040 if (f == null) 041 return false; 042 return checkName (f.getName ()); 043 } 044 045 /** 046 * Returns true if f is an Image file. 047 * 048 * @param f a <code>ZipEntry</code> value 049 * @return a <code>boolean</code> value 050 */ 051 public boolean accept (ZipEntry f) { 052 if (f == null) 053 return false; 054 return checkName (f.getName ()); 055 } 056 057 /** 058 * Determines if name represents a Image file/entry name. 059 * 060 * @param name a <code>String</code> value 061 * @return a <code>boolean</code> value 062 */ 063 protected boolean checkName (String name) { 064 if (name == null) 065 return false; 066 if (isAJPG (name)) 067 return true; 068 if (isAPNG (name)) 069 return true; 070 if (isAGIF (name)) 071 return true; 072 return false; 073 } 074 075 private boolean isAJPG (String name) { 076 if (name.endsWith (".jpg")) 077 return true; 078 if (name.endsWith (".JPG")) 079 return true; 080 if (name.endsWith (".jpeg")) 081 return true; 082 if (name.endsWith (".JPEG")) 083 return true; 084 return false; 085 } 086 private boolean isAGIF (String name) { 087 if (name.endsWith (".gif")) 088 return true; 089 if (name.endsWith (".GIF")) 090 return true; 091 if (name.endsWith (".Gif")) 092 return true; 093 return false; 094 } 095 private boolean isAPNG (String name) { 096 if (name.endsWith (".png")) 097 return true; 098 if (name.endsWith (".PNG")) 099 return true; 100 if (name.endsWith (".Png")) 101 return true; 102 return false; 103 } 104 /** 105 * Returns description of this file filter. 106 * 107 * @return a <code>String</code> value 108 */ 109 public String getDescription () { 110 return "Image Files"; 111 } 112 113 }