-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputFileFilter.java
More file actions
59 lines (54 loc) · 1.33 KB
/
InputFileFilter.java
File metadata and controls
59 lines (54 loc) · 1.33 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import javax.swing.filechooser.FileFilter;
import java.io.File;
/**
* Created by Darkrengarius on 20.04.2016.
*/
/**
* Creates a filter which allows to choose only .txt files
*/
class InputFileFilter extends FileFilter {
/**
* File extension
*/
private String extension;
/**
* Description show in the chooser (".txt")
*/
private String description;
/**
* Initializes class fields
*
* @param extension File extension
* @param description Description
*/
InputFileFilter(String extension, String description) {
this.extension = extension;
this.description = description;
}
/**
* Gets the description
*
* @return Description
*/
@Override
public String getDescription() {
return description;
}
/**
* Checks if the file should be shown in the file choosing dialog
*
* @param file File descriptor
* @return True if the file is a directory or ends with ".txt", false -
* otherwise
*/
@Override
public boolean accept(File file) {
if(file != null) {
if(file.isDirectory()) {
return true;
}
return file.toString().endsWith(extension);
}
return false;
}
}