www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregstepinput/xregstepinput.m
function out = xregstepinput(fH , name , range , num , callback , varargin) %function obj = xregstepinput(FigureHandle , 'Name' , range , num , 'Callback') % %FigureHandle. The Parent figure for the object. %Name. The name of the input which will be displayed in the leftmost text-box. %range. A two-element vector which specifies the range over which this input % should exist. %num. the number of points over the range. %callback. A callback to be executed after stepping in the range or typing in the editable box. % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. obj = struct('text' , [] , ... 'leftbutton' , [] , ... 'rightbutton' , [] , ... 'edit' , []); if exist('fH', 'var') == 0 fH = gcf; end if ~isgraphics(fH , 'figure') error(message('mbc:xregstepinput:InvalidArgument')); end %Set up a structure which will be the editable box userdata. edud.range = []; edud.index = []; edud.currstr = ''; edud.callback = []; edud.UserData = []; % find the location of the icon file thisdir = fileparts( mfilename( 'fullpath' ) ); icons = fullfile( thisdir, 'stepInputIcons.mat' ); % load the icon data from the file LeftE = []; LeftD = []; RightE = []; RightD = []; load( icons, 'LeftE', 'LeftD', 'RightE', 'RightD' ); edud.LeftEn = LeftE; edud.LeftDis = LeftD; edud.RightEn = RightE; edud.RightDis = RightD; if isgraphics(fH, 'figure') bgc = get(fH,'Color'); else bgc = get(fH,'BackgroundColor'); end obj.text = uicontrol('Parent' , fH , ... 'BackgroundColor' , bgc , ... 'Style' , 'text' , ... 'HorizontalAlignment' , 'left' , ... 'Visible' , 'off'); obj.leftbutton = uicontrol('Parent' , fH , ... 'Style' , 'push' , ... 'Visible' , 'off' , ... 'CData' , edud.LeftEn , ... 'Callback' , {@mbcgui.util.legacycallback,@stepLeft,obj.text}); obj.edit = uicontrol('Parent' , fH , ... 'Style' , 'edit' , ... 'BackgroundColor' , [1 1 1] , ... 'Visible' , 'off' , ... 'Callback' , {@mbcgui.util.legacycallback,@typeText,obj.text}); obj.rightbutton = uicontrol('Parent' , fH , ... 'Style' , 'push' , ... 'Visible' , 'off' , ... 'CData' , edud.RightEn , ... 'Callback' , {@mbcgui.util.legacycallback,@stepRight,obj.text}); if nargin == 0 else if ~ischar(name) error(message('mbc:xregstepinput:InvalidArgument1')); end set(obj.text , 'String' , name); if ~isnumeric(range) || length(range) ~= 2 || diff(range) <= 0 error(message('mbc:xregstepinput:InvalidArgument2')); end if ~isnumeric(num) || ~isscalar(num) error(message('mbc:xregstepinput:InvalidArgument3')); end if num < 2 num = 3; end edud.range = linspace(range(1) , range(2) , num); edud.index = floor(num/2); edud.callback = callback; edud.currstr = num2str(edud.range(edud.index)); edud.enable = 1; set(obj.edit , 'String' , num2str(edud.range(edud.index))); end set(obj.edit , 'UserData' , edud); out = class(obj , 'xregstepinput'); if nargin > 5 out = set(out , varargin{:}); end builtin('set' , obj.text , 'UserData' , out);