%
% PRMENU set up selection menus at top of current figure (window)
%
%        Parts of PRMENU employ routines written by Keith Rogers for
%        his MATLAB suite MATDRAW; 'Text', and 'Draw' Menus and SubMenus,
%        as well as his PageSetup, which has been renamed PrintSetup.
%
% Call as: Prmenu
%
%        Brian O. Blanton
%        Curriculum in Marine Science
%        Ocean Processes Numerical Modeling Laboratory
%        15-1A Venable Hall
%        CB# 3300
%        Uni. of North Carolina
%        Chapel Hill, NC
%                 27599-3300
%
%        919-962-4466
%        blanton@marine.unc.edu
%
%        Winter 1994
%

%        'BackGr' is an abbreviation for 'BackGroundColor'
%        'ForeGr' is an abbreviation for 'ForeGroundColor'
function Prmenu(opt,subopt)

global LASTOBJECT LASTTYPE

if nargin==0   % Set up menu bar
   % See if another Prmenu exists in Current figure; return if so
   Prmenu=findobj(gcf,'Type','uimenu','Tag','Prmenu');
   if ~isempty(Prmenu),return,end
   
   % initialize globals used to keep to track of last touched object
   lastouch

   set(gcf, 'WindowButtonDownFcn', 'lastouch', ...
            'WindowButtonUpFcn', '', ...
	    'WindowButtonMotionFcn', '');
	
   % always set paper position to full page size
   % set(gcf, 'PaperPosition', [0 0 get(gcf, 'PaperSize')]);
  
   al=uimenu('Label','Axis','BackGr','g','ForeGr','k','Tag','Prmenu');
   
   al1=uimenu(al,'Label','Axis',...
       'BackGr','g',...
       'ForeGr','k',...
       'Tag','PrAxis');

   uimenu(al1,'Label','Equal',...
       'Callback','EditAxis(''axis'',''equal'')',...
       'BackGr','g','ForeGr','k','Tag','PrAxisEq');
   uimenu(al1,'Label','Square',...
       'Callback','EditAxis(''axis'',''square'')',...
       'BackGr','g','ForeGr','k','Tag','PrAxisSq');
   uimenu(al1,'Label','Normal',...
       'Callback','EditAxis(''axis'',''normal'')',...
       'BackGr','g','ForeGr','k','Tag','PrAxisNo');
   uimenu(al1,'Label','Auto',...
       'Callback','EditAxis(''axis'',''auto'')',...
       'BackGr','g','ForeGr','k','Tag','PrAxisAu');
   uimenu(al1,'Label','Image',...
       'Callback','EditAxis(''axis'',''image'')',...
       'BackGr','g','ForeGr','k','Tag','PrAxisIm');
%   uimenu(al1,'Label','Axis (on/off)',...
%       'Callback','EditAxis(''axis'',''on'')',...
%       'BackGr','g','ForeGr','k','Tag','PrAxisOnOff');

   al2=uimenu(al,'Label','Scale',...
       'BackGr','g',...
       'ForeGr','k',...
       'Tag','PrScale');

   uimenu(al2,'Label','Linear',...
       'Callback','EditAxis(''scale'',''linear'')',...
       'BackGr','g','ForeGr','k','Tag','PrScaleLin');
   uimenu(al2,'Label','Semi-Log X',...
       'Callback','EditAxis(''scale'',''semilogx'')',...
       'BackGr','g','ForeGr','k','Tag','PrScaleLogx');
   uimenu(al2,'Label','Semi-Log Y',...
       'Callback','EditAxis(''scale'',''semilogy'')',...
       'BackGr','g','ForeGr','k','Tag','PrScaleLogy');
   uimenu(al2,'Label','Log-Log',...
       'Callback','EditAxis(''scale'',''loglog'')',...
       'BackGr','g','ForeGr','k','Tag','PrScaleLogLog');
   
   uimenu(al,'Label', 'Box (on/off)', ....
       'Callback', 'EditAxis(''box'')',...
       'BackGr','g','ForeGr','k','Tag','PrAxisBox');

   uimenu(al,'Label','Edit Limits','Callback','EditAxis',...
          'BackGr','g','ForeGr','k','Tag','ChAxis');
   uimenu(al,'Label','Edit Labels','Callback','EditLabel',...
          'BackGr','g','ForeGr','k','Tag','ChLabel');
          
   gl=uimenu('Label','Grid',...
       'BackGr','b', 'ForeGr','w','Tag','PrGrid');   
   gl1=uimenu(gl,'Label','Major',...
       'BackGr','b', 'ForeGr','w','Tag','PrMajor');
   gl2=uimenu(gl,'Label','Minor',...
       'BackGr','b','ForeGr','w','Tag','PrMinor');
   
   uimenu(gl1, 'Label', 'Grid (on/off)', ...
       'Callback', 'EditAxis(''grid'',''majgrid'')', ...
       'BackGr','b', 'ForeGr','w', 'Tag', 'PrMajGrid');
   gl1s=uimenu(gl1, 'Label', 'Line Style', ...
       'BackGr','b', 'ForeGr','w');

   uimenu(gl1s,'Label','_____','Callback','gca;EditLine(1,''-'',''Grid'')',...
       'BackGr','k','ForeGr','w');
   uimenu(gl1s,'Label','.....','Callback','gca;EditLine(1,'':'',''Grid'')',...
       'BackGr','k','ForeGr','w','Separator','on');
   uimenu(gl1s,'Label','_ _ _','Callback','gca;EditLine(1,''--'',''Grid'')',... 
       'BackGr','k','ForeGr','w','Separator','on');
   uimenu(gl1s,'Label','_._._','Callback','gca;EditLine(1,''-.'',''Grid'')',...
            'BackGr','k','ForeGr','w','Separator','on');

   uimenu(gl2, 'Label', 'Grid (on/off)', ...
       'Callback', 'EditAxis(''grid'',''minorgrid'')', ...
       'BackGr','b', 'ForeGr','w', 'Tag', 'PrMinGrid');
   uimenu(gl2, 'Label', 'Tick (on/off)', ...
       'Callback', 'EditAxis(''grid'',''minortick'')', ...
       'BackGr','b', 'ForeGr','w');
   gl2s=uimenu(gl2, 'Label', 'Line Style', ...
       'BackGr','b', 'ForeGr','w');
   
   uimenu(gl2s,'Label','_____',...
       'Callback','gca;EditLine(1,''-'',''MinorGrid'')',...
       'BackGr','k','ForeGr','w');
   uimenu(gl2s,'Label','.....',...
       'Callback','gca;EditLine(1,'':'',''MinorGrid'')',...
       'BackGr','k','ForeGr','w','Separator','on');
   uimenu(gl2s,'Label','_ _ _',...
       'Callback','gca;EditLine(1,''--'',''MinorGrid'')',... 
       'BackGr','k','ForeGr','w','Separator','on');
   uimenu(gl2s,'Label','_._._',...
       'Callback','gca;EditLine(1,''-.'',''MinorGrid'')',...
       'BackGr','k','ForeGr','w','Separator','on');
	 
   zl=uimenu('Label','Zoom','BackGr','g','ForeGr','k','Tag','PrZoom');
   uimenu(zl,'Label','Zoom In','Callback','Prmenu(1,1)','BackGr','g',...
             'ForeGr','k','Tag','PrZoomIn');
   uimenu(zl,'Label','Zoom Out','Callback','Prmenu(1,2)','BackGr','g',...
             'ForeGr','k','Tag','PrZoomOut','Enable','off');
   uimenu(zl,'Label','Zoom Off','Callback','Prmenu(1,3)','BackGr','g',...
             'ForeGr','k','Tag','PrZoomOff','Enable','off');
	 
   pl=uimenu(zl,'Label','Pan','Callback','pan',...
          'BackGr','g','ForeGr','k',...
          'interruptible','no','Tag','PrPan');
      
% FONT MAIN MENU
   fm = uimenu('BackGr','b',...
       'Enable','on',...
       'ForeGr','w',...
       'Label','Text',...
       'Tag','PrTextMenu',...
       'Position',5);
   fms1 = uimenu(fm,...
                     'BackGr','b',...
   		     'Enable','on',...
                     'ForeGr','w',...
                     'Tag','PrTextFontMenu',...
                     'Label','Font');
   fms2 = uimenu(fm,...
                     'BackGr','b',...
   		     'Enable','on',...
                     'ForeGr','w',...
                     'Tag','PrTextStyleMenu',...
                     'Label','Style');
   fms3 = uimenu(fm,...
                     'BackGr','b',...
   		     'Enable','on',...
                     'ForeGr','w',...
                     'Tag','PrTextSizeMenu',...
                     'Label','Size');
   fms4 = uimenu(fm,...
                     'BackGr','b',...
   		     'Enable','on',...
                     'ForeGr','w',...
                     'Tag','PrTextJustifyMenu',...
                     'Label','Justify');

   fms5 = uimenu(fm,...
                     'BackGr','b',...
                     'CallBack','Prmenu(2,1)',...
		     'Separator', 'on', ...
                     'Enable','on',...
                     'ForeGr','w',...
                     'Tag','PrTextMoveMBON',...
                     'Label','MoveText ON');
   fms6 = uimenu(fm,...
                     'BackGr','b',...
                     'CallBack','Prmenu(2,2)',...
                     'Enable','off',...
                     'ForeGr','w',...
                     'Tag','PrTextMoveMBOFF',...
                     'Label','MoveText OFF');
   fms7 = uimenu(fm,...
                     'BackGr','b',...
                     'CallBack','EditText(8)',...
		     'Separator', 'on', ...
                     'Enable','on',...
                     'ForeGr','w',...
		     'interruptible', 'yes', ...
                     'Tag','PrTextEditText',...
                     'Label','Edit Text');
   fms8 = uimenu(fm,...
                     'BackGr','b',...
                     'CallBack','EditText(9)',...
                     'Enable','on',...
                     'ForeGr','w',...
		     'interruptible', 'yes', ...
                     'Tag','PrTextAddText',...
                     'Label','Add Text');
   % Font Sub Menu
   fontlist=str2mat('Avant Garde','Bookman','Courier','Geneva',...
                 'Helvetica','Kyoto','Osaka','Palatino','Symbol',...
                 'Times');
   fontlist=str2mat(fontlist,'Zapf Chancery','Zapf Dingbats');
   [m,n]=size(fontlist);
   for i=1:m
      fontname = fontlist(i,1:n);
      uimenu(fms1,'Label',fontname,'BackGr','b','ForeGr','w', ...
	  'Callback',['gca;EditText(1,''' deblank(fontname) ''')']);
   end

   % Text Style Sub Menu

   uimenu(fms2,'Label','Plain',  'Callback','gca;EditText(4,''plain'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms2,'Label','Italic', 'Callback','gca;EditText(2,''italic'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms2,'Label','Oblique','Callback','gca;EditText(2,''oblique'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms2,'Label','Light',  'Callback','gca;EditText(3,''light'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms2,'Label','Demi',   'Callback','gca;EditText(3,''demi'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms2,'Label','Bold',   'Callback','gca;EditText(3,''bold'')',...
       'BackGr','b','ForeGr','w');

% Text Size Sub Menu

   uimenu(fms3,'Label','6','Callback','gca;EditText(5,6)',...
       'BackGr','b','ForeGr','w');
   uimenu(fms3,'Label','9','Callback','gca;EditText(5,9)',...
       'BackGr','b','ForeGr','w');
   uimenu(fms3,'Label','12','Callback','gca;EditText(5,12)',...
       'BackGr','b','ForeGr','w');
   uimenu(fms3,'Label','14','Callback','gca;EditText(5,14)',...
       'BackGr','b','ForeGr','w');
   uimenu(fms3,'Label','18','Callback','gca;EditText(5,18)',...
       'BackGr','b','ForeGr','w');
   uimenu(fms3,'Label','24','Callback','gca;EditText(5,24)',...
       'BackGr','b','ForeGr','w');
   uimenu(fms3,'Label','Other','Callback','gca;EditText(5,0)',...
       'BackGr','b','ForeGr','w', 'interruptible', 'yes');
   
% Text Justify Sub Menu

   fms4v = uimenu(fms4,'Label','Vert', 'BackGr','b','ForeGr','w');
   fms4h = uimenu(fms4,'Label','Horiz', 'BackGr','b','ForeGr','w');
   
   uimenu(fms4v,'Label','top', 'Callback','gca;EditText(6,''top'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms4v,'Label','center', 'Callback','gca;EditText(6,''middle'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms4v,'Label','bottom', 'Callback','gca;EditText(6,''bottom'')',...
       'BackGr','b','ForeGr','w');
   
   uimenu(fms4h,'Label','left', 'Callback','gca;EditText(7,''left'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms4h,'Label','center', 'Callback','gca;EditText(7,''center'')',...
       'BackGr','b','ForeGr','w');
   uimenu(fms4h,'Label','right', 'Callback','gca;EditText(7,''right'')',...
       'BackGr','b','ForeGr','w');

% Line Obj Main Menu
   lm = uimenu('BackGr','g',...
            'CallBack','',...
            'Enable','on',...
            'ForeGr','k',...
            'Label','Line',...
            'Tag','PrLine');
   lms1 = uimenu(lm,'Label','Line Style','BackGr','g','ForeGr','k');
   lms2 = uimenu(lm,'Label','Line Width','BackGr','g','ForeGr','k');
   lms5 = uimenu(lm,'Label','Marker Size','BackGr','g','ForeGr','k');

   uimenu(lms1,'Label','_______','Callback','gca;EditLine(1,''-'')',...
       'BackGr','k','ForeGr','w');
   uimenu(lms1,'Label','.......','Callback','gca;EditLine(1,'':'')',...
       'BackGr','k','ForeGr','w','Separator','on');
   uimenu(lms1,'Label','_ _ _ _','Callback','gca;EditLine(1,''--'')',... 
       'BackGr','k','ForeGr','w','Separator','on');
   uimenu(lms1,'Label','_._._._','Callback','gca;EditLine(1,''-.'')',...
            'BackGr','k','ForeGr','w','Separator','on');
   uimenu(lms1,'Label','*','Callback','gca;EditLine(1,''*'')',...
            'BackGr','k','ForeGr','w','Separator','on');
   uimenu(lms1,'Label','+','Callback','gca;EditLine(1,''+'')',...
            'BackGr','k','ForeGr','w','Separator','on');
   uimenu(lms1,'Label','o','Callback','gca;EditLine(1,''o'')',...
            'BackGr','k','ForeGr','w','Separator','on');
   uimenu(lms1,'Label','.','Callback','gca;EditLine(1,''.'')',...
            'BackGr','k','ForeGr','w','Separator','on');

   uimenu(lms2,'Label','0.5 point','Callback','gca;EditLine(2,.5)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms2,'Label','1.0 point','Callback','gca;EditLine(2,1)',....
       'BackGr','k','ForeGr','w');
   uimenu(lms2,'Label','2.0 point','Callback','gca;EditLine(2,2)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms2,'Label','4.0 point','Callback','gca;EditLine(2,4)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms2,'Label','Other','Callback','gca;EditLine(2,0)',...
       'Enable','on','BackGr','g','ForeGr','k', 'interruptible', 'yes');

   uimenu(lms5,'Label','1 point','Callback','gca;EditLine(5,1)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms5,'Label','3 point','Callback','gca;EditLine(5,3)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms5,'Label','6 point','Callback','gca;EditLine(5,6)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms5,'Label','10 point','Callback','gca;EditLine(5,10)',...
       'BackGr','k','ForeGr','w');
   uimenu(lms5,'Label','Other','Callback','gca;EditLine(5,0)',...
       'Enable','on','BackGr','g','ForeGr','k', 'interruptible', 'yes');


% Color Obj Main Menu

   cm = uimenu('BackGr','b',...
            'CallBack','',...
            'Enable','on',...
            'ForeGr','w',...
            'Label','Color',...
            'Tag','PrColor');
   cms1 = uimenu(cm,'Label','Pen','BackGr','b','ForeGr','w');
   cms2 = uimenu(cm,'Label','Fill','BackGr','b','ForeGr','w');
   cms3 = uimenu(cm,'Label','Edit Color','BackGr','b','ForeGr','w', ...
       'Enable', 'on', 'Callback', 'gca; EditColor');

   uimenu(cms1,'Label','Yellow','Callback','gca;EditColor(0,3,''y'')',...
       'BackGr','k','ForeGr','y');
   uimenu(cms1,'Label','Violet','Callback','gca;EditColor(0,3,''m'')',...
       'BackGr','k','ForeGr','m');
   uimenu(cms1,'Label','Cyan','Callback','gca;EditColor(0,3,''c'')',...
       'BackGr','k','ForeGr','c');
   uimenu(cms1,'Label','Red','Callback','gca;EditColor(0,3,''r'')',...
       'BackGr','k','ForeGr','r');
   uimenu(cms1,'Label','Green','Callback','gca;EditColor(0,3,''g'')',...
       'BackGr','k','ForeGr','g');
   uimenu(cms1,'Label','Blue','Callback','gca;EditColor(0,3,''b'')',...
       'BackGr','k','ForeGr','b');
   uimenu(cms1,'Label','White','Callback','gca;EditColor(0,3,''w'')',...
       'BackGr','k','ForeGr','w');
   uimenu(cms1,'Label','Black','Callback','gca;EditColor(0,3,''k'')',...
       'BackGr','w','ForeGr','k');
   uimenu(cms1,'Label','70% Grey',...
       'Callback','gca;EditColor(0,3,[.7 .7 .7])',...
       'BackGr','k','ForeGr',[.7 .7 .7],...
       'Separator','on');

   uimenu(cms2,'Label','Yellow','Callback','gca;EditLine(4,[1 1 0])',...
       'BackGr','y','ForeGr','k');
   uimenu(cms2,'Label','Violet','Callback','gca;EditLine(4,[1 0 1])',...
       'BackGr','m','ForeGr','k');
   uimenu(cms2,'Label','Cyan','Callback','gca;EditLine(4,[0 1 1])',...
       'BackGr','c','ForeGr','k');
   uimenu(cms2,'Label','Red','Callback','gca;EditLine(4,[1 0 0])',...
       'BackGr','r','ForeGr','k');
   uimenu(cms2,'Label','Green','Callback','gca;EditLine(4,[0 1 0])',...
       'BackGr','g','ForeGr','k');
   uimenu(cms2,'Label','Blue','Callback','gca;EditLine(4,[0 0 1])',...
       'BackGr','b','ForeGr','w');
   uimenu(cms2,'Label','White','Callback','gca;EditLine(4,[1 1 1])',...
       'BackGr','w','ForeGr','k');
   uimenu(cms2,'Label','Black','Callback','gca;EditLine(4,[0 0 0])',...
       'BackGr','k','ForeGr','w');
   uimenu(cms2,'Label','70% Grey','Callback','gca;EditLine(4,[.7 .7 .7])',...
       'BackGr','k','ForeGr','w');
   uimenu(cms2,'Label','None','Callback','gca;EditLine(4,''none'')',...
       'BackGr',[.7 .7 .7],'ForeGr','k');

   % Insert Blank menus
   uimenu('Label','      ','Position',7,'BackGr',[.7 .7 .7],'Enable','off');
   
   prmenu=uimenu('Label','Print','BackGr','b','ForeGr','w','Tag','PrPrint');
       uimenu(prmenu,'Label','Page Setup','Callback','PrintSetup',...
              'Enable','on','BackgroundColor','b','ForegroundColor','w');
	  
       uimenu(prmenu,'Label','To lphp','Callback','print',...
                     'BackGr','b','ForeGr','w');
       uimenu(prmenu,'Label','To lptom','Callback','print -Plptom',...
                     'Enable','off','BackGr','b','ForeGr','w');
       uimenu(prmenu,'Label','To file','Callback','printfile(1)',...
                     'Separator','on','BackGr','b','ForeGr','w');

   wsmenu=uimenu('Label','Workspace','BackGr','g','Tag','PrWorkS');
       uimenu(wsmenu,'Label', 'WYSIWYG', ...
	   'Callback', 'wysiwyg', ...
	   'BackGr','g');       	   
       uimenu(wsmenu,'Label', 'Reduce View', ...
	   'Callback', 'ChangeView(''reduce'')', ...
	   'BackGr','g');       	   
       uimenu(wsmenu,'Label', 'Enlarge View', ...
	   'Callback', 'ChangeView(''enlarge'')', ...
	   'BackGr','g');       	   
       uimenu(wsmenu,'Label', 'Layout', ...
	   'Callback', 'layout(''initialize'')', ...
	   'separator', 'on', 'BackGr','g');       
       uimenu(wsmenu,'Label', 'Refresh Screen', ...
	   'Callback', 'refresh(gcf)', ...
	   'separator', 'on', 'BackGr','g');
       uimenu(wsmenu,'Label','Remove Prmenu','Callback','Prmenu(3)',...
	   'BackGr','g')
       uimenu(wsmenu,'Label','Clear Plot','Callback','cla;reset(gca)',...
                     'BackGr','g');
       uimenu(wsmenu,'Label','Close Figure','Callback','close(gcf)',...
                     'BackGr','g');
		 
   mtmenu=uimenu('Label','Template', ...
       'BackGr','b','ForeGr','w', ...
       'Tag','PrTemplate');	 
       uimenu(mtmenu,'Label','Save As','Callback','SaveAs',...
                     'BackGr','b','ForeGr','w');
       uimenu(mtmenu,'Label','Open','Callback','OpenAs',...
                     'BackGr','b','ForeGr','w');
		 
   % Insert some more Blank menus
   uimenu('Label','      ','Position',11,'BackGr',[.7 .7 .7],'Enable','off');
   %uimenu('Label','      ','Position',12,'BackGr',[.7 .7 .7],'Enable','off');
   %uimenu('Label','      ','Position',13,'BackGr',[.7 .7 .7],'Enable','off');

   % menu items that show lasttype and lastobject touched
   uimenu('Label', LASTTYPE, ...
       'BackGr',[.7 .7 .7], 'ForeGr', 'k', ...
       'Enable','on', 'Tag', 'PrType');
   uimenu('Label', num2str(LASTOBJECT,6), ...
       'BackGr',[.7 .7 .7], 'ForeGr', 'k', ...
       'Enable','on', 'Tag', 'PrObject');
   
   
elseif opt==1
   PrZoomIn=findobj(gcf,'Type','uimenu','Tag','PrZoomIn');
   PrZoomOut=findobj(gcf,'Type','uimenu','Tag','PrZoomOut');
   PrZoomOff=findobj(gcf,'Type','uimenu','Tag','PrZoomOff');   
   if subopt==1
      set(PrZoomIn,'Enable','off');
      set(PrZoomOut,'Enable','on');
      set(PrZoomOff,'Enable','on');
      zoom on
   elseif subopt==2
      zoom out
   else
      set(PrZoomIn,'Enable','on');
      set(PrZoomOut,'Enable','off');
      set(PrZoomOff,'Enable','off');
      zoom off
      set(gcf, 'WindowButtonDownFcn', 'lastouch', ...
               'WindowButtonUpFcn', '', ...
	       'WindowButtonMotionFcn', '');
   end
elseif opt==2
   MTON=findobj(gcf,'Type','uimenu','Tag','PrTextMoveMBON');
   MTOFF=findobj(gcf,'Type','uimenu','Tag','PrTextMoveMBOFF');
   if subopt==1
      figure(gcf);
      axes(gca);
      movetext('on');
      set(MTON,'Enable','off')
      set(MTOFF,'Enable','on')
   else
      movetext('off');
      set(MTON,'Enable','on')
      set(MTOFF,'Enable','off')
   end
elseif opt==3
   fig_ch=get(gcf,'Children');
   menus=findobj(fig_ch,'flat','Type','uimenu');
   delete(menus);
   refresh(gcf);
end