% GUImakemapmenu
% function for the MODIS GUI
% Copyright by Jasmine S Nahorniak, Oregon State University.
% Feb 29 2000

function GUImakemapmenu(mapfig)

% ********************************************************
% menu contents

GUIdefaults;

% ********************************************************
% make menus

% ****************
% projection

choices=guiprojection;

h1=uimenu('Parent',mapfig,'Callback','','Label','Projection');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  projec=cat(1,choicecell{:});   % convert cell to string
  if projec(1:3)~='ani' & projec(1:3)~='glo',   % not globes
       uimenu('Parent',h1, ...
	'Callback',['setm(findobj(gcbf,''Tag'',''Mapaxes''),''MapProjection'', ''' projec '''); view(2);'], ...
	'Label',projec)
  elseif projec(1:3)=='glo',
      uimenu('Parent',h1, ...
	'Callback','setm(findobj(gcbf,''Tag'',''Mapaxes''),''MapProjection'', ''globe''); view(str2num(get(findobj(''Tag'',''EditText14''),''String''))+90, str2num(get(findobj(''Tag'',''EditText13''),''String''))); xlabel(''''); ylabel('''');', ...
	'Label',projec)
  elseif projec(1:3)=='ani',
      uimenu('Parent',h1, ...
	'Callback','[globemovie]=GUIanimglobe;', ...
	'Label',projec)
  end
end

% ****************
% ****************
% COLORS

h0=uimenu('Parent',mapfig,'Callback','','Label','Colors');

% ****************
% colormap

choices=guicolormap;

h1=uimenu('Parent',h0,'Callback','','Label','Colormap');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  colmap=cat(1,choicecell{:});   % convert cell to string
  if (colmap(1)=='n' & colmap(2)=='o' & colmap(3)=='n'),  % is 'none'
     uimenu('Parent',h1, ...
	'Callback',['mycolmap=get(gcbf,''Colormap''); nmask=get(gcbf,''UserData''); mycolmap(nmask+1:end,:)=NaN; colormap(mycolmap); clear mycolmap nmask;'], ...
	'Label',colmap)
  else
     uimenu('Parent',h1, ...
	'Callback',['mycolmap=get(gcbf,''Colormap''); colsize=size(mycolmap); nmask=get(gcbf,''UserData''); mycolmap(nmask+1:colsize(1),:)=' colmap '(colsize(1)-nmask); colormap(mycolmap); clear mycolmap colsize nmask;'], ...
	'Label',colmap)
  end
end

% ****************
% background color

choices=guibackgroundcolors;

colns=GUIcol2num(choices);

h1=uimenu('Parent',h0,'Callback','','Label','Background color');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  col=cat(1,choicecell{:});   % convert cell to string
  numcol=['[' num2str(colns(i,:)) ']'];
  uimenu('Parent',h1, ...
	'Callback',['set(gcbf,''Color'',' numcol '); set(findobj(gcbf,''Tag'',''Mapaxes''),''Color'',' numcol ', ''XColor'',' numcol ',''YColor'',' numcol ',''ZColor'',' numcol ');'], ...
	'Label',col)
  end

% ****************
% axis/label color

choices=guiaxiscolors;

colns=GUIcol2num(choices);

h1=uimenu('Parent',h0,'Callback','','Label','Axis/label color');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  col=cat(1,choicecell{:});   % convert cell to string
  numcol=['[' num2str(colns(i,:)) ']'];
  if col(1:3)=='non',  % is 'none'
     uimenu('Parent',h1, ...
	'Callback',['setm(findobj(gcbf,''Tag'',''Mapaxes''),''fontcolor'',get(gcbf,''Color'')); xlabel(''''); ylabel(''''); setm(gca,''parallellabel'',''off'',''meridianlabel'',''off'')'], ...
	'Label',col)
  else
     uimenu('Parent',h1, ...
	'Callback',['setm(findobj(gcbf,''Tag'',''Mapaxes''),''fontcolor'',' numcol '); set(get(gca,''Title''),''Color'',' numcol '); xlabel(''Longitude'',''Color'',' numcol '); ylabel(''Latitude'',''Color'',' numcol '); setm(gca,''parallellabel'',''on'',''meridianlabel'',''on''); setm(gca,''gcolor'',' numcol '); set(findobj(gcbf,''Tag'',''Colorbar''),''XColor'',' numcol ',''YColor'',' numcol ');'], ...
	'Label',col) 
  end
end


% ****************
% land color

choices=guilandcolors;

landcolns=GUIcol2num(guilandcolors);

h1=uimenu('Parent',h0,'Callback','','Label','Land color');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  landcol=cat(1,choicecell{:});   % convert cell to string
  uimenu('Parent',h1, ...
	'Callback',['mycolmap=get(gcbf,''Colormap''); nmask=get(gcbf,''UserData''); if nmask>0, mycolmap(1,:)=[' num2str(landcolns(i,:)) ']; colormap(mycolmap); end; clear nmask mycolmap;'], ...
	'Label',landcol)
  end

% ****************
% mask color

choices=guimaskcolors;

maskcolns=GUIcol2num(guimaskcolors);

h1=uimenu('Parent',h0,'Callback','','Label','Mask color');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  maskcol=cat(1,choicecell{:});   % convert cell to string
  uimenu('Parent',h1, ...
	'Callback',['mycolmap=get(gcbf,''Colormap''); nmask=get(gcbf,''UserData''); if nmask==1, mycolmap(1,:)=[' num2str(maskcolns(i,:)) ']; elseif nmask==2, mycolmap(2,:)=[' num2str(maskcolns(i,:)) ']; end; colormap(mycolmap); clear nmask mycolmap;'], ...
	'Label',maskcol)
  end

% ****************
% coastline

choices=guicoastline;

colns=GUIcol2num(choices);

h1=uimenu('Parent',h0,'Callback','','Label','Coastline');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  coastline=cat(1,choicecell{:});   % convert cell to string
  if coastline(1:3)~='non',
    uimenu('Parent',h1, ...
	'Callback',['set(findobj(gcbf,''Tag'',''Coastline''),''Color'', [' num2str(colns(i,:)) '],''Visible'',''on'');'], ...
	'Label',coastline)
  else
    uimenu('Parent',h1, ...
	'Callback',['set(findobj(gcbf,''Tag'',''Coastline''),''Visible'',''off'');'], ...
	'Label',coastline)
  end
end


% ****************
% colorbar

choices=guicolorbar;

h1=uimenu('Parent',mapfig,'Callback','','Label','Colorbar');

for i=1:length(choices(:,1));
  choicecell=choices(i,:);
  colbar=cat(1,choicecell{:});   % convert cell to string
  if colbar(1:3)=='ver',
    uimenu('Parent',h1, ...
	'Callback','delete(findobj(gcbf,''Tag'',''Colorbar'')); hcb=colorbar(''vert''); pause(0.05); set(hcb,''Tag'',''Colorbar'',''YTickLabelMode'',''auto''); clear hcb;', ...
	'Label',colbar)
  elseif colbar(1:3)=='hor',
    uimenu('Parent',h1, ...
	'Callback','delete(findobj(gcbf,''Tag'',''Colorbar'')); hcb=colorbar(''horiz''); pause(0.05); set(hcb,''Tag'',''Colorbar'',''XTickLabelMode'',''auto''); clear hcb;', ...
	'Label',colbar)
  elseif colbar(1:3)=='off',
    uimenu('Parent',h1, ...
	'Callback','delete(findobj(gcbf,''Tag'',''Colorbar''))', ...
	'Label',colbar)
  end
end



% ****************
% grid

choices=guigrid;

h1=uimenu('Parent',mapfig,'Callback','','Label','Grid');

for i=1:length(choices(:,1)),
  choicecell=choices(i,:);
  gridchoice=cat(1,choicecell{:});   % convert cell to string
  uimenu('Parent',h1, ...
	'Callback',['gridm ' gridchoice '; curcol=getm(gca,''fontcolor''); setm(gca,''gcolor'',curcol);'], ...
	'Label',gridchoice)
end

% ****************
% output figure

choices=guioutfig;

h1=uimenu('Parent',mapfig,'Callback','','Label','Save Figure');

for i=1:length(choices(:,1)),
  choicecell=choices(i,:);
  outputchoice=cat(1,choicecell{:});   % convert cell to string
  uimenu('Parent',h1, ...
	'Callback',['GUIoutputfig(''' outputchoice ''')'], ...
	'Label',outputchoice)
end

% ***************
