source: an2_juigetfiles.m @ 78

Last change on this file since 78 was 78, checked in by tjniskan, 10 years ago
  • Moved fMRI related plugins to their own subdirectories
  • Created a subdirectory for map calculation plugins and added a few

basic plugins for those. At the moment these plugins do not support
masking etc. and I didn't test them at all so be cautious...

  • Made a minor memory optimation to an2_readfid.m
  • Fixed a few issues in files related updating via SVN
  • Disabled some annoying warnings that Matlab R2008a and higher

generate from uitree and uitreenode functions inan2_juigetfiles.m

  • Coded something minor to an2_maptool.m. This is still stub and does

not work at all. Please don't try to use it.

  • Fixed a bug that caused Aedes to fail without generating an error

when reading VNMR FID-files that don't have PROCPAR in the same folder.

  • Fixed a javaFrame -warning (with R2008a and higher) in aedes.m

M an2_revision.m
M an2_data_read.m
M an2_maptool.m
M aedes.m
D plugins/calculate_t2_map.m
D plugins/calculate_t1r_map.m
D plugins/basic_fmri_analysis.m
D plugins/resting_state_fc.m
A plugins/fmri_plugins
A plugins/fmri_plugins/basic_fmri_analysis.m
A plugins/fmri_plugins/resting_state_fc.m
A plugins/map_plugins
A plugins/map_plugins/t2.m
A plugins/map_plugins/t1_3_parameter_fit.m
A plugins/map_plugins/t1_saturation_recovery.m
A plugins/map_plugins/t1_rho.m
A plugins/map_plugins/t2_rho.m
A plugins/map_plugins/t1_inversion_recovery.m
M an2_readfid.m
M an2_check_updates.m
M an2_juigetfiles.m
M an2_update.m

File size: 32.3 KB
Line 
1function [filename,filepath,filterindex] = an2_juigetfiles(filefilter,ftitle,defaultdir)
2% AN2_JUIGETFILES - A Java based file browser for selecting multiple files in
3% non-sorted order from different folders.
4%   
5%
6% Synopsis:
7%       [FILENAME, PATHNAME, FILTERINDEX] = AN2_JUIGETFILES(FILTERSPEC,TITLE, DEFAULTPATH)
8%
9% Description:
10%       The behavior of AN2_JUIGETFILES is very similar to UIGETFILE with a few
11%       exceptions. The UIGETFILE properties 'location' and 'multiselect'
12%       are not available. Output arguments FILENAME and PATHNAME will
13%       always be cell arrays, if cancel is not pressed. The last input
14%       argument is not the default file but the default
15%       directory. FILTERSPEC must always be a cell array.
16%
17%       NOTE: Utilizes heavily the Matlab Java interface and undocumented
18%       and unsupported functions. This is due to change from version to
19%       version and, thus, this function will probably be broken in future
20%       Matlab releases. At the moment, however, AN2_JUIGETFILES should
21%       work with Matlab version from R14SP2 to R2007b.
22%
23% Examples:
24%       [filename, pathname, filterindex] = an2_juigetfiles( ...
25%       {'*.m;*.fig;*.mat;*.mdl', 'All MATLAB Files (*.m, *.fig, *.mat, *.mdl)';
26%        '*.m',  'M-files (*.m)'; ...
27%        '*.fig','Figures (*.fig)'; ...
28%        '*.mat','MAT-files (*.mat)'; ...
29%        '*.mdl','Models (*.mdl)'; ...
30%        '*.*',  'All Files (*.*)'}, ...
31%        'Pick a file(s)',pwd);
32%
33% See also:
34%       UIGETFILE
35
36% This function is a part of Aedes - A graphical tool for analyzing
37% medical images
38%
39% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
40%
41% Department of Physics, Department of Neurobiology
42% University of Kuopio, FINLAND
43%
44% This program may be used under the terms of the GNU General Public
45% License version 2.0 as published by the Free Software Foundation
46% and appearing in the file LICENSE.TXT included in the packaging of
47% this program.
48%
49% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
50% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
51
52
53%% Parse input arguments
54if nargin==0
55  filefilter = {'*.*','All Files (*.*)'};
56  ftitle = 'Select File(s)';
57  defaultdir = 0;
58elseif nargin==1
59  ftitle = 'Select File(s)';
60  defaultdir = 0;
61elseif nargin==2
62  defaultdir = 0;
63elseif nargin>3
64  error('Too many input arguments')
65end
66%keyboard
67%% Default colors and fonts for gui
68%FigColor=get(0,'DefaultUicontrolBackgroundcolor');
69GD=an2_gui_defaults;
70FigColor = GD.col.mainfig;
71
72%% Draw main figure
73scrsz=get(0,'screensize');
74fig_w = 870;%780;
75fig_h = 535;
76fig_pos = [scrsz(3)/2-fig_w/2 scrsz(4)/2-fig_h/2 fig_w fig_h];
77fh=figure('position',fig_pos,...
78          'Name',ftitle, ...
79          'Numbertitle','off', ...
80          'Tag','an2_juigetfiles_main_fig', ...
81          'Color',FigColor,...%[236 233 216]./255,...%GD.col.mainfig, ...
82          'Toolbar','none', ...
83          'Menubar','none', ...
84          'DoubleBuffer','on', ...
85          'DockControls','off',...
86          'renderer','painters',...
87          'closereq','uiresume(gcbf)',...
88          'windowstyle','modal',...
89          'handlevisibility','off',...
90          'resize','off');
91H.fh=fh;
92%pos = [5 60 200 420];
93pos=[5 60 320 420];
94%% Check if defaultdir exists
95if ischar(defaultdir)
96  if ~isdir(defaultdir)
97    defaultdir=0;
98  end
99end
100
101%% Try to find icon path
102tmp = which('an2_juigetfiles');
103if ~isempty(tmp)
104  [fp,fn,fe]=fileparts(tmp);
105  iconpath = [fp,filesep,'icons',filesep];
106else
107  iconpath = [pwd,filesep,'icons',filesep];
108end
109
110%% Disable warnings about deprecated functions in Matlab R2008a->
111ver = version;
112ver = str2num(ver(1:3));
113if ver>=7.6
114  warning('off','MATLAB:uitree:DeprecatedFunction');
115  warning('off','MATLAB:uitreenode:DeprecatedFunction');
116end
117
118%% Create uitree for directory browsing --------------
119rooticonpath = [iconpath,'MyComputer.gif'];
120rootnode = uitreenode('My Computer','My Computer',rooticonpath,false);
121tree = uitree(fh,'Root',rootnode,'position',pos);%,'ExpandFcn',@l_ExpFcn);
122set(tree,'NodeExpandedCallback',{@l_ExpFcnAlt,tree})
123
124
125%% Create uitree for files ---------------------------
126filetree = uitree(fh,'position',[pos(1)+pos(3)+5 pos(2) 220 pos(4)]);
127set(filetree,'MultipleSelectionEnabled',true,...
128             'NodeCollapsedCallback',{@l_FileTreeNodeCollapsed,filetree},...
129             'NodeExpandedCallback',{@l_OpenDirectory,tree,1});
130%'NodeSelectedCallback',{@l_FileTreeNodeSelected,filetree},...
131fileroot = uitreenode('Loading','Loading...','',false);
132filetree.setRoot(fileroot);
133filetree.reloadNode(fileroot);
134
135%% Set NodeSelected callback for directory tree
136set(tree,'NodeSelectedCallback',{@l_DirNodeSelected,tree,filetree});
137
138%% Create selected files uitree
139pos2=get(filetree,'position');
140selfiletreeroot = uitreenode('Selected Files','0 Files Selected','',false);
141selfiletree = uitree(fh,'Root',selfiletreeroot,'position',[pos(1)+pos2(3)+pos(3)+100 pos(2) 220 pos(4)]);
142set(selfiletree,'DndEnabled',true);
143set(selfiletree,'MultipleSelectionEnabled',true);
144set(selfiletree,'NodeDroppedCallback',{@l_SelFileTreeNodeDropped,selfiletree});
145
146
147% Expand My Computer
148tree.expand(rootnode);
149
150%% UICONTROLS ----------------------------------
151% Folders text
152tmp=get(tree,'position');
153dir_tx = uicontrol('parent',fh,...
154                   'position',[tmp(1)+5 tmp(2)+tmp(4) 150 13],...
155                   'style','text',...
156                   'string','Folders',...
157                   'fontweight','bold',...
158                   'horizontalalign','left',...
159                   'backgroundcolor',FigColor);%[236 233 216]./255);
160
161% Files text
162tmp=get(filetree,'position');
163files_tx = uicontrol('parent',fh,...
164                     'position',[tmp(1) tmp(2)+tmp(4) 150 13],...
165                     'style','text',...
166                     'string','Files',...
167                     'fontweight','bold',...
168                     'horizontalalign','left',...
169                     'backgroundcolor',FigColor);%[236 233 216]./255);
170
171% Selected Files text
172tmp=get(selfiletree,'position');
173selfiles_tx = uicontrol('parent',fh,...
174                        'position',[tmp(1) tmp(2)+tmp(4) 150 13],...
175                        'style','text',...
176                        'string','Selected Files',...
177                        'fontweight','bold',...
178                        'horizontalalign','left',...
179                        'backgroundcolor',FigColor);%[236 233 216]./255);
180
181
182
183% Add and Remove buttons
184tmp=get(filetree,'position');
185addallbnt = uicontrol('parent',fh,...
186  'units','pixel',...
187  'position',[tmp(1)+tmp(3)+5 (tmp(4))/1.5+tmp(2) 85 25],...
188  'string','Add all >>',...
189  'tooltip','Add all files from current folder to list',...
190  'style','pushbutton',...
191  'callback',{@l_AddRemFiles,'addall',filetree,selfiletree});
192addbtn = uicontrol('parent',fh,...
193  'units','pixel',...
194  'position',[tmp(1)+tmp(3)+5 (tmp(4))/2+tmp(2) 85 25],...
195  'string','Add >>',...
196  'style','pushbutton',...
197  'tooltip','Add selected files to list',...
198  'callback',{@l_AddRemFiles,'add',filetree,selfiletree});
199tmp=get(addbtn,'position');
200rembtn = uicontrol('parent',fh,...
201  'units','pixel',...
202  'position',[tmp(1) tmp(2)-25-5 85 25],...
203  'string','<< Remove',...
204  'tooltip','Remove selected files from list',...
205  'style','pushbutton',...
206  'callback',{@l_AddRemFiles,'remove',filetree,selfiletree});
207tmp=get(filetree,'position');
208rembtn = uicontrol('parent',fh,...
209  'units','pixel',...
210  'position',[tmp(1)+tmp(3)+5 (tmp(4))/4+tmp(2) 85 25],...
211  'string','<< Remove all',...
212  'tooltip','Remove all files from list',...
213  'style','pushbutton',...
214  'callback',{@l_AddRemFiles,'removeall',filetree,selfiletree});
215
216
217% Show path -checkbox
218tmp=get(selfiletree,'pos');
219showpathcb = uicontrol('parent',fh,...
220                       'units','pixel',...
221                       'position',[tmp(1) tmp(2)-17 150 15],...
222                       'style','checkbox',...
223                       'value',0,...
224                       'backgroundcolor',FigColor,...%[236 233 216]./255,...
225                       'string','Show full path',...
226                       'callback',{@l_ShowHidePathNames,selfiletree});
227
228% Back/Forward buttons
229tmp=get(tree,'position');
230back_btn = uicontrol('parent',fh,...
231                     'units','pixel',...
232                     'position',[tmp(1) tmp(2)+tmp(4)+20 80 25],...
233                     'string','<< Back',...
234                     'style','pushbutton',...
235                     'callback',{@l_BackForward,'back',tree},...
236                     'enable','off',...
237                     'busyaction','cancel',...
238                     'Interruptible','off');
239forward_btn = uicontrol('parent',fh,...
240                        'units','pixel',...
241                        'position',[tmp(1)+85 tmp(2)+tmp(4)+20 80 25],...
242                        'string','Forward >>',...
243                        'style','pushbutton',...
244                        'callback',{@l_BackForward,'forward',tree},...
245                        'enable','off',...
246                        'busyaction','cancel',...
247                        'Interruptible','off');
248
249% Path edit
250tmp=get(forward_btn,'position');
251pathedit = uicontrol('parent',fh,...
252                     'units','pixel',...
253                     'position',[tmp(1)+tmp(3)+5 tmp(2) 690 25],...
254                     'string','',...
255                     'style','edit',...
256                     'horizontalalign','left',...
257                     'backgroundcolor','w',...
258                     'callback',{@l_OpenDirectory,tree,[]});
259
260
261% Open and Cancel buttons
262tmp=get(selfiletree,'pos');
263openbtn = uicontrol('parent',fh,...
264                    'units','pixel',...
265                    'position',[tmp(1)+tmp(3)-80 10 80 25],...
266                    'string','Open',...
267                    'style','pushbutton',...
268                    'userdata',0,...
269                    'callback','set(gcbo,''userdata'',1),uiresume(gcbf)',...
270                    'enable','off');
271tmp=get(openbtn,'pos');
272cancelbtn = uicontrol('parent',fh,...
273                      'units','pixel',...
274                      'position',[tmp(1)-85 10 80 25],...
275                      'string','Cancel',...
276                      'style','pushbutton',...
277                      'userdata',1,...
278                      'callback','uiresume(gcbf)');
279
280% File Filter popup
281tmp=get(tree,'position');
282filefilter_popup = uicontrol('parent',fh,...
283                             'units','pixel',...
284                             'position',[tmp(1)+105 tmp(2)-35 440 25],...
285                             'string',{' '},...
286                             'value',1,...
287                             'style','popup',...
288                             'backgroundcolor','w',...
289                             'callback',{@l_DirNodeSelected,tree,filetree});
290ff_tx = uicontrol('parent',fh,...
291                  'units','pixel',...
292                  'position',[tmp(1) tmp(2)-35 100 20],...
293                  'string','Show Files of Type:',...
294                  'horizontalalign','left',...
295                  'style','text',...
296                  'backgroundcolor',FigColor);%[236 233 216]./255);
297
298ffstr = {filefilter{:,2}};
299
300% Construct find string for regexp
301regexp_str = strrep(strrep(strrep({filefilter{:,1}},';','|'),'*.','\.'),'\.*','.+');
302set(filefilter_popup,'string',ffstr,'userdata',regexp_str)
303
304H.tree = tree;
305H.filetree = filetree;
306H.selfiletree = selfiletree;
307H.openbtn = openbtn;
308H.cancelbtn = cancelbtn;
309H.filefilter_popup = filefilter_popup;
310H.pathedit = pathedit;
311H.back_btn = back_btn;
312H.forward_btn = forward_btn;
313H.showpathcb = showpathcb;
314H.addbtn = addbtn;
315H.rembtn = rembtn;
316H.history = {};
317H.historyind = 1;
318H.updateHistory = true;
319H.iconpath = iconpath;
320setappdata(H.fh,'H',H)
321
322% Try to open default directory
323if ~ischar(defaultdir)
324  if isunix
325        defaultdir = getenv('HOME');
326  else
327        defaultdir = getenv('USERPROFILE');
328  end
329  %defaultdir=pwd;
330end
331l_OpenDirectory([],[],tree,defaultdir)
332drawnow
333
334% Wait for exit
335uiwait(H.fh)
336if get(H.openbtn,'userdata')==0
337  % Action canceled
338  filename=0;
339  filepath=0;
340  filterindex=0;
341  delete(H.fh)
342  return
343end
344
345% Get selected files
346filename = {};
347filepath = {};
348filterindex = get(H.filefilter_popup,'value');
349selfileroot = handle(selfiletree.getRoot);
350childcount=selfileroot.ChildCount;
351for ii=1:childcount
352  node = selfileroot.getChildAt(ii-1);
353  value = node.getValue;
354  [fpath,fname,fext]=fileparts(value);
355  filename{ii}=[fname,fext];
356  filepath{ii}=[fpath,filesep];
357end
358
359fig_h = H.fh;
360clear H tree filetree selfiletree
361
362% Close window
363delete(fig_h)
364clear an2_juigetfiles
365return
366
367
368% $$$ %%%%%%%%%%%%%%%%%%%%%%%%%
369% $$$ % Expand function
370% $$$ %%%%%%%%%%%%%%%%%%%%%%%%%
371% $$$ function nodes=l_ExpFcn(tree,value)
372% $$$ %disp('Calling ExpFcn...')
373% $$$ set(gcf,'pointer','watch')
374% $$$ drawnow
375% $$$ if strcmpi(value,'My Computer')
376% $$$   
377% $$$   %% Use Java to determine available drives
378% $$$   drives = {};
379% $$$   r=java.io.File.listRoots;
380% $$$   for n=1:length(r)
381% $$$     drives{n} = char(r(n).toString);
382% $$$   end
383% $$$   
384% $$$   % Add drives to the tree
385% $$$   %nodes = [];
386% $$$   for ii=1:length(drives)
387% $$$     if any(strcmpi(drives{ii},{'A:\','B:\'}))
388% $$$       iconpath = '.\icons\floppyicon.gif';
389% $$$     else
390% $$$       iconpath = '.\icons\driveicon.gif';
391% $$$     end
392% $$$     nodes(ii) = uitreenode(drives{ii},drives{ii},iconpath,0);
393% $$$   end
394% $$$ else
395% $$$   count = 0;
396% $$$   ch = dir(value);
397% $$$   if isempty(ch)
398% $$$     tmp=tree.SelectedNodes;
399% $$$     node = handle(tmp(1));
400% $$$     
401% $$$     % Set loaded state for the node back to false
402% $$$     tree.setLoaded(node,false)
403% $$$     
404% $$$     % Set leafing back to "off" position
405% $$$     %node.Leaf(false)
406% $$$     
407% $$$     % Refresh node
408% $$$     tree.reloadNode(node)
409% $$$     
410% $$$     nodes=[];
411% $$$     h=warndlg(['Cannot access "' value '"'],'Access error');
412% $$$     set(gcf,'pointer','arrow')
413% $$$     return
414% $$$   else
415% $$$     directories = {ch([ch(:).isdir]).name};
416% $$$   end
417% $$$   %files = {ch(~[ch(:).isdir]).name};
418% $$$   
419% $$$   for ii=1:length(directories)
420% $$$     if (any(strcmp(directories{ii}, {'.', '..', ''})) == 0)
421% $$$       count = count + 1;
422% $$$       iconpath = '.\icons\Folder.gif';
423% $$$       
424% $$$       leafing=l_CheckLeafing([value, directories{ii}, filesep]);
425% $$$       nodes(count) = uitreenode([value, directories{ii}, filesep], ...
426% $$$                                 directories{ii}, iconpath, leafing);
427% $$$     end
428% $$$   end
429% $$$   
430% $$$   if count==0
431% $$$     nodes = [];
432% $$$   end
433% $$$ end
434% $$$ set(gcf,'pointer','arrow')
435
436
437
438%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
439% Alternate expand function
440%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441function l_ExpFcnAlt(h,evd,tree)
442
443H=getappdata(findall(0,'tag','an2_juigetfiles_main_fig'),'H');
444set(H.fh,'pointer','watch')
445drawnow
446
447evdnode = evd.getCurrentNode;
448value=evdnode.getValue;
449
450if ~tree.isLoaded(evdnode)
451
452  if strcmpi(value,'My Computer')
453   
454    %% Use Java to determine available drives, as using DIR is veeryy
455    %% slooow
456    drives = {};
457    r=java.io.File.listRoots;
458    for n=1:length(r)
459      drives{n} = char(r(n).toString);
460    end
461   
462    % Add drives to the tree
463        for ii=1:length(drives)
464          if any(strcmpi(drives{ii},{'A:\','B:\'}))
465                iconpath = [H.iconpath,'floppyicon.gif'];
466          else
467                iconpath = [H.iconpath,'driveicon.gif'];
468          end
469          nodes(ii) = uitreenode(drives{ii},drives{ii},iconpath,0);
470        end
471  else
472    count = 0;
473    ch = dir(value);
474    if isempty(ch)
475      %tmp=tree.SelectedNodes;
476      %node = handle(tmp(1));
477     
478      % Set loaded state for the node back to false
479      tree.setLoaded(evdnode,false);
480     
481      % Refresh node
482      tree.reloadNode(evdnode);
483     
484      h=warndlg(['Cannot access "' value '"'],'Access error','modal');
485      set(H.fh,'pointer','arrow')
486      return
487    else
488      directories = {ch([ch(:).isdir]).name};
489          if isunix
490                % Hide hidden directories in Linux
491                ind = regexp(directories,'^\.');
492                directories = {directories{cellfun('isempty',ind)}};
493          end
494    end
495   
496    for ii=1:length(directories)
497      if (any(strcmp(directories{ii}, {'.', '..', ''})) == 0)
498        count = count + 1;
499        iconpath = [H.iconpath,'Folder.gif'];
500       
501        %leafing=l_CheckLeafing([value, directories{ii}, filesep]);
502        leafing=false;
503        nodes(count) = uitreenode([value, directories{ii}, filesep], ...
504                                  directories{ii}, iconpath, leafing);
505      end
506    end
507   
508    if count==0
509      % Set loaded state for the node back to false
510      tree.setLoaded(evdnode,false);
511     
512      % Refresh node
513      tree.reloadNode(evdnode);
514     
515      set(H.fh,'pointer','arrow')
516      return
517    end
518  end
519 
520  %% Add child nodes
521  matlab_ver = version;
522  if length(nodes)==1 && strcmp(matlab_ver(1:3),'7.1')
523    % Make nodes a JavaArray
524    tmpnodes = nodes;
525    nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
526    nodes(1) = java(tmpnodes);
527  end
528 
529  tree.add(evdnode,nodes);
530  tree.setLoaded(evdnode,true);
531  tree.reloadNode(evdnode);
532end
533set(H.fh,'pointer','arrow')
534
535
536%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537% Check leafing for directories
538%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539function leafing=l_CheckLeafing(path)
540
541s=dir(path);
542if isempty(s)
543  leafing = true;
544  return
545end
546
547if length(s([s(:).isdir]))>2
548  leafing = false;
549else
550  leafing = true;
551end
552
553%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
554% Execute when directory node is selected
555%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
556function l_DirNodeSelected(h,evd,tree,filetree)
557
558H=getappdata(findall(0,'tag','an2_juigetfiles_main_fig'),'H');
559set(H.fh,'pointer','watch')
560drawnow
561
562% Clear file tree view
563filetree.setRoot([]);
564fileroot = uitreenode('Loading','Loading...','',false);
565filetree.setRoot(fileroot);
566filetree.reloadNode(fileroot);
567
568
569% Get Root
570%fileroot = handle(filetree.getRoot);
571
572% Remove all children
573%filetree.removeAllChildren(fileroot);
574%filetree.reloadNode(fileroot);
575
576
577% Get selected node
578currentnode=tree.getSelectedNodes;
579currentnode=handle(currentnode(1));
580
581% Get path
582path = currentnode.getValue;
583if strcmp(path,'My Computer')
584  %selfiletree.add(selfileroot,new_nodes);
585  %selfiletree.setLoaded(selfileroot,true);
586  %selfiletree.expand(selfileroot);
587  %selfileroot.setName([num2str(length(new_nodes)) ' Files Selected'])
588  fileroot.setValue('My Computer');
589  fileroot.setName('My Computer');
590  filetree.reloadNode(fileroot)
591  set(H.fh,'pointer','arrow')
592  return
593end
594
595
596% Try to get file information from the path
597ch=dir(path);
598if isempty(ch)
599  %rootnode = uitreenode(['Cannot access ' path],['Cannot access 'path],'',false);
600  %filetree.setRoot(rootnode);
601  %filetree.reloadNode(rootnode);
602  fileroot.setName(['Cannot access ' path]);
603  fileroot.setValue(['Cannot access ' path]);
604  filetree.reloadNode(fileroot)
605  set(H.pathedit,'string',path)
606  h=warndlg(['Cannot access "' path '"'],'Access error','modal');
607  set(H.fh,'pointer','arrow')
608  return
609end
610
611if H.updateHistory
612  % Add path to history
613  if H.historyind<length(H.history)
614    H.history(H.historyind+1:end)=[];
615  end
616  if isempty(H.history) || ~strcmp(H.history{end},path)
617    H.history{end+1} = path;
618  end
619  H.historyind = length(H.history);
620  set(H.forward_btn,'enable','off')
621  if length(H.history)>1
622    set(H.back_btn,'enable','on')
623  end
624 
625  % Keep maximum of 50 folders in history
626  if length(H.history)>50
627    H.history(1)=[];
628  end
629  setappdata(H.fh,'H',H)
630end
631
632% Get Name
633name = currentnode.getName;
634
635% Set up file tree root
636%rootnode = uitreenode(path,path,'',false);
637%filetree.setRoot(rootnode);
638fileroot.setName(path);
639fileroot.setValue(path);
640
641
642% Filter filenames
643filenames={ch(~[ch(:).isdir]).name};
644filter_val=get(H.filefilter_popup,'value');
645regexp_str = get(H.filefilter_popup,'userdata');
646regexp_str = regexp_str{filter_val};
647if ~strcmp(regexp_str,'.+')
648  [s_ind,e_ind]=regexpi(filenames,['(' regexp_str ')$']);
649  if ~isempty(s_ind)
650    ind = (double(char(s_ind{:}))-double(char(e_ind{:})))~=0;
651    filenames = {filenames{logical(ind)}};
652  else
653    filenames = {};
654  end
655end
656directories={ch([ch(:).isdir]).name};
657if isunix
658  % Hide hidden directories in Linux
659  ind = regexp(directories,'^\.');
660  directories = {directories{cellfun('isempty',ind)}};
661end
662
663% Create child nodes
664count=0;
665for ii=1:length(directories)
666  if ~any(strcmp(directories{ii},{'.','..'}))
667    count=count+1;
668    nodes(count)=uitreenode([path,directories{ii},filesep],directories{ii},[H.iconpath,'Folder.gif'],false);
669  end
670end
671for ii=1:length(filenames)
672  count=count+1;
673  nodes(count)=uitreenode([path,filenames{ii}],filenames{ii},[H.iconpath,'new.gif'],true);
674end
675
676set(H.pathedit,'string',path)
677if count==0;
678  filetree.reloadNode(fileroot);
679  set(H.fh,'pointer','arrow')
680  return
681end
682
683%% Add child nodes
684matlab_ver = version;
685if length(nodes)==1 && any(strcmp(matlab_ver(1:3),{'7.1','7.2'}))
686  % Make nodes a JavaArray
687  tmpnodes = nodes;
688  nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
689  nodes(1) = java(tmpnodes);
690end
691
692filetree.add(fileroot,nodes);
693filetree.setLoaded(fileroot,true);
694filetree.expand(fileroot);
695filetree.reloadNode(fileroot)
696set(H.fh,'pointer','arrow')
697%filetree.add(rootnode,nodes);
698%filetree.setLoaded(rootnode,true);
699%filetree.expand(rootnode);
700
701
702%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703% Files selected
704%%%%%%%%%%%%%%%%%%%%%%%%%%%%
705function l_FileTreeNodeSelected(h,evd,filetree)
706%disp('l_FileTreeNodeSelected')
707
708nodes=filetree.getSelectedNodes;
709if isempty(nodes)
710  return
711end
712
713% Don't allow selection of directories
714count=0;
715for ii=1:length(nodes)
716  if ~nodes(ii).isRoot
717    count=count+1;
718    selnodes(count)=nodes(ii);
719  end
720end
721
722if count==0
723  filetree.setSelectedNodes([]);
724else
725  % Reselect only files
726  filetree.setSelectedNodes(selnodes);
727end
728
729
730%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
731% Filetree collapsed
732%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
733function l_FileTreeNodeCollapsed(h,evd,filetree)
734
735% Don't let the filetree root node to collapse
736filetree.expand(filetree.getRoot);
737
738%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
739% Node Dropped to selected files tree
740%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
741function l_SelFileTreeNodeDropped(h,evd,selfiletree)
742
743tmp=handle(evd);
744SourceNode=tmp.getSourceNode;
745TargetNode=tmp.getTargetNode;
746
747target_value = TargetNode.getValue;
748source_value = SourceNode.getValue;
749if SourceNode.isRoot || TargetNode.isRoot
750  return
751end
752if strcmp(target_value,source_value)
753  return
754end
755
756
757% Reorder nodes
758selfileroot = handle(selfiletree.getRoot);
759childcount=selfileroot.ChildCount;
760
761% Construct a new javaArray for nodes
762nodes=javaArray('com.mathworks.hg.peer.UITreeNode',childcount);
763
764
765count=0;
766fromUp = false;
767if childcount ~= 0
768  for ii=0:childcount-1
769    tmp=selfileroot.getChildAt(ii);
770    if strcmp(tmp.getValue,target_value)
771      if fromUp
772        count=count+1;
773        nodes(count) = TargetNode;
774        count=count+1;
775        nodes(count) = SourceNode;
776      else
777        count=count+1;
778        nodes(count) = SourceNode;
779        count=count+1;
780        nodes(count) = TargetNode;
781      end
782    elseif ~strcmp(tmp.getValue,source_value)
783      count=count+1;
784      nodes(count) = tmp;
785    else
786      fromUp = true;
787    end
788  end
789end
790
791%selfiletree.setRoot([]);
792%selfileroot = uitreenode('Selected Files','Selected Files','',false);
793%selfiletree.setRoot(selfileroot);
794selfiletree.removeAllChildren(selfileroot);
795
796% Add new nodes to the tree
797selfiletree.add(selfileroot,nodes);
798selfiletree.expand(selfileroot);
799selfiletree.reloadNode(selfileroot);
800
801
802%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
803% ADD/REMOVE Files
804%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
805function l_AddRemFiles(h,evd,opt,filetree,selfiletree)
806
807% Get handles
808H=getappdata(findall(0,'tag','an2_juigetfiles_main_fig'),'H');
809
810switch opt
811 case {'add','addall'}
812 
813  % Look for a quick return
814  if isempty(filetree.getSelectedNodes) && strcmpi(opt,'add')
815    return
816  end
817 
818  % Get Rootnode
819  selfileroot = handle(selfiletree.getRoot);
820 
821   
822   if get(H.showpathcb,'value')
823     ShowPaths = true;
824   else
825     ShowPaths = false;
826   end
827   
828   if strcmpi(opt,'add')
829         % Get selected nodes
830         selnodes=filetree.getSelectedNodes;
831         filecount = length(selnodes);
832   elseif strcmpi(opt,'addall')
833         selnodes=filetree.getRoot;
834         filecount=selnodes.getChildCount;
835   end
836   
837   % Get existing nodes in the selfiletree
838   childcount=selfileroot.ChildCount;
839   count=0;
840   if childcount ~= 0
841     for ii=0:childcount-1
842       count=count+1;
843       selfilenodes(count) = selfileroot.getChildAt(ii);
844     end
845   end
846   
847   % Add existing nodes to new_nodes
848   selfilenodevalues={};
849   for ii=1:childcount
850     if ShowPaths
851       name_str = selfilenodes(ii).getValue;
852     else
853       [fpath,fname,fext] = fileparts(selfilenodes(ii).getValue);
854       name_str = [fname,fext];
855     end
856     new_nodes(ii) = uitreenode(selfilenodes(ii).getValue,...
857                                name_str,...
858                                [H.iconpath,'new.gif'],...
859                                true);
860     selfilenodevalues{ii}=selfilenodes(ii).getValue;
861   end
862   
863   % Add selected nodes to new_nodes
864   count=childcount;
865   count2=0;
866   for ii=childcount+1:childcount+filecount
867         count2=count2+1;
868         if strcmpi(opt,'add')
869           % Add selected
870           nodeVal=selnodes(count2).getValue;
871           isNodeRoot = selnodes(count2).isRoot;
872         else
873           % Add all files
874           nodeVal=selnodes.getChildAt(count2-1).getValue;
875           isNodeRoot = selnodes.getChildAt(count2-1).isRoot;
876         end
877         if ~any(strcmp(selfilenodevalues,nodeVal)) && ...
878                 ~strcmp(nodeVal(end),filesep) && ~isNodeRoot
879           if ShowPaths
880                 name_str = nodeVal;
881           else
882                 [fpath,fname,fext] = fileparts(nodeVal);
883                 name_str = [fname,fext];
884           end
885           count=count+1;
886           new_nodes(count) = uitreenode(nodeVal,...
887                 name_str,...
888                 [H.iconpath,'new.gif'],...
889                 true);
890         end
891   end
892       
893   
894   
895   if count==0
896     return
897   end
898   
899   % Enable Open button
900   set(H.openbtn,'enable','on')
901   
902   
903   matlab_ver = version;
904   if length(new_nodes)==1 && strcmp(matlab_ver(1:3),'7.1')
905     % Make nodes a JavaArray
906     tmpnodes = new_nodes;
907     new_nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
908     new_nodes(1) = java(tmpnodes);
909   end
910   
911   % Remove old nodes from the tree
912   %selfiletree.setRoot([]);
913   %selfileroot = uitreenode('Selected Files','Selected Files','',false);
914   %selfiletree.setRoot(selfileroot);
915   selfileroot.removeAllChildren;
916   selfiletree.reloadNode(selfileroot);
917   %selfiletree.repaint;
918   %selfiletree.removeAllChildren(selfileroot);
919   
920   % Add new nodes to the tree
921   selfiletree.add(selfileroot,new_nodes);
922   %selfiletree.setLoaded(selfileroot,true);
923   selfiletree.expand(selfileroot);
924   selfileroot.setName([num2str(length(new_nodes)) ' Files Selected'])
925   selfiletree.reloadNode(selfileroot)
926
927   
928 case {'remove','removeall'}
929  %keyboard
930  selnodes = selfiletree.getSelectedNodes;
931 
932  % Look for a quick return
933  if isempty(selnodes) && strcmpi(opt,'remove')
934    return
935  end
936 
937  % Get values to the selected nodes
938  selnodevalues = cell(1,length(selnodes));
939  for ii=1:length(selnodes)
940    tmp=handle(selnodes(ii));
941    selnodevalues{ii}=tmp.getValue;
942  end
943 
944  % Get Root
945  selfileroot=selfiletree.getRoot;
946 
947  if strcmpi(opt,'removeall')
948        selfileroot.removeAllChildren;
949        selfiletree.reloadNode(selfileroot);
950       
951        % Disable Open button
952        set(H.openbtn,'enable','off')
953        selfileroot.setName('0 Files Selected')
954        selfiletree.reloadNode(selfileroot)
955        selfiletree.expand(selfileroot);
956        return
957  end
958 
959  % Get number of files in the tree
960  childcount = selfileroot.getChildCount;
961 
962  count = 0;
963  for ii=0:childcount-1
964    tmp=selfileroot.getChildAt(ii);
965    if ~any(strcmp(tmp.getValue,selnodevalues))
966      count=count+1;
967      new_nodes(count) = tmp;
968    end
969  end
970 
971  %selfiletree.setRoot([]);
972  %selfileroot = uitreenode('Selected Files','Selected Files','',false);
973  %selfiletree.setRoot(selfileroot);
974  selfileroot.removeAllChildren;
975  selfiletree.reloadNode(selfileroot);
976  %selfiletree.removeAllChildren(selfileroot);
977   
978  % Add new nodes to the tree
979  if count~=0
980    selfiletree.add(selfileroot,new_nodes);
981    selfileroot.setName([num2str(length(new_nodes)) ' Files Selected'])
982    selfiletree.reloadNode(selfileroot)
983  else
984    % Unenable Open button
985    set(H.openbtn,'enable','off')
986   
987    selfileroot.setName('0 Files Selected')
988    selfiletree.reloadNode(selfileroot)
989  end
990  %selfiletree.setLoaded(selfileroot,true);
991  selfiletree.expand(selfileroot);
992end
993
994%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
995% Open directory
996%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997function l_OpenDirectory(h,evd,tree,directory)
998
999% Get handles
1000H=getappdata(findall(0,'tag','an2_juigetfiles_main_fig'),'H');
1001set(H.fh,'pointer','watch')
1002drawnow
1003
1004if isempty(directory)
1005  directory = get(h,'string');
1006elseif isnumeric(directory)
1007  tmp=evd.getCurrentNode;
1008  if tmp.isRoot
1009    set(H.fh,'pointer','arrow')
1010    return
1011  end
1012  directory=tmp.getValue;
1013end
1014% Check that directory exists
1015if ~isdir(directory)
1016  h=errordlg({['Cannot open folder "' directory '".'],['Make sure the path is ' ...
1017                      'correct.']},'Cannot open folder','modal');
1018  set(H.fh,'pointer','arrow')
1019  return
1020end
1021if ~strcmp(directory(end),filesep)
1022  directory = [directory,filesep];
1023end
1024
1025% See if we are in the specified directory already
1026%keyboard
1027tmp=tree.getSelectedNodes;
1028if ~isempty(tmp)
1029  tmp=handle(tmp(1));
1030  if strcmp(tmp.getValue,directory)
1031    set(H.fh,'pointer','arrow')
1032    return
1033  end
1034end
1035
1036if H.updateHistory
1037  % Add path to history
1038  if H.historyind<length(H.history)
1039    H.history(H.historyind+1:end)=[];
1040  end
1041  if isempty(H.history) || ~strcmp(H.history{end},directory)
1042    H.history{end+1} = directory;
1043  end
1044  H.historyind = length(H.history);
1045  set(H.forward_btn,'enable','off')
1046  if length(H.history)>1
1047    set(H.back_btn,'enable','on')
1048  end
1049 
1050  % Keep maximum of 50 folders in history
1051  if length(H.history)>50
1052    H.history(1)=[];
1053  end
1054  setappdata(H.fh,'H',H)
1055end
1056
1057% Get root
1058rootnode = tree.getRoot;
1059
1060
1061ind=find(directory==filesep);
1062
1063%keyboard
1064drawnow
1065drawnow
1066start_ind=0;
1067currentnode = rootnode;
1068for ii=1:length(ind)
1069  if ii==1
1070    currentdir=directory(start_ind+1:ind(ii));
1071  else
1072    currentdir=directory(start_ind+1:ind(ii)-1);
1073  end
1074  childcount=currentnode.getChildCount;
1075  for kk=1:childcount
1076    tmp=currentnode.getChildAt(kk-1);
1077    name=tmp.getName;
1078    if strcmp(name,currentdir)
1079      %tree.expand(tmp);
1080      %tree.setLoaded(tmp,true)
1081      %tree.reloadNode(tmp);
1082      currentnode=tmp;
1083      if ii~=length(ind)
1084        tree.expand(currentnode)
1085      end
1086      %tree.setLoaded(tmp,true)
1087      %tree.setSelectedNode(currentnode);
1088      %tree.reloadNode(currentnode);
1089      %pause(12)
1090      drawnow
1091      break;
1092    end
1093  end
1094  start_ind = ind(ii);
1095end
1096
1097%tree.expand(currentnode)
1098%tree.setLoaded(currentnode,true)
1099tree.setSelectedNode(currentnode);
1100tree.reloadNode(currentnode);
1101set(H.fh,'pointer','arrow')
1102%tree.setSelectedNode(currentnode)
1103
1104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1105% SHOW/HIDE path names from selected files
1106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1107function l_ShowHidePathNames(h,evd,selfiletree)
1108
1109if get(h,'value')==1
1110  ShowPaths = true;
1111else
1112  ShowPaths = false;
1113end
1114
1115% Redraw all nodes in the tree
1116selfileroot = handle(selfiletree.getRoot);
1117childcount=selfileroot.ChildCount;
1118if childcount==0
1119  return
1120end
1121
1122count=0;
1123if childcount ~= 0
1124  for ii=0:childcount-1
1125    count=count+1;
1126    childnode=selfileroot.getChildAt(ii);
1127    if ShowPaths
1128      childnode.setName(childnode.getValue);
1129    else
1130      [fpath,fname,fext] = fileparts(childnode.getValue);
1131      childnode.setName([fname,fext])
1132    end
1133  end
1134end
1135
1136% Reload root node
1137selfiletree.reloadNode(selfileroot);
1138
1139
1140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1141% BACK/FORWARD functions
1142%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1143function l_BackForward(h,evd,opt,tree)
1144
1145% Get handles
1146H=getappdata(findall(0,'tag','an2_juigetfiles_main_fig'),'H');
1147%set(H.back_btn,'enable','inactive')
1148%set(H.forward_btn,'enable','inactive')
1149
1150% Put up a flag that prevents the history to be updated
1151H.updateHistory = false;
1152setappdata(H.fh,'H',H)
1153
1154switch opt
1155 case 'back'
1156  %keyboard
1157  if length(H.history)>1
1158    H.historyind = H.historyind-1;
1159    drawnow % Java seems to be slow to update...
1160    l_OpenDirectory([],[],tree,H.history{H.historyind})
1161    drawnow
1162    set(H.forward_btn,'enable','on')
1163    if H.historyind==1
1164      set(H.back_btn,'enable','off')
1165    end
1166  end
1167 
1168  % Put history update flag down
1169  H.updateHistory = true;
1170  setappdata(H.fh,'H',H)
1171  %H.history
1172  %H.historyind
1173 case 'forward'
1174  if length(H.history)==H.historyind
1175    return
1176  end
1177 
1178  if H.historyind<length(H.history)
1179    H.historyind = H.historyind+1;
1180    drawnow
1181    l_OpenDirectory([],[],tree,H.history{H.historyind})
1182    drawnow
1183    set(H.back_btn,'enable','on')
1184    if H.historyind==length(H.history)
1185      set(H.forward_btn,'enable','off')
1186    end
1187  end
1188 
1189  % Put history update flag down
1190  H.updateHistory = true;
1191  setappdata(H.fh,'H',H)
1192  %H.history
1193  %H.historyind
1194end
1195
1196
1197%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198% Resize Function
1199%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200function l_Resize(h,evd)
1201
1202% To be written...
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008