From 72440e789343a3a1cc1092bbea3c3c327ec79042 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 14 Oct 2013 12:55:39 +0200 Subject: [PATCH] Added missing class FileNameExtensionFilter --- .../filechooser/FileNameExtensionFilter.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 app/src/processing/app/javax/swing/filechooser/FileNameExtensionFilter.java diff --git a/app/src/processing/app/javax/swing/filechooser/FileNameExtensionFilter.java b/app/src/processing/app/javax/swing/filechooser/FileNameExtensionFilter.java new file mode 100644 index 000000000..a0ef01318 --- /dev/null +++ b/app/src/processing/app/javax/swing/filechooser/FileNameExtensionFilter.java @@ -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; + } +}