Home > marsbar > @mardo > ui_et_edit_cb.m

ui_et_edit_cb

PURPOSE ^

method to handle callbacks from ui_et_edit

SYNOPSIS ^

function varargout = ui_et_edit_cb(D, action, varargin)

DESCRIPTION ^

 method to handle callbacks from ui_et_edit 
 FORMAT varargout = ui_et_edit_cb(D, action, varargin)

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = ui_et_edit_cb(D, action, varargin)
0002 % method to handle callbacks from ui_et_edit
0003 % FORMAT varargout = ui_et_edit_cb(D, action, varargin)
0004 %
0005 % $Id$
0006 
0007 if nargin < 2
0008   error('Need action');
0009 end
0010 
0011 F  = gcbf;
0012 action = lower(action);
0013 switch action
0014  case 'ok'
0015   % Deblank name, and check name is not empty
0016   hName = findobj(F, 'Tag', 'ui_et_name');
0017   new_name = get(hName, 'String');
0018   old_name = get(hName, 'UserData');
0019   new_name = deblank(fliplr(deblank(fliplr(new_name))));
0020   if isempty(new_name) | strcmp(new_name, 'New event')
0021     msgbox('Need a name for this event type'); return
0022   end
0023   % Check if name has been changed
0024   if ~strcmp(new_name, old_name)
0025     % Check name has not been used
0026     ets = event_types(D);
0027     if ~isempty(ets)
0028       if ismember(new_name, {ets(:).name})
0029     msgbox(['Event type ' new_name ' already exists']); return
0030       end    
0031     end
0032   end
0033   % Check events not empty
0034   if isempty(get(findobj(F, 'Tag', 'ui_et_IN'), 'String'))
0035     msgbox('Need events for this event type'); return
0036   end
0037   % Put (deblanked) string back, and set Done flag
0038   set(hName, 'String', new_name);
0039   set(findobj(F,'Tag','ui_et_done'),'UserData',1);
0040  case 'cancel'
0041   set(findobj(F,'Tag','ui_et_done'),'UserData',0);
0042  case {'add', 'remove'}
0043   switch action
0044    case 'add'
0045     hListTO   = findobj(F, 'Tag', 'ui_et_IN');
0046     hListFROM = findobj(F, 'Tag', 'ui_et_OUT');
0047    case 'remove'
0048     hListFROM   = findobj(F, 'Tag', 'ui_et_IN');
0049     hListTO     = findobj(F, 'Tag', 'ui_et_OUT');
0050   end
0051   TO_evs  = get(hListTO,  'UserData');
0052   FROM_evs = get(hListFROM, 'UserData');
0053   if isempty(FROM_evs), msgbox(['No events to ' action]); end
0054   es_to_add = get(hListFROM, 'Value');
0055   if isempty(es_to_add)
0056     msgbox(['Please select events to ' action]); return
0057   end
0058   TO_evs.names   = [TO_evs.names; FROM_evs.names(es_to_add)];
0059   FROM_evs.names(es_to_add) = [];
0060   TO_evs.e_spec = [TO_evs.e_spec FROM_evs.e_spec(:, es_to_add)];
0061   FROM_evs.e_spec(:, es_to_add) = [];
0062   set(hListTO, 'UserData', TO_evs);
0063   set(hListFROM, 'UserData', FROM_evs);
0064   set(hListFROM, 'Value', []);
0065   ui_et_edit_cb(D, 'sort');
0066  case 'sort'
0067   sort_obj  = findobj(F, 'Tag', 'ui_et_sort');
0068   sort_strs = cellstr(get(sort_obj, 'String'));
0069   sort_type = sort_strs{get(sort_obj, 'Value')};
0070   for H = [findobj(F, 'Tag', 'ui_et_IN') findobj(F, 'Tag', 'ui_et_OUT')]
0071     evs = pr_sort_evs(get(H, 'UserData'), sort_type);
0072     set(H, 'String', evs.names);
0073     set(H, 'UserData', evs);
0074   end
0075  otherwise
0076   error([ action ' is deviant' ]);
0077 end
0078 
0079 return
0080 
0081 
0082   
0083   

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019