www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcgraph/@legend/pGenLegend.m

    function pGenLegend(obj, hItems, sLabels)
%PGENLEGEND Private method for creating a legend
%
%  PGENLEGEND(OBJ, HITEMS, LABELS) creates a Matlab legend and stores it
%  in the object.  Listeners are correctly hooked up for it and its
%  properties are set to match the capabilities required in the mbc legend.

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


if ~isempty(obj.LegendDestructionList)
    % Remove the old listener on the legend's destruction
    delete(obj.LegendDestructionList);
    obj.LegendDestructionList = [];
end

if ~isempty(hItems)
    % Create a new legend
    obj.hLegend = mbcCreateLegend(hItems, sLabels);
    set(obj.hLegend, 'visible', obj.Visible, ...
        'Location', obj.Location, ...
        'Interpreter', obj.Interpreter);

    % Remove context menu
    delete(get(obj.hLegend, 'UIContextMenu'));

    % Set up move mode correctly
    obj.pSetupMoveMode;
    
    % Add listener to synchronise destruction of objects
    obj.LegendDestructionList = mbcgui.hgclassesutil.listener(obj.hLegend, ...
        'ObjectBeingDestroyed', ...
        mbcutils.callback(@i_deletelegend, obj));
elseif ~isempty(obj.hLegend)
    delete(obj.hLegend);
    obj.hLegend = [];    
end



function i_deletelegend(src, evt, obj)
delete(obj);