function thisrender(this, varargin)
%RENDER Render the Sampling Frequency Specifier

%   Author(s): J. Schickler
%   Copyright 1988-2011 The MathWorks, Inc.

frpos = parserenderinputs(this, varargin{:});

sz   = gui_sizes(this);
bgc  = get(0,'DefaultUicontrolBackgroundColor');
hFig = get(this,'FigureHandle');
cbs  = siggui_cbs(this);

if isempty(frpos), frpos = [10 10 160 sz.uh*3+sz.uuvs]*sz.pixf; end

% Title Position
pos = [frpos(1)+5 frpos(2)+frpos(4)-sz.uh frpos(3)-sz.hfus sz.uh];

h.fstitle = uicontrol(hFig,...
    'Style',              'text',...
    'Position',           pos,...
    'Visible',            'Off',...
    'String',             getString(message('signal:sigtools:siggui:SamplingFrequency1')),...
    'Tag',                'fsspecifier_title',...
    'HorizontalAlignment','left');

% Label Position
lbl = getString(message('signal:sigtools:siggui:Units'));
pos(3) = largestuiwidth ({lbl});
pos(2) = pos(2)-sz.uh;

h.units_lbl = uicontrol(hFig,...
    'Style',               'text',...
    'Position',            pos,...
    'Visible',             'Off',...
    'String',              lbl, ...
    'Tag',                 'fsspecifier_popup_lbl',...
    'HorizontalAlignment', 'right');

pos(2) = pos(2) - sz.uh - sz.uuvs;
h.value_lbl = uicontrol(hFig,...
    'Style',               'text',...
    'Position',            pos,...
    'Visible',             'Off',...
    'String',              'Fs:',...
    'Tag',                 'fsspecifier_editbox_lbl',...
    'HorizontalAlignment', 'right');

pos    = get(h.units_lbl, 'Position');
pos(1) = pos(1)+pos(3)+sz.uuhs;
pos(3) = 113*sz.pixf;

if pos(3) + pos(1) > frpos(1)+frpos(3)
    pos(3) = frpos(3)-pos(1)+frpos(1);
end

% Untranslated and translated strings
strU = set(this,'Units');
strT = getTranslatedStringcell('signal:siggui:labelsandvalues:updateuis',strU);

h.units = uicontrol(hFig, ...
    'Style',           'popup', ...
    'BackgroundColor', 'White', ...
    'Position',        pos,...
    'String',          strT, ...
    'Tag',             'fsspecifier_popup', ...
    'Visible',         'Off', ...
    'Callback',        {cbs.property, this, 'units', 'change Fs units'});

% Save untranslated strings in the app data for use in the callback  
setappdata(h.units, 'PopupStrings', strU);

% Edit box position
pos(2) = pos(2) - sz.uh - sz.uuvs;

h.value = uicontrol(hFig,...
    'Style',               'edit',...
    'BackgroundColor',     'white',...
    'Position',            pos,...
    'Tag',                 'fsspecifier_editbox',...
    'Visible',             'Off',...
    'String',              this.Value,...
    'HorizontalAlignment', 'left',...
    'Callback',            {cbs.property, this, 'value', 'change Fs'});

set(this,'Handles',h)

wrl = handle.listener(this, [this.findprop('Units') this.findprop('Value')], ...
        'PropertyPostSet', @lclprop_listener);
set(wrl,'CallbackTarget',this);
set(this,'WhenRenderedListeners',wrl);

prop_listener(this, 'units');

setupenablelink(this, 'units', {'hz', 'khz','mhz','ghz'}, 'value');

% -------------------------------------------------------------------------
function lclprop_listener(this, eventData)

prop_listener(this, eventData);

% [EOF]
