Home > m > gui > @jcontrol > subsasgn.m

subsasgn

PURPOSE ^

SUBSASGN method overloaded for JCONTROL class

SYNOPSIS ^

function obj=subsasgn(obj, index, val)

DESCRIPTION ^

 SUBSASGN method overloaded for JCONTROL class

 subsasgn provides access to JCONTROL properties via MATLAB's dot notation
 Examples:
 obj.Units='characters';
 obj.Enabled=1
 obj.hgcontainer.Opaque='on'

 obj may be an element of a JCONTROL vector e.g.
 obj(3).Units='pixels';

 See also: jcontrol
 -------------------------------------------------------------------------
 Author: Malcolm Lidierth 06/07
 Copyright  The Author & King's College London 2007
 -------------------------------------------------------------------------

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function obj=subsasgn(obj, index, val)
0002 % SUBSASGN method overloaded for JCONTROL class
0003 %
0004 % subsasgn provides access to JCONTROL properties via MATLAB's dot notation
0005 % Examples:
0006 % obj.Units='characters';
0007 % obj.Enabled=1
0008 % obj.hgcontainer.Opaque='on'
0009 %
0010 % obj may be an element of a JCONTROL vector e.g.
0011 % obj(3).Units='pixels';
0012 %
0013 % See also: jcontrol
0014 % -------------------------------------------------------------------------
0015 % Author: Malcolm Lidierth 06/07
0016 % Copyright  The Author & King's College London 2007
0017 % -------------------------------------------------------------------------
0018 
0019 % Note: Left-hand assignments are not needed with dot assignments
0020 % because both the hgcontainer and the hgcontrol are passed by reference
0021 % rather than by value.
0022 % With () calls, left-hand assignments are needed when initializing an
0023 % element. In these cases the caller workspace will contain a reference to
0024 % the JCONTROL set up by subsasgn or passed to subsasgn by MATLAB in val.
0025 % In all cases, changes here to JCONTROL properties affect the original
0026 % JCONTROL contents, and all copies of them in all MATLAB workspaces.
0027 
0028 switch index(1).type
0029     case '.'
0030         switch lower(index(1).subs)
0031             case {'hgcontainer' 'hgcontrol' 'hghandle'}
0032                 if length(index)==1 || strcmp(index(1).subs,'hghandle')
0033                     error('The %s property is not settable',index(1).subs);
0034                 else
0035                     subsasgn(obj.(index(1).subs), index(2:end), val);
0036                 end
0037             otherwise
0038                 % obj.property/method where the property could be in hgcontainer
0039                 % or hgcontrol. Find out which and invoke appropriate subsasgn
0040                 if isprop(obj.hgcontainer, index(1).subs) &&...
0041                         isprop(obj.hgcontrol, index(1).subs)
0042                     if strcmpi(index(end).subs,'visible')
0043                         % Set Visible property in the container, MATLAB will
0044                         % update the hgcontrol
0045                         obj.hgcontainer.Visible=VisibleProperty(val);
0046                         return
0047                     else
0048                     error('Shared property name ''%s''\nYou must explicitly specify the target object',...
0049                         index(1).subs);
0050                     end
0051                 end
0052                 if isprop(obj.hgcontainer, index(1).subs)
0053                     % hgcontainer property
0054                     subsasgn(obj.hgcontainer, index, val);
0055                 elseif isprop(obj.hgcontrol, index(1).subs) || ismethod(obj.hgcontrol,index(1).subs)
0056                     % hgcontrol property or method
0057                     subsasgn(obj.hgcontrol, index, val);
0058                 else
0059                     error('No such property or method');
0060                 end
0061         end
0062     case '()'
0063         % obj is empty so initialize
0064         if isempty(obj)
0065             % Assign first element - avoids conversion to double errors
0066             % when initializing with subscripts
0067             obj=jcontrol();
0068             % Set the target element - need not already exist
0069             obj(index(1).subs{1})=val;
0070             return
0071         end
0072 
0073         if strcmp(class(val),'jcontrol')
0074             % Initializing or adding element to an array
0075             obj(index(1).subs{1})=val;
0076         else
0077             % Assigning field to pre-existing element
0078             if isvector(obj) && length(index(1).subs)==1 &&...
0079                     index(1).subs{1}<=length(obj)
0080                 subsasgn(obj(index(1).subs{1}), index(2:end), val);
0081             elseif ~isvector(obj) || length(index(1).subs)>1
0082                 error('Scalar or vector JCONTROL and index required on input');
0083             elseif index(1).subs{1}>length(obj)
0084                 error('Index exceeds length of JCONTROL vector');
0085             end
0086         end
0087 end
0088 return
0089 end
0090

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003