www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffgui/@listCentricUI/pMakeGraphsContextMenu.m

    function uic = pMakeGraphsContextMenu(obj)
%PMAKEGRAPHSCONTEXTMENU Create a context menu for the tradeoff graphs view
%
%  UIC = PMAKEGRAPHSCONTEXTMENU(OBJ) creates and returns a handle to a
%  context menu that is designed for use with the tradeoff graphs view.

%  Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.


uic = uicontextmenu('Parent', obj.Parent);
cmdStruct = obj.pGetCommands;

find_menus(1) = uimenu(uic, ...
    'Label', 'Find Mi&nimum of Y vs X', ...
    'Callback', {cmdStruct.MinimizeInput, obj}, ...
    'Enable', 'off');
find_menus(2) = uimenu(uic, ...
    'Label', 'Find Ma&ximum of Y vs X', ...
    'Callback', {cmdStruct.MaximizeInput, obj}, ...
    'Enable', 'off');
find_menus(3) = uimenu(uic, ...
    'Label', 'Find Turning &Point of Y vs X', ...
    'Callback', {cmdStruct.TurningOfInput, obj}, ...
    'Enable', 'off');

resetzoom = uimenu(uic, ...
    'Label', '&Reset Graph Zooms', ...
    'Callback', {@i_resetzoom, obj}, ...
    'Separator', 'on');

% Attach a listener to keep max/min/turning point menus updated correctly
obj.hGraphSelChangeList_Graphs = handle.listener( ...
    obj.GraphsView, 'SelectionChange', {@i_inputfinderenable, find_menus});



function i_inputfinderenable(src, evt, hMenus)
if ~isempty(evt.data.Row) && evt.data.Row>0
    pIn = src.SelectedInput;
    pOut = src.SelectedOutput;
    sIn = pIn.getname;
    sOut = pOut.getname;
    set(hMenus, 'Enable', 'on', ...
        {'Label'}, {sprintf('Find Minimum of %s vs %s', sOut, sIn); ...
        sprintf('Find Maximum of %s vs %s', sOut, sIn); ...
        sprintf('Find Turning Point of %s vs %s', sOut, sIn)});
else
    set(hMenus, 'Enable', 'off', ...
        {'Label'}, {'Find Minimum of Y vs X'; ...
        'Find Maximum of Y vs X'; ...
        'Find Turning Point of Y vs X'});
end


function i_resetzoom(src, evt, obj)
obj.pStartLongAction;
obj.GraphsView.resetZoom;
obj.pEndLongAction;