Skip to content

Commit cab55d3

Browse files
quantitativeTEMquantitativeTEM
authored andcommitted
Updating for Mac
1 parent a0c1bdd commit cab55d3

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Examples/uigetfiles.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function [pathname] = uigetfiles(FilterSpec,DialogTitle,varargin)
2+
% Pick multiple directories and/or files
3+
4+
import javax.swing.JFileChooser;
5+
% First check inputs
6+
start_path = '';
7+
multi = 1;
8+
dialog_title = [];
9+
10+
if isempty(start_path) % Allow a null argument.
11+
start_path = pwd;
12+
end
13+
14+
jchooser = javaObjectEDT('javax.swing.JFileChooser', start_path);
15+
16+
jchooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
17+
if ~isempty(dialog_title)
18+
jchooser.setDialogTitle(dialog_title);
19+
end
20+
21+
if multi==0
22+
jchooser.setMultiSelectionEnabled(false);
23+
elseif multi==1
24+
jchooser.setMultiSelectionEnabled(true);
25+
end
26+
27+
status = jchooser.showOpenDialog([]);
28+
29+
if status == JFileChooser.APPROVE_OPTION
30+
jFile = jchooser.getSelectedFiles();
31+
pathname{size(jFile, 1)}=[];
32+
for i=1:size(jFile, 1)
33+
pathname{i} = char(jFile(i).getAbsolutePath);
34+
end
35+
36+
elseif status == JFileChooser.CANCEL_OPTION
37+
pathname = [];
38+
else
39+
error('Error occured while picking file.');
40+
end

0 commit comments

Comments
 (0)