www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregGui/@popupmenu/init.m
function init(obj,labels,callbacks,enabled,separators) % Copyright 2000-2007 The MathWorks, Inc. and Ford Global Technologies, Inc. % POPUPMENU\INIT Initialises the menu items to be included % in this popup menu. Intended as a shorthand for setting % member variable 'items' without the overhead of setting % up an array of structures. % % Usage: % obj.init(labels,callbacks,enabled,separators) % obj.init(labels,callbacks,enabled) % obj.init(labels,callbacks) % % All parameters are cell arrays of the same length, and % their members must be: % label: strings, labelling the menu items. % callbacks: function handles or cell arrays in which the first entry % is a function handle and further entries are arguments to % be passed to this function when it is called. % enabled: 'on'/'off', depending on whether the menu item should be % available or 'greyed-out'. Default is 'on'. % separators: 'on'/'off', depending on whether this menu item should % be preceded by a separator or not. Default is 'off'. len=length(labels); if length(callbacks)~=len error(message('mbc:xregGui:popupmenu:InvalidSize1')); end if (nargin<4) enabled=repmat({'on'},len,1); elseif length(enabled)~=len error(message('mbc:xregGui:popupmenu:InvalidSize2')); end if (nargin<5) separators=repmat({'off'},len,1); elseif length(separators)~=len error(message('mbc:xregGui:popupmenu:InvalidSize3')); end items=[]; for k=1:len items(k).label=labels{k}; items(k).callback=callbacks{k}; items(k).enabled=enabled{k}; items(k).separator=separators{k}; end obj.items = items; % the listener will update the menus