source: aedes_juigetfiles.m

Last change on this file was 213, checked in by tjniskan, 2 years ago
  • Fixed Aedes for Handle Graphics version 2 (HG2).

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

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