Mercurial > hg > ltpda
comparison m-toolbox/m/gui/@jcontrol/set.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 varargout=set(varargin) | |
2 % SET method overloaded for JCONTROL class | |
3 % | |
4 % Examples: | |
5 % set(obj,PropertyName, PropertyValue) | |
6 % set(obj, PropertyName1, Value1, PropertyName2, Value2....) | |
7 % | |
8 % The propertyname/valuename sequence can have an embedded cell array if | |
9 % that contains property/value pairs e.g | |
10 % standardvalues={'Units', 'normalized'} | |
11 % set(myobj, 'javax.swing.JPane',... | |
12 % 'ToolTipText','MyTip',... | |
13 % standardvalues); | |
14 %s | |
15 % Also: | |
16 % set(obj, s) | |
17 % set(obj, pn, pm) | |
18 % where s in a structure with fieldnames corresponding to property names | |
19 % and values corresponding to property values | |
20 % pn and pm and name/value cell vectors (note pm may not be a matrix) | |
21 % | |
22 % If obj is a vector of JCONTROLs, SET will act on each element. | |
23 % In this case, the specified properties must be present in all the | |
24 % JCONTROLs or an error will result | |
25 % | |
26 % | |
27 % See also: jcontrol | |
28 % | |
29 % ------------------------------------------------------------------------- | |
30 % Author: Malcolm Lidierth 07/07 | |
31 % Copyright © The Author & King's College London 2007 | |
32 % ------------------------------------------------------------------------- | |
33 | |
34 % Note: The usual assignin(...) call is not needed here because both the | |
35 % hgcontainer and the hgcontrol are passed by reference rather than by | |
36 % value. Changes here affect the original JCONTROL contents, and all copies | |
37 % of them in all MATLAB workspaces. | |
38 | |
39 obj=varargin{1}; | |
40 | |
41 if nargin==1 | |
42 % Return setable properties | |
43 s=set(obj.hgcontainer); | |
44 s.hgcontrol=set(obj.hgcontrol); | |
45 varargout{1}=s; | |
46 return | |
47 end | |
48 | |
49 % Otherwise make sure we have enough inputs | |
50 if nargin==2 && isstruct(varargin{2}) | |
51 % Property/value pairs in structure | |
52 % Get the names | |
53 propnames=fieldnames(varargin{2}); | |
54 % get the values | |
55 propvalues=cell(length(propnames),1); | |
56 for i=1:length(propnames) | |
57 propvalues{i}=varargin{2}.(propnames{i}); | |
58 end | |
59 % Recursive call to set | |
60 set(varargin{1}, propnames, propvalues); | |
61 return | |
62 elseif nargin==3 && iscell(varargin{2}) && iscell(varargin{3}) | |
63 % set(obj, pn, pm) where pn and pm are property and value cell vectors | |
64 if numel(varargin{2})~=numel(varargin{3}) | |
65 error('Multiple values for each property not supported'); %#ok<ERTAG> | |
66 end | |
67 proplist=cell(1,2*length(varargin{2})); | |
68 count=1; | |
69 for i=1:length(varargin{2}) | |
70 proplist(count)=varargin{2}(i); | |
71 proplist(count+1)=varargin{3}(i); | |
72 count=count+2; | |
73 end | |
74 else | |
75 % Allow cell arrays in the property/values pairs list | |
76 % Expand these where present | |
77 pcount=1; | |
78 vcount=2; | |
79 proplist={}; | |
80 for i=1:(length(varargin)-1)/2 | |
81 if ischar(varargin{vcount}) | |
82 % Property/Value pair | |
83 proplist{pcount}=varargin{vcount}; | |
84 proplist{pcount+1}=varargin{vcount+1}; | |
85 pcount=pcount+2; | |
86 vcount=vcount+2; | |
87 elseif iscell(varargin{vcount}) | |
88 % Cell array | |
89 proplist=[proplist varargin{vcount}]; %#ok<AGROW> | |
90 pcount=length(proplist)+1; | |
91 vcount=vcount+1; | |
92 end | |
93 end | |
94 end | |
95 | |
96 % For loop allows vector (or matrix) of JCONTROLs on input but all elements | |
97 % must have all the target properties or an error will be generated | |
98 for idx=1:numel(obj) | |
99 switch lower(proplist{1}) | |
100 case {'hgcontainer', 'hgcontrol' 'hghandle' 'Parent' 'Children'} | |
101 error('The %s property of a jcontrol object can not be changed', lower(varargin{2})); | |
102 otherwise | |
103 for i=1:2:length(proplist) | |
104 property=proplist{i}; | |
105 value=proplist{i+1}; | |
106 if isprop(obj(idx).hgcontainer, property) &&... | |
107 isprop(obj(idx).hgcontrol, property) | |
108 if strcmpi(property,'Visible') | |
109 % Set Visible property in the container, MATLAB will | |
110 % update the hgcontrol | |
111 obj(idx).hgcontainer.Visible=VisibleProperty(value); | |
112 continue | |
113 else | |
114 error('Shared property name ''%s''\nYou must explicitly specify the target object',... | |
115 proplist{i}); | |
116 end | |
117 end | |
118 if isprop(obj(idx).hgcontainer, property) | |
119 obj(idx).hgcontainer.(property)=value; | |
120 elseif isprop(obj(idx).hgcontrol, property) | |
121 obj(idx).hgcontrol.(property)=value; | |
122 else | |
123 error('No such property: ''%s'' in %s(%d)', property, inputname(1), idx); | |
124 end | |
125 end | |
126 end | |
127 end | |
128 return | |
129 end |