function frH = framewlabel(frameParentH,framePos,label,tag,bgc)
% FRAMEWLABEL Creates a frame with the specified label.
%
% To create a frame without a label specify an empty string ('') for the 
% input argument label.
%
% Inputs:
%    frameParentH - handle to the parent of the frame (figure handle).
%    framePos     - frame position [x y w h].
%    label        - label for the frame.
%    tag          - string for the frame's tag property.
%    bgc          - background color of the frame.
%
% Outputs:
%    frH - two element vector:
%          frH(1) - frame handle.
%          frH(2) - frame label handle.

%   Author(s): P. Pacheco
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.2 $  $Date: 2000/06/13 21:23:07 $ 

sz  = gui_sizes;
lfs = sz.lfs;   % label/frame spacing
tw  = sz.tw;    % text width
lh  = sz.lh;    % label height

labelPos = [framePos(1)+lfs framePos(2)+framePos(4)-lh/2 tw lh];

% Set up default background color in case color was not specified.
if nargin < 5,
	bgc = get(frameParentH,'color');
end
% Set up default tag in case tag was not specified.
if nargin < 4,
    tag = '';
end

frH(1) = uicontrol('Parent',frameParentH, ...
   'Style','frame',...
   'BackgroundColor',bgc,...
   'Position',framePos, ...
   'Tag',tag);

if nargin > 2  & ~isempty(label) % Label was specified
   frH(2) = uicontrol('Parent',frameParentH, ...
      'HorizontalAlignment','Center', ...
      'BackgroundColor',bgc,...
      'Position',labelPos, ...
      'String',label, ...
      'Style','text',...
      'Tag',tag,...
      'visible','off');
   
   frLabelExt = get(frH(2),'extent');
   textPos = get(frH(2),'Position');
   textPos = [textPos(1) textPos(2) frLabelExt(3) textPos(4)];
   set(frH(2),'Position',textPos,'visible','on');
end

% [EOF] framewlabel.m
