source: aedes_headerbrowser.m @ 147

Last change on this file since 147 was 147, checked in by tjniskan, 9 years ago
  • Added support for Windows network paths (
    server\share) to

aedes_juigetfiles.m (Windows only)

  • Added a link for suppressing the license information from printing to

workspace

  • Fixed some uicontrol colors in aedes_headerbrowser.m
  • Changed the buffer size for reading VNMR PROCPAR to 1MB. The

previous buffer size (10kB) was apparently too low for some SWIFT data

  • aedes_killfigs.m now has an option to force close only Aedes-related

figures

  • Updated figure tags for aedes_killfigs.m
  • Added a request for restarting Aedes to the "Update successful" dialog

M aedes_readprocpar.m
M aedes_killfigs.m
M aedes_data_read.m
M aedes_gui_defaults.m
M aedes_resviewer.m
M aedes.m
M aedes_update.m
M aedes_export_gui.m
M aedes_headerbrowser.m
M aedes_revision.m
M aedes_juigetfiles.m
M aedes_errordump.m

File size: 31.6 KB
RevLine 
[146]1function aedes_headerbrowser(inStruct)
2% AEDES_HEADERBROWSER - Browse and search file header information or any
3%                       Matlab structure
[2]4%   
5%
[146]6% Synopsis:
7%       aedes_headerbrowser(DATA) % Open the file format specific header
[2]8%
[146]9%       aedes_headerbrowser(STRUCT) % Browse a generic Matlab structure
10%
[2]11% Description:
[146]12%       
[2]13%
14% Examples:
15%
16% See also:
[146]17%       AEDES, AEDES_READPROCPAR, AEDES_READ_NIFTI
[2]18
[39]19% This function is a part of Aedes - A graphical tool for analyzing
[36]20% medical images
[2]21%
[36]22% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
23%
[45]24% Department of Physics, Department of Neurobiology
[39]25% University of Kuopio, FINLAND
[36]26%
27% This program may be used under the terms of the GNU General Public
28% License version 2.0 as published by the Free Software Foundation
29% and appearing in the file LICENSE.TXT included in the packaging of
30% this program.
31%
32% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
33% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
[2]34
[144]35% Public variables
36H = [];    % Handles structure
37Dat = [];  % Internal data structure
[2]38
[144]39% Do some error checking
40if nargin ~= 1
41  error('Invalid number of input arguments!')
42end
[2]43
[146]44% Check that the input argument is structure
45if ~isstruct(inStruct)
46  error('Input argument must be structure!')
47end
48
49% Get the saved Favourite list
50try
51  Dat.FavList = getpref('Aedes','HeaderBrowserFavList');
52catch
53  Dat.FavList.nifti = {};
54  Dat.FavList.vnmr = {};
55  Dat.FavList.dcm = {};
56  Dat.FavList.genheader = {};
57  Dat.FavList.generic = {};
58end
59
[144]60% Check if input is a Aedes data structure
[146]61if isfield(inStruct,'HDR') && isfield(inStruct,'FTDATA')
62  if isfield(inStruct,'DataFormat')
63    if any(strcmpi(inStruct.DataFormat,{'NIfTI(1)','NIfTI(2)','Analyze75'}))
64      % NIfTI and Analyze75 files
65      Dat.HeaderFileName = [inStruct.HDR.fpath,inStruct.HDR.fname];
66      Dat.FileFormatName = 'NIfTI/Analyze';
67      try
68        Dat.FavouriteList = Dat.FavList.nifti;
69      catch
70        Dat.FavList.nifti = {}
71        Dat.FavouriteList = Dat.FavList.nifti;
72      end
73      inStruct=inStruct.HDR.FileHeader;
74     
75    elseif strcmpi(inStruct.DataFormat,'VNMR')
76      % Varian VNMR files
77      Dat.HeaderFileName = [inStruct.HDR.fpath,'procpar'];
78      Dat.FileFormatName = 'VNMR Procpar';
79      try
80        Dat.FavouriteList = Dat.FavList.vnmr;
81      catch
82        Dat.FavList.vnmr = {}
83        Dat.FavouriteList = Dat.FavList.vnmr;
84      end
85      inStruct=inStruct.PROCPAR;
86     
87    elseif strcmpi(inStruct.DataFormat,'DCM')
88      % DICOM files
89      Dat.HeaderFileName = [inStruct.HDR.fpath,inStruct.HDR.fname];
90      Dat.FileFormatName = 'DICOM';
91      try
92        Dat.FavouriteList = Dat.FavList.dcm;
93      catch
94        Dat.FavList.dcm = {}
95        Dat.FavouriteList = Dat.FavList.dcm;
96      end
97      inStruct=inStruct.HDR.FileHeader;
98     
99    else
100      % Generic header
101      Dat.HeaderFileName = [inStruct.HDR.fpath,inStruct.HDR.fname];
102      Dat.FileFormatName = 'generic header';
103      try
104        Dat.FavouriteList = Dat.FavList.genheader;
105      catch
106        Dat.FavList.genheader = {}
107        Dat.FavouriteList = Dat.FavList.genheader;
108      end
109      inStruct=inStruct.HDR.FileHeader;
110     
111    end
112  else
113    % Generic header
114    inStruct=inStruct.HDR.FileHeader;
115    Dat.FileFormatName = 'generic header';
116    try
117      Dat.FavouriteList = Dat.FavList.genheader;
118    catch
119      Dat.FavList.genheader = {}
120      Dat.FavouriteList = Dat.FavList.genheader;
121    end
122    Dat.HeaderFileName = [inStruct.HDR.fpath,inStruct.HDR.fname];
123  end
[144]124else
[146]125  % Generic Matlab structure
126  Dat.HeaderFileName = '';
127  Dat.FileFormatName = 'generic structure';
128  try
129    Dat.FavouriteList = Dat.FavList.generic;
130  catch
131    Dat.FavList.generic = {}
132    Dat.FavouriteList = Dat.FavList.generic;
133  end
[144]134end
[2]135
[146]136% Initialize the cell array for uitable
137Dat.FullTable = {};
138Dat.StructMaxDepth = 10; % Limit recursion to something reasonable...
139Dat.FieldSeparator = '\';
140Dat.TableFavSeparator = '<html><b>=============</b></html>';
141Dat.SelectedCells = [];
[2]142
[144]143% Draw main GUI
[146]144[H,Dat]=l_DrawGui(Dat);
145l_ParseHeaderStructure(inStruct,'',0);
146Dat.DataTable = Dat.FullTable;
147l_SearchParams([],[]);
[2]148
[144]149% Update Data Table
150l_UpdateDataTable([],[]);
151
152% Set initial focus to search editbox
153uicontrol(H.SearchEdit);
154
[146]155% Get java handle to the table for Matlab R2007a and older
156if Dat.MatlabVersion<=7.05
157  drawnow, pause(0.01) % Force refresh
158 
159  % Set Table to non-editable
160  set(H.DataTable,'Editable',false)
161 
162  % Get java handle
163  H.DataTableJavaHandle = handle(H.DataTable.getTable,'callbackproperties');
164 
165  % Set KeyPressedCallback
166  set(H.DataTableJavaHandle.KeyPressedCallback,@l_KeyPressFcn)
167end
[144]168
[147]169% For debuging
170%assignin('base','H',H) % debug
171
[146]172%% ------------------------------------------
173  function [H,Dat]=l_DrawGui(Dat)
174
[144]175    % Load default font and colors
176    Dat.GD=aedes_gui_defaults;
[145]177   
178    % Get Matlab version
179    Dat.MatlabVersion = aedes_getmatlabversion;
[144]180
181    % Position figure to the center of the screen
182    scrsz = get(0,'screensize');
183    fig_w = 600;
184    fig_h = 700;
185    fig_pos = [scrsz(3)/2-fig_w/2 scrsz(4)/2-fig_h/2 fig_w fig_h];
186   
187   
188    % Main Figure ----------------------------
[146]189    H.Fig = figure('Units','Pixel', ...
[144]190      'position',fig_pos,...
[146]191      'Name',['File Header Browser - ',Dat.FileFormatName], ...
[144]192      'Numbertitle','off', ...
[146]193      'Tag','header_browser_fig', ...
[144]194      'Color',Dat.GD.col.mainfig, ...
195      'Toolbar','none', ...
196      'Menubar','none', ...
197      'DoubleBuffer','on', ...
198      'DockControls','off',...
199      'renderer','painters',...
200      'resize','off',...
201      'Handlevisibility','off',...
[146]202      'KeyPressFcn',@l_KeyPressFcn,...
[144]203      'CloseReq',@l_CloseFig);
204   
205    % File name
206    fname_txh = 0;
[146]207    if ~isempty(Dat.HeaderFileName)
[144]208      fname_txh = 70;
[146]209      H.FileNameUipanel = uipanel('parent',H.Fig,...
[144]210        'units','pixel',...
211        'position',[10 fig_h-fname_txh fig_w-20 fname_txh-10],...
212        'title','File Name',...
213        'backgroundcolor',Dat.GD.col.mainfig);
214     
215      tmp_pos=get(H.FileNameUipanel,'position');
216      H.FileNameText = uicontrol('parent',H.FileNameUipanel,...
217        'style','text',...
[146]218        'string',Dat.HeaderFileName,...
[144]219        'units','pixel',...
220        'position',[10 5 tmp_pos(3)-20 fname_txh-35],...
221        'horizontalalign','left',...
222        'backgroundcolor',Dat.GD.col.mainfig);
223    end
224   
225    % Search uipanel ----------------------
226    up_height = 80;
[146]227    H.SearchUipanel = uipanel('parent',H.Fig,...
[144]228      'units','pixel',...
229      'position',[10 fig_h-up_height-10-fname_txh fig_w-20 up_height],...
230      'title','Search Options',...
231      'backgroundcolor',Dat.GD.col.mainfig);
232
233    % Search text
234    pos=get(H.SearchUipanel,'position');
[146]235    %H.SearchText = uicontrol('parent',H.SearchUipanel,...
236    %  'style','text',...
237    %  'string','Parameter:',...
238    %  'units','pixel',...
239    %  'position',[10 pos(4)-45 100 19],...
240    %  'horizontalalign','left',...
241    %  'backgroundcolor',Dat.GD.col.mainfig);
242    try
243      val=getpref('Aedes','HeaderBrowserSearchWhere');
244    catch
245      val=1;
246    end
247    H.SearchWherePopup = uicontrol('parent',H.SearchUipanel,...
248      'style','popup',...
249      'string',{'Parameter',...
250      'Value'},...
[144]251      'units','pixel',...
[146]252      'position',[10 pos(4)-45 100 22],...
253      'value',val,...
254      'tag','',...
255      'backgroundcolor',Dat.GD.col.popup,...
256      'callback',@l_SearchParams,...
257      'KeyPressFcn',@l_KeyPressFcn);
258   
[144]259    % Search type popupmenu
260    try
[146]261      val = getpref('Aedes','HeaderBrowserSearchHow');
[144]262    catch
263      val = 1;
264    end
[146]265    tmp_pos = get(H.SearchWherePopup,'position');
266    %tmp_pos = get(H.SearchText,'position');
[144]267    H.SearchHowPopup = uicontrol('parent',H.SearchUipanel,...
268      'style','popup',...
269      'string',{'contains...',...
270      'is exactly...','begins with...',...
[146]271      'ends with...',...
272      'matches regexp...'},...
[144]273      'units','pixel',...
274      'position',[tmp_pos(1)+tmp_pos(3)+5 tmp_pos(2) ...
275      150 22],...
276      'value',val,...
277      'tag','',...
278      'backgroundcolor',Dat.GD.col.popup,...
279      'callback',@l_SearchParams,...
[146]280      'KeyPressFcn',@l_KeyPressFcn);
[144]281
282    % Search editbox
283    tmp_pos = get(H.SearchHowPopup,'position');
284    H.SearchEdit = uicontrol('parent',H.SearchUipanel,...
285      'style','edit',...
286      'units','pixel',...
287      'position',[tmp_pos(1)+tmp_pos(3)+5 tmp_pos(2) pos(3)-tmp_pos(1)-tmp_pos(3)-15 tmp_pos(4)],...
288      'Callback',@l_SearchParams,...
289      'backgroundcolor',Dat.GD.col.edit,...
290      'KeyPressFcn',@l_SearchParams);
291   
292    % Case sensitive
293    try
[146]294      val = getpref('Aedes','HeaderBrowserCaseSensitivity');
[144]295    catch
296      val = 1;
297    end
298    tmp_pos = get(H.SearchEdit,'position');
299    H.SearchCaseSens = uicontrol('parent',H.SearchUipanel,...
300      'style','checkbox',...
301      'units','pixel',...
302      'string','Case sensitive',...
303      'position',[tmp_pos(1) tmp_pos(2)-25 tmp_pos(3) tmp_pos(4)],...
304      'Callback',@l_SearchParams,...
305      'value',val,...
306      'backgroundcolor',Dat.GD.col.mainfig,...
[146]307      'KeyPressFcn',@l_KeyPressFcn);
[144]308   
309    % --------------------------------------
310    % Favourite params list
311    favup_height = 150;
312    tmp_pos = get(H.SearchUipanel,'position');
[146]313    H.FavUipanel = uipanel('parent',H.Fig,...
[144]314      'units','pixel',...
315      'position',[10 fig_h-up_height-favup_height-fname_txh-15 fig_w-20 favup_height],...
[146]316      'title',['Favourite parameters for ',Dat.FileFormatName],...
[144]317      'backgroundcolor',Dat.GD.col.mainfig);
318   
319    tmp_pos = get(H.FavUipanel,'position');
320    InfoTx = {['The parameter names entered here will be searched ',...
321      'automatically. The matching parameters are placed on top of the parameter list ',...
322      'in boldface. This automatic search is case sensitive and only returns exact matches.']};
323    H.FavInfoText = uicontrol('parent',H.FavUipanel,...
324      'style','text',...
325      'units','pixel',...
326      'string','',...
327      'position',[10 10 250 120],...
328      'horizontalalign','left',...
329      'fontsize',10,...
330      'backgroundcolor',[0.85 0.85 0.85]);%Dat.GD.col.mainfig);
331    InfoTx=textwrap(H.FavInfoText,InfoTx);
332    set(H.FavInfoText,'string',InfoTx)
333   
334    tmp_pos = get(H.FavInfoText,'position');
335    H.FavAdd = uicontrol('parent',H.FavUipanel,...
336      'style','pushbutton',...
337      'units','pixels',...
338      'position',[tmp_pos(1)+tmp_pos(3)+5 ...
339      tmp_pos(2)+tmp_pos(4)-25 70 25],...
340      'String','Add',...
[146]341      'callback',{@l_AddFavourite,[]},...
342      'KeyPressFcn',@l_KeyPressFcn);
[144]343   
344    H.FavRem = uicontrol('parent',H.FavUipanel,...
345      'style','pushbutton',...
346      'units','pixels',...
347      'position',[tmp_pos(1)+tmp_pos(3)+5 ...
348      tmp_pos(2)+tmp_pos(4)-2*25-5 70 25],...
349      'String','Remove',...
350      'callback',@l_RemFavourite,...
[146]351      'KeyPressFcn',@l_KeyPressFcn);
[144]352   
353    tmp_pos = get(H.FavInfoText,'position');
354    H.FavListBox = uicontrol('parent',H.FavUipanel,...
355      'style','listbox',...
356      'units','pixels',...
357      'min',1,...
358      'max',3,...
359      'position',[tmp_pos(1)+tmp_pos(3)+80 ...
360      tmp_pos(2) fig_w-30-tmp_pos(3)-90 tmp_pos(4)],...
361      'String',Dat.FavouriteList,...
362      'value',[],...
363      'backgroundcolor','w',...
[146]364      'KeyPressFcn',@l_KeyPressFcn);
[144]365   
366    % Close & Export to workspace btns -------
367    tmp_pos = get(H.FavUipanel,'position');
[146]368    btn_w = (fig_w-20-2*5)/3;
369    %btn_w = 200;
[144]370    btn_h = 25;
[146]371    H.ExportBtn = uicontrol('parent',H.Fig,...
[144]372      'style','pushbutton',...
373      'units','pixels',...
374      'position',[tmp_pos(1) ...
375      tmp_pos(2)-btn_h-5 btn_w btn_h],...
376      'string','Export to workspace',...
377      'callback',@l_ExportToWorkspace,...
[146]378      'KeyPressFcn',@l_KeyPressFcn);
[144]379   
[146]380    %btn_w = 200;
[144]381    btn_h = 25;
[146]382    H.AddParamsToFavBtn = uicontrol('parent',H.Fig,...
[144]383      'style','pushbutton',...
384      'units','pixels',...
[146]385      'position',[tmp_pos(1)+btn_w+5 tmp_pos(2)-btn_h-5 btn_w btn_h],...
386      'string','Add to favourites',...
387      'enable','off',...
388      'callback',@l_AddToFavBtnCallback,...
389      'KeyPressFcn',@l_KeyPressFcn);
390    if Dat.MatlabVersion<=7.05
391      % With Matlab R2007b and older this has to be handled differently
392      set(H.AddParamsToFavBtn,'enable','on');
393    end
394   
395    %btn_w = 200;
396    btn_h = 25;
397    H.CloseBtn = uicontrol('parent',H.Fig,...
398      'style','pushbutton',...
399      'units','pixels',...
[144]400      'position',[tmp_pos(1)+tmp_pos(3)-btn_w ...
401      tmp_pos(2)-btn_h-5 btn_w btn_h],...
402      'string','Close',...
403      'callback',@l_CloseFig,...
[146]404      'KeyPressFcn',@l_KeyPressFcn);
[144]405   
406    % Data Table -----------------------------
407    pos=get(H.FavUipanel,'position');
[145]408    if Dat.MatlabVersion>=7.06
[146]409      H.DataTable = uitable('Parent',H.Fig,...
410        'Data',{'loading...','loading...'},...
[145]411        'units','pixel',...
412        'position',[10 10 fig_w-20 pos(2)-20-btn_h-5],...
[146]413        'KeyPressFcn',@l_KeyPressFcn,...
414        'CellSelectionCallback',@l_DataTableCellSelectionFcn,...
415        'ColumnFormat',{'char','char'},...
416        'ColumnWidth',{280,280},...
417        'RowName',[],...
418        'ColumnName',{'Parameter','Value(s)'});
[145]419    else
[146]420      H.DataTable = uitable('Parent',H.Fig,...
[145]421        'position',[10 10 fig_w-20 pos(2)-20-btn_h-5],...
422        'Data',{'loading...','loading...'},...
[146]423        'ColumnWidth',265,...
[145]424        'ColumnNames',{'Parameter','Value(s)'});
425    end
[146]426   
427    % If other header browser windows are currently open, the figure name
428    % has to be unique for finding the correct javaFrame.
429    figs=findall(0,'tag','header_browser_fig');
430    if length(figs)>1
431      set(H.Fig,'Name',['File Header Browser - ',Dat.FileFormatName,' (',num2str(H.Fig),')']);
432      drawnow,pause(0.02);
433    end
434    H.SearchEditJavaHandle=l_GetEditboxJavaHandle(H.Fig);
435    if isempty(H.SearchEditJavaHandle)
436      % Fall back to basic matlab code -> no search as you type... :-(
437      Dat.SearchEditUseJava = false;
438      set(H.SearchEdit,'KeyPressFcn','')
439    else
440      Dat.SearchEditUseJava = true;
441    end
442    set(H.Fig,'Name',['File Header Browser - ',Dat.FileFormatName]); % Set Figure name back to original...
443   
[144]444  end
445
[146]446  function l_ParseHeaderStructure(inStruct,parent,level)
447    % This subfunction goes throught the input structure recursively and
448    % constructs the n-by-2 cell array for the uitable.
449   
450    % Get fieldnames
451    fldnames = fieldnames(inStruct);
452    fldnames = sort(fldnames);
453   
454    % Loop over the field names
[144]455    for ii=1:length(fldnames)
[146]456      cVal = inStruct.(fldnames{ii});
457     
458      % Structures
459      if isstruct(cVal)
460        if level>=Dat.StructMaxDepth
461          % Don't go beyond the StructMaxDepth level
462          Dat.FullTable{end,2} = regexprep(regexprep(mat2str(size(cVal)),'\s','x'),'\]$',' struct]');
463        else
464          % Recursively go through the next level
465          if isempty(parent) % First level
466            l_ParseHeaderStructure(cVal,fldnames{ii},level+1);
467          else
468            l_ParseHeaderStructure(cVal,[parent,Dat.FieldSeparator,fldnames{ii}],level+1);
469          end
470        end
471      else
472        if isempty(parent)
473          Dat.FullTable{end+1,1} = fldnames{ii};
474        else
475          Dat.FullTable{end+1,1} = [parent,Dat.FieldSeparator,fldnames{ii}];
476        end
477       
478        % Numeric values
479        if isnumeric(cVal)
480          if ndims(cVal)<=2 || any(size(cVal)==1)
481            Dat.FullTable{end,2} = mat2str(cVal);
482          else
483            Dat.FullTable{end,2} = regexprep(regexprep(mat2str(size(cVal)),'\s','x'),'\]$',' matrix]');
484          end
485         
486          % Logical arrays
487        elseif islogical(cVal)
488          if ndims(cVal)<=2 || any(size(cVal)==1)
489            Dat.FullTable{end,2} = num2str(cVal);
490          else
491            Dat.FullTable{end,2} = regexprep(regexprep(mat2str(size(cVal)),'\s','x'),'\]$',' logical]');
492          end
493         
494          % Character strings
495        elseif ischar(cVal)
496          Dat.FullTable{end,2} = ['''',cVal,''''];
497         
498          % Cell arrays
499        elseif iscell(cVal)
500          str = '{';
501          for kk=1:length(cVal)
502            if kk==1
503              sep='';
504            else
505              sep=', ';
506            end
507            if ischar(cVal{kk})
508              str = [str,sep,'''',cVal{kk},''''];
509            elseif isnumeric(cVal{kk}) || islogical(cVal{kk})
510              if ndims(cVal{kk})>1
511                tmp_str = regexprep(regexprep(mat2str(size(cVal{kk})),'\s','x'),'\]$',' matrix]');
512                str = [str,sep,tmp_str];
513              else
514                str = [str,sep,mat2str(cVal{kk})];
[144]515              end
[146]516            elseif iscell(cVal{kk})
517              % Don't handle cell arrays inside cell arrays
518              tmp_str = regexprep(regexprep(mat2str(size(cVal{kk})),'\s','x'),'\]$',' cell array]');
519              str = [str,sep,tmp_str];
520            elseif isstruct(cVal{kk})
521              % Don't handle structures inside cell arrays
522              tmp_str = regexprep(regexprep(mat2str(size(cVal{kk})),'\s','x'),'\]$',' struct]');
523              str = [str,sep,tmp_str];
[144]524            else
[146]525              tmp_str = regexprep(regexprep(mat2str(size(cVal{kk})),'\s','x'),'\]$',[' ',class(cVal{kk}),']']);
526              str = [str,sep,tmp_str];
[144]527            end
528          end
[146]529          str(end+1) = '}';
530          Dat.FullTable{end,2} = str;
531         
532          % Unsupported class/object
[144]533        else
[146]534          tmp_str = regexprep(regexprep(mat2str(size(cVal)),'\s','x'),'\]$',[' ',class(cVal),']']);
535          Dat.FullTable{end,2} = tmp_str;
[144]536        end
[2]537      end
[144]538    end
[146]539   
[144]540    % Put favourites on top
[146]541    %Dat.DataTable = l_PutFavouritesOnTop(Dat.FullTable);
542   
[144]543  end
544
545%% ---------------------------------------------
546  function l_SearchParams(fh,evd)
547
548    if ~isempty(evd) && isfield(evd,'Key') && ...
549        strcmpi(evd.Key,'escape')
[146]550      l_KeyPressFcn(fh,evd);
[144]551      return
552    end
553   
554    % Get the search string
555    if Dat.SearchEditUseJava
[146]556      drawnow
557      SearchStr = get(H.SearchEditJavaHandle,'Text');
[2]558    else
[144]559      SearchStr = get(H.SearchEdit,'string');
560    end
561   
562    % Get case sensitivity
563    CaseSens = get(H.SearchCaseSens,'value');
564    if CaseSens==0
565      RegExpOpt = 'ignorecase';
566    else
567      RegExpOpt = 'matchcase';
568    end
569   
[146]570    % Search from parameters or values...?
571    col_ind=get(H.SearchWherePopup,'value');
572   
[144]573    if isempty(SearchStr)
574      % If the search string is empty, show full table
575      Dat.DataTable = l_PutFavouritesOnTop(Dat.FullTable);
576    else
[146]577      OrigSearchStr = SearchStr;
578     
579      % Escape the regexp special characters
580      SearchStr=regexptranslate('escape',SearchStr);
581     
582      if col_ind==1
583        SearchStr=strrep(SearchStr,' ','|');
584      end
[144]585      switch get(H.SearchHowPopup,'value')
586        case 1
587          % Search contains
588          RegExpStr = SearchStr;
589        case 2
590          % Search is exactly
[146]591          SearchStr=regexprep(SearchStr,'\|','\$\|\^');
[144]592          RegExpStr = ['^',SearchStr,'$'];
593        case 3
594          % Search begins with
[146]595          SearchStr=regexprep(SearchStr,'\|','\|\^');
[144]596          RegExpStr = ['^',SearchStr];
597        case 4
598          % Search ends with
[146]599          SearchStr=regexprep(SearchStr,'\|','\$\|');
[144]600          RegExpStr = [SearchStr,'$'];
[146]601        case 5
602          % Search matches regexp
603          RegExpStr = OrigSearchStr;
604          SearchStr = OrigSearchStr;
[2]605      end
[144]606     
607      % Regexp the full table parameters
[146]608      ind=find(~cellfun('isempty',regexp(Dat.FullTable(:,col_ind),RegExpStr,RegExpOpt)));
[144]609     
610      % Update DataTable
611      if isempty(ind)
[145]612        if Dat.MatlabVersion>=7.06
613          Dat.DataTable = {'<html><b>No matches!</b></html>',''};
614          %set(H.SearchEdit,'string',['<html><font color="red">',SearchStr,'</font></html>']);
615        else
616          Dat.DataTable = {'<html><b>No matches!</b></html>','<html><b>No matches!</b></html>';...
617            '=============','============='};
618        end
[144]619      else
620        Dat.DataTable = Dat.FullTable(ind,:);
[146]621        Dat.DataTable(:,col_ind)=regexprep(Dat.DataTable(:,col_ind),['(',SearchStr,')'],['<b>$1</b>'],RegExpOpt);
622        Dat.DataTable(:,col_ind)=regexprep(Dat.DataTable(:,col_ind),'(^.*$)','<html>$1</html>',RegExpOpt);
[144]623      end
[2]624    end
[144]625
626    % Update Data Table
627    l_UpdateDataTable([],[])
628   
[146]629   
630   
[144]631  end
632
633%% ---------------------------------------------
634  function l_UpdateDataTable(fh,evd)
635   
[145]636    if Dat.MatlabVersion>=7.06
[146]637      set(H.DataTable,'Data',Dat.DataTable)
[145]638    else
[146]639      if size(Dat.DataTable,1)==1
640        Dat.DataTable(end+1,:)={Dat.TableFavSeparator,Dat.TableFavSeparator};
641      end
642      set(H.DataTable,'Data',Dat.DataTable)
[145]643    end
644   
[144]645  end
646
647%% ---------------------------------------------
[146]648  function l_AddFavourite(h,evd,param)
[144]649   
[146]650    if isempty(param)
651      % Prompt for a favourite search string
652      resp = aedes_inputdlg('Search text to be added:');
653      if isempty(resp) || isempty(resp{1})
654        return
655      end
656      param = resp;
[144]657    end
658   
[146]659    params_added = 0;
660    for ii=1:length(param)
661     
662      % Check if parameter is separator
663      if strcmp(param{ii},Dat.TableFavSeparator)
664        continue
665      end
666     
667      % Check if the parameter is already in favourites
668      if any(strcmp(param{ii},Dat.FavouriteList))
669        % Parameter already in the favourite list
670        %if ~isempty(h) && h==H.FavAdd
671          % Put the favourite on top of the list, if already exists
672          ind = find(strcmp(param{ii},Dat.FavouriteList));
673          inds = [ind setdiff(1:length(Dat.FavouriteList),ind)];
674          Dat.FavouriteList = Dat.FavouriteList(inds);
675          params_added = params_added + 1;
676        %else
677          % Add search string to list
678          %Dat.FavouriteList{end+1} = param{ii};
679          %params_added = params_added + 1;
680        %  continue
681        %end
682      else
683        % Add search string to list
684        Dat.FavouriteList{end+1} = param{ii};
685        params_added = params_added + 1;
686      end
687    end
[144]688   
[146]689    if params_added>0
690      set(H.FavListBox,'string',Dat.FavouriteList,...
691        'value',[]);
[144]692   
[146]693      % Run search
694      l_SearchParams([],[]);
695    end
696   
[144]697  end
698
699%% ---------------------------------------------
[146]700  function l_AddToFavBtnCallback(h,evd)
701   
702    % Matlab R2008a onwards...
703    if Dat.MatlabVersion>=7.06
704      if isempty(Dat.SelectedCells)
705        % This should not happen, but return immediately if it does...
706        return
707      end
708     
709      ind = find(Dat.SelectedCells(:,2)==1);
710      if isempty(ind)
711        return
712      end
713     
714      % Get index to favourites separator
715      ind=Dat.SelectedCells(ind,1);
716      sep_ind=find(strcmp(Dat.TableFavSeparator,Dat.DataTable(:,1)));
717     
718      % Remove separator from the list
719      if ~isempty(sep_ind)
720        ind=setdiff(ind,sep_ind);
721        if isempty(ind)
722          return
723        end
724      end
725      %if ~isempty(sep_ind)
726      %  ind(ind<=sep_ind)=[];
727      %  if isempty(ind)
728      %    return
729      %  end
730      %end
731    else
732      % Matlab R2007a and older
733      selCols = H.DataTableJavaHandle.SelectedColumns;
734      selRows = H.DataTableJavaHandle.SelectedRows;
735     
736      if any(selCols==0)
737        ind = selRows+1;
738      else
739        return
740      end
741     
742      % Get index to favourites separator
743      sep_ind=find(strcmp(Dat.TableFavSeparator,Dat.DataTable(:,1)));
744     
745      % Remove separator from the list
746      if ~isempty(sep_ind)
747        ind=setdiff(ind,sep_ind);
748        if isempty(ind)
749          return
750        end
751      end
752    end
753   
754    % Get the parameters to be added
755    params=Dat.DataTable(ind,1);
756   
757    % Remove html tags from the strings
758    params=regexprep(params,'<html>|</html>|<b>|</b>','');
759   
760    % Add to favourites
761    l_AddFavourite([],[],params);
762   
763  end
764
765%% ---------------------------------------------
[144]766  function l_RemFavourite(fh,evd)
767   
768    % Get selected indices
769    ind = get(H.FavListBox,'value');
770    if isempty(ind)
771      return
772    end
773   
774    % Ask for confirmation
775    resp = questdlg('Remove selected favourites?',...
776      'Remove favourites','Yes','No','No');
777    if strcmpi(resp,'No')
778      return
779    end
780    Dat.FavouriteList(ind)=[];
781    set(H.FavListBox,'string',Dat.FavouriteList,...
782      'value',[]);
783   
784    % Run search to update changes
785    l_SearchParams([],[]);
786   
787  end
788
789
790%% ---------------------------------------------
791  function TableOut = l_PutFavouritesOnTop(TableIn)
792   
[146]793    FavouriteList = Dat.FavouriteList;%get(H.FavListBox,'string');
[144]794   
795    % Put favourite list matches on top of the search list and bold face
796    ind = [];
797    for ii=1:length(FavouriteList)
[146]798      SearchStr = regexptranslate('escape',FavouriteList{ii});
799      tmp_ind=find(~cellfun('isempty',regexp(TableIn(:,1),['^',SearchStr,'$'])));
800      if ~isempty(tmp_ind)
801        ind = [ind tmp_ind];
802      end
[144]803      if isempty(tmp_ind)
804        % If favourite is not found, color it red in the listbox
805        ListboxStr=get(H.FavListBox,'string');
[146]806        ListboxStr = regexprep(ListboxStr,['(^',SearchStr,'$)'],...
[144]807          '<html><font color="red"><b>$1 (not found)</b></font></html>');
808        set(H.FavListBox,'string',ListboxStr)
809      end
810    end
811    if ~isempty(ind)
812      ind2 = setdiff(1:size(TableIn,1),ind);
[146]813      tmpFavList = TableIn(ind,:);
814      tmpFavList(:,1)=regexprep(tmpFavList(:,1),'(.*)',...
[144]815        '<html><b>$1</b></html>');
816      TableOut = cat(1,...
[146]817        tmpFavList,...
818        {Dat.TableFavSeparator,Dat.TableFavSeparator},...
[144]819        TableIn(ind2,:));
[2]820    else
[144]821      TableOut = TableIn;
[2]822    end
823  end
824
[144]825%% --------------------------------------
826  function l_ExportToWorkspace(fh,evd)
827   
[146]828    varname = 'header_struct';
829    assignin('base',varname,inStruct);
830    msgstr = sprintf('Structure exported to variable "%s".',varname);
[144]831   
832    % Print notification to workspace
[146]833    fprintf(1,['AEDES_HEADERBROWSER: ',msgstr,'\n']);
[144]834   
835    % Nag with a dialog...
[146]836    helpdlg(msgstr,'Structure exported!')
[144]837   
838  end
[2]839
[144]840%% --------------------------------------------
[146]841  function l_KeyPressFcn(fh,evd)
[144]842   
843    % Call l_CloseFig if ESC is pressed
844    if ~isempty(evd) && isfield(evd,'Key') && ...
845        strcmpi(evd.Key,'escape')
846      l_CloseFig([],[])
[146]847     
848    elseif ~isempty(evd) && ~isempty(evd.Modifier)
849      if ( strcmpi(evd.Modifier{1},'control') && strcmpi(evd.Key,'l') ) || ...
850          ( strcmpi(evd.Modifier{1},'alt') && strcmpi(evd.Key,'d') )
851        % Change focus to the search editbox
852        % using CTRL-L or ALT-D
853        uicontrol(H.SearchEdit);
854      end
[144]855    end
856   
857  end
[2]858
[146]859%% ---------------------------------------------
860  function l_DataTableCellSelectionFcn(h,evd)
861
862    if isfield(evd,'Indices')
863      Dat.SelectedCells = evd.Indices;
864      if isempty(Dat.SelectedCells)
865        set(H.AddParamsToFavBtn,'enable','off');
866      else
867        set(H.AddParamsToFavBtn,'enable','on');
868      end
869    else
870      Dat.SelectedCells = [];
871      set(H.AddParamsToFavBtn,'enable','off');
872    end
873   
874  end
[144]875%% --------------------------------------------
876  function l_CloseFig(fh,evd)
877   
878    % Try to save preferences to disk before exiting
879    try
880      CaseSens = get(H.SearchCaseSens,'value');
[146]881      setpref('Aedes','HeaderBrowserCaseSensitivity',CaseSens);
[144]882     
[146]883      valhow = get(H.SearchHowPopup,'value');
884      setpref('Aedes','HeaderBrowserSearchHow',valhow);
[144]885     
[146]886      valwhere = get(H.SearchWherePopup,'value');
887      setpref('Aedes','HeaderBrowserSearchWhere',valwhere);
888     
889      % Update the corresponding FavList
890      if strcmp(Dat.FileFormatName,'NIfTI/Analyze')
891        Dat.FavList.nifti = Dat.FavouriteList;
892      elseif strcmp(Dat.FileFormatName,'VNMR Procpar')
893        Dat.FavList.vnmr = Dat.FavouriteList;
894      elseif strcmp(Dat.FileFormatName,'DICOM')
895        Dat.FavList.dcm = Dat.FavouriteList;
896      elseif strcmp(Dat.FileFormatName,'generic header')
897        Dat.FavList.genheader = Dat.FavouriteList;
898      else strcmp(Dat.FileFormatName,'generic structure')
899        Dat.FavList.generic = Dat.FavouriteList;
900      end
901      setpref('Aedes','HeaderBrowserFavList',Dat.FavList);
[144]902    catch
[146]903      disp('Warning: Could not save AEDES_HEADERBROWSER preferences!');
[144]904    end
[146]905    delete(H.Fig)
[144]906   
907  end
908
909%% -----------------------------------------------
910  function jhEditBox=l_GetEditboxJavaHandle(hFig)
911    % Parts of this code are originally written by Yair Altman, whose
912    % wizardry in Java programming in Matlab has been of great help in many
913    % occasions. Please see http://undocumentedmatlab.com and the
914    % comp.soft-sys.matlab news group for further information. The
915    % following license notice is for findjobj.m (by Yair Altman, available
916    % in the Matlab File Exchange,
917    % http://www.mathworks.com/matlabcentral/fileexchange/14317) from which
918    % I have used code snippets in this subfunction.
919    %
920    %
921    % Copyright (c) 2009, Yair Altman All rights reserved.
922    %
923    % Redistribution and use in source and binary forms, with or without
924    % modification, are permitted provided that the following conditions
925    % are met:
926    %
927    %   * Redistributions of source code must retain the above copyright
928    %     notice, this list of conditions and the following disclaimer.
929    %   * Redistributions in binary form must reproduce the above copyright
930    %     notice, this list of conditions and the following disclaimer in
931    %     the documentation and/or other materials provided with the
932    %     distribution
933    %
934    % THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
935    % "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
936    % LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
937    % A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
938    % OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
939    % SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
940    % LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
941    % DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
942    % THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
943    % (INCLUDING NEGLIGENCE OR OTHERWISE) RISING IN ANY WAY OUT OF THE USE
944    % OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
945   
946    % Ensure that objects have been drawn
947    drawnow;
948    pause(0.01);
949   
950    % Get figure's root pane
951     try
952       figName = get(hFig,'Name');
953       mde = com.mathworks.mde.desk.MLDesktop.getInstance;
954       jFigPanel = mde.getClient(figName);
955       jRootPane = jFigPanel;
956       jRootPane = jFigPanel.getRootPane;
957     catch
958       try
959         warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');  % R2008b compatibility
960         jFrame = get(hFig,'JavaFrame');
961         jFigPanel = get(jFrame,'FigurePanelContainer');
962         jRootPane = jFigPanel;
963         jRootPane = jFigPanel.getComponent(0).getRootPane;
964       catch
965         % Never mind
966       end
967     end
968     try
969      % If invalid RootPane - try another method...
970      warning('off','MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame');  % R2008b compatibility
971      jFrame = get(hFig,'JavaFrame');
972      jAxisComponent = get(jFrame,'AxisComponent');
973      jRootPane = jAxisComponent.getParent.getParent.getRootPane;
974     catch
975      % Never mind
976     end
977     %jRootPane=handle(jRootPane,'callbackproperties');
978     
979     % Find java handle to Search editbox recursively
980     Dat.javaHandleFound = false;
981     jhEditBox=l_FindJavaHandle(jRootPane);
982  end
983
984% Recursion function for finding java handle for search editbox
985  function jhout=l_FindJavaHandle(jhin)
986    jhout = handle([]);
987    jhin=handle(jhin,'callbackproperties');
988   
989    if ~isempty(regexp(char(jhin.toString),'EditTextPeer\$hgTextField'))
990      jhout = jhin;
991      Dat.javaHandleFound=true;
992      return;
993    else
994      try
995        compCount = jhin.getComponentCount;
996        for ii=0:compCount-1
997          childComp = jhin.getComponent(ii);
998          if ~Dat.javaHandleFound
999            jhout=l_FindJavaHandle(childComp);
1000          else
1001            break;
1002          end
1003        end
1004      catch
1005        % Nothing to do here...
1006      end
1007    end
1008   
1009  end
1010     
1011
1012end
1013
1014 
Note: See TracBrowser for help on using the repository browser.

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