www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@mbcmultiview/@ToggleAction/setSelectedValueSource.m
function setSelectedValueSource(obj, src, prop) %SETSELECTEDVALUESOURCE Lock the selected property's value to another object % % SETSELECTEDVALUESOURCE(OBJ, SRC, PROP) attaches a listener to the % property PROP of the object SRC. When the value of PROP changes, the % Selected property of OBJ is updated to match it. PROP must contain a % value that can be converted to a boolean - either a scalar numeric value % or an on/off type. % Copyright 2005-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. obj.Selected = i_getbool(get(src, prop)); if isgraphics(src) obj.ToggleSourceListener = mbcgui.hgclassesutil.proplistener(... src, prop, 'PostSet', mbcutils.callback(@i_setselected, obj)); elseif isa(src, 'mbcgui.wdget.Component') % MCOS widget obj.ToggleSourceListener = event.proplistener(... src, src.findprop(prop), 'PostSet', mbcutils.callback(@i_setselected, obj)); else % Assume a UDD widget obj.ToggleSourceListener = handle.listener(... src, src.findprop(prop), 'PropertyPostSet', {@i_setselected, obj}); end function i_setselected(src, evt, obj) val = get(evt.AffectedObject, src.Name); obj.Selected = i_getbool(val); function bVal = i_getbool(Val) if ischar(Val) if strcmpi(Val, 'on') bVal = true; else bVal = false; end else bVal = logical(Val); end