Menu

[r9]: / XMLTool / src / xmltool / utils / FileChooserUtil.java  Maximize  Restore  History

Download this file

42 lines (32 with data), 1.5 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
package xmltool.utils;
import java.io.File;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
public class FileChooserUtil {
private static final FileChooser fileChooser = new FileChooser();
public static void setFilter(String label, String pattern) {
fileChooser.getExtensionFilters().retainAll(new FileChooser.ExtensionFilter(label, pattern));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(label, pattern));
}
public static void setFilter(String label, String[] patternArray) {
fileChooser.getExtensionFilters().retainAll(new FileChooser.ExtensionFilter(label, patternArray));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(label, patternArray));
}
public static void addFilter(String label, String pattern) {
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(label, pattern));
}
public static File getFile(Stage stage) {
File toReturn = fileChooser.showOpenDialog(stage);
if (toReturn != null) {
fileChooser.setInitialDirectory(toReturn.getParentFile());
DirectoryChooserUtil.presetInitialPath(toReturn.getParentFile());
}
return toReturn;
}
protected static void presetInitialPath(File initial) {
fileChooser.setInitialDirectory(initial);
}
protected static File getInitialPath() {
return fileChooser.getInitialDirectory();
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.