function varargout=propedit(h,varargin)
%PROPEDIT  Graphical property editor
%   PROPEDIT edits all properties of any selected HG object through the 
%   use of a graphical interface.  PROPEDIT(HandleList) edits the 
%   properties for the object(s) in HandleList.  If HandleList is omitted,
%   the property editor will edit the current figure.
%
%   Launching the property editor will enable plot editing for the figure.
%
%   See also PLOTEDIT

%   Karl Critz
%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.124 $ $Date: 2000/06/14 20:54:47 $

%  PROPEDIT(HandleList,'-noselect') will not put selection handles around
%   the objects or update the SCRIBE internal list of selected handles.  Be
%   careful using this - it is really only intended to be used if you have already
%   used SCRIBE to select the object.
%
%  PROPEDIT(HandleList,'-noopen') will not force the property editor to open.
%   If the property editor has not been opened yet or is invisible, it will
%   not pop open.
%
%  PROPEDIT(HandleList,'-tTABNAME') will open the property editor to the
%   requested tab.  Note that TABNAME is case sensitive and may be affected by
%   internationalization.
%
%  WARNSTR = PROPEDIT(...) will return warning messages as a string instead of
%   calling the warning command.

noOpen=any(strcmpi(varargin,'-noopen'));

noSelect=any(strcmpi(varargin,'-noselect'));

matchedTab = strmatch('-t',varargin);
if length(matchedTab)>0
    tabName=varargin{matchedTab(1)};
    tabName=tabName(3:end);
else
    tabName='';
end
    

if nargin<1
    h=get(0,'currentfigure');
    if isempty(h)
        h=0;
        currentFigure = [];
    else
        currentFigure = h;
    end
else
    currentFigure = [];
    h=unique(double(h(ishandle(h))));
end

if ~isempty(h)
    if (~usejava('mwt')) 
        r11propedit(h,noOpen,noSelect);
    else
        if ~isempty(currentFigure)
            prevCursor = get(currentFigure, 'pointer');
            set(currentFigure,'pointer','watch')
        end

        a = requestJavaAdapter(h);
        com.mathworks.ide.inspector.Inspector.inspectIfOpen(a);

        com.mathworks.page.propertyeditor.PropertyEditor.edit(h,...
            ~noSelect, ~noOpen, tabName);
        
        
        if ~isempty(currentFigure) & ...
            ishandle(currentFigure) & ...
            strcmp(get(currentFigure,'Pointer'),'watch')
            %if another application has changed the pointer, don't reset
            set(currentFigure,'pointer',prevCursor)
        end
    end
    warnStr='';
else
    warnStr='No valid objects passed to propedit';
end

if nargout>0
    varargout{1}=warnStr;
elseif ~isempty(warnStr)
    warning(warnStr);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function r11propedit(h,noOpen,noSelect)


if ~noSelect
    jpropeditutils('jselect',h);    
end

h=h(1); %panels can't handle multi-select
if ~noOpen
    switch get(h,'type')
    case 'line'
        scribelinedlg(scribehandle(getorcreateobj(h)));
    case 'axes'
        scribeaxesdlg(scribehandle(getorcreateobj(h)));
    case 'text'
        scribetextdlg(scribehandle(getorcreateobj(h)));
    otherwise
        %do nothing - no M property editor available
	warning('No property editor available');
    end
end
