source: aedes_juigetfiles.m @ 204

Last change on this file since 204 was 204, checked in by tjniskan, 6 years ago
  • Fixed a java issue with aedes_juigetfiles and Matlab R2012b

M aedes_revision.m
M aedes_juigetfiles.m

File size: 38.2 KB
Line 
1function [filename,filepath,filterindex] = aedes_juigetfiles(filefilter,ftitle,defaultdir)
2% AEDES_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] = AEDES_JUIGETFILES(FILTERSPEC,TITLE, DEFAULTPATH)
8%
9% Description:
10%       The behavior of AEDES_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, AEDES_JUIGETFILES should
21%       work with Matlab version from R14SP2 to R2007b.
22%
23% Examples:
24%       [filename, pathname, filterindex] = aedes_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=aedes_gui_defaults;
70FigColor = GD.col.mainfig;
71
72fig_w = 870;%780;
73fig_h = 545;%535;
74fig_location = aedes_dialoglocation([fig_w,fig_h]);
75fig_pos = [fig_location(1) fig_location(2) fig_w fig_h];
76fh=figure('position',fig_pos,...
77          'Name',ftitle, ...
78          'Numbertitle','off', ...
79          'Tag','aedes_juigetfiles_main_fig', ...
80          'Color',FigColor,...%[236 233 216]./255,...%GD.col.mainfig, ...
81          'Toolbar','none', ...
82          'Menubar','none', ...
83          'DoubleBuffer','on', ...
84          'DockControls','off',...
85          'renderer','painters',...
86          'closereq','uiresume(gcbf)',...'windowstyle','modal',...
87          'handlevisibility','off',...
88          'resize','off',...
89          'keypressfcn',@l_KeyPressFcn);
90H.fh=fh;
91%pos = [5 60 200 420];
92%pos=[5 60 320 420];
93pos=[5 70 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('aedes_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->
111version_number = aedes_getmatlabversion;
112%if version_number>=7.06
113%  warning('off','MATLAB:uitree:DeprecatedFunction');
114%  warning('off','MATLAB:uitreenode:DeprecatedFunction');
115%end
116
117%% Create uitree for directory browsing --------------
118rooticonpath = [iconpath,'MyComputer.gif'];
119if version_number>=7.06
120  rootnode = uitreenode('v0','My Computer','My Computer',rooticonpath,false);
121  tree = uitree('v0',fh,'Root',rootnode,'position',pos);%,'ExpandFcn',@l_ExpFcn);
122else
123  rootnode = uitreenode('My Computer','My Computer',rooticonpath,false);
124  tree = uitree(fh,'Root',rootnode,'position',pos);%,'ExpandFcn',@l_ExpFcn);
125end
126drawnow
127
128
129%% Create uitree for files ---------------------------
130if version_number>=7.06
131  filetree = uitree('v0',fh,'position',[pos(1)+pos(3)+5 pos(2) 220 pos(4)]);
132else
133  filetree = uitree(fh,'position',[pos(1)+pos(3)+5 pos(2) 220 pos(4)]);
134end
135drawnow
136
137%'NodeSelectedCallback',{@l_FileTreeNodeSelected,filetree},...
138if version_number>=7.06
139  fileroot = uitreenode('v0','Loading','Loading...','',false);
140else
141  fileroot = uitreenode('Loading','Loading...','',false);
142end
143filetree.setRoot(fileroot);
144filetree.reloadNode(fileroot);
145drawnow
146
147
148%% Create selected files uitree
149pos2=get(filetree,'position');
150if version_number>=7.06
151  selfiletreeroot = uitreenode('v0','Selected Files','0 Files Selected','',false);
152  selfiletree = uitree('v0',fh,'Root',selfiletreeroot,'position',[pos(1)+pos2(3)+pos(3)+100 pos(2) 220 pos(4)]);
153else
154  selfiletreeroot = uitreenode('Selected Files','0 Files Selected','',false);
155  selfiletree = uitree(fh,'Root',selfiletreeroot,'position',[pos(1)+pos2(3)+pos(3)+100 pos(2) 220 pos(4)]);
156end
157drawnow
158
159
160
161
162%% UICONTROLS ----------------------------------
163% Folders text
164tmp=get(tree,'position');
165dir_tx = uicontrol('parent',fh,...
166                   'position',[tmp(1)+5 tmp(2)+tmp(4) 150 13],...
167                   'style','text',...
168                   'string','Folders',...
169                   'fontweight','bold',...
170                   'horizontalalign','left',...
171                   'backgroundcolor',FigColor);%[236 233 216]./255);
172
173% Files text
174tmp=get(filetree,'position');
175files_tx = uicontrol('parent',fh,...
176                     'position',[tmp(1) tmp(2)+tmp(4) 150 13],...
177                     'style','text',...
178                     'string','Files',...
179                     'fontweight','bold',...
180                     'horizontalalign','left',...
181                     'backgroundcolor',FigColor);%[236 233 216]./255);
182
183% Selected Files text
184tmp=get(selfiletree,'position');
185selfiles_tx = uicontrol('parent',fh,...
186                        'position',[tmp(1) tmp(2)+tmp(4) 150 13],...
187                        'style','text',...
188                        'string','Selected Files',...
189                        'fontweight','bold',...
190                        'horizontalalign','left',...
191                        'backgroundcolor',FigColor);%[236 233 216]./255);
192
193
194
195% Add and Remove buttons
196tmp=get(filetree,'position');
197addallbnt = uicontrol('parent',fh,...
198  'units','pixel',...
199  'position',[tmp(1)+tmp(3)+5 (tmp(4))/1.5+tmp(2) 85 25],...
200  'string','Add all >>',...
201  'tooltip','Add all files from current folder to list',...
202  'style','pushbutton',...
203  'callback',{@l_AddRemFiles,'addall',filetree,selfiletree});
204addbtn = uicontrol('parent',fh,...
205  'units','pixel',...
206  'position',[tmp(1)+tmp(3)+5 (tmp(4))/2+tmp(2) 85 25],...
207  'string','Add >>',...
208  'style','pushbutton',...
209  'tooltip','Add selected files to list',...
210  'callback',{@l_AddRemFiles,'add',filetree,selfiletree});
211tmp=get(addbtn,'position');
212rembtn = uicontrol('parent',fh,...
213  'units','pixel',...
214  'position',[tmp(1) tmp(2)-25-5 85 25],...
215  'string','<< Remove',...
216  'tooltip','Remove selected files from list',...
217  'style','pushbutton',...
218  'callback',{@l_AddRemFiles,'remove',filetree,selfiletree});
219tmp=get(filetree,'position');
220rembtn = uicontrol('parent',fh,...
221  'units','pixel',...
222  'position',[tmp(1)+tmp(3)+5 (tmp(4))/4+tmp(2) 85 25],...
223  'string','<< Remove all',...
224  'tooltip','Remove all files from list',...
225  'style','pushbutton',...
226  'callback',{@l_AddRemFiles,'removeall',filetree,selfiletree});
227
228
229% Show path -checkbox
230tmp=get(selfiletree,'pos');
231showpathcb = uicontrol('parent',fh,...
232                       'units','pixel',...
233                       'position',[tmp(1) tmp(2)-17 150 15],...
234                       'style','checkbox',...
235                       'value',0,...
236                       'backgroundcolor',FigColor,...%[236 233 216]./255,...
237                       'string','Show full path',...
238                       'callback',{@l_ShowHidePathNames,selfiletree});
239
240% Back/Forward buttons
241tmp=get(tree,'position');
242back_btn = uicontrol('parent',fh,...
243                     'units','pixel',...
244                     'position',[tmp(1) tmp(2)+tmp(4)+20 80 25],...
245                     'string','<< Back',...
246                     'style','pushbutton',...
247                     'callback',{@l_BackForward,'back',tree},...
248                     'enable','off',...
249                     'busyaction','cancel',...
250                     'Interruptible','off');
251forward_btn = uicontrol('parent',fh,...
252                        'units','pixel',...
253                        'position',[tmp(1)+85 tmp(2)+tmp(4)+20 80 25],...
254                        'string','Forward >>',...
255                        'style','pushbutton',...
256                        'callback',{@l_BackForward,'forward',tree},...
257                        'enable','off',...
258                        'busyaction','cancel',...
259                        'Interruptible','off');
260
261% Path edit
262tmp=get(forward_btn,'position');
263pathedit = uicontrol('parent',fh,...
264                     'units','pixel',...
265                     'position',[tmp(1)+tmp(3)+5 tmp(2) 690 25],...
266                     'string','',...
267                     'style','edit',...
268                     'horizontalalign','left',...
269                     'backgroundcolor','w',...
270                     'callback',{@l_OpenDirectory,tree,[]});
271
272
273% Open and Cancel buttons
274tmp=get(selfiletree,'pos');
275openbtn = uicontrol('parent',fh,...
276                    'units','pixel',...
277                    'position',[tmp(1)+tmp(3)-80 10 80 25],...
278                    'string','Open',...
279                    'style','pushbutton',...
280                    'userdata',0,...
281                    'callback','set(gcbo,''userdata'',1),uiresume(gcbf)',...
282                    'enable','off');
283tmp=get(openbtn,'pos');
284cancelbtn = uicontrol('parent',fh,...
285                      'units','pixel',...
286                      'position',[tmp(1)-85 10 80 25],...
287                      'string','Cancel',...
288                      'style','pushbutton',...
289                      'userdata',1,...
290                      'callback','uiresume(gcbf)');
291
292% File Filter popup
293tmp=get(tree,'position');
294filefilter_popup = uicontrol('parent',fh,...
295                             'units','pixel',...
296                             'position',[tmp(1)+105 tmp(2)-35 440 25],...
297                             'string',{' '},...
298                             'value',1,...
299                             'style','popup',...
300                             'backgroundcolor','w',...
301                             'callback',{@l_DirNodeSelected,tree,filetree});
302ff_tx = uicontrol('parent',fh,...
303                  'units','pixel',...
304                  'position',[tmp(1) tmp(2)-35 100 20],...
305                  'string','Show Files of Type:',...
306                  'horizontalalign','left',...
307                  'style','text',...
308                  'backgroundcolor',FigColor);%[236 233 216]./255);
309if isunix
310  set(ff_tx,'fontsize',8)
311end
312ffstr = {filefilter{:,2}};
313
314% Custom Filter Edit
315tmp=get(ff_tx,'position');
316custom_filter_tx = uicontrol('parent',fh,...
317  'units','pixel',...
318  'position',[tmp(1) tmp(2)-30 100 20],...
319  'string','Custom Filter:',...
320  'horizontalalign','left',...
321  'style','text',...
322  'backgroundcolor',FigColor);
323if isunix
324  set(custom_filter_tx,'fontsize',8)
325end
326tmp=get(filefilter_popup,'position');
327customfilter_popup = uicontrol('parent',fh,...
328  'units','pixel',...
329  'position',[tmp(1) tmp(2)-30 tmp(3)/2 25],...
330  'string',' ',...
331  'tooltip','Filter using regular expressions',...
332  'style','edit',...
333  'backgroundcolor','w',...
334  'callback',{@l_DirNodeSelected,tree,filetree});
335
336
337% Construct find string for regexp
338%regexp_str = strrep(strrep(strrep({filefilter{:,1}},';','|'),'*.','\.'),'\.*','.*');
339regexp_str={filefilter{:,1}};
340for ii=1:numel(regexp_str)
341  str=regexp_str{ii};
342  if any(str==';')
343    [delim,tmp_str]=regexp(str,';','match','split');
344    tmp_str=regexprep(regexprep(regexprep(regexprep(tmp_str,'\*\.','\\\.'),'^([^\\\.\*])','\^$1'),'([^\*])$','$1\$'),'^\\\.\*$','\.\*');
345    str = sprintf('(%s)|',tmp_str{:});
346    str = str(1:end-1);
347  else
348    str=regexprep(regexprep(regexprep(regexprep(str,'\*\.','\\\.'),'^([^\\\.\*])','\^$1'),'([^\*])$','$1\$'),'^\\\.\*$','\.\*');
349  end
350  regexp_str{ii} = str;
351end
352set(filefilter_popup,'string',ffstr,'userdata',regexp_str)
353
354H.tree = tree;
355H.filetree = filetree;
356H.selfiletree = selfiletree;
357H.openbtn = openbtn;
358H.cancelbtn = cancelbtn;
359H.filefilter_popup = filefilter_popup;
360H.pathedit = pathedit;
361H.back_btn = back_btn;
362H.forward_btn = forward_btn;
363H.showpathcb = showpathcb;
364H.addbtn = addbtn;
365H.rembtn = rembtn;
366H.history = {};
367H.historyind = 1;
368H.updateHistory = true;
369H.iconpath = iconpath;
370H.customfilter_popup = customfilter_popup;
371setappdata(H.fh,'H',H)
372
373%% Set tree callbacks and options
374set(tree,'NodeExpandedCallback',{@l_ExpFcnAlt,tree})
375set(filetree,'MultipleSelectionEnabled',true,...
376             'NodeCollapsedCallback',{@l_FileTreeNodeCollapsed,filetree},...
377             'NodeExpandedCallback',{@l_OpenDirectory,tree,1});
378set(tree,'NodeSelectedCallback',{@l_DirNodeSelected,tree,filetree});
379set(selfiletree,'DndEnabled',true);
380set(selfiletree,'MultipleSelectionEnabled',true);
381set(selfiletree,'NodeDroppedCallback',{@l_SelFileTreeNodeDropped,selfiletree});
382
383% Expand My Computer
384tree.expand(rootnode);
385
386% Try to open default directory
387if ~ischar(defaultdir)
388  if isunix
389        defaultdir = getenv('HOME');
390  else
391        defaultdir = getenv('USERPROFILE');
392  end
393  %defaultdir=pwd;
394end
395l_OpenDirectory([],[],tree,defaultdir)
396drawnow
397
398% Wait for exit
399uiwait(H.fh)
400if get(H.openbtn,'userdata')==0
401  % Action canceled
402  filename=0;
403  filepath=0;
404  filterindex=0;
405  delete(H.fh)
406  return
407end
408
409% Get selected files
410filename = {};
411filepath = {};
412filterindex = get(H.filefilter_popup,'value');
413selfileroot = handle(selfiletree.getRoot);
414childcount=selfileroot.ChildCount;
415for ii=1:childcount
416  node = selfileroot.getChildAt(ii-1);
417  value = node.getValue;
418  [fpath,fname,fext]=fileparts(value);
419  filename{ii}=[fname,fext];
420  filepath{ii}=[fpath,filesep];
421end
422
423fig_h = H.fh;
424clear H tree filetree selfiletree
425
426% Close window
427delete(fig_h)
428clear aedes_juigetfiles
429return
430
431
432% $$$ %%%%%%%%%%%%%%%%%%%%%%%%%
433% $$$ % Expand function
434% $$$ %%%%%%%%%%%%%%%%%%%%%%%%%
435% $$$ function nodes=l_ExpFcn(tree,value)
436% $$$ %disp('Calling ExpFcn...')
437% $$$ set(gcf,'pointer','watch')
438% $$$ drawnow
439% $$$ if strcmpi(value,'My Computer')
440% $$$   
441% $$$   %% Use Java to determine available drives
442% $$$   drives = {};
443% $$$   r=java.io.File.listRoots;
444% $$$   for n=1:length(r)
445% $$$     drive s{n} = char(r(n).toString);
446% $$$   end
447% $$$   
448% $$$   % Add drives to the tree
449% $$$   %nodes = [];
450% $$$   for ii=1:length(drives)
451% $$$     if any(strcmpi(drives{ii},{'A:\','B:\'}))
452% $$$       iconpath = '.\icons\floppyicon.gif';
453% $$$     else
454% $$$       iconpath = '.\icons\driveicon.gif';
455% $$$     end
456% $$$     nodes(ii) = uitreenode(drives{ii},drives{ii},iconpath,0);
457% $$$   end
458% $$$ else
459% $$$   count = 0;
460% $$$   ch = dir(value);
461% $$$   if isempty(ch)
462% $$$     tmp=tree.SelectedNodes;
463% $$$     node = handle(tmp(1));
464% $$$     
465% $$$     % Set loaded state for the node back to false
466% $$$     tree.setLoaded(node,false)
467% $$$     
468% $$$     % Set leafing back to "off" position
469% $$$     %node.Leaf(false)
470% $$$     
471% $$$     % Refresh node
472% $$$     tree.reloadNode(node)
473% $$$     
474% $$$     nodes=[];
475% $$$     h=warndlg(['Cannot access "' value '"'],'Access error');
476% $$$     set(gcf,'pointer','arrow')
477% $$$     return
478% $$$   else
479% $$$     directories = {ch([ch(:).isdir]).name};
480% $$$   end
481% $$$   %files = {ch(~[ch(:).isdir]).name};
482% $$$   
483% $$$   for ii=1:length(directories)
484% $$$     if (any(strcmp(directories{ii}, {'.', '..', ''})) == 0)
485% $$$       count = count + 1;
486% $$$       iconpath = '.\icons\Folder.gif';
487% $$$       
488% $$$       leafing=l_CheckLeafing([value, directories{ii}, filesep]);
489% $$$       nodes(count) = uitreenode([value, directories{ii}, filesep], ...
490% $$$                                 directories{ii}, iconpath, leafing);
491% $$$     end
492% $$$   end
493% $$$   
494% $$$   if count==0
495% $$$     nodes = [];
496% $$$   end
497% $$$ end
498% $$$ set(gcf,'pointer','arrow')
499
500
501
502%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
503% Alternate expand function
504%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
505function l_ExpFcnAlt(h,evd,tree)
506
507H=getappdata(findall(0,'tag','aedes_juigetfiles_main_fig'),'H');
508set(H.fh,'pointer','watch')
509drawnow
510
511evdnode = evd.getCurrentNode;
512value=evdnode.getValue;
513version_number = aedes_getmatlabversion;
514
515if ~tree.isLoaded(evdnode)
516
517
518        if strcmpi(value,'My Computer')
519   
520    %% Use Java to determine available drives, as using DIR is veeryy
521    %% slooow
522    drives = {};
523    r=java.io.File.listRoots;
524    for n=1:length(r)
525      drives{n} = char(r(n).toString);
526    end
527   
528    % Add drives to the tree
529        for ii=1:length(drives)
530          if any(strcmpi(drives{ii},{'A:\','B:\'}))
531                iconpath = [H.iconpath,'floppyicon.gif'];
532          else
533                iconpath = [H.iconpath,'driveicon.gif'];
534    end
535    if version_number >= 7.06
536      nodes(ii) = uitreenode('v0',drives{ii},drives{ii},iconpath,0);
537    else
538      nodes(ii) = uitreenode(drives{ii},drives{ii},iconpath,0);
539    end
540        end
541        else
542               
543                if ispc && length(value)>=4 && strcmpi(value(1:2),'\\') && ...
544                                length(find(value=='\'))==3
545                       
546                        % Handle Windows network shares
547                        [t,s]=dos(['net view ',value]);
548                        if t~=0
549                                directories = {'.','..'};
550                        else
551                                % Use regexp to find share names
552                                tmp=regexp(s,'([\w-\$]+)\s+Disk','tokens');
553                                directories=cat(1,tmp{:});
554                        end
555                        count = 0;
556                else
557                        count = 0;
558                        ch = dir(value);
559                        if isempty(ch)
560                                directories = {};
561                        else
562                                directories = {ch([ch(:).isdir]).name};
563                        end
564                end
565               
566   
567                if isempty(directories)
568      %tmp=tree.SelectedNodes;
569      %node = handle(tmp(1));
570     
571      % Set loaded state for the node back to false
572      tree.setLoaded(evdnode,false);
573     
574      % Refresh node
575      tree.reloadNode(evdnode);
576     
577      h=warndlg(['Cannot access "' value '"'],'Access error','modal');
578      set(H.fh,'pointer','arrow')
579      return
580    else
581      %directories = {ch([ch(:).isdir]).name};
582                        if isunix
583                                % Hide hidden directories in Linux
584                                ind = regexp(directories,'^\.');
585                                directories = {directories{cellfun('isempty',ind)}};
586                        end
587                end
588   
589    for ii=1:length(directories)
590      if (any(strcmp(directories{ii}, {'.', '..', ''})) == 0)
591        count = count + 1;
592        iconpath = [H.iconpath,'Folder.gif'];
593       
594        %leafing=l_CheckLeafing([value, directories{ii}, filesep]);
595        leafing=false;
596        if version_number >= 7.06
597          nodes(count) = uitreenode('v0',[value, directories{ii}, filesep], ...
598            directories{ii}, iconpath, leafing);
599        else
600          nodes(count) = uitreenode([value, directories{ii}, filesep], ...
601            directories{ii}, iconpath, leafing);
602        end
603      end
604    end
605   
606    if count==0
607      % Set loaded state for the node back to false
608      tree.setLoaded(evdnode,false);
609     
610      % Refresh node
611      tree.reloadNode(evdnode);
612     
613      set(H.fh,'pointer','arrow')
614      return
615    end
616  end
617 
618  %% Add child nodes
619  version_number = aedes_getmatlabversion;
620  if length(nodes)==1 && version_number==7.01
621    % Make nodes a JavaArray
622    tmpnodes = nodes;
623    nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
624    nodes(1) = java(tmpnodes);
625  end
626 
627  tree.add(evdnode,nodes);
628  tree.setLoaded(evdnode,true);
629  tree.reloadNode(evdnode);
630end
631set(H.fh,'pointer','arrow')
632
633
634%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
635% Check leafing for directories
636%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
637function leafing=l_CheckLeafing(path)
638
639s=dir(path);
640if isempty(s)
641  leafing = true;
642  return
643end
644
645if length(s([s(:).isdir]))>2
646  leafing = false;
647else
648  leafing = true;
649end
650
651%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
652% Execute when directory node is selected
653%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
654function l_DirNodeSelected(hCaller,evd,tree,filetree)
655
656H=getappdata(findall(0,'tag','aedes_juigetfiles_main_fig'),'H');
657set(H.fh,'pointer','watch')
658drawnow
659version_number = aedes_getmatlabversion;
660
661% Clear file tree view
662filetree.setRoot([]);
663if version_number >=7.06
664  fileroot = uitreenode('v0','Loading','Loading...','',false);
665else
666  fileroot = uitreenode('Loading','Loading...','',false);
667end
668filetree.setRoot(fileroot);
669filetree.reloadNode(fileroot);
670
671
672% Get Root
673%fileroot = handle(filetree.getRoot);
674
675% Remove all children
676%filetree.removeAllChildren(fileroot);
677%filetree.reloadNode(fileroot);
678
679
680% Get selected node
681currentnode=tree.getSelectedNodes;
682if isempty(currentnode)
683        set(H.fh,'pointer','arrow')
684  return
685else
686        currentnode=handle(currentnode(1));
687end
688
689% Get path
690path = currentnode.getValue;
691if strcmp(path,'My Computer')
692  %selfiletree.add(selfileroot,new_nodes);
693  %selfiletree.setLoaded(selfileroot,true);
694  %selfiletree.expand(selfileroot);
695  %selfileroot.setName([num2str(length(new_nodes)) ' Files Selected'])
696  fileroot.setValue('My Computer');
697  fileroot.setName('My Computer');
698  filetree.reloadNode(fileroot)
699  set(H.fh,'pointer','arrow')
700  return
701end
702
703
704% Try to get file information from the path
705if strncmp(path,'\\',2) && length(find(path=='\'))==3
706        [t,s]=dos(['net view ',path]);
707        if t~=0
708                %directories = {'.','..'};
709                ch = [];
710        else
711                % Use regexp to find share names
712                tmp=regexp(s,'([\w-\$]+)\s+Disk','tokens');
713                directories=cat(1,tmp{:});
714                ch = 1;
715        end
716        filenames = {};
717else
718        ch=dir(path);
719        filenames={ch(~[ch(:).isdir]).name};
720        directories={ch([ch(:).isdir]).name};
721end
722
723if isempty(ch)
724  %rootnode = uitreenode(['Cannot access ' path],['Cannot access 'path],'',false);
725  %filetree.setRoot(rootnode);
726  %filetree.reloadNode(rootnode);
727  fileroot.setName(['Cannot access ' path]);
728  fileroot.setValue(['Cannot access ' path]);
729  filetree.reloadNode(fileroot)
730  set(H.pathedit,'string',path)
731  h=warndlg(['Cannot access "' path '"'],'Access error','modal');
732  set(H.fh,'pointer','arrow')
733  return
734end
735
736if H.updateHistory
737  % Add path to history
738  if H.historyind<length(H.history)
739    H.history(H.historyind+1:end)=[];
740  end
741  if isempty(H.history) || ~strcmp(H.history{end},path)
742    H.history{end+1} = path;
743  end
744  H.historyind = length(H.history);
745  set(H.forward_btn,'enable','off')
746  if length(H.history)>1
747    set(H.back_btn,'enable','on')
748  end
749 
750  % Keep maximum of 50 folders in history
751  if length(H.history)>50
752    H.history(1)=[];
753  end
754  setappdata(H.fh,'H',H)
755end
756
757% Get Name
758name = currentnode.getName;
759
760% Set up file tree root
761%rootnode = uitreenode(path,path,'',false);
762%filetree.setRoot(rootnode);
763fileroot.setName(path);
764fileroot.setValue(path);
765
766
767% Filter filenames
768
769filter_val=get(H.filefilter_popup,'value');
770if ~isempty(hCaller) && hCaller~=H.customfilter_popup
771  regexp_str = get(H.filefilter_popup,'userdata');
772  regexp_str = regexp_str{filter_val};
773else
774  regexp_str = get(H.customfilter_popup,'string');
775end
776if ~strcmp(regexp_str,'.*')
777  [s_ind,e_ind]=regexpi(filenames,regexp_str);
778  ind=~cellfun('isempty',s_ind);
779  filenames = {filenames{ind}};
780 
781%   if ~isempty(s_ind)
782%     ind = (double(char(s_ind{:}))-double(char(e_ind{:})))~=0;
783%     filenames = {filenames{logical(ind)}};
784%   else
785%     filenames = {};
786%   end
787end
788
789
790if isunix
791  % Hide hidden directories in Linux
792  ind = regexp(directories,'^\.');
793  directories = {directories{cellfun('isempty',ind)}};
794end
795
796% Set regexp filter string to custom filter editbox
797if ~isempty(hCaller) && hCaller~=H.customfilter_popup
798  set(H.customfilter_popup,'string',regexp_str)
799end
800
801% Create child nodes
802count=0;
803for ii=1:length(directories)
804  if ~any(strcmp(directories{ii},{'.','..'}))
805    count=count+1;
806    if version_number>=7.06
807      nodes(count)=uitreenode('v0',[path,directories{ii},filesep],directories{ii},[H.iconpath,'Folder.gif'],false);
808    else
809      nodes(count)=uitreenode([path,directories{ii},filesep],directories{ii},[H.iconpath,'Folder.gif'],false);
810    end
811  end
812end
813for ii=1:length(filenames)
814  count=count+1;
815  if version_number>=7.06
816    nodes(count)=uitreenode('v0',[path,filenames{ii}],filenames{ii},[H.iconpath,'new.gif'],true);
817  else
818    nodes(count)=uitreenode([path,filenames{ii}],filenames{ii},[H.iconpath,'new.gif'],true);
819  end
820end
821
822set(H.pathedit,'string',path)
823if count==0;
824  filetree.reloadNode(fileroot);
825  set(H.fh,'pointer','arrow')
826  return
827end
828
829%% Add child nodes
830version_number = aedes_getmatlabversion;
831if length(nodes)==1 && ( version_number==7.01 | version_number==7.02)
832  % Make nodes a JavaArray
833  tmpnodes = nodes;
834  nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
835  nodes(1) = java(tmpnodes);
836end
837
838filetree.add(fileroot,nodes);
839filetree.setLoaded(fileroot,true);
840filetree.expand(fileroot);
841filetree.reloadNode(fileroot)
842set(H.fh,'pointer','arrow')
843%filetree.add(rootnode,nodes);
844%filetree.setLoaded(rootnode,true);
845%filetree.expand(rootnode);
846
847
848%%%%%%%%%%%%%%%%%%%%%%%%%%%%
849% Files selected
850%%%%%%%%%%%%%%%%%%%%%%%%%%%%
851function l_FileTreeNodeSelected(h,evd,filetree)
852%disp('l_FileTreeNodeSelected')
853
854nodes=filetree.getSelectedNodes;
855if isempty(nodes)
856  return
857end
858
859% Don't allow selection of directories
860count=0;
861for ii=1:length(nodes)
862  if ~nodes(ii).isRoot
863    count=count+1;
864    selnodes(count)=nodes(ii);
865  end
866end
867
868if count==0
869  filetree.setSelectedNodes([]);
870else
871  % Reselect only files
872  filetree.setSelectedNodes(selnodes);
873end
874
875
876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
877% Filetree collapsed
878%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
879function l_FileTreeNodeCollapsed(h,evd,filetree)
880
881% Don't let the filetree root node to collapse
882filetree.expand(filetree.getRoot);
883
884%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885% Node Dropped to selected files tree
886%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
887function l_SelFileTreeNodeDropped(h,evd,selfiletree)
888
889tmp=handle(evd);
890SourceNode=tmp.getSourceNode;
891TargetNode=tmp.getTargetNode;
892
893target_value = TargetNode.getValue;
894source_value = SourceNode.getValue;
895if SourceNode.isRoot || TargetNode.isRoot
896  return
897end
898if strcmp(target_value,source_value)
899  return
900end
901
902
903% Reorder nodes
904selfileroot = handle(selfiletree.getRoot);
905childcount=selfileroot.ChildCount;
906
907% Construct a new javaArray for nodes
908nodes=javaArray('com.mathworks.hg.peer.UITreeNode',childcount);
909
910
911count=0;
912fromUp = false;
913if childcount ~= 0
914  for ii=0:childcount-1
915    tmp=selfileroot.getChildAt(ii);
916    if strcmp(tmp.getValue,target_value)
917      if fromUp
918        count=count+1;
919        nodes(count) = TargetNode;
920        count=count+1;
921        nodes(count) = SourceNode;
922      else
923        count=count+1;
924        nodes(count) = SourceNode;
925        count=count+1;
926        nodes(count) = TargetNode;
927      end
928    elseif ~strcmp(tmp.getValue,source_value)
929      count=count+1;
930      nodes(count) = tmp;
931    else
932      fromUp = true;
933    end
934  end
935end
936
937%selfiletree.setRoot([]);
938%selfileroot = uitreenode('Selected Files','Selected Files','',false);
939%selfiletree.setRoot(selfileroot);
940selfiletree.removeAllChildren(selfileroot);
941
942% Add new nodes to the tree
943selfiletree.add(selfileroot,nodes);
944selfiletree.expand(selfileroot);
945selfiletree.reloadNode(selfileroot);
946
947
948%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
949% ADD/REMOVE Files
950%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
951function l_AddRemFiles(h,evd,opt,filetree,selfiletree)
952
953% Get handles
954H=getappdata(findall(0,'tag','aedes_juigetfiles_main_fig'),'H');
955
956version_number = aedes_getmatlabversion;
957
958
959switch opt
960 case {'add','addall'}
961 
962  % Look for a quick return
963  if isempty(filetree.getSelectedNodes) && strcmpi(opt,'add')
964    return
965  end
966 
967  % Get Rootnode
968  selfileroot = handle(selfiletree.getRoot);
969 
970   
971   if get(H.showpathcb,'value')
972     ShowPaths = true;
973   else
974     ShowPaths = false;
975   end
976   
977   if strcmpi(opt,'add')
978         % Get selected nodes
979         selnodes=filetree.getSelectedNodes;
980         filecount = length(selnodes);
981   elseif strcmpi(opt,'addall')
982         selnodes=filetree.getRoot;
983         filecount=selnodes.getChildCount;
984   end
985   
986   % Get existing nodes in the selfiletree
987   childcount=selfileroot.ChildCount;
988   count=0;
989   if childcount ~= 0
990     for ii=0:childcount-1
991       count=count+1;
992       selfilenodes(count) = selfileroot.getChildAt(ii);
993     end
994   end
995   
996   % Add existing nodes to new_nodes
997   selfilenodevalues={};
998   for ii=1:childcount
999     if ShowPaths
1000       name_str = selfilenodes(ii).getValue;
1001     else
1002       [fpath,fname,fext] = fileparts(selfilenodes(ii).getValue);
1003       name_str = [fname,fext];
1004     end
1005     if version_number >= 7.06
1006       new_nodes(ii) = uitreenode('v0',selfilenodes(ii).getValue,...
1007         name_str,...
1008         [H.iconpath,'new.gif'],...
1009         true);
1010     else
1011       new_nodes(ii) = uitreenode(selfilenodes(ii).getValue,...
1012         name_str,...
1013         [H.iconpath,'new.gif'],...
1014         true);
1015     end
1016     selfilenodevalues{ii}=selfilenodes(ii).getValue;
1017   end
1018   
1019   % Add selected nodes to new_nodes
1020   count=childcount;
1021   count2=0;
1022   for ii=childcount+1:childcount+filecount
1023         count2=count2+1;
1024         if strcmpi(opt,'add')
1025           % Add selected
1026           nodeVal=selnodes(count2).getValue;
1027           isNodeRoot = selnodes(count2).isRoot;
1028         else
1029           % Add all files
1030           nodeVal=selnodes.getChildAt(count2-1).getValue;
1031           isNodeRoot = selnodes.getChildAt(count2-1).isRoot;
1032         end
1033         if ~any(strcmp(selfilenodevalues,nodeVal)) && ...
1034                 ~strcmp(nodeVal(end),filesep) && ~isNodeRoot
1035           if ShowPaths
1036                 name_str = nodeVal;
1037           else
1038                 [fpath,fname,fext] = fileparts(nodeVal);
1039                 name_str = [fname,fext];
1040           end
1041           count=count+1;
1042     if version_number >= 7.06
1043       new_nodes(count) = uitreenode('v0',nodeVal,...
1044         name_str,...
1045         [H.iconpath,'new.gif'],...
1046         true);
1047     else
1048       new_nodes(count) = uitreenode(nodeVal,...
1049         name_str,...
1050         [H.iconpath,'new.gif'],...
1051         true);
1052     end
1053         end
1054   end
1055       
1056   
1057   
1058   if count==0
1059     return
1060   end
1061   
1062   % Enable Open button
1063   set(H.openbtn,'enable','on')
1064   
1065   
1066   version_number = aedes_getmatlabversion;
1067   if length(new_nodes)==1 && version_number==7.01
1068     % Make nodes a JavaArray
1069     tmpnodes = new_nodes;
1070     new_nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
1071     new_nodes(1) = java(tmpnodes);
1072   end
1073   
1074   % Remove old nodes from the tree
1075   %selfiletree.setRoot([]);
1076   %selfileroot = uitreenode('Selected Files','Selected Files','',false);
1077   %selfiletree.setRoot(selfileroot);
1078   selfileroot.removeAllChildren;
1079   selfiletree.reloadNode(selfileroot);
1080   %selfiletree.repaint;
1081   %selfiletree.removeAllChildren(selfileroot);
1082   
1083   % Add new nodes to the tree
1084   selfiletree.add(selfileroot,new_nodes);
1085   %selfiletree.setLoaded(selfileroot,true);
1086   selfiletree.expand(selfileroot);
1087   selfileroot.setName([num2str(length(new_nodes)) ' Files Selected'])
1088   selfiletree.reloadNode(selfileroot)
1089
1090   
1091 case {'remove','removeall'}
1092  %keyboard
1093  selnodes = selfiletree.getSelectedNodes;
1094 
1095  % Look for a quick return
1096  if isempty(selnodes) && strcmpi(opt,'remove')
1097    return
1098  end
1099 
1100  % Get values to the selected nodes
1101  selnodevalues = cell(1,length(selnodes));
1102  for ii=1:length(selnodes)
1103    tmp=handle(selnodes(ii));
1104    selnodevalues{ii}=tmp.getValue;
1105  end
1106 
1107  % Get Root
1108  selfileroot=selfiletree.getRoot;
1109 
1110  if strcmpi(opt,'removeall')
1111        selfileroot.removeAllChildren;
1112        selfiletree.reloadNode(selfileroot);
1113       
1114        % Disable Open button
1115        set(H.openbtn,'enable','off')
1116        selfileroot.setName('0 Files Selected')
1117        selfiletree.reloadNode(selfileroot)
1118        selfiletree.expand(selfileroot);
1119        return
1120  end
1121 
1122  % Get number of files in the tree
1123  childcount = selfileroot.getChildCount;
1124 
1125  count = 0;
1126  for ii=0:childcount-1
1127    tmp=selfileroot.getChildAt(ii);
1128    if ~any(strcmp(tmp.getValue,selnodevalues))
1129      count=count+1;
1130      new_nodes(count) = tmp;
1131    end
1132  end
1133 
1134  %selfiletree.setRoot([]);
1135  %selfileroot = uitreenode('Selected Files','Selected Files','',false);
1136  %selfiletree.setRoot(selfileroot);
1137  selfileroot.removeAllChildren;
1138  selfiletree.reloadNode(selfileroot);
1139  %selfiletree.removeAllChildren(selfileroot);
1140   
1141  % Add new nodes to the tree
1142  if count~=0
1143    selfiletree.add(selfileroot,new_nodes);
1144    selfileroot.setName([num2str(length(new_nodes)) ' Files Selected'])
1145    selfiletree.reloadNode(selfileroot)
1146  else
1147    % Unenable Open button
1148    set(H.openbtn,'enable','off')
1149   
1150    selfileroot.setName('0 Files Selected')
1151    selfiletree.reloadNode(selfileroot)
1152  end
1153  %selfiletree.setLoaded(selfileroot,true);
1154  selfiletree.expand(selfileroot);
1155end
1156
1157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1158% Open directory
1159%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1160function l_OpenDirectory(h,evd,tree,directory)
1161
1162% Get handles
1163H=getappdata(findall(0,'tag','aedes_juigetfiles_main_fig'),'H');
1164set(H.fh,'pointer','watch')
1165drawnow
1166
1167if isempty(directory)
1168  directory = get(h,'string');
1169elseif isnumeric(directory)
1170  tmp=evd.getCurrentNode;
1171  if tmp.isRoot
1172    set(H.fh,'pointer','arrow')
1173    return
1174  end
1175  directory=tmp.getValue;
1176end
1177
1178% Check that directory exists
1179if ~isdir(directory) && ( ~ispc | ~strncmp(directory,'\\',2) )
1180  h=errordlg({['Cannot open folder "' directory '".'],['Make sure the path is ' ...
1181                      'correct.']},'Cannot open folder','modal');
1182  set(H.fh,'pointer','arrow')
1183  return
1184elseif strncmp(directory,'\\',2) && ispc
1185        % Test if the Windows computer is accessible
1186        ind=find(directory=='\');
1187        if ind<3
1188                str = directory;
1189        else
1190                str = directory(1:ind(3)-1);
1191        end
1192        [t,s]=dos(['net view ',str]);
1193        if t~=0
1194                h=errordlg(s,'Cannot open folder','modal');
1195                set(H.fh,'pointer','arrow')
1196                return
1197        end
1198end
1199if ~strcmp(directory(end),filesep)
1200  directory = [directory,filesep];
1201end
1202
1203% See if we are in the specified directory already
1204%keyboard
1205tmp=tree.getSelectedNodes;
1206if ~isempty(tmp)
1207  tmp=handle(tmp(1));
1208  if strcmp(tmp.getValue,directory)
1209    set(H.fh,'pointer','arrow')
1210    return
1211  end
1212end
1213
1214if H.updateHistory
1215  % Add path to history
1216  if H.historyind<length(H.history)
1217    H.history(H.historyind+1:end)=[];
1218  end
1219  if isempty(H.history) || ~strcmp(H.history{end},directory)
1220    H.history{end+1} = directory;
1221  end
1222  H.historyind = length(H.history);
1223  set(H.forward_btn,'enable','off')
1224  if length(H.history)>1
1225    set(H.back_btn,'enable','on')
1226  end
1227 
1228  % Keep maximum of 50 folders in history
1229  if length(H.history)>50
1230    H.history(1)=[];
1231  end
1232  setappdata(H.fh,'H',H)
1233end
1234
1235% Get root
1236rootnode = tree.getRoot;
1237
1238% Get Matlab version
1239version_number = aedes_getmatlabversion;
1240
1241% Split the directory using file separator
1242if ispc
1243        sDir = regexp(directory,'\\','split');
1244        if isempty(sDir{1})
1245                % Windows network drive
1246                sDir([1 2])=[];
1247                sDir{1} = ['\\',sDir{1},'\'];
1248                childcount=rootnode.getChildCount;
1249                nodeFound = false;
1250                for kk=1:childcount
1251                        tmp=rootnode.getChildAt(kk-1);
1252                        name=tmp.getName;
1253                        if strcmp(name,sDir{1})
1254                                nodeFound = true;
1255                        end
1256                end
1257                if ~nodeFound
1258                        if version_number >= 7.06
1259                                nodes = uitreenode('v0',sDir{1},sDir{1},'',0);
1260                        else
1261                                nodes = uitreenode(sDir{1},sDir{1},'',0);
1262                        end
1263                        if length(nodes)==1 && version_number==7.01
1264                                % Make nodes a JavaArray
1265                                tmpnodes = nodes;
1266                                nodes=javaArray('com.mathworks.hg.peer.UITreeNode',1);
1267                                nodes(1) = java(tmpnodes);
1268                        end
1269                        tree.add(rootnode,nodes);
1270                        %tree.setSelectedNode(nodes);
1271                        tree.setLoaded(rootnode,true);
1272                        tree.reloadNode(rootnode);
1273                        tree.setSelectedNode(nodes);
1274                end
1275        else
1276                sDir{1} = [sDir{1},'\'];
1277        end
1278        if isempty(sDir{end})
1279                sDir(end)=[];
1280        end
1281else
1282        sDir = regexp(directory,'/','split');
1283        sDir{1}='/';
1284end
1285
1286%ind=find(directory==filesep);
1287%if ind(1)==1 && ind(2)==2
1288%       % Windows network share
1289%       ind(1)=[];
1290%end
1291
1292
1293
1294%keyboard
1295drawnow
1296drawnow
1297start_ind=0;
1298currentnode = rootnode;
1299for ii=1:length(sDir)
1300  %if ii==1
1301  %  currentdir=sDir{ii};
1302  %else
1303    currentdir=sDir{ii};
1304  %end
1305  childcount=currentnode.getChildCount;
1306  for kk=1:childcount
1307    tmp=currentnode.getChildAt(kk-1);
1308    name=tmp.getName;
1309    if strcmp(name,currentdir)
1310      %tree.expand(tmp);
1311      %tree.setLoaded(tmp,true)
1312      %tree.reloadNode(tmp);
1313      currentnode=tmp;
1314      if ii~=length(sDir)
1315        tree.expand(currentnode)
1316      end
1317      %tree.setLoaded(tmp,true)
1318      %tree.setSelectedNode(currentnode);
1319      %tree.reloadNode(currentnode);
1320      %pause(12)
1321      drawnow
1322      break;
1323    end
1324  end
1325  %start_ind = ind(ii);
1326end
1327
1328%tree.expand(currentnode)
1329%tree.setLoaded(currentnode,true)
1330tree.setSelectedNode(currentnode);
1331drawnow, pause(0.01)
1332tree.reloadNode(currentnode);
1333set(H.fh,'pointer','arrow')
1334%tree.setSelectedNode(currentnode)
1335
1336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337% SHOW/HIDE path names from selected files
1338%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1339function l_ShowHidePathNames(h,evd,selfiletree)
1340
1341if get(h,'value')==1
1342  ShowPaths = true;
1343else
1344  ShowPaths = false;
1345end
1346
1347% Redraw all nodes in the tree
1348selfileroot = handle(selfiletree.getRoot);
1349childcount=selfileroot.ChildCount;
1350if childcount==0
1351  return
1352end
1353
1354count=0;
1355if childcount ~= 0
1356  for ii=0:childcount-1
1357    count=count+1;
1358    childnode=selfileroot.getChildAt(ii);
1359    if ShowPaths
1360      childnode.setName(childnode.getValue);
1361    else
1362      [fpath,fname,fext] = fileparts(childnode.getValue);
1363      childnode.setName([fname,fext])
1364    end
1365  end
1366end
1367
1368% Reload root node
1369selfiletree.reloadNode(selfileroot);
1370
1371
1372%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1373% BACK/FORWARD functions
1374%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1375function l_BackForward(h,evd,opt,tree)
1376
1377% Get handles
1378H=getappdata(findall(0,'tag','aedes_juigetfiles_main_fig'),'H');
1379%set(H.back_btn,'enable','inactive')
1380%set(H.forward_btn,'enable','inactive')
1381
1382% Put up a flag that prevents the history to be updated
1383H.updateHistory = false;
1384setappdata(H.fh,'H',H)
1385
1386switch opt
1387 case 'back'
1388  %keyboard
1389  if length(H.history)>1
1390    H.historyind = H.historyind-1;
1391    drawnow % Java seems to be slow to update...
1392    l_OpenDirectory([],[],tree,H.history{H.historyind})
1393    drawnow
1394    set(H.forward_btn,'enable','on')
1395    if H.historyind==1
1396      set(H.back_btn,'enable','off')
1397    end
1398  end
1399 
1400  % Put history update flag down
1401  H.updateHistory = true;
1402  setappdata(H.fh,'H',H)
1403  %H.history
1404  %H.historyind
1405 case 'forward'
1406  if length(H.history)==H.historyind
1407    return
1408  end
1409 
1410  if H.historyind<length(H.history)
1411    H.historyind = H.historyind+1;
1412    drawnow
1413    l_OpenDirectory([],[],tree,H.history{H.historyind})
1414    drawnow
1415    set(H.back_btn,'enable','on')
1416    if H.historyind==length(H.history)
1417      set(H.forward_btn,'enable','off')
1418    end
1419  end
1420 
1421  % Put history update flag down
1422  H.updateHistory = true;
1423  setappdata(H.fh,'H',H)
1424  %H.history
1425  %H.historyind
1426end
1427
1428
1429%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1430% Resize Function
1431%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1432function l_Resize(h,evd)
1433
1434% To be written...
1435
1436%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1437% Key press callback
1438%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1439function l_KeyPressFcn(h,evd)
1440
1441% Exit with Esc
1442if strcmp(evd.Key,'escape')
1443  uiresume(gcbf)
1444end
Note: See TracBrowser for help on using the repository browser.

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