FileDocCategorySizeDatePackage
ExtensionFilter.javaAPI DocExample755Tue Feb 14 13:39:32 GMT 2006com.elharo.swing.filechooser

ExtensionFilter.java

package com.elharo.swing.filechooser;

import java.io.*;
import javax.swing.filechooser.*;
import javax.swing.*;

public class ExtensionFilter extends javax.swing.filechooser.FileFilter {

  private String extension;
  private String description;

  public ExtensionFilter(String extension, String description) {

    if (extension.indexOf('.') == -1) {
      extension = "." + extension;
    }
    this.extension = extension;
    this.description = description;
  }
  
  public boolean accept(File f) {
  
    if (f.getName().endsWith(extension)) {
      return true;
    }
    else if (f.isDirectory()) { 
      return true;
    }
    return false;
  }
    
  public String getDescription() {
    return this.description + "(*" + extension + ")";
  }
}