summaryrefslogtreecommitdiffstats
path: root/Bachelor/ERGO/TierheimVerw/thv/ImageFilter.java
blob: bf8a5979805f9768c2c6d6bda85ae9475e32b204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.File;
import javax.swing.filechooser.*;

/**
 * @author Andreas Spirka, Sven Eisenhauer
 * Filter Klasse zur Verwenung mit JFileChooser
 * filtert nach .jpg .jpeg .gif
 *
 */
public class ImageFilter extends FileFilter {
	
	/* (non-Javadoc)
	 * @see javax.swing.filechooser.FileFilter#accept(java.io.File)
	 */
	public boolean accept(File f) {
		if (f.isDirectory()) {
			return true;
		}
		String fileName = f.getName();
		String extension = null;
		int pos = fileName.lastIndexOf('.');
		if (pos > 0 &&  pos < fileName.length() - 1) {
			extension = fileName.substring(pos+1).toLowerCase();
		}
		if (extension != null) {
			if (extension.equals("gif") ||
					extension.equals("jpeg") ||
					extension.equals("jpg") ){
				return true;
			} else {
				return false;
			}
		}
		
		return false;
	}
	
	//The description of this filter
	/* (non-Javadoc)
	 * @see javax.swing.filechooser.FileFilter#getDescription()
	 */
	public String getDescription() {
		return "JPG & GIF Dateien";
	}
}