Home > m > gui > @jcontrol > set.m

set

PURPOSE ^

SET method overloaded for JCONTROL class

SYNOPSIS ^

function varargout=set(varargin)

DESCRIPTION ^

 SET method overloaded for JCONTROL class

 Examples:
 set(obj,PropertyName, PropertyValue)
 set(obj, PropertyName1, Value1, PropertyName2, Value2....)

 The propertyname/valuename sequence can have an embedded cell array if
 that contains property/value pairs e.g
           standardvalues={'Units', 'normalized'}
           set(myobj, 'javax.swing.JPane',...
                      'ToolTipText','MyTip',...
                       standardvalues);
s
 Also:
 set(obj, s)
 set(obj, pn, pm)
 where s in a structure with fieldnames corresponding to property names
 and values corresponding to property values
 pn and pm and name/value cell vectors (note pm may not be a matrix)

 If obj is a vector of JCONTROLs, SET will act on each element.
 In this case, the specified properties must be present in all the 
 JCONTROLs or an error will result
 
 
 See also: jcontrol

 -------------------------------------------------------------------------
 Author: Malcolm Lidierth 07/07
 Copyright © The Author & King's College London 2007
 -------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout=set(varargin)
0002 % SET method overloaded for JCONTROL class
0003 %
0004 % Examples:
0005 % set(obj,PropertyName, PropertyValue)
0006 % set(obj, PropertyName1, Value1, PropertyName2, Value2....)
0007 %
0008 % The propertyname/valuename sequence can have an embedded cell array if
0009 % that contains property/value pairs e.g
0010 %           standardvalues={'Units', 'normalized'}
0011 %           set(myobj, 'javax.swing.JPane',...
0012 %                      'ToolTipText','MyTip',...
0013 %                       standardvalues);
0014 %s
0015 % Also:
0016 % set(obj, s)
0017 % set(obj, pn, pm)
0018 % where s in a structure with fieldnames corresponding to property names
0019 % and values corresponding to property values
0020 % pn and pm and name/value cell vectors (note pm may not be a matrix)
0021 %
0022 % If obj is a vector of JCONTROLs, SET will act on each element.
0023 % In this case, the specified properties must be present in all the
0024 % JCONTROLs or an error will result
0025 %
0026 %
0027 % See also: jcontrol
0028 %
0029 % -------------------------------------------------------------------------
0030 % Author: Malcolm Lidierth 07/07
0031 % Copyright © The Author & King's College London 2007
0032 % -------------------------------------------------------------------------
0033 
0034 % Note: The usual assignin(...) call is not needed here because both the
0035 % hgcontainer and the hgcontrol are passed by reference rather than by
0036 % value. Changes here affect the original JCONTROL contents, and all copies
0037 % of them in all MATLAB workspaces.
0038 
0039 obj=varargin{1};
0040 
0041 if nargin==1
0042     % Return setable properties
0043     s=set(obj.hgcontainer);
0044     s.hgcontrol=set(obj.hgcontrol);
0045     varargout{1}=s;
0046     return
0047 end
0048 
0049 % Otherwise make sure we have enough inputs
0050 if nargin==2 && isstruct(varargin{2})
0051     % Property/value pairs in structure
0052     % Get the names
0053     propnames=fieldnames(varargin{2});
0054     % get the values
0055     propvalues=cell(length(propnames),1);
0056     for i=1:length(propnames)
0057         propvalues{i}=varargin{2}.(propnames{i});
0058     end
0059     % Recursive call to set
0060     set(varargin{1}, propnames, propvalues);
0061     return
0062 elseif nargin==3 && iscell(varargin{2}) && iscell(varargin{3})
0063     % set(obj, pn, pm) where pn and pm are property and value cell vectors
0064     if numel(varargin{2})~=numel(varargin{3})
0065         error('Multiple values for each property not supported'); %#ok<ERTAG>
0066     end
0067     proplist=cell(1,2*length(varargin{2}));
0068     count=1;
0069     for i=1:length(varargin{2})
0070         proplist(count)=varargin{2}(i);
0071         proplist(count+1)=varargin{3}(i);
0072         count=count+2;
0073     end
0074 else
0075     % Allow cell arrays in the property/values pairs list
0076     % Expand these where present
0077     pcount=1;
0078     vcount=2;
0079     proplist={};
0080     for i=1:(length(varargin)-1)/2
0081         if ischar(varargin{vcount})
0082             % Property/Value pair
0083             proplist{pcount}=varargin{vcount};
0084             proplist{pcount+1}=varargin{vcount+1};
0085             pcount=pcount+2;
0086             vcount=vcount+2;
0087         elseif iscell(varargin{vcount})
0088             % Cell array
0089             proplist=[proplist varargin{vcount}]; %#ok<AGROW>
0090             pcount=length(proplist)+1;
0091             vcount=vcount+1;
0092         end
0093     end
0094 end
0095             
0096 % For loop allows vector (or matrix) of JCONTROLs on input but all elements
0097 % must have all the target properties or an error will be generated
0098 for idx=1:numel(obj)
0099     switch lower(proplist{1})
0100         case {'hgcontainer', 'hgcontrol' 'hghandle' 'Parent' 'Children'}
0101             error('The %s property of a jcontrol object can not be changed', lower(varargin{2}));
0102         otherwise
0103             for i=1:2:length(proplist)
0104                 property=proplist{i};
0105                 value=proplist{i+1};
0106                 if isprop(obj(idx).hgcontainer, property) &&...
0107                         isprop(obj(idx).hgcontrol, property)
0108                     if strcmpi(property,'Visible')
0109                         % Set Visible property in the container, MATLAB will
0110                         % update the hgcontrol
0111                         obj(idx).hgcontainer.Visible=VisibleProperty(value);
0112                         continue
0113                     else
0114                         error('Shared property name ''%s''\nYou must explicitly specify the target object',...
0115                         proplist{i});
0116                     end
0117                 end
0118                 if isprop(obj(idx).hgcontainer, property)
0119                     obj(idx).hgcontainer.(property)=value;
0120                 elseif isprop(obj(idx).hgcontrol, property)
0121                     obj(idx).hgcontrol.(property)=value;
0122                 else
0123                     error('No such property: ''%s'' in %s(%d)', property, inputname(1), idx);
0124                 end
0125             end
0126     end
0127 end
0128 return
0129 end

Generated on Mon 31-Mar-2008 21:41:00 by m2html © 2003