source: aedes_juigetfiles.m @ 196

Last change on this file since 196 was 155, checked in by tjniskan, 8 years ago
  • Added support for multiple monitor systems

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

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