function txtobj = axistext(x,y,str,varargin)
%AXISTEXT/AXISTEXT Make axistext object
%   This file is an internal helper function for plot annotation.

%   Copyright 1984-2011 The MathWorks, Inc.

if nargin==0
   txtobj.Class = 'axistext';
   txtobj.Notes = [];
   txtobj = class(txtobj,'axistext',axischild);
   return
end

if nargin == 1
   HG = x;
   if any(ishghandle(getobj(HG)))
      return
   end
else
   HG = text(x,y,str);
   set(HG,varargin{:});
end

axischildObj = axischild(HG);
% enable dragging for text objects
axischildObj = set(axischildObj,'DragConstraint','');
set(HG,'CreateFcn','');
setappdata(HG,'ScribeButtonDownFcn','doclick');

txtobj.Class = 'axistext';
txtobj.Notes = [];

txtobj = class(txtobj,'axistext',axischildObj);

fig = get(get(HG,'Parent'),'Parent');
u = findall(fig,'Tag','ScribeAxistextObjContextMenu');

if any(ishghandle(u))
   if length(u)>1
       warning(message('MATLAB:axistext:RedundantContext'))
   end
   % set(HG,'UIContextMenu',u(1));
   setscribecontextmenu(HG,u(1));
else
   u = uicontextmenu(...
           'Parent',fig,...
           'Serializable','off', ...
           'HandleVisibility','off',...
           'Callback','domymenu update',...
           'Tag','ScribeAxistextObjContextMenu');

   % set(HG,'UIContextMenu',u);
   setscribecontextmenu(HG,u);
   
   ucut = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Cut')),...
           'Callback', 'domymenu cut',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjCutMenu');
   ucopy = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Copy')),...
           'Callback', 'domymenu copy',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjCopyMenu');
   upaste = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Paste')),...
           'Callback', 'domymenu paste',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjPasteMenu');
   uclear = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Clear')),...
           'Callback', 'domymenu clear',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjClearMenu');

   u0 = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:String')),...
           'Callback', 'domymenu string',...
           'Separator', 'on',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjStringMenu');
   u1 = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:FontSize')),...
           'Callback', 'domymenu size',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjSizeMenu');
   u2 = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:FontStyle')),...
           'Callback', 'domymenu style',...        
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjStyleMenu');
   u3 = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Color')),...
           'Callback', 'domymenu color',...        
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjColorMenu');
   u4 = uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Properties')),...
           'Callback', 'domymenu font',...
           'Enable','on',...
           'Separator','on',...
           'Parent',u,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjMoreMenu');

   sizes = [4 6 8 9 10 11 12 14 18 24 32];
   for i = 1:length(sizes)
      val = num2str(sizes(i));
      uimenu(...
           'Label',val,...
           'Callback', ['domymenu size ' val],...        
           'Parent',u1,...
           'HandleVisibility','off',...
           'Tag',['ScribeEditlineObjSizeMenu' val]);
   end
   u1more = uimenu(...
           'Label', getString(message('MATLAB:uistring:axistext:More')),...
           'Callback', 'domymenu font',...
           'Enable','on',...
           'Parent',u1,...
           'HandleVisibility','off',...
           'Tag','ScribeEditlineObjSizeMenuMore');
   
   u21 =  uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Normal')),...
           'Callback', 'domymenu style normal',...        
           'Parent',u2,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjStyleMenuNormal');
   u22 =  uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Italic')),...
           'Callback', 'domymenu style italic',...
           'Parent',u2,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextdObjStyleMenuItalic');
   u23 =  uimenu(...
           'Label',getString(message('MATLAB:uistring:axistext:Bold')),...
           'Callback', 'domymenu style bold',...        
           'Parent',u2,...
           'HandleVisibility','off',...
           'Tag','ScribeAxistextObjStyleMenuBold');

end

