www.gusucode.com > mbclayouts 工具箱 matlab 源码程序 > mbclayouts/@xregsplitlayout/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]
%     RESIZABLE :   'on', 'off' - dynamic resizing bar switch
%     ORIENTATION :  'lr', 'ud'  sets the split orientation
%     DIVIDERSTYLE : '3d' or 'flat'
%     DIVIDERWIDTH : width in pixels of dividing strip
%     CALLBACK :     Callback string executed after a resize
%     LEFT/TOP :     set object in left/top pane
%     RIGHT/BOTTOM : set object in right/top pane
%     OUTERBORDER :  [N E S W] outside border of layout
%                    Note this property is obsolete: use the container
%                    BORDER property instead.
%     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.
%     MINWIDTHUNITS : Units for minimum width settings: either 'pixels'
%                     or 'normalized'.

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



norepack = 1;

if ~isa(obj,'xregsplitlayout')
   builtin('set',obj,varargin{:});
else
   ud=obj.datastore.info;
   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 'RESIZABLE'
         ud = setResize(obj,ud,value);
      case 'ORIENTATION'
         ud = setOrientation(value,ud);
      case 'DIVIDERSTYLE'
         ud = setDividerStyle(obj,value,ud);
      case 'DIVIDERWIDTH'
         ud.divwidth=value;
      case 'CALLBACK'
         ud.callbackstr=value;
         reqnorepack=1;
      case {'LEFT','TOP'}
         replace(obj.xregcontainer,value,1);
      case {'RIGHT','BOTTOM'}
         replace(obj.xregcontainer,value,2);
      case 'OUTERBORDER'
         % convert to 'border' type inputs
         value=value(end:-1:1);
         set(obj.xregcontainer,'border',value);
      case {'LEFTINNERBORDER','TOPINNERBORDER'}
         if isnumeric(value) && length(value(:))==4
            ud.innerborderl=value(:)';
         end
      case {'RIGHTINNERBORDER','BOTTOMINNERBORDER'}
         if isnumeric(value) && length(value(:))==4
            ud.innerborderr=value(:)';
         end
      case 'VISIBLE'
         [ud,reqnorepack] = setVisible(obj,ud,value);
      case 'MINWIDTH'
         ud.minwidth=value;
      case 'MINWIDTHUNITS'
         ud = setMinWidthUnits(obj,value,ud);
      otherwise
         [obj.xregcontainer, reqnorepack] = set(obj.xregcontainer,parameter,value);
      end
      norepack=(norepack & reqnorepack);
   end
   obj.datastore.info=ud;
   
   if ~norepack && get(obj,'boolpackstatus')
      repack(obj);
   end
end





function i_doResizerVis(obj,vis)

if ~strcmp(vis,get(obj.rsbutton,'Visible'))
   set(obj.rsbutton,'Visible',vis);
   fig=get(obj,'Parent');
   MM=MotionManager(fig);
   if strcmp(vis,'on')
      MM.RegisterManager(obj.PointerRegion);    
   else
      MM.UnregisterManager(obj.PointerRegion);  
   end
end

function ud = setPosition(obj,value,ud)
position=value;
if position(3) <= 0
   position(3) = 1;
end
if position(4) <= 0
   position(4) = 1;
end
% check new position against minimum split positions
minw=ud.minwidth;
if any(minw)
   if ud.orientation
      sz=position(4);
   else
      sz=position(3);
   end
   % check to see if split needs changing
   if strcmp(ud.minwidthunits,'normalized')
      minw=minw.*sz;
   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
set(obj.xregcontainer,'Position',position);

function ud = setSplit(obj,value,ud)
% normalise values
value=value./sum(value);
% 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
   % check to see if split needs changing
   if strcmp(ud.minwidthunits,'pixels')
      minw=minw./sz;
   end
   
   violation=value<minw;
   if any(violation) && ~all(violation)
      pane=find(violation);
      otherpane= ~violation;
      value(pane)=minw(pane);
      value(otherpane)=1-value(pane);
   end
end
ud.split=value;

function ud = setResize(obj,ud,value)
rsnow=ud.resizable;
ud.resizable=find( strncmpi( value,{ 'off'; 'on' },length(value) ) )-1;
if (rsnow~=ud.resizable) && ud.resizable && ud.visible
   i_doResizerVis(obj,'on');
else
   i_doResizerVis(obj,'off');
end

function ud = setOrientation(value,ud)
if strcmpi(value,'lr')
   ud.orientation=0;
elseif strcmpi(value,'ud')
   ud.orientation=1;
end

function [ud,reqnorepack] = setVisible(obj,ud,value)
if ~ud.resizable
   % keep button off
   vis='off';
else
   vis=value;
end
ud.visible=find( strncmpi( value,{ 'off'; 'on' },length(value) ) )-1;
i_doResizerVis(obj,vis);
% iterate over elements
el=get(obj.xregcontainer,'elements');
for k=1:length(el)
   set(el{k},'Visible',value);
end
reqnorepack=1;

function ud = setMinWidthUnits(obj,value,ud)
if any(strcmp(value,{'pixels','normalized'}))
   if ~strcmp(value,ud.minwidthunits)
      ud.minwidthunits=value;
      % convert minwidth values
      pos=get(obj,'Position');
      if ud.orientation
         pos=pos(4);
      else
         pos=pos(3);
      end
      if strcmp(ud.minwidthunits,'pixels')
         ud.minwidth=ud.minwidth.*pos;
      else
         ud.minwidth=ud.minwidth./pos;
      end
   end
end

function ud = setDividerStyle(obj,value,ud)
if strcmpi(value,'flat')
   set(obj.rsbutton,'Style','text');
   ud.divstyle=0;
elseif strcmpi(value,'3d')
   set(obj.rsbutton,'Style','pushbutton');
   ud.divstyle=1;
end