function update_actionbtn(funcName,hFig)
%UPDATE_ACTIONBTN Updates the action button by setting it's label to 
%                 the correct string (i.e., Design, Import or Quantize),
%                 its width, and enable state.
%
% Inputs:
%   funcName - string containing the name of a local function.
%   hFig     - handle to fdatool's figure.

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

feval(funcName,hFig)

% Update the Undo Changes choice in the Filter menu.
update_menus('update_undochanges', hFig);

%-------------------------------------------------------------------------
function update_all(hFig)
%UPDATE_ALL Calls all relevant update functions to update the action button.

update_enablestate(hFig);   % Updates the enable state.
update_visstate(hFig);      % Updates the visibility state.

%-------------------------------------------------------------------------
function update_enablestate(hFig)
%UPDATE_ENABLESTATE Updates the enable state of the Apply button.
%
% Inputs:
%   hFig - handle to GUI's figure.

% Get the data structure stored in the figure & get the handle to the button.
ud = get(hFig,'Userdata');
h_btn = ud.h.actionFr.btn;

% Set enable state of Apply button based on whether the filter is current.
mode = ud.mode.current;
switch mode,
case 1, % Design
    filter_updated = ud.flags.filter_designed;
    
case 2, % Import
    % Don't disable the Import Filter button
    filter_updated = 0; % ud.flags.filter_imported;    
    
case 3, % Quantize
    if ud.flags.quantizationswitch,
        filter_updated = ud.flags.filter_quantized;
        
    else  % Disable the APPLY button when the whole tab is disabled.
        set(h_btn(mode),'Enable','off');
        set(ud.h.status.Text,'String','Select "Turn quantization on" to quantize the filter.');
        return; % No need to proceed.
    end
end

if ~filter_updated,
    % Enable the Apply button and update the status box.
    state = 'on';
    
    % Create status string based on the current mode.
    statusText = new_statusText(h_btn,mode);
    
    % Update the titlebar.
    update_titlebar(hFig);
else
    state = 'off';
    statusText = 'Ready';        
end
set(h_btn(mode),'Enable',state);
set(ud.h.status.Text,'String',statusText);

%-------------------------------------------------------------------------
function update_visstate(hFig)
%UPDATE_VISSTATE Updates the visibility state of the "Apply" buttons.
%
% Inputs:
%   hFig - handle to GUI's figure.

% Get the data structure stored in the figure & get the handle to the button.
ud = get(hFig,'Userdata');
mode = ud.mode.current;
h_btn = ud.h.actionFr.btn;

set(h_btn,'Visible','off');      % Set all "APPLY" buttons invisible.
set(h_btn(mode),'Visible','on'); % Set the correct "APPLY" btn visible.

%-------------------------------------------------------------------------
function statusText = new_statusText(h_btn,mode)
%NEW_STATUSTEXT Create the status text based on the current mode (tab).
%
% Inputs:
%   h_btn - handle to the "Apply" buttons.
%   mode  - integer indicating the current mode (tab).

% GUI can be in one of the following three modes (tabs):
%    1 - Filter Design Mode [default]
%    2 - Import Filter (Specify Coefficients) Mode 
%    3 - Quantize Coefficients Mode

btnLabel = get(h_btn(mode),'String'); % Get the label of the button.
statusText = ['Click ', btnLabel];
switch mode
case 1,
    statusText = [statusText, ' to design the filter and update the plot.'];
case 2,
    statusText = [statusText, ' to import the filter and update the plot.'];
case 3,
    statusText = [statusText, ' to set the quantization parameters.'];
end


% [EOF] udpate_actionbtn.m
