function radiotgl(varargin)
% RADIO_TOGGLE( OBJECT1, [ OBJECT2, [ OBJECT3, ... ]] )
%
% Toggle the 'Checked' feature of on-screen objects in radio-button fashion.
%
% If only one object is listed, the 'Checked' feature of that object is toggled.
%
% If more than one object are listed, all of the objects in the list are cleared
%    ('Checked' set to 'off'), then 'Checked' of the first listed object is set to 'on'.
%    Extra objects are cleared BEFORE the first object is set, so that you can list
%    the first object twice if you want to.
%
% Objects which are not of type uimenu are silently ignored.
%
% EXAMPLES:
%
% >> radiotgl( 'Bob' );
%
%    If the object with tag 'Bob' is checked, clear it.  If 'Bob' is not checked, check him.
%
% >> radiotgl( 'Bob', 'Mary', 'Sue', 'Bob', 'George' );
%
%    Check the object whose tag is 'Bob', and clear the objects whose tags are 'Mary',
%    'Sue', and 'George'.
%
%  Mark Hasegawa-Johnson, 6/3/99
%

% Find the object to use as a root
root=gcbf;
if length(root)==0, root=0; end

% Check the length of the argument list
if length(varargin)==1,
  % If only one argument, just toggle it

  h = findobj(root,'Tag',varargin{1});
  t = get(h,'Type');
  if strcmp(t,'uimenu'),
    v = get(h,'Checked');

    switch v,
      case 'on',
	set(h, 'Checked', 'off');
      case 'off',
	set(h, 'Checked', 'on');
    end
  end
  
elseif length(varargin)>1,
  % Clear the second and higher objects
  for i=2:length(varargin),
    h = findobj(root, 'Tag', varargin{i});
    t = get(h, 'Type');
    if strcmp(t, 'uimenu'),
      set(h, 'Checked', 'off');
    end
  end
  
  % Set the first object
  h = findobj(root, 'Tag', varargin{1});
  t = get(h, 'Type');
  if strcmp(t, 'uimenu'),
    set(h, 'Checked', 'on');  
  end
end

   
