function axismenu(FigureNumber)
%AXISMENU - Creates a menu for opening axisgui
%  axismenu(FigureHandle)
%
%  Creates a menu on the figure referenced by FigureHandle which
%  will open the axis GUI (axisgui) and control the grid property.
%  If FigureHandle is empty, the current figure will be used (gcf).
%
%  See also axisgui
%
%  Written by Greg Portmann (May 1997)

% Calls:  axisgui

if nargin < 1
   Cfig = gcf;
else
   Cfig = FigureNumber;
end

FigureList = findobj('Type','figure');
ResizeFigureList = get(findobj('Tag','Close'),'Parent');

if isempty(ResizeFigureList)
   FigureNumber=Cfig;
elseif find(Cfig==ResizeFigureList)
   FigureNumber=figure;
else
   % if an axis menu already exists, then return
   if strcmp(get(findobj(Cfig,'tag','MenuAxis'),'label'),'&Axis')==1
      return
   end
end

b = uimenu('Parent',FigureNumber, ...
	'Label','&Axis', ...
	'Tag','MenuAxis');


CallbackAxisTool = [... 
'if strcmp(lower(get(findobj(gcbf,''Tag'',''MenuAxisTool''),''Checked'')),''on'')==1;', ...
'  set(findobj(gcbf,''Tag'',''MenuAxisTool''),''Checked'',''off'');', ...
'  FigHandle = get(findobj(gcbf,''Tag'',''MenuAxisTool''),''Userdata'');', ...
'  close(FigHandle);', ...
'else;', ...
'  FigHandle = axisgui(gca);', ...
'  set(findobj(gcbf,''Tag'',''MenuAxisTool''),''Checked'',''on'');', ...
'  set(findobj(gcbf,''Tag'',''MenuAxisTool''),''Userdata'',FigHandle);', ...
'end;', ...
];

% Userdata contains the handle for the resize figure
c = uimenu('Parent',b, ...
	'Callback', CallbackAxisTool, ...
	'CreateFcn','set(findobj(gcbf,''Tag'',''MenuAxisTool''),''Checked'',''off'');', ...
   'DeleteFcn','if strcmp(lower(get(findobj(gcbf,''Tag'',''MenuAxisTool''),''Checked'')),''on'')==1;FigHandle=get(findobj(gcbf,''Tag'',''MenuAxisTool''),''Userdata'');close(FigHandle);end;', ...
   'Label','Axis Tool', ...
   'Userdata', [], ...
   'Tag','MenuAxisTool');

c = uimenu('Parent',b, ...
	'Callback','grid on;set(findobj(gcbf,''Tag'',''MenuGridOn''),''Checked'',''on'');set(findobj(gcbf,''Tag'',''MenuGridOff''),''Checked'',''off'');', ...
	'CreateFcn','set(findobj(gcbf,''Tag'',''MenuGridOn''),''Checked'',''off'');', ...
	'Label','Grid On', ...
	'Separator','on', ...
	'Tag','MenuGridOn');
c = uimenu('Parent',b, ...
	'Callback','grid off;set(findobj(gcbf,''Tag'',''MenuGridOn''),''Checked'',''off'');set(findobj(gcbf,''Tag'',''MenuGridOff''),''Checked'',''on'');', ...
	'CreateFcn','grid off;set(findobj(gcbf,''Tag'',''MenuGridOff''),''Checked'',''on'');', ...
	'Label','Grid Off', ...
	'Tag','MenuGridOff');
