Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/main/java/net/sf/javaanpr/gui/tools/ImageFileFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@
import javax.swing.filechooser.FileFilter;
import java.io.File;

/**
* This class filters filenames using the filename extension.
*/
public class ImageFileFilter extends FileFilter {

/**
* This method will accept the given filename if its extension is .bmp, .jpg, .jpeg, .png or .gif.
* @param name The filename to check
* @return true if the filename has one of the accepted extensions
*/
public static boolean accept(String name) {
int lastIndex = name.lastIndexOf('.');
if (lastIndex < 0) {
Expand All @@ -31,15 +39,25 @@ public static boolean accept(String name) {
.equals("gif");
}

/**
* This method will accept the given file if it is a directory or if it has a filename which is accepted
* by {@link ImageFileFilter#accept(String)}.
* @param file The file to check
* @return true if the file is a directory or its filename is accepted by {@link ImageFileFilter#accept(String)}
*/
@Override
public boolean accept(File f) {
if (f.isDirectory()) {
public boolean accept(File file) {
if (file.isDirectory()) {
return true;
}
String name = f.getName();
String name = file.getName();
return accept(name);
}

/**
* This method returns a description of the file extensions which are currently accepted.
* @return "images (*.jpg, *.bmp, *.gif, *.png)"
*/
@Override
public String getDescription() {
return "images (*.jpg, *.bmp, *.gif, *.png)";
Expand Down