-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileChoice.java
More file actions
57 lines (46 loc) · 1.51 KB
/
FileChoice.java
File metadata and controls
57 lines (46 loc) · 1.51 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
import javax.swing.JFileChooser;
import java.io.File;
/**********************************************
* Chooses an input file for main to read from.
* @author Gloire Rubambiza
* @since 11/28/2017
************************************************/
public class FileChoice {
/*******************
* Empty constructor.
********************/
public FileChoice () {
}
/***************************************
* Chooses the file to be used as input.
* @return the absolute path of the file.
***************************************/
public String chooseFile () {
String fileName = "";
// Set the current directory as default.
File file = new File(System.getProperty("user.dir"));
JFileChooser select = new JFileChooser(file);
select.setFileFilter(new Filter());
select.setDialogTitle("Select an input file for ViMPaReS ");
int status = 0;
select.setDialogType(JFileChooser.OPEN_DIALOG);
status = select.showOpenDialog(null);
if ( status == JFileChooser.APPROVE_OPTION ) {
fileName = select.getSelectedFile().getAbsolutePath();
}
return fileName;
}
/***************************************
* Narrows the selection to *.data files.
****************************************/
class Filter extends javax.swing.filechooser.FileFilter {
@Override
public boolean accept(File f) {
return f.isDirectory( ) || f.getAbsolutePath( ).endsWith( ".data" );
}
@Override
public String getDescription() {
return "Data files ( *.data )";
}
}
}