www.gusucode.com > mbclayouts 工具箱 matlab 源码程序 > mbclayouts/@xreggridlayout/set.m
function varargout=set(obj,varargin) % Synopsis % function set(obj,parameter,value,setChildren) % % Description % Set the parameter of the handles. This works very similar % to the set methods for handles. The only difference is that % some methods have been overloaded to perform differently % on the package. Non overload methods just perform the set % recursively on all submembers. % % Overloaded methods % Position : ( xmin xmax width height) of the whole package. % Elements : { control1 control2 control.... controlN } % Dimension : { nrows, ncols } % Gap : Set x and y intercontrol spacing % Gapx : Set x intercontrol spacing % Gapy : Set y intercontrol spacing % RowRatios : Set the relative sizes of rows % ColRatios : Set the relative sizes of columns % CorrectAlg : 'on'/{'off'}. Sets the gridlayout to using a % newer more correct algorithm for positioning. % Rowsizes : explicit row sizes in pixels for fixing rows % (Vector - use size<0 to free a row. This function % is only available if correctalg='on') % Colsizes : explicit col sizes in pixels for fixing cols % (Vector - use size<0 to free a col. This function % is only available if correctalg='on') % Slidersize : sets the width of scrolling sliderbars % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. norepack = 1; doscrollvis = 0; data = obj.g.info; if ~isa(obj,'xreggridlayout') set(mbcgui.hgclassesutil.toHandle(obj),varargin{:}); else VALIDATE_GRID = false; for arg=1:2:length(varargin) parameter = varargin{arg}; value = varargin{arg+1}; reqnorepack=0; switch upper(parameter) case 'POSITION' obj.xregcontainer = set(obj.xregcontainer,'Position',value); doscrollvis=1; case 'DIMENSION' obj.hGrid.Rows = value(1); obj.hGrid.Columns = value(2); obj.hGrid.fixMerge; VALIDATE_GRID = true; case 'ROWRATIOS' obj.hGrid.RowRatios = value/sum(value); VALIDATE_GRID = true; case 'COLRATIOS' obj.hGrid.ColumnRatios = value/sum(value); VALIDATE_GRID = true; case 'GAP' obj.hGrid.RowGap = value; obj.hGrid.ColumnGap = value; case 'GAPX' obj.hGrid.ColumnGap = value; case 'GAPY' obj.hGrid.RowGap = value; case 'CORRECTALG' if strcmpi(value,'on') data.usecorrectalg = 1; else data.usecorrectalg = 0; end case 'ROWSIZES' obj.hGrid.RowSizes = value; VALIDATE_GRID = true; case 'COLSIZES' obj.hGrid.ColumnSizes = value; VALIDATE_GRID = true; case 'MERGEBLOCK' obj.hGrid.merge(value{1},value{2}); case 'CLEARMERGE' obj.hGrid.clearMerge; case 'HSCROLL' data.hscrollon = find( strncmp( value,{ 'off'; 'on'},length(value) ) )-1; if ~(data.hscrollon || data.vscrollon) vis = {'off','on'}; vis = vis{data.visible+1}; set(obj.xregcontainer,'Visible',vis); end if data.hscrollon data.usecorrectalg = 1; if isempty(data.objH); data = i_createscrollobj(data,get(obj,'Parent'),obj); end end doscrollvis=1; case 'VSCROLL' data.vscrollon = find( strncmp( value,{ 'off'; 'on' },length(value) ) )-1; if ~(data.hscrollon || data.vscrollon) vis = {'off','on'}; vis = vis{data.visible+1}; set(obj.xregcontainer,'Visible',vis); end if data.vscrollon data.usecorrectalg = 1; if isempty(data.objH); data = i_createscrollobj(data,get(obj,'Parent'),obj); end end doscrollvis = 1; case 'CURRENTROW' data.currentrow = value; case 'CURRENTCOL' data.currentcol = value; case 'VISIBLE' data.visible = find( strncmp( value,{ 'off'; 'on' },length(value) ) )-1; if ~(data.hscrollon || data.vscrollon) set(obj.xregcontainer,'Visible',value); else doscrollvis = 1; if ~data.visible set(obj.xregcontainer,'Visible',value); else % only set the relevant elements on i_setvison(obj); end end reqnorepack = 1; case 'SLIDERSIZE' data.slidersize = value; otherwise [obj.xregcontainer,reqnorepack] = set(obj.xregcontainer,parameter,value); end norepack=(norepack & reqnorepack); end obj.g.info=data; if VALIDATE_GRID % Check that the grid settings are ok obj.hGrid.checkSettings; end if nargout>1 varargout{1}=obj; varargout{2}=norepack; else varargout{1}=obj; if ~norepack && getBoolPackstatus(obj) repack(obj); end end if doscrollvis data=obj.g.info; i_doscrollobjvis(data); end end function data=i_createscrollobj(data,fig,obj) data.objH=[uicontrol('Parent',fig,'Style','slider','Visible','off',... 'Interruptible','off','Min',1,'Max',2,'Value',1,'Tag','hscroll','Callback',{@i_hscroll,obj}),... uicontrol('Parent',fig,'Style','slider','Visible','off',... 'Interruptible','off','Min',-2,'Max',-1,'Value',-1,'Tag','vscroll','Callback',{@i_vscroll,obj}),... uicontrol('Parent',fig,'Style','pushbutton','Visible','off','Interruptible','off',... 'Enable','inactive')]; function i_doscrollobjvis(data) if ~isempty(data.objH) if data.hscrollon && data.visible && size(data.colsteps,1)>1 set(data.objH(1),'Visible','on'); else set(data.objH(1),'Visible','off'); end if data.vscrollon && data.visible && size(data.rowsteps,1)>1 set(data.objH(2),'Visible','on'); else set(data.objH(2),'Visible','off'); end if (data.hscrollon && data.vscrollon) && data.visible && size(data.colsteps,1)>1 && size(data.rowsteps,1)>1 set(data.objH(3),'Visible','on'); else set(data.objH(3),'Visible','off'); end end function i_hscroll(srcobj,~,obj) if get(obj,'boolpackstatus') set(obj,'currentcol',round(get(srcobj,'Value'))); else set(obj,'currentcol',round(get(srcobj,'Value')),'boolpackstatus',true); set(obj,'boolpackstatus',false); end function i_vscroll(srcobj,~,obj) if get(obj,'boolpackstatus') set(obj,'currentrow',-(round(get(srcobj,'Value')))); else set(obj,'currentrow',-(round(get(srcobj,'Value'))),'boolpackstatus',true); set(obj,'boolpackstatus',false); end function i_setvison(obj) el=get(obj,'elements'); Nels=length(el(:)); data=obj.g.info; R = min(size(data.rowsteps,1), max(1, data.currentrow)); C = min(size(data.colsteps,1), max(1, data.currentcol)); dim = [obj.hGrid.Rows, obj.hGrid.Columns]; if any(dim==0) % Nothing to do return end for n = R:data.rowsteps(R,2) for m = C:data.colsteps(C,2) i=sub2ind(dim, n, m); if i<=Nels && ~isempty(el{i}) set(el{i},'Visible','on'); end end end