1 7 8 package org.gjt.jclasslib.mdi; 9 10 import javax.swing.filechooser.FileFilter ; 11 import java.io.File ; 12 13 19 public class BasicFileFilter extends FileFilter { 20 21 private String [] extensions; 22 private String description; 23 24 29 public BasicFileFilter(String [] extensions, String description) { 30 31 this.extensions = extensions; 32 33 StringBuffer buffer = new StringBuffer (description); 34 buffer.append(" ("); 35 for (int i = 0; i < extensions.length; i++) { 36 if (i > 0) { 37 buffer.append(", "); 38 } 39 buffer.append("*."); 40 buffer.append(extensions[i]); 41 } 42 buffer.append(")"); 43 44 this.description = buffer.toString(); 45 } 46 47 52 public BasicFileFilter(String extension, String description) { 53 54 this(new String [] {extension}, description); 55 } 56 57 public boolean accept(File file) { 58 59 if (extensions == null) 60 return true; 61 62 for (int i = 0; i < extensions.length; i++) { 63 if (file.isDirectory() || file.getName().endsWith(extensions[i])) 64 return true; 65 } 66 return false; 67 } 68 69 public String getDescription() { 70 return description + ""; 71 } 72 } 73 74 | Popular Tags |