comparison m-toolbox/m/gui/@jcontrol/subsasgn.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function obj=subsasgn(obj, index, val)
2 % SUBSASGN method overloaded for JCONTROL class
3 %
4 % subsasgn provides access to JCONTROL properties via MATLAB's dot notation
5 % Examples:
6 % obj.Units='characters';
7 % obj.Enabled=1
8 % obj.hgcontainer.Opaque='on'
9 %
10 % obj may be an element of a JCONTROL vector e.g.
11 % obj(3).Units='pixels';
12 %
13 % See also: jcontrol
14 % -------------------------------------------------------------------------
15 % Author: Malcolm Lidierth 06/07
16 % Copyright © The Author & King's College London 2007
17 % -------------------------------------------------------------------------
18
19 % Note: Left-hand assignments are not needed with dot assignments
20 % because both the hgcontainer and the hgcontrol are passed by reference
21 % rather than by value.
22 % With () calls, left-hand assignments are needed when initializing an
23 % element. In these cases the caller workspace will contain a reference to
24 % the JCONTROL set up by subsasgn or passed to subsasgn by MATLAB in val.
25 % In all cases, changes here to JCONTROL properties affect the original
26 % JCONTROL contents, and all copies of them in all MATLAB workspaces.
27
28 switch index(1).type
29 case '.'
30 switch lower(index(1).subs)
31 case {'hgcontainer' 'hgcontrol' 'hghandle'}
32 if length(index)==1 || strcmp(index(1).subs,'hghandle')
33 error('The %s property is not settable',index(1).subs);
34 else
35 subsasgn(obj.(index(1).subs), index(2:end), val);
36 end
37 otherwise
38 % obj.property/method where the property could be in hgcontainer
39 % or hgcontrol. Find out which and invoke appropriate subsasgn
40 if isprop(obj.hgcontainer, index(1).subs) &&...
41 isprop(obj.hgcontrol, index(1).subs)
42 if strcmpi(index(end).subs,'visible')
43 % Set Visible property in the container, MATLAB will
44 % update the hgcontrol
45 obj.hgcontainer.Visible=VisibleProperty(val);
46 return
47 else
48 error('Shared property name ''%s''\nYou must explicitly specify the target object',...
49 index(1).subs);
50 end
51 end
52 if isprop(obj.hgcontainer, index(1).subs)
53 % hgcontainer property
54 subsasgn(obj.hgcontainer, index, val);
55 elseif isprop(obj.hgcontrol, index(1).subs) || ismethod(obj.hgcontrol,index(1).subs)
56 % hgcontrol property or method
57 subsasgn(obj.hgcontrol, index, val);
58 else
59 error('No such property or method');
60 end
61 end
62 case '()'
63 % obj is empty so initialize
64 if isempty(obj)
65 % Assign first element - avoids conversion to double errors
66 % when initializing with subscripts
67 obj=jcontrol();
68 % Set the target element - need not already exist
69 obj(index(1).subs{1})=val;
70 return
71 end
72
73 if strcmp(class(val),'jcontrol')
74 % Initializing or adding element to an array
75 obj(index(1).subs{1})=val;
76 else
77 % Assigning field to pre-existing element
78 if isvector(obj) && length(index(1).subs)==1 &&...
79 index(1).subs{1}<=length(obj)
80 subsasgn(obj(index(1).subs{1}), index(2:end), val);
81 elseif ~isvector(obj) || length(index(1).subs)>1
82 error('Scalar or vector JCONTROL and index required on input');
83 elseif index(1).subs{1}>length(obj)
84 error('Index exceeds length of JCONTROL vector');
85 end
86 end
87 end
88 return
89 end
90