5
5
import java.io.FilenameFilter;
6
6
import java.io.IOException;
7
import java.nio.file.Path;
7
8
import java.util.regex.Matcher;
8
9
import java.util.regex.Pattern;
16
17
class NativeFileBrowserFallback extends FileBrowser {
17
18
private FileDialog fc;
18
19
private String ext;
20
private String specifiedPath;
19
21
private JFileChooser fileChooser;
21
23
This show native open/save dialogs for all type of dialogs except multifile open,
27
29
NativeFileBrowserFallback(String filetype, final String ext, final String optionalExt, String path) {
28
30
fc = new FileDialog(CreateGui.getAppGui(), filetype);
30
33
if (filetype == null) {
33
if(path == null) path = lastPath;
36
//if(path == null) path = lastPath;
36
fc.setDirectory(path);
39
//fc.setDirectory(path);
38
41
/* Setup JFileChooser for multi file selection */
39
42
fileChooser = new JFileChooser();
73
76
public File openFile() {
77
if(specifiedPath == null) specifiedPath = lastOpenPath;
78
fc.setDirectory(specifiedPath);
74
79
fc.setFile(ext.equals("")? "":"*."+ext);
75
80
fc.setMode(FileDialog.LOAD);
76
81
fc.setVisible(true);
77
82
String selectedFile = fc.getFile();
78
83
String selectedDir = fc.getDirectory();
79
lastPath = selectedDir;
84
lastOpenPath = selectedDir;
80
85
File file = selectedFile == null? null:new File(selectedDir + selectedFile);
84
89
public File[] openFiles() {
85
if (lastPath != null) {
90
if(specifiedPath == null) specifiedPath = lastOpenPath;
91
if(new File(specifiedPath).exists()) fileChooser.setCurrentDirectory(new File(specifiedPath));
92
/*if (lastPath != null) {
86
93
File path = new File(lastPath);
87
94
if (path.exists()) {
88
95
fileChooser.setCurrentDirectory(path);
91
98
File[] filesArray = new File[0];
92
99
int result = fileChooser.showOpenDialog(null);
93
100
if (result == JFileChooser.APPROVE_OPTION) {
94
101
filesArray = fileChooser.getSelectedFiles();
103
//They should all come from the same directory so we just take one
104
lastOpenPath = filesArray[0].getAbsolutePath();
96
105
return filesArray;
100
109
public String saveFile(String suggestedName) {
110
if(specifiedPath == null) specifiedPath = lastSavePath;
111
fc.setDirectory(specifiedPath);
101
112
fc.setFile(suggestedName + (suggestedName.endsWith("."+ext)? "":"."+ext));
102
113
fc.setMode(FileDialog.SAVE);
103
114
fc.setVisible(true);
105
116
String file = fc.getFile() == null? null: fc.getDirectory() + fc.getFile();
106
lastPath = fc.getDirectory();
117
lastSavePath = fc.getDirectory();
108
119
if(file == null){