function noticeOK(varargin)
%noticeOK Message box.
%  noticeOK(Message) creates a message box that automatically wraps the
%  Message to fit an appropriately sized Figure.  Message is a string
%  vector, string matrix or cell array.
%
%  noticeOK(Message,Title) specifies the title of the message box.
%
%  noticeOK(Message, ... ,CreateMode) specifies whether the message box
%  is modal or non-modal.  Valid values for CreateMode are:
%  'modal' or 'non-modal'.  ('modal'= default)
  
%  Modeled after msgbox.m   12/'00


% Check input
%-------------------------------------------------------------------------
if nargin<1,error('Too few input arguments for noticeOK.');end  
  
BodyTextString=varargin{1};
if ~iscell(BodyTextString),BodyTextString=cellstr(BodyTextString);end

if strcmp(BodyTextString{1},'#FigKeyPressFcn'),
   AsciiVal= abs(get(get(0,'CurrentFigure'),'CurrentCharacter'));
   if ~isempty(AsciiVal),
      if AsciiVal==32 | AsciiVal==13,
         delete(get(0,'CurrentFigure'));
      end
   end
   return
end

if nargin>3, error('Too many input arguments for noticeOK.'); end
  
CreateMode='modal';
switch nargin,
  case 1,
    TitleString=' ';   
  case 2,
     if strcmp(lower(varargin{2}),'non-modal') | strcmp(lower(varargin{2}),'modal') 
        CreateMode = lower(varargin{2});
        TitleString = ' '; 
     else,
        TitleString = varargin{2};
     end     
  case 3,
     if strcmp(lower(varargin{3}),'non-modal') | strcmp(lower(varargin{3}),'modal')
        TitleString = varargin{2}; 
        CreateMode = lower(varargin{3});
     else
        error('Invalid string for "CreateMode" entered');
        help noticeOK;
        return;
     end
end  %switch
  

% Set positions
%-------------------------------------------------------------------------
DefFigPos=get(0,'DefaultFigurePosition');

MsgOff=7;
FigWidth=125;
MsgTxtWidth=FigWidth-2*MsgOff;
FigHeight=50;
DefFigPos(3:4)=[FigWidth FigHeight];

OKWidth=40;
OKHeight=20;
OKXOffset=(FigWidth-OKWidth)/2;
OKYOffset=MsgOff;

MsgTxtXOffset=MsgOff;
MsgTxtYOffset=MsgOff+OKYOffset+OKHeight;
MsgTxtHeight=FigHeight-MsgOff-MsgTxtYOffset;
MsgTxtForeClr='k';


% Create
%-------------------------------------------------------------------------

if strcmp(CreateMode,'modal'),
   WindowStyle='modal';
else,
   WindowStyle='normal';
end

BoxHandle=dialog(                               ...
   'Name'            ,TitleString             , ...
   'Pointer'         ,'arrow'                 , ...
   'Units'           ,'points'                , ...
   'Visible'         ,'off'                   , ...
   'KeyPressFcn'     ,'noticeOK #FigKeyPressFcn', ...
   'WindowStyle'     ,WindowStyle             , ...
   'Color'           ,[.92 .92 .97]           , ...
   'HandleVisibility','callback'                ...
   );


FigColor = [.92 .92 .97]; %get(BoxHandle,'Color');

MsgTxtBackClr=FigColor;

Font.FontUnits='points';
Font.FontSize=get(0,'FactoryUIControlFontSize');

OKHandle=uicontrol(BoxHandle, Font                         , ...
   'Style'              ,'pushbutton'                      , ...
   'Units'              ,'points'                          , ...
   'Position'           ,[ OKXOffset OKYOffset  ...
                           OKWidth   OKHeight   ...
                         ]                                 , ...
   'CallBack'           ,'delete(get(0,''CurrentFigure''))', ...
   'String'             ,'OK'                              , ...
   'BackgroundColor'    ,[.87 .8 .8]                       , ...
   'HorizontalAlignment','center'                          , ...
   'Tag'                ,'OKButton'                          ...
   );

MsgHandle=uicontrol(BoxHandle, Font     , ...
   'Style'              ,'text'         , ...
   'Units'              ,'points'       , ...
   'Position'           ,[MsgTxtXOffset   ...
                            MsgTxtYOffset ...
                            MsgTxtWidth   ...
                            MsgTxtHeight  ...
                         ]              , ...
   'String'             ,' '            , ...
   'HorizontalAlignment','left'         , ...    
   'BackgroundColor'    ,MsgTxtBackClr  , ...
   'ForegroundColor'    ,MsgTxtForeClr    ...
);


[WrapString,NewMsgTxtPos]=textwrap(MsgHandle,BodyTextString,75);
NumLines=size(WrapString,1);

MsgTxtWidth=max(MsgTxtWidth,NewMsgTxtPos(3))+45;
MsgTxtHeight=max(MsgTxtHeight,NewMsgTxtPos(4));

FigWidth=MsgTxtWidth+2*MsgOff;  
MsgTxtYOffset=OKYOffset+OKHeight+MsgOff;
FigHeight=MsgTxtYOffset+MsgTxtHeight+MsgOff;    

OKXOffset=(FigWidth-OKWidth)/2; 
DefFigPos(3:4)=[FigWidth FigHeight];

ScreenUnits=get(0,'Units');
set(0,'Units','points');
ScreenSize=get(0,'ScreenSize');
set(0,'Units',ScreenUnits);

DefFigPos(1)=(ScreenSize(3)-FigWidth)/2;
DefFigPos(2)=(ScreenSize(4)-FigHeight)/2;

set(BoxHandle,'Position',DefFigPos);
set(OKHandle,'Position',[OKXOffset OKYOffset OKWidth OKHeight]);  
  
delete(MsgHandle);
AxesHandle=axes('Parent',BoxHandle,'Position',[0 0 1 1],'Visible','off');

MsgHandle=text( ...
    'Parent'              ,AxesHandle                        , ...
    'Units'               ,'points'                          , ...
    'HorizontalAlignment' ,'left'                            , ...
    'VerticalAlignment'   ,'bottom'                          , ...
    'HandleVisibility'    ,'callback'                        , ...
    'Position'            ,[ MsgTxtXOffset MsgTxtYOffset+5 0], ...
    'String'              ,WrapString                        , ...
    'Interpreter'         ,'none'                            , ...
    'FontSize'            , 13                               , ...
    'FontWeight'          ,'normal'                            ...
    );

set(BoxHandle,'HandleVisibility','callback','Visible','on');






