www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregclicktolinput/xregclicktolinput.m
function obj = xregclicktolinput(varargin) %xregtextinput Constructor for the text control/input object. % Usage: % C=xregclicktolinput % C=xregclicktolinput(FIG) % C=xregclicktolinput('Property1',Value1,...) % C=xregclicktolinput(FIG,'Property1',Value1,...) % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. obj.text = []; obj.clickedit=[]; obj.tolerancetext = []; obj.tolerance = []; obj.layout=[]; if nargin>0 && mbcgui.util.isComponentParent(varargin{1}) fh=varargin{1}; varargin(1)=[]; else fh=gcf; end % default position; set called at end if position input pos = [10 10 200 17]; if isgraphics(fh, 'figure') bgc = get(fh,'Color'); else bgc = get(fh,'BackgroundColor'); end obj.text = uicontrol('Style','text',... 'Visible','off',... 'Parent',fh,... 'String','xregclickinput',... 'HorizontalAlignment','left',... 'BackgroundColor',bgc); obj.clickedit = mbcgui.widget.Spinner('Parent', fh,... 'Position',pos); obj.tolerancetext = uicontrol('Style','text',... 'Visible','off',... 'Parent',fh,... 'String','Tol:',... 'HorizontalAlignment','right',... 'BackgroundColor',bgc); obj.tolerance = uicontrol('Style','edit',... 'Visible','off',... 'Parent',fh,... 'String','',... 'UserData','',... 'BackgroundColor','w'); obj.layout = xreggridbaglayout(fh,... 'dimension',[2 4],.... 'elements',{[],obj.text,... obj.clickedit,[],... [],obj.tolerancetext,... obj.tolerance,[]},... 'mergeblock',{[1 2],[2 2]},... 'mergeblock',{[1 2],[4 4]},... 'rowsizes',[-1 17],... 'colsizes',[-1,70,20,40],... 'gapx',5,... 'position',pos); obj = class(obj,'xregclicktolinput'); set(obj.tolerance,'Callback',{@i_toleranceCb,obj.clickedit}); if ~isempty(varargin) obj=set(obj,varargin{:}); end function i_toleranceCb(src,event,clickedit) % check edit contents are sensible % then call the clickedit callback if there is one tol= get(src,'String'); oldTol = get(src,'UserData'); if isempty(str2num(tol)) % return to last sensible tolerance set(src,'String',oldTol); else % keep new tolerance in userdata set(src,'UserData',tol); % call clickedit callback cb=get(clickedit,'Callback'); if ~isempty(cb) xregcallback(cb); end end