Home > m > gui > @jcontrol > subsref.m

subsref

PURPOSE ^

SUBSREF method overloaded for jcontrol class

SYNOPSIS ^

function ret=subsref(obj, index)

DESCRIPTION ^

 SUBSREF method overloaded for jcontrol class

 subsref provides access to jcontrol properties via MATLAB's dot notation
 Examples:
 obj.hgcontainer
 obj.hgcontrol.Name

 subsref also provides access to the java component's methods
 Example:
 obj.setToolTipText('MyText');
 a=obj.getToolTipText();

 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:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function ret=subsref(obj, index)
0002 % SUBSREF method overloaded for jcontrol class
0003 %
0004 % subsref provides access to jcontrol properties via MATLAB's dot notation
0005 % Examples:
0006 % obj.hgcontainer
0007 % obj.hgcontrol.Name
0008 %
0009 % subsref also provides access to the java component's methods
0010 % Example:
0011 % obj.setToolTipText('MyText');
0012 % a=obj.getToolTipText();
0013 %
0014 % See also: jcontrol
0015 %
0016 % -------------------------------------------------------------------------
0017 % Author: Malcolm Lidierth 07/07
0018 % Copyright  The Author & King's College London 2007
0019 % -------------------------------------------------------------------------
0020 
0021 % Revisions:
0022 % 21.08.07    Methods now called properly when index(1).subs=='hgcontrol'.
0023 %             Previously subsref(obj.hgcontrol,...) was called from here with
0024 %             index(1:end) instead of index(2:end).
0025 % 21.08.07    Tests nargout before calling hgcontrol methods. No output is
0026 %             requested if nargout==0. This prevents "One or more output
0027 %             arguments not assigned..." errors being generated internally
0028 %             e.g calling setXXXX calls. These errors will still be generated
0029 %             (as they should)if an output is requested when none is
0030 %             available. See 09.09.07 below.
0031 % 09.09.07    Improve above fix with try/catch blocks. Now getXXXX calls
0032 %             return in ans if nargout==0
0033 % 20.09.07    Nest try/catch blocks to reduce isprop() and ismethod()
0034 %             calls. This is substantially faster.
0035 
0036 switch index(1).type
0037     case '.'
0038         switch lower(index(1).subs)
0039             case 'hgcontainer'
0040                 if length(index)==1
0041                     % obj.hgcontainer
0042                     ret=obj.hgcontainer;
0043                 elseif isprop(obj.hgcontainer, index(2).subs)
0044                     % obj.hgcontainer.property
0045                     ret=subsref(obj.hgcontainer,index(2:end));
0046                 elseif isempty(obj.hgcontainer)
0047                     % Empty default object?
0048                     ret=[];
0049                 else
0050                     % Otherwise no property with this name
0051                     error('No appropriate property %s',index(2).subs);
0052                 end
0053             case 'hgcontrol'
0054                 if length(index)==1
0055                     % obj.hgcontrol
0056                     ret=obj.hgcontrol;
0057                 else
0058                     try
0059                         ret=subsref(obj.hgcontrol, index(2:end));
0060                     catch
0061                         try
0062                             CheckErr();
0063                             subsref(obj.hgcontrol, index(2:end));
0064                         catch
0065                             if isempty(obj.hghandle)
0066                                 % Maybe subsref failed because obj has
0067                                 % empty properties
0068                                 ret=[];
0069                             elseif ~isprop(obj.hghandle, index(2).subs) &&...
0070                                     ~ismethod(obj.hghandle, index(2).subs)
0071                                 error('jcontrol:subsref: No such property or method');
0072                             else
0073                                 error('jcontrol:subsref: Unexpected error');
0074                             end
0075                         end
0076                     end
0077                 end
0078             case 'hghandle'
0079                 ret=obj.hghandle;
0080             otherwise
0081                 % obj.property/method where the property could be in hgcontainer
0082                 % or hgcontrol. Find out which and invoke subsref
0083                 % recursively
0084                 if isprop(obj.hgcontainer, index(1).subs) &&...
0085                         isprop(obj.hgcontrol, index(1).subs)
0086                     % Visible is an exception -  take this from the container, MATLAB
0087                     % links this property for the container and object
0088                     if strcmpi(index(1).subs,'visible')
0089                         ret=obj.hgcontainer.Visible;
0090                         return
0091                     else
0092                     error('Shared property name ''%s''\nYou must explicitly specify the target object',...
0093                         index(1).subs);
0094                     end
0095                 end
0096 
0097                 if isprop(obj.hgcontainer, index(1).subs)
0098                     % hgcontainer property
0099                     ret=subsref(obj.hgcontainer, index);
0100                 else
0101                     % hgcontrol property or method?
0102                     try
0103                         ret=subsref(obj.hgcontrol, index);
0104                     catch
0105                         try
0106                             CheckErr();
0107                             subsref(obj.hgcontrol, index);
0108                         catch
0109                             if isempty(obj.hghandle)
0110                                 % Maybe subsref failed because obj has
0111                                 % empty properties
0112                                 ret=[];
0113                             elseif ~isprop(obj.hghandle, index(1).subs) &&...
0114                                     ~ismethod(obj.hghandle, index(1).subs)
0115                                 error('jcontrol:subsref: No such property or method');
0116                             else
0117                                 error('jcontrol:subsref: Unexpected error');
0118                             end
0119                         end
0120                     end
0121                 end
0122         end
0123     case '()'
0124         % array of jcontrols
0125         if length(index)==1
0126             % One or more elements or a JCONTROL array/matrix wanted
0127             ret=obj(index(1).subs{:});
0128         else
0129             obj=obj(index(1).subs{:});
0130             if numel(obj)==1
0131                 ret=subsref(obj, index(2:end));
0132             else
0133                 error('Single element of ''%s'' must be specified', inputname(1));
0134             end
0135         end
0136 end
0137 return
0138 end
0139 
0140 %-------------------------------------------------------------------------
0141 function CheckErr()
0142 % CheckErr checks that the exception has been thrown for the expected
0143 % reason - if not rethrow it.
0144 err=lasterror();
0145 if strcmp(err.identifier,'MATLAB:unassignedOutputs');
0146     return
0147 else
0148     rethrow(err);
0149 end
0150 return
0151 end
0152 %-------------------------------------------------------------------------

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