classdef app3k < matlab.apps.AppBase

  % Properties that correspond to app components
  properties (Access = public)
    UIFigure       matlab.ui.Figure
    DateiMenu      matlab.ui.container.Menu
    BeendenMenu    matlab.ui.container.Menu
    AnsichtMenu    matlab.ui.container.Menu
    surfMenu       matlab.ui.container.Menu
    meshMenu       matlab.ui.container.Menu
    InfoMenu       matlab.ui.container.Menu
    DropDown       matlab.ui.control.DropDown
    DropDownLabel  matlab.ui.control.Label
    UIAxes         matlab.ui.control.UIAxes
    ContextMenu    matlab.ui.container.ContextMenu
    surfMenu_2     matlab.ui.container.Menu
    meshMenu_2     matlab.ui.container.Menu
  end

  properties (Access = private)
    handles % Description
  end
  

  % Callbacks that handle component events
  methods (Access = private)

    % Code that executes after component creation
    function startupFcn(app)
      [X,Y] = meshgrid(-8:.5:8); 
      R = sqrt(X.^2 + Y.^2) + eps;
      app.handles.Z = sin(R)./R;
      surf( app.UIAxes, app.handles.Z );     
    end

    % Value changed function: DropDown
    function DropDownValueChanged(app, event)
      value = app.DropDown.Value;
      if( strcmp( value, 'surf' ) )
        surf( app.UIAxes, app.handles.Z );      
      else
        mesh( app.UIAxes, app.handles.Z );      
      end
    end

    % Menu selected function: surfMenu
    function surfMenuSelected(app, event)
      surf( app.UIAxes, app.handles.Z ); 
      app.DropDown.Value = 'surf';
    end

    % Menu selected function: meshMenu
    function meshMenuSelected(app, event)
      mesh( app.UIAxes, app.handles.Z );
      app.DropDown.Value = 'mesh';
    end

    % Menu selected function: BeendenMenu
    function BeendenMenuSelected(app, event)
      delete( app.UIFigure );
    end

    % Menu selected function: InfoMenu
    function InfoMenuSelected(app, event)
      msgbox( {'Grafik-Beispiel','zum App Designer in MATLAB'},'Info' );
    end

    % Menu selected function: surfMenu_2
    function surfMenu_2Selected(app, event)
      surf( app.UIAxes, app.handles.Z ); 
      app.DropDown.Value = 'surf';      
    end

    % Menu selected function: meshMenu_2
    function meshMenu_2Selected(app, event)
      mesh( app.UIAxes, app.handles.Z ); 
      app.DropDown.Value = 'mesh';   
    end

    % Key press function: UIFigure
    function UIFigureKeyPress(app, event)
      key = event.Key;
      switch( key )
        case 's'
          surf( app.UIAxes, app.handles.Z ); 
          app.DropDown.Value = 'surf'; 
        case 'm'
          mesh( app.UIAxes, app.handles.Z ); 
          app.DropDown.Value = 'mesh';  
        otherwise
      end
    end
  end

  % Component initialization
  methods (Access = private)

    % Create UIFigure and components
    function createComponents(app)

      % Create UIFigure and hide until all components are created
      app.UIFigure = uifigure('Visible', 'off');
      app.UIFigure.Position = [100 100 435 377];
      app.UIFigure.Name = 'MATLAB App';
      app.UIFigure.KeyPressFcn = createCallbackFcn(app, @UIFigureKeyPress, true);

      % Create DateiMenu
      app.DateiMenu = uimenu(app.UIFigure);
      app.DateiMenu.Text = 'Datei';

      % Create BeendenMenu
      app.BeendenMenu = uimenu(app.DateiMenu);
      app.BeendenMenu.MenuSelectedFcn = createCallbackFcn(app, @BeendenMenuSelected, true);
      app.BeendenMenu.Text = 'Beenden';

      % Create AnsichtMenu
      app.AnsichtMenu = uimenu(app.UIFigure);
      app.AnsichtMenu.Text = 'Ansicht';

      % Create surfMenu
      app.surfMenu = uimenu(app.AnsichtMenu);
      app.surfMenu.MenuSelectedFcn = createCallbackFcn(app, @surfMenuSelected, true);
      app.surfMenu.Text = 'surf';

      % Create meshMenu
      app.meshMenu = uimenu(app.AnsichtMenu);
      app.meshMenu.MenuSelectedFcn = createCallbackFcn(app, @meshMenuSelected, true);
      app.meshMenu.Text = 'mesh';

      % Create InfoMenu
      app.InfoMenu = uimenu(app.UIFigure);
      app.InfoMenu.MenuSelectedFcn = createCallbackFcn(app, @InfoMenuSelected, true);
      app.InfoMenu.Text = 'Info';

      % Create UIAxes
      app.UIAxes = uiaxes(app.UIFigure);
      title(app.UIAxes, 'Title')
      xlabel(app.UIAxes, 'X')
      ylabel(app.UIAxes, 'Y')
      zlabel(app.UIAxes, 'Z')
      app.UIAxes.XTick = [];
      app.UIAxes.YTick = [];
      app.UIAxes.ZTick = [];
      app.UIAxes.Position = [69 160 300 185];

      % Create DropDownLabel
      app.DropDownLabel = uilabel(app.UIFigure);
      app.DropDownLabel.HorizontalAlignment = 'right';
      app.DropDownLabel.Position = [129 79 65 22];
      app.DropDownLabel.Text = 'Drop Down';

      % Create DropDown
      app.DropDown = uidropdown(app.UIFigure);
      app.DropDown.Items = {'surf', 'mesh'};
      app.DropDown.ValueChangedFcn = createCallbackFcn(app, @DropDownValueChanged, true);
      app.DropDown.Position = [209 79 100 22];
      app.DropDown.Value = 'surf';

      % Create ContextMenu
      app.ContextMenu = uicontextmenu(app.UIFigure);

      % Create surfMenu_2
      app.surfMenu_2 = uimenu(app.ContextMenu);
      app.surfMenu_2.MenuSelectedFcn = createCallbackFcn(app, @surfMenu_2Selected, true);
      app.surfMenu_2.Text = 'surf';

      % Create meshMenu_2
      app.meshMenu_2 = uimenu(app.ContextMenu);
      app.meshMenu_2.MenuSelectedFcn = createCallbackFcn(app, @meshMenu_2Selected, true);
      app.meshMenu_2.Text = 'mesh';
      
      % Assign app.ContextMenu
      app.UIAxes.ContextMenu = app.ContextMenu;

      % Show the figure after all components are created
      app.UIFigure.Visible = 'on';
    end
  end

  % App creation and deletion
  methods (Access = public)

    % Construct app
    function app = app3k

      % Create UIFigure and components
      createComponents(app)

      % Register the app with App Designer
      registerApp(app, app.UIFigure)

      % Execute the startup function
      runStartupFcn(app, @startupFcn)

      if nargout == 0
        clear app
      end
    end

    % Code that executes before app deletion
    function delete(app)

      % Delete UIFigure when app is deleted
      delete(app.UIFigure)
    end
  end
end