Home > functions > gui > batch > vb_parm_editor > vb_parm_editor_gui_callback.m

vb_parm_editor_gui_callback

PURPOSE ^

SYNOPSIS ^

function vb_parm_editor_gui_callback(fig, hObj)

DESCRIPTION ^

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_parm_editor_gui_callback(fig, hObj)
0002 %
0003 % Copyright (C) 2011, ATR All Rights Reserved.
0004 % License : New BSD License(see VBMEG_LICENSE.txt)
0005 
0006 data = guidata(fig);
0007 
0008 H = data.H;
0009 
0010 idx = get(H.contents_listbox, 'Value');
0011 current_variable_name = data.accessor{idx};
0012 set(H.error_window_edit, 'String', '');
0013 switch(hObj)
0014     case H.contents_listbox
0015         % set selected variable name to gui
0016         set(H.value_name_edit, 'String', [current_variable_name ' =']);
0017 
0018         % get selected variable and convert it to evaluative string
0019         val = eval(['data.' current_variable_name]);
0020         [evalstr, available,type_dim] = vb_var2evalstr(val);
0021 
0022         % set Variable type to gui
0023         set(H.type_dim_text, 'String', type_dim);
0024  
0025         % gui status change(editable or not)
0026         if available
0027             set(H.value_edit, 'String', evalstr);
0028             set(H.value_edit, 'Style', 'edit');   % These 2lines automatically
0029             set(H.value_edit, 'Style', 'listbox');% adjust display status.
0030             set_edit_state(H, 'editable');
0031             % If listbox is double clicked, change mode to editting
0032             if strcmpi(get(fig, 'SelectionType'), 'open')
0033                 set_edit_state(H, 'editting');
0034             end
0035         else
0036             set(H.error_window_edit, 'String', 'structure or over 3D variable cannot be edited.');
0037             set_edit_state(H, 'uneditable');
0038         end
0039     case H.show_file_parameter_checkbox
0040         data.show_file_parameters = get(hObj, 'Value');
0041         % create listbox string and data accessor
0042         data = vb_parm_editor_gui_data_make(data);
0043         guidata(fig, data);
0044         % update
0045         set(H.contents_listbox, 'String', data.listbox_strings);
0046         set(H.contents_listbox, 'Value', 1');
0047     case H.case_sensitive_checkbox
0048         data.case_sensitive = get(hObj, 'Value');
0049         % create listbox string and data accessor
0050         data = vb_parm_editor_gui_data_make(data);
0051         guidata(fig, data);
0052         % update
0053         set(H.contents_listbox, 'String', data.listbox_strings);
0054         set(H.contents_listbox, 'Value', 1');
0055     case H.search_text_edit
0056         search_name = get(hObj, 'String');
0057         if isempty(search_name)
0058             search_name = '*';
0059         end
0060         % prepare for use regexp
0061         % meta character: '.' is cancelled out.
0062         search_name = strrep(search_name, '.', '\.');
0063         % meta character: '$' is cancelled out.
0064         search_name = strrep(search_name, '$', '\$');
0065         % meta character: '*' is replaced to '.*'
0066         search_name = strrep(search_name, '*', '.*');
0067         data.search_name = search_name;
0068         % create listbox string and data accessor
0069         data = vb_parm_editor_gui_data_make(data);
0070         guidata(fig, data);
0071         % update
0072         set(H.contents_listbox, 'String', data.listbox_strings);
0073         set(H.contents_listbox, 'Value', 1');
0074     case H.value_edit
0075         % If listbox is double clicked, change mode to editting
0076         if strcmpi(get(fig, 'SelectionType'), 'open')
0077             set_edit_state(H, 'editting');
0078         end
0079     case H.value_edit_push
0080         set_edit_state(H, 'editting');
0081     case H.value_apply_push
0082         try
0083             % get string list from editbox(devided by linefeed on editbox)
0084             str = get(H.value_edit, 'String');
0085             tmp = '';
0086             error_line = [];
0087             % concatenate string list into one line.
0088             % add \n to each line.(replicate for execute eval function)
0089             for k=1:size(str, 1)
0090                 % inspect line
0091                 line = sprintf('%s\n', deblank(str(k, :)));
0092                 ix = strfind(line, '$');
0093                 Ndollar = length(ix);
0094                 err = false;
0095                 if (mod(Ndollar, 2) ~= 0)
0096                     err = true;
0097                 end
0098                 if Ndollar ~= 0 && (mod(Ndollar, 2) == 0 )
0099                     for k=1:(Ndollar/2)
0100                         if ix(2*k-1)+1 == (ix(2*k))
0101                             % found '$$'
0102                             err = true;
0103                         end
0104                     end
0105                 end
0106                 if err
0107                     error_line = [error_line, line];
0108                 end
0109                 tmp = [tmp, line];
0110             end
0111             if ~isempty(error_line)
0112                 error(sprintf('\nIncomplete variables were found.($VAL$) : \n%s', error_line));
0113             end
0114             % get value
0115             val = eval(tmp);
0116             base = eval(['data.' current_variable_name]);
0117             val_info = whos('val');
0118             base_info = whos('base');
0119             % Type check
0120             if ~strcmp(val_info.class, base_info.class)
0121                 res = questdlg('Variable type will change. Are you sure?',...
0122                                'Confirm', 'Yes', 'No', 'No');
0123                 if strcmpi(res, 'no'), return; end
0124             end
0125             % Update variable and save data
0126             command = ['data.', current_variable_name '=val;'];
0127             eval(command);
0128             data.modified = true;
0129             guidata(fig, data);
0130             set_edit_state(H, 'editable');
0131         catch
0132             % evaluate failed
0133             set(H.value_edit, 'BackgroundColor', [0.80, 0.2, 0.2]);
0134             set(H.error_window_edit, 'String', lasterr);
0135         end
0136     case H.value_cancel_push
0137         vb_parm_editor_gui_callback(fig, H.contents_listbox);
0138     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0139     %   Close gui
0140     case H.cancel_push
0141         vb_parm_editor_gui_closereq(fig);
0142     case H.save_push
0143         data.cancel_flag = false;
0144         guidata(fig, data);
0145         vb_parm_editor_gui_closereq(fig, false);
0146         
0147 end
0148 
0149 function set_edit_state(H, state)
0150 
0151 switch(state)
0152     case 'editting'
0153         set(H.value_edit, 'Style', 'edit');
0154         set(H.value_edit, 'BackgroundColor', [0.3 0.7 0.6]); %
0155         set(H.value_edit, 'ForegroundColor', [1 1 1]); %white
0156         set(H.value_edit_push, 'Enable', 'off');
0157         set(H.value_apply_push, 'Enable', 'on');
0158     case 'editable'
0159         set(H.value_edit, 'Style', 'listbox', 'Enable', 'on', 'Value', []);
0160         set(H.value_edit, 'Listboxtop', 1);
0161         set(H.value_edit, 'BackgroundColor', [1 1 1]); %white
0162         set(H.value_edit, 'ForegroundColor', [0 0 0]); %black
0163         set(H.value_edit_push, 'Enable', 'on');
0164         set(H.value_apply_push, 'Enable', 'off');
0165     case 'uneditable'
0166         set(H.value_edit, 'Style', 'listbox', 'Enable', 'Inactive', 'Value', []);
0167         set(H.value_edit, 'BackgroundColor', [1 1 1]);
0168         set(H.value_edit_push, 'Enable', 'off');
0169         set(H.value_apply_push, 'Enable', 'off');
0170         set(H.value_edit, 'String', '');
0171 end

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005