1 41 package org.jfree.ui; 42 43 import java.io.File ; 44 import java.io.FilenameFilter ; 45 import javax.swing.filechooser.FileFilter ; 46 47 52 public class FilesystemFilter extends FileFilter implements FilenameFilter { 53 54 55 private String [] fileext; 56 57 private String descr; 58 59 private boolean accDirs; 60 61 67 public FilesystemFilter(final String fileext, final String descr) { 68 this(fileext, descr, true); 69 } 70 71 78 public FilesystemFilter(final String fileext, final String descr, 79 final boolean accDirs) { 80 this(new String []{fileext}, descr, accDirs); 81 } 82 83 91 public FilesystemFilter(final String [] fileext, final String descr, 92 final boolean accDirs) { 93 this.fileext = (String []) fileext.clone(); 94 this.descr = descr; 95 this.accDirs = accDirs; 96 } 97 98 99 106 public boolean accept(final File dir, final String name) { 107 final File f = new File (dir, name); 108 if (f.isDirectory() && acceptsDirectories()) { 109 return true; 110 } 111 112 for (int i = 0; i < fileext.length; i++) { 113 if (name.endsWith(this.fileext[i])) { 114 return true; 115 } 116 } 117 return false; 118 } 119 120 127 public boolean accept(final File dir) { 128 if (dir.isDirectory() && acceptsDirectories()) { 129 return true; 130 } 131 132 for (int i = 0; i < fileext.length; i++) { 133 if (dir.getName().endsWith(this.fileext[i])) { 134 return true; 135 } 136 } 137 return false; 138 } 139 140 145 public String getDescription() { 146 return this.descr; 147 } 148 149 154 public void acceptDirectories(final boolean b) { 155 this.accDirs = b; 156 } 157 158 163 public boolean acceptsDirectories() { 164 return this.accDirs; 165 } 166 167 } 168 | Popular Tags |