function FigureMenu = figmenus(this)
%  FIGMENUS Creates customized menus for the figure.

%   Authors: Kamesh Subbarao
%   Copyright 1986-2013 The MathWorks, Inc.
%
%---File Menu
FigMenu.FileMenu.Main = uimenu(this.Figure, ...
    'Label',getString(message('Control:viewer:menuFile')), ...
    'HandleVis','off','Tag','LTIViewer_File');
FigMenu.FileMenu.NewViewer = uimenu(FigMenu.FileMenu.Main,...
   'Label',getString(message('Control:viewer:menuNewViewer')), ...
   'Accelerator','N','Callback','ltiview;','Tag','LTIViewer_NewViewer');
FigMenu.FileMenu.Import = uimenu(FigMenu.FileMenu.Main,'Separator','on',...
   'Label',getString(message('Control:viewer:menuImportEllipsis')), ...
   'Callback',{@localImport this},'Tag','LTIViewer_Import');
FigMenu.FileMenu.Export = uimenu(FigMenu.FileMenu.Main,...
   'Label',getString(message('Control:viewer:menuExportEllipsis')), ...
   'Callback',{@localExport this},'Tag','LTIViewer_Export');
if usejava('MWT')
   FigMenu.FileMenu.ToolboxPreferences = uimenu(FigMenu.FileMenu.Main,'Separator','on',...
      'Label',getString(message('Control:viewer:menuToolboxPreferencesEllipsis')),...
      'Callback','ctrlpref','Tag','LTIViewer_ToolboxPreferences');
end
FigMenu.FileMenu.PageSetup = uimenu(FigMenu.FileMenu.Main,'Separator','on',...
   'Label',getString(message('Control:viewer:menuPageSetupEllipsis')),...
   'Callback',{@localPageSetup this},'Tag','LTIViewer_PageSetup');
FigMenu.FileMenu.Print = uimenu(FigMenu.FileMenu.Main,...
   'Label',getString(message('Control:viewer:menuPrintEllipsis')),...
   'Accelerator','P','Callback',{@localPrintPaper this},'Tag','LTIViewer_Print');
FigMenu.FileMenu.PrintToFigure = uimenu(FigMenu.FileMenu.Main,...
   'Label',getString(message('Control:viewer:menuPrintToFigure')),...
   'Callback',{@localPrintFigure this},'Tag','LTIViewer_PrintToFigure');
FigMenu.FileMenu.Close = uimenu(FigMenu.FileMenu.Main,'Separator','on',...
   'Label',getString(message('Control:viewer:menuClose')),...
   'Accelerator','W','CallBack',{@localClose this},'Tag','LTIViewer_Close');
% -------------------------------------------------------------------------
%---Edit Menu
FigMenu.EditMenu.Main = uimenu(this.Figure,...
    'Label',getString(message('Control:viewer:menuEdit')),...
    'HandleVis','off','Tag','LTIViewer_Edit');
FigMenu.EditMenu.PlotConfigurations = uimenu(FigMenu.EditMenu.Main,...
   'Label',getString(message('Control:viewer:menuPlotConfigEllipsis')),...
   'Callback',{@localPlotConfig this},'Tag','LTIViewer_PlotConfigurations');
FigMenu.EditMenu.RefreshSystems = uimenu(FigMenu.EditMenu.Main,...
   'Label', getString(message('Control:viewer:menuRefreshSystems')),...
   'Callback',{@localRefresh this},'Tag','LTIViewer_RefreshSystems');
FigMenu.EditMenu.DeleteSystems = uimenu(FigMenu.EditMenu.Main,...
   'Label', getString(message('Control:viewer:menuDeleteSystemsEllipsis')),...
   'Callback',{@localDelete this},'Tag','LTIViewer_DeleteSystems');
FigMenu.EditMenu.LineStyles = uimenu(FigMenu.EditMenu.Main,'Separator','on',...
   'Label', getString(message('Control:viewer:menuLineStylesEllipsis')), ...
   'Callback',{@localLineStyle this},'Tag','LTIViewer_LineStyles');
FigMenu.EditMenu.ViewerPreferences = uimenu(FigMenu.EditMenu.Main,...
   'Label',getString(message('Control:viewer:menuViewerPreferencesEllipsis')), ...
   'Callback',{@localViewPref this},'Tag','LTIViewer_ViewerPreferences');
% -------------------------------------------------------------------------
%---Window Menu
FigMenu.WinMenu.Main = matlab.ui.internal.createWinMenu(this.Figure,...
    getString(message('Control:viewer:menuWindow')));
set(FigMenu.WinMenu.Main,'HandleVis','off');
% -------------------------------------------------------------------------
% ---Help Menu
FigMenu.HelpMenu.Main = uimenu(this.Figure,...
    'Label',getString(message('Control:viewer:menuHelp')),...
    'HandleVis','off','Tag','LTIViewer_Help');
FigMenu.HelpMenu.ViewerHelp = uimenu(FigMenu.HelpMenu.Main,...
   'Label',getString(message('Control:viewer:menuLTIViewerHelp')),...
   'Callback','ctrlguihelp(''viewermainhelp'');','Tag','LTIViewer_ViewerHelp');
FigMenu.HelpMenu.ToolboxHelp = uimenu(FigMenu.HelpMenu.Main,...
   'Label',getString(message('Control:viewer:menuControlSystemToolboxHelp')),...
   'Callback','doc(''control/'');','Tag','LTIViewer_CSTHelp');
FigMenu.HelpMenu.ImportExportHelp = uimenu(FigMenu.HelpMenu.Main,'Separator','on',...
   'Label',getString(message('Control:viewer:menuImportingExportingModels')),...
   'Callback','ctrlguihelp(''viewer_importexport'');','Tag','LTIViewer_ImportExportHelp');
FigMenu.HelpMenu.RespTypeHelp = uimenu(FigMenu.HelpMenu.Main,...
   'Label',getString(message('Control:viewer:menuSelectingResponseTypes')),...
   'Callback','ctrlguihelp(''viewer_responsetypes'');','Tag','LTIViewer_SelectResponseTypeHelp');
FigMenu.HelpMenu.MIMOHelp = uimenu(FigMenu.HelpMenu.Main,...
   'Label',getString(message('Control:viewer:menuAnalyzingMIMOModels')),...
   'Callback','ctrlguihelp(''viewer_mimomodels'');','Tag','LTIViewer_AnalyzingMIMOModelsHelp');
FigMenu.HelpMenu.PropPrefHelp = uimenu(FigMenu.HelpMenu.Main,...
   'Label',getString(message('Control:viewer:menuCustomizingLTIViewer')),...
   'Callback','ctrlguihelp(''viewer_customizing'');','Tag','LTIViewer_CustomizingViewerHelp');
FigMenu.HelpMenu.DemosHelp = uimenu(FigMenu.HelpMenu.Main,'Separator','on',...
   'Label',getString(message('Control:viewer:menuDemos')),...
   'Callback','demo toolbox control','Tag','LTIViewer_Demos');
FigMenu.HelpMenu.AboutHelp = uimenu(FigMenu.HelpMenu.Main,'Separator','on',...
   'Label',getString(message('Control:viewer:menuAboutControlSystemToolbox')),...
   'Callback','aboutcst','Tag','LTIViewer_About');
% -------------------------------------------------------------------------
FigureMenu = FigMenu;
% -------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pass these callbacks to class methods %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localImport
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localImport(~,~,this)
%
importdlg(this);
% 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localExport
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localExport(eventSrc,~,this)
%
if isempty(this.Systems)
    errordlg(getString(message('Control:viewer:msgNoSystemsToExport')),...
           getString(message('Control:viewer:strExprtSystems')));
    return;
end

if isempty(this.ExportDialog) || ~isvalid(this.ExportDialog)
    this.ExportDialog = viewgui.internal.ExportDialog(this);
    show(this.ExportDialog,this.Figure);
else
    show(this.ExportDialog);
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localPageSetup
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localPageSetup(~,~,this)
h = ctrlMsgUtils.SuspendWarnings; %#ok<NASGU>
setappdata(this.Figure,'useDeprecatedPageSetupDlg',true)
printpreview(this.Figure); 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localPrint
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localPrintPaper(~,~,this)
print(this,'printer');

function localPrintFigure(~,~,this)
print(this,'figure');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localRefresh
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localRefresh(~,~,this)
refreshsys(this);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localDelete
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localDelete(eventSrc,~,this)
%
if isempty(this.Systems)
    errordlg(getString(message('Control:viewer:errNoSystemsToDelete')), ...
        getString(message('Control:viewer:strDeleteSystems')));
    return;
end

if isempty(this.DeleteDialog) || ~isvalid(this.DeleteDialog)
    this.DeleteDialog = viewgui.internal.DeleteDialog(this);
    show(this.DeleteDialog,this.Figure);
else
    show(this.DeleteDialog);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localLineStyle
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localLineStyle(eventSrc,~,this)
%

StyleFrame = get(eventSrc,'UserData');
if isempty(StyleFrame)
    % Create style dialog
    StyleFrame = styledlg(this);
    set(eventSrc,'UserData',StyleFrame);
else
    % Bring it up front
    set(StyleFrame,'Visible','on');
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localViewPref
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localViewPref(~,~,this)
edit(this.Preferences);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localClose
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localClose(~,~,this)
close(this);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  localPlotConfig
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function localPlotConfig(eventSrc,~,this)
%
ConfigFrame = get(eventSrc,'UserData');
if isempty(ConfigFrame)
   % Create configuration dialog
   configdlg(this);
else
   % Bring it up front
   set(ConfigFrame,'Visible','on');
end
