//package com.Sondaicus.GUI.utils; import java.io.File; /** Generic File Filter

This class is a method of having a generic file filter to be used with any file extension that you require. At construction time this information is supplied to the constructor

Copyright © Sondaicus.com and Jon Sharpe 1999.


Please note this code is distributed "as is" and without any form of warrenty. If you find any bugs please email jonsharpe@sondaicus.com

Please contact Sondaicus.com (jonsharpe@sondaicus.com) for details of licensing
@author Jon Sharpe @version 1.0 */ public class GenericFileFilter extends javax.swing.filechooser.FileFilter { private static final boolean ONE = true; private String fileExt; private String[] fileExts; private boolean type=false; private String description; private int length; private String extension; /** This is the constructor - it takes in the following:-
filesExtsIn - this is the array of file extensions that you wish to create a file filter for.
description - this is the description that will be displayed in the file chooser dialog box. */ public GenericFileFilter(String[] filesExtsIn, String description) { if (filesExtsIn.length==1) {//we only have one file type=ONE; fileExt=filesExtsIn[0]; } else { fileExts=filesExtsIn; length = fileExts.length; } this.description=description; } /** This is the method to allow a file to bee added to the displayed list or not. This method is called by the model that handles the FileChooser dialog */ public boolean accept(File f) { if (f.isDirectory()) { return true; } extension = getExtension(f); if (extension != null) { if(type) return check(fileExt); else { for(int i=0;i 0 && i < length - 1) return filename.substring(i+1).toLowerCase(); return null; } }