forked from WPIRoboticsEngineering/LabCodeRepoSetup
-
Notifications
You must be signed in to change notification settings - Fork 2
/
getFile.groovy
110 lines (94 loc) · 2.62 KB
/
getFile.groovy
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import com.neuronrobotics.bowlerstudio.scripting.ScriptingEngine
import javafx.application.Platform
import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser
import javafx.stage.FileChooser.ExtensionFilter
//Your code here
public class FileHolder{
private boolean done=false;
private File file=null;
public boolean isDone() {
return done;
}
public void setDone(boolean done) {
this.done = done;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
}
public class FileSelectionFactory {
FileHolder file=new FileHolder();
public FileSelectionFactory() {
}
public File GetFile(File start, boolean save, ExtensionFilter... filter) {
if(start==null)
throw new NullPointerException();
file=new FileHolder();
//com.sun.javafx.application.PlatformImpl.startup(()->{});
Platform.runLater({
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(start.isDirectory()?start:start.getParentFile());
if(filter!=null)
fileChooser.getExtensionFilters().addAll(filter);
fileChooser.setTitle("Bowler File Chooser");
if(save)
file.setFile(fileChooser.showSaveDialog(null));
else
file.setFile(fileChooser.showOpenDialog(null));
file.setDone(true);
});
while(!file.isDone()){
try {
Thread.sleep(16);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return file.getFile();
}
public File GetFile(File start, ExtensionFilter... filter) {
return GetFile(start, false,filter);
}
public File GetDirectory(File start) {
if(start==null)
throw new NullPointerException();
file=new FileHolder();
Platform.runLater({
DirectoryChooser fileChooser = new DirectoryChooser();
fileChooser.setInitialDirectory(start.isDirectory()?start:start.getParentFile());
fileChooser.setTitle("Bowler File Chooser");
file.setFile(fileChooser.showDialog(null));
file.setDone(true);
});
while(!file.isDone()){
try {
Thread.sleep(16);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return file.getFile();
}
}
public static String getTeamAssignmentFile(String[] a) {
if (a==null)
a=new String[0];
String teamAssignmentsFile;
if (a.length == 0) {
String p = new FileSelectionFactory().GetFile(
ScriptingEngine.getRepositoryCloneDirectory("https://github.com/BancroftRoboDogs/LabCodeRepoSetup.git"),
new ExtensionFilter("json file", "*.JSON", "*.json")
).getAbsolutePath();
teamAssignmentsFile = p;
} else{
teamAssignmentsFile = a[0];
}
return teamAssignmentsFile;
}
return getTeamAssignmentFile(null)