www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/@xregrangeinput/xregrangeinput.m

    function obj = xregrangeinput(varargin)
% XREGRANGEINPUT Constructor for the constant control/input object.
%   Usage:
%   R=XREGRANGEINPUT
%   R=XREGRANGEINPUT(FIG)
%   R=XREGRANGEINPUT('Property1',Value1,...)
%   R=XREGRANGEINPUT(FIG,'Property1',Value1,...)

%  Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc.




% copy of object in ud of edit(end)
% other info in ud of 'name' text object

obj.name = [];
obj.text = [];
obj.edit = [];
obj.layout = [];
ud.min = 0;
ud.max = 1;
ud.points = 10;
ud.callback = '';

% just return copy of object???
% a trick to get hold of object using last edit box handle
if nargin==2 && isgraphics(varargin{1},'uicontrol')...   
   && strcmp(get(varargin{1},'Style'),'edit')
   obj = get(varargin{1},'UserData');
   return
end


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
% min height = 15, name = 20, other controls = 60
pos = [10 10 200 20];

if isgraphics(fh, 'figure')
    bgc = get(fh,'Color');
else
    bgc = get(fh,'BackgroundColor');
end

% 60 <= edit <= 120 length for all uicontrols
textH(1) = uicontrol('Style','text',...
   'Visible','off',...
   'Parent',fh,...
   'BackgroundColor',bgc,...
   'String','Min:',...
   'HorizontalAlignment','right');
textH(2) = uicontrol('Style','text',...
   'Visible','off',...
   'Parent',fh,...
   'BackgroundColor',bgc,...
   'String','Max:',...
   'HorizontalAlignment','right');
textH(3) = uicontrol('Style','text',...
   'Visible','off',...
   'Parent',fh,...
   'BackgroundColor',bgc,...
   'String','Pts:',...
   'HorizontalAlignment','right');

editH(1) = uicontrol('Style','edit',...
   'Visible','off',...
   'Parent',fh,...
   'BackgroundColor',[1 1 1],...
   'String','0',...
   'HorizontalAlignment','left');
editH(2) = uicontrol('Style','edit',...
   'Visible','off',...
   'Parent',fh,...
   'BackgroundColor',[1 1 1],...
   'String','1',...
   'HorizontalAlignment','left');
editH(3) = uicontrol('Style','edit',...
   'Visible','off',...
   'Parent',fh,...
   'BackgroundColor',[1 1 1],...
   'String','10',...
   'HorizontalAlignment','left');

nameH = uicontrol('Style','text',...
   'Visible','off',...
   'Parent',fh,...
   'String','',...
   'HorizontalAlignment','left',...
   'BackgroundColor',bgc);

layout = xreggridbaglayout(fh,...
   'dimension',[2 7],....
   'elements',{[],nameH,...
      [],textH(1),...
      editH(1),[],...
      [],textH(2),...
      editH(2),[],...
      [],textH(3),...
      editH(3),[]},...
   'mergeblock',{[1 2],[3 3]},...
   'mergeblock',{[1 2],[5 5]},...
   'mergeblock',{[1 2],[7 7]},...
   'rowsizes',[-1 17],...
   'colsizes',[-1,23,50,23,50,20,30],...
   'gapx',5,...
   'position',pos);

% all data fields in ud of 'name' text control
set(nameH,'UserData',ud);

obj.edit = editH;
obj.text = textH;
obj.name = nameH;
obj.layout = layout;
% class constructor
obj = class(obj,'xregrangeinput');

% set all callbacks of edit boxes to be the same
set(editH(1),...
   'Callback',{@mbcgui.util.legacycallback,@callback,editH(3),1});
set(editH(2),...
   'Callback',{@mbcgui.util.legacycallback,@callback,editH(3),2});
set(editH(3),...
   'Callback',{@mbcgui.util.legacycallback,@callback,editH(3),3});
% save copy of object in LAST edit box
builtin('set',editH(3),'userdata',obj);

if ~isempty(varargin)
   obj=set(obj,varargin{:});
end