Professional Documents
Culture Documents
Jcontrol
Jcontrol
persistent TransparencyFlag;
if nargin==0
% Default constructor
obj.hgcontrol=[];
obj.hghandle=[];
obj.hgcontainer=[];
obj.uipanel=[];
obj=class(orderfields(obj),'jcontrol');
return
elseif nargin==1
switch lower(Parent)
case 'usetransparency'
TransparencyFlag=true;
case 'notransparency'
TransparencyFlag=false;
end
return
end
if isempty(TransparencyFlag)
TransparencyFlag=true;
end
obj.uipanel=[];
% Check parent
if ishandle(Parent) && Parent==0
% Root as parent - create a figure and panel
fh=figure('MenuBar','none');
%obj.uipanel=createuipanel(fh, varargin{:});
container=fh;
elseif strcmp(class(Parent),'jcontrol')
% Jcontrol - use its existing uipanel
% Note this will be removed in a future version - do not parent
% jcontrols by other jcontrols
warning('JCONTROL:obsolete', 'Using a jcontrol as a parent of a jcontrol will
become obsolete in a future version');
if isempty(Parent.uipanel) || isstruct(Parent.uipanel)
container=ancestor(Parent.hgcontainer, 'uipanel');
else
container=Parent.uipanel;
end
elseif strcmp(class(Parent),'hgjavacomponent')
% Jcontrol hgcontainer - get the uipanel from the hgcontrol
% Note this will be removed in a future version - do not parent
% jcontrols by other jcontrols
warning('JCONTROL:obsolete', 'Using an hgjavacomponent as a parent of a
jcontrol will become obsolete in a future version');
container=get(get(Parent, 'UserData'),'uipanel');
% Modified 05.11.08
elseif ishandle(Parent) && strcmpi(get(Parent, 'Type'),'uipanel')
% Uipanel provided explicitly so use it
container=Parent;
set(Parent, 'BorderType', 'none');
elseif ishandle(Parent) && strcmpi(get(Parent,'Type'), 'uitab')
container=Parent;
elseif ishandle(Parent) && strcmpi(get(Parent,'Type'), 'figure')
% Create an empty uipanel for subsequent calls to jcontrol with this
% jcontrol as parent
obj.uipanel=createuipanel(Parent, varargin{:});
container=Parent;
else
% Use anything the user specifies.
obj.uipanel=[];
container=Parent;
end
if isempty(container) || ishandle(container)==0
error('Invalid target for jcontrol');
end
% Java object
if ischar(Style)
% Create a default object
javaobject=javaObject(Style);
elseif isjava(Style)
% or use supplied object
javaobject=Style;
elseif iscell(Style)
javaobject=Style{1}(Style{2:end});
elseif isa(Style, 'function_handle')
javaobject=Style();
end
% Default to normalized
set(obj, 'Units','normalized');
return
end