www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcfoundation/@interfaceobject/addPropertyListeners.m
function L = addPropertyListeners(obj, Prop, Callback, Event) %ADDPROPERTYLISTENERS Create and add listeners to object properties % % L = ADDPROPERTYLISTENERS(OBJ, PROP, CALLBACK, EVENT) creates a new listener, L, % that is attached to the EVENT event of property PROP and that % fires CALLBACK. The listener's CallbackTarget is set to be OBJ. % L = ADDPROPERTYLISTENERS(OBJ, PROPS, CALLBACKS, EVENT) where PROPS and % CALLBACKS are cell arrays of properties and corresponding callbacks will % create a vector of listeners. % The EVENT argument defaults to 'PropertyPostSet' if not supplied. % % Copyright 2004-2010 The MathWorks, Inc. if nargin < 4 Event = 'PropertyPostSet'; end if ischar(Prop) % Single listener being created. L = handle.listener(obj, obj.findprop(Prop), Event, Callback); else % Lots of listeners being created. nL = numel(Prop); L = mbcutils.handleArray(nL,1); for n = 1:nL L(n) = handle.listener(obj, obj.findprop(Prop{n}), Event, Callback{n}); end end set(L, 'CallbackTarget', obj); obj.ComponentListeners = [obj.ComponentListeners; L];