Mercurial > hg > ltpda
comparison m-toolbox/m/gui/@jcontrol/subsref.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 ret=subsref(obj, index) | |
2 % SUBSREF method overloaded for jcontrol class | |
3 % | |
4 % subsref provides access to jcontrol properties via MATLAB's dot notation | |
5 % Examples: | |
6 % obj.hgcontainer | |
7 % obj.hgcontrol.Name | |
8 % | |
9 % subsref also provides access to the java component's methods | |
10 % Example: | |
11 % obj.setToolTipText('MyText'); | |
12 % a=obj.getToolTipText(); | |
13 % | |
14 % See also: jcontrol | |
15 % | |
16 % ------------------------------------------------------------------------- | |
17 % Author: Malcolm Lidierth 07/07 | |
18 % Copyright © The Author & King's College London 2007 | |
19 % ------------------------------------------------------------------------- | |
20 | |
21 % Revisions: | |
22 % 21.08.07 Methods now called properly when index(1).subs=='hgcontrol'. | |
23 % Previously subsref(obj.hgcontrol,...) was called from here with | |
24 % index(1:end) instead of index(2:end). | |
25 % 21.08.07 Tests nargout before calling hgcontrol methods. No output is | |
26 % requested if nargout==0. This prevents "One or more output | |
27 % arguments not assigned..." errors being generated internally | |
28 % e.g calling setXXXX calls. These errors will still be generated | |
29 % (as they should)if an output is requested when none is | |
30 % available. See 09.09.07 below. | |
31 % 09.09.07 Improve above fix with try/catch blocks. Now getXXXX calls | |
32 % return in ans if nargout==0 | |
33 % 20.09.07 Nest try/catch blocks to reduce isprop() and ismethod() | |
34 % calls. This is substantially faster. | |
35 | |
36 switch index(1).type | |
37 case '.' | |
38 switch lower(index(1).subs) | |
39 case 'hgcontainer' | |
40 if length(index)==1 | |
41 % obj.hgcontainer | |
42 ret=obj.hgcontainer; | |
43 elseif isprop(obj.hgcontainer, index(2).subs) | |
44 % obj.hgcontainer.property | |
45 ret=subsref(obj.hgcontainer,index(2:end)); | |
46 elseif isempty(obj.hgcontainer) | |
47 % Empty default object? | |
48 ret=[]; | |
49 else | |
50 % Otherwise no property with this name | |
51 error('No appropriate property %s',index(2).subs); | |
52 end | |
53 case 'hgcontrol' | |
54 if length(index)==1 | |
55 % obj.hgcontrol | |
56 ret=obj.hgcontrol; | |
57 else | |
58 try | |
59 ret=subsref(obj.hgcontrol, index(2:end)); | |
60 catch | |
61 try | |
62 CheckErr(); | |
63 subsref(obj.hgcontrol, index(2:end)); | |
64 catch | |
65 if isempty(obj.hghandle) | |
66 % Maybe subsref failed because obj has | |
67 % empty properties | |
68 ret=[]; | |
69 elseif ~isprop(obj.hghandle, index(2).subs) &&... | |
70 ~ismethod(obj.hghandle, index(2).subs) | |
71 error('jcontrol:subsref: No such property or method'); | |
72 else | |
73 error('jcontrol:subsref: Unexpected error'); | |
74 end | |
75 end | |
76 end | |
77 end | |
78 case 'hghandle' | |
79 ret=obj.hghandle; | |
80 otherwise | |
81 % obj.property/method where the property could be in hgcontainer | |
82 % or hgcontrol. Find out which and invoke subsref | |
83 % recursively | |
84 if isprop(obj.hgcontainer, index(1).subs) &&... | |
85 isprop(obj.hgcontrol, index(1).subs) | |
86 % Visible is an exception - take this from the container, MATLAB | |
87 % links this property for the container and object | |
88 if strcmpi(index(1).subs,'visible') | |
89 ret=obj.hgcontainer.Visible; | |
90 return | |
91 else | |
92 error('Shared property name ''%s''\nYou must explicitly specify the target object',... | |
93 index(1).subs); | |
94 end | |
95 end | |
96 | |
97 if isprop(obj.hgcontainer, index(1).subs) | |
98 % hgcontainer property | |
99 ret=subsref(obj.hgcontainer, index); | |
100 else | |
101 % hgcontrol property or method? | |
102 try | |
103 ret=subsref(obj.hgcontrol, index); | |
104 catch | |
105 try | |
106 CheckErr(); | |
107 subsref(obj.hgcontrol, index); | |
108 catch | |
109 if isempty(obj.hghandle) | |
110 % Maybe subsref failed because obj has | |
111 % empty properties | |
112 ret=[]; | |
113 elseif ~isprop(obj.hghandle, index(1).subs) &&... | |
114 ~ismethod(obj.hghandle, index(1).subs) | |
115 error('jcontrol:subsref: No such property or method'); | |
116 else | |
117 error('jcontrol:subsref: Unexpected error'); | |
118 end | |
119 end | |
120 end | |
121 end | |
122 end | |
123 case '()' | |
124 % array of jcontrols | |
125 if length(index)==1 | |
126 % One or more elements or a JCONTROL array/matrix wanted | |
127 ret=obj(index(1).subs{:}); | |
128 else | |
129 obj=obj(index(1).subs{:}); | |
130 if numel(obj)==1 | |
131 ret=subsref(obj, index(2:end)); | |
132 else | |
133 error('Single element of ''%s'' must be specified', inputname(1)); | |
134 end | |
135 end | |
136 end | |
137 return | |
138 end | |
139 | |
140 %------------------------------------------------------------------------- | |
141 function CheckErr() | |
142 % CheckErr checks that the exception has been thrown for the expected | |
143 % reason - if not rethrow it. | |
144 err=lasterror(); | |
145 if strcmp(err.identifier,'MATLAB:unassignedOutputs'); | |
146 return | |
147 else | |
148 rethrow(err); | |
149 end | |
150 return | |
151 end | |
152 %------------------------------------------------------------------------- |