www.gusucode.com > mbclayouts 工具箱 matlab 源码程序 > mbclayouts/@xregsnapsplitlayout/set.m
function obj = set(obj,varargin) % Synopsis % function obj = 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 set methods % POSITION : [xmin xmax width height] of the whole package. % SPLIT : [lfraction rfraction] % ORIENTATION : 'lr', 'ud' sets the split orientation % STYLE : {'toleft','totop'}/{'toright'/'tobottom'}/{'leftright','topbottom'} % SNAPSTYLE: 'tozero'/'tominimum' % CALLBACK : Callback string executed after a resize % LEFT/TOP : set object in left/top pane % RIGHT/BOTTOM : set object in right/top pane % LEFTINNERBORDER } [N E S W] inner border for left/top pane % TOPINNERBORDER } % RIGHTINNERBORDER } [N E S W] inner border for right/bottom pane % BOTTOMINNERBORDER } % MINWIDTH : [lmin rmin] set a minimum size for each pane in the % splitlayout. % STATE : {'left','top'}/{'right','bottom'}/'center' % ENABLE : 'on'/'off' % SPLITENABLE: 'on'/'off' Enable/disable the splitterbar only % Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. norepack = 1; if ~isa(obj,'xregsnapsplitlayout') set(mbcgui.hgclassesutil.toHandle(obj),varargin{:}); else ud=get(obj.xregcontainer,'UserData'); for arg=1:2:nargin-1 parameter = varargin{arg}; value = varargin{arg+1}; reqnorepack=0; switch upper(parameter) case 'POSITION' ud = setPosition(obj,value,ud); case 'SPLIT' ud = setSplit(obj,value,ud); case 'ORIENTATION' ud = setOrientation(obj,value,ud); case 'STYLE' ud = setStyle(obj,value,ud); case 'STATE' ud = setState(obj,value,ud); case 'SNAPSTYLE' [ud,reqnorepack] = setSnapStyle(obj,value,ud,reqnorepack); case 'CALLBACK' ud.callbackstr=value; reqnorepack=1; case {'LEFT','TOP'} replace(obj.xregcontainer,value,1); case {'RIGHT','BOTTOM'} replace(obj.xregcontainer,value,2); case {'LEFTINNERBORDER','TOPINNERBORDER'} if isnumeric(value) && length(value(:))==4 ud.innerborders(1,:)=value(:)'; end case {'RIGHTINNERBORDER','BOTTOMINNERBORDER'} if isnumeric(value) && length(value(:))==4 ud.innerborders(2,:)=value(:)'; end case 'VISIBLE' reqnorepack = setVisible(obj,value,ud); case 'MINWIDTH' ud.minwidth=value; case 'MINWIDTHUNITS' if ~strcmpi(value,'pixels') error(message('mbc:xregsnapsplitlayout:InvalidProperty')); end case 'ENABLE' set(obj.DragBar,'Enable',value); [obj.xregcontainer, reqnorepack] = set(obj.xregcontainer,parameter,value); case 'SPLITENABLE' set(obj.DragBar,'Enable',value); reqnorepack=1; case 'BARSTYLE' [obj,ud,reqnorepack] = setBarSyle(obj,value,ud,reqnorepack); otherwise [obj.xregcontainer, reqnorepack] = set(obj.xregcontainer,parameter,value); end norepack=(norepack & reqnorepack); end end set(obj.xregcontainer,'UserData',ud); if ~norepack && get(obj.xregcontainer,'boolpackstatus') repack(obj); end function i_setupSnapStyle(obj,ud) switch ud.state case 0 switch ud.behaviour case 0 st='TO_A'; case 1 st='BOTH'; case 2 st='TO_B'; end case 1 st='TO_B'; case 2 st='TO_A'; end obj.DragBar.Peer.setSnapStyle(st); function ud = setPosition(obj,position,ud) position(3:4)=max([1 1],position(3:4)); set(obj.xregcontainer,'Position',position); position=get(obj.xregcontainer,'innerposition'); % check new position against minimum split positions minw=ud.minwidth; if ud.snapposition || ~ud.state % don't need checks if we are snapped to side at [0 1] if any(minw) if ud.orientation sz=position(4); else sz=position(3); end newspl=ud.split.*sz; violation=newspl<minw; if any(violation) && ~all(violation) pane=find(violation); otherpane= ~violation; ud.split(pane)=minw(pane)./sz; ud.split(otherpane)=1-ud.split(pane); end end end function ud = setSplit(obj,value,ud) % normalise values value=value./sum(value); % check against minwidth property if ud.snapposition || ~ud.state % don't need checks if we are snapped to side at [0 1] minw=ud.minwidth; if any(minw) pos=get(obj.xregcontainer,'innerposition'); if ud.orientation sz=pos(4); else sz=pos(3); end minw=minw./sz; violation=value<minw; if any(violation) && ~all(violation) pane=find(violation); otherpane= ~violation; value(pane)=minw(pane); value(otherpane)=1-value(pane); end end end if ud.state==0 ud.split=value; end ud.splitmem=value; function ud = setOrientation(obj,value,ud) if strcmpi(value,'lr') ud.orientation=0; obj.DragBar.Peer.setOrientation('LEFTRIGHT'); elseif strcmpi(value,'ud') ud.orientation=1; obj.DragBar.Peer.setOrientation('UPDOWN'); end function ud = setStyle(obj,value,ud) switch lower(value) case {'toleft','totop'} ud.behaviour=0; case {'toright','tobottom'} ud.behaviour=2; case {'leftright','topbottom'} ud.behaviour=1; end i_setupSnapStyle(obj,ud); function ud = setState(obj,value,ud) % check the asked-for state is allowed by the style newst=ceil((find( strncmpi( value,{ 'center'; 'left'; 'top'; 'right'; 'bottom' },length(value) ) )-1).*0.5); if isempty(newst) error(message('mbc:xregsnapsplitlayout:InvalidArgument')); end if (ud.behaviour==0 && newst==2) || (ud.behaviour==2 && newst==1) error(message('mbc:xregsnapsplitlayout:InvalidArgument1')); end % move to state if newst~=ud.state switch newst case 0 newspl=ud.splitmem; case 1 newspl=[0 1]; case 2 newspl=[1 0]; otherwise newspl=ud.splitmem; end if ud.snapposition || ~newst % don't need checks if we are snapped to side at [0 1] % check against minwidth property minw=ud.minwidth; if any(minw) pos=get(obj.xregcontainer,'innerposition'); if ud.orientation sz=pos(4); else sz=pos(3); end minw=minw./sz; violation=newspl<minw; if any(violation) && ~all(violation) pane=find(violation); otherpane= ~violation; newspl(pane)=minw(pane); newspl(otherpane)=1-newspl(pane); end end end if newst % turn snapped-to-side component invisible if any(newspl==0) el=get(obj.xregcontainer,'elements'); if length(el)>=newst set(el{newst},'Visible','off'); end end else % if old split was at zero then turn component back on if any(ud.split==0) el=get(obj.xregcontainer,'elements'); if length(el)>=ud.state set(el{ud.state},'Visible','on'); end end end ud.state=newst; ud.split=newspl; i_setupSnapStyle(obj,ud); end function [ud,reqnorepack] = setSnapStyle(obj,value,ud,reqnorepack) newset=find( strncmpi( value,{ 'tozero'; 'tominimum'},length(value) ) )-1; if ~isempty(newset) && newset~=ud.snapposition ud.snapposition=newset; if ud.state newspl=[0 0]; newspl(ud.state)=1; if ud.snapposition % don't need checks if we are snapped to side at [0 1] % check against minwidth property minw=ud.minwidth; if any(minw) pos=get(obj.xregcontainer,'innerposition'); if ud.orientation sz=pos(4); else sz=pos(3); end minw=minw./sz; violation=newspl<minw; if any(violation) && ~all(violation) pane=find(violation); otherpane= ~violation; newspl(pane)=minw(pane); newspl(otherpane)=1-newspl(pane); end end end ud.split=newspl; else reqnorepack=1; end else reqnorepack=1; end function reqnorepack = setVisible(obj,value,ud) set(obj.DragBar,'Visible',value); % iterate over elements el=get(obj.xregcontainer,'elements'); for k=1:length(el) if ud.split(k) set(el{k},'Visible',value); end end reqnorepack=1; function [obj,ud,reqnorepack] = setBarSyle(obj,value,ud,reqnorepack) if value~=ud.barstyle ud.barstyle=value; if value==0 % raised obj.DragBar.BorderType = 'beveledout'; ud.barwidth = 8; else % flat obj.DragBar.BorderType = 'none'; ud.barwidth = 4; end else reqnorepack=1; end