View Javadoc
1 /* ------------------------------------------------------------------- 2 * Java source file for the class ExtensionFileFilter 3 * 4 * Copyright (c), 2002, Masahiro Takatsuka. 5 * All Rights Researved. 6 * 7 * Original Author: Masahiro Takatsuka (masa@jbeans.net) 8 * $Author: takatsukam $ 9 * 10 * $Date: 2003/07/25 04:51:45 $ 11 * 12 * $Id: ExtensionFileFilter.java,v 1.1.1.1 2003/07/25 04:51:45 takatsukam Exp $ 13 * 14 * Reference: Document no: 15 * ___ ___ 16 * 17 * To Do: 18 * ___ 19 * 20 ------------------------------------------------------------------- */ 21 22 /* --------------------------- Package ---------------------------- */ 23 package net.jbeans.io; 24 25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">color="#329900"> ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">color="#329900"> ------------------ Import classes (packages) ------------------- */ 26 import java.util.*; 27 import javax.swing.filechooser.*; 28 29 /*==================================================================== 30 Implementation of class ExtensionFileFilter 31 ====================================================================*/ 32 /*** 33 * ExtensionFileFilter filters out the specified file extentions. 34 * 35 * @version $Revision: 1.1.1.1 $ 36 * @author Masahiro Takatsuka (masa@jbeans.net) 37 * @see FileFilter 38 */ 39 40 public final class ExtensionFileFilter extends FileFilter implements java.io.FileFilter { 41 private ArrayList extensions; 42 private String description; 43 44 public ExtensionFileFilter() { 45 super(); 46 this.extensions = new ArrayList(); 47 } 48 49 public ExtensionFileFilter(String ext) { 50 this(); 51 this.extensions.add(ext); 52 } 53 54 public ExtensionFileFilter(String[] exts) { 55 this(); 56 for (int i = 0; i < exts.length; i++) { 57 this.extensions.add(exts[i]); 58 } 59 } 60 61 public final void addExtension(String ext) { 62 this.extensions.add(ext); 63 } 64 65 public final void removeExtension(String ext) { 66 this.extensions.remove(ext); 67 } 68 69 // Accept all directories and all gif, jpg, or tiff files. 70 public final boolean accept(java.io.File f) { 71 if (f.isDirectory()) { 72 return true; 73 } 74 75 String extension = FilenameUtil.getExtension(f.getName()); 76 if (extension != null) { 77 for (int i = 0; i < this.extensions.size(); i++) { 78 if (extension.equals((String) this.extensions.get(i))) { 79 return true; 80 } 81 } 82 } 83 return false; 84 } 85 86 // The description of this filter 87 public final String getDescription() { 88 return this.description; 89 } 90 91 // The description of this filter 92 public final void setDescription(String description) { 93 this.description = description; 94 } 95 }

This page was automatically generated by Maven