www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/+mbcgui/+util/isComponentHandle.m

    function ret = isComponentHandle(H)
%ISCOMPONENTHANDLE Check whether the argument is a valid component handle
%
%   ISCOMPONENTHANDLE(H) checks whether H contains a valid scalar handle
%   for a component in MBC.  Valid components may be either:
%      (1) A V5 Matlab OOPS object
%      (2) A valid UDD handle
%      (3) A valid MCOS handle object that derives from
%          mbcgui.widget.Component
%      (4) An HG handle
%
%   Note that if H contains a structure-based Matlab object, it is not
%   possible to ascertain whether the object is still valid or whether it
%   has been "deleted".  In this case it is always assumed to be valid.

%   Copyright 2008-2013 The MathWorks, Inc.

% The following input types need to be separated out:
%      TYPE                         RETURN
%   1 Not scalar                      0
%   2 Not-an-object                   0
%   3 Valid HG handle                 1
%   4 Valid MBC MCOS handle           1
%   5 Invalid MBC MCOS handle         0
%   6 Other MCOS (value/handle)       0
%   7 Valid UDD                       1
%   8 Deleted UDD                     0
%   9 Struct OOPS                     1
%   10 Java                           0
%   11 handle(Java)                   0

% Filter 10: standard java objects
ret = ~isjava(H);
if ~ret
    return
end

% Filter 1
try
    % We need a special-case for xregtable; this has a size method that
    % means it is not scalar.
    ret = isa(H, 'xregtable') || isscalar(H);
catch E
    % Anything that cannot execute isscalar is not a component
    ret = false;
end
if ~ret
    return
end

% Filter 3
ret = isgraphics(H);
if ret
    return
end

if isobject(H)  % 4, 5, 6, 9
    % MCOS or struct-type object
    ret = (isa(H, 'mbcgui.widget.Component') && isvalid(H)) ... % MCOS widget
        || isempty(metaclass(H));                               % Struct-style object

else % 2, 7, 8, 11
    % Filter for 7 and 11
    ret = ishandle(H);
    if ~ret
        return
    end
    
    % Check for common UDD handle classes that are not MBC.  Java handles
    % can appear here if they have had handle() called on them
    c = class(H);
    ret = ~strncmp(c, 'java', 4);
end