1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Added missing class FileNameExtensionFilter

This commit is contained in:
Federico Fissore 2013-10-14 12:55:39 +02:00
parent 21ef50beb4
commit 72440e7893

View File

@ -0,0 +1,48 @@
package processing.app.javax.swing.filechooser;
import javax.swing.filechooser.FileFilter;
import java.io.File;
import java.util.Locale;
public class FileNameExtensionFilter extends FileFilter {
private final String description;
private final String[] extensions;
public FileNameExtensionFilter(String description, String... exts) {
this.description = description;
this.extensions = new String[exts.length];
for (int i = 0; i < exts.length; i++) {
this.extensions[i] = exts[i].toLowerCase(Locale.ENGLISH);
}
}
@Override
public boolean accept(File f) {
if (f == null) {
return false;
}
if (f.isDirectory()) {
return true;
}
String fileName = f.getName();
int i = fileName.lastIndexOf('.');
if (i > 0 && i < fileName.length() - 1) {
String fileExtension = fileName.substring(i + 1).toLowerCase(Locale.ENGLISH);
for (String extension : extensions) {
if (extension.equals(fileExtension)) {
return true;
}
}
}
return false;
}
@Override
public String getDescription() {
return description;
}
}