function hndlMatrix=buttons(figNumber)
% Buttons Initializes all uicontrol buttons for Tour GUI.

%    Yama Habibzai
%   Copyright (c) 1984-98 by The MathWorks, Inc. All Rights Reserved
%    $Revision: 1.12 $
%    $Date: 1997/11/21 19:38:39 $

% Initialize info for all buttons
% Startup constants
% Constants in pixel units

btnColor=[192 192 192]/255;
btnTextColor=[0 0 0];
Xleftcol = 110;
Xrightcol = 340;
Ytoprow = 255;
spacing = 24;
Ysecrow = Ytoprow - 1.2*spacing;
Ythirdrow = Ysecrow - 1.2*spacing;
Yforthrow = Ythirdrow - 1.2*spacing;
Yfifthrow = Yforthrow - 1.2*spacing;
Ysixthrow = Yfifthrow - 1.2*spacing;
Yseventhrow = Ysixthrow - 1.2*spacing;


%=====================================
% Initialize the Mathematics Region
visitBtnCallbackStr='tour(''showmath'')';
mainHndl(2)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xrightcol Ysecrow-3 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the Dynamic System Simulation Region
visitBtnCallbackStr='tour(''showdss'')';
mainHndl(3)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xrightcol Yforthrow-2 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the TOOLBOX Region
visitBtnCallbackStr='tour(''showtoolbox'')';
mainHndl(4)=uicontrol(figNumber, ...
        'Style','pushbutton', ...
        'Units','pixels', ...
        'Position',[Xleftcol Ythirdrow+9 20 20], ...
        'BackgroundColor',btnColor, ...
        'ForegroundColor',btnTextColor, ...
        'String',' ', ...
        'Visible','off', ...
        'Tag', 'firstPage', ...
        'Callback',visitBtnCallbackStr);
    
%=====================================
% Initialize the Control Region
visitBtnCallbackStr='tour(''showcont'')';
mainHndl(6)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xrightcol Yfifthrow 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the Programming Region 
visitBtnCallbackStr='tour(''showprog'')';
mainHndl(7)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xrightcol Ythirdrow-2 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the Signal Region
visitBtnCallbackStr='tour(''showsig'')';

mainHndl(8)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xrightcol Ysixthrow 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the MATLAB section
visitBtnCallbackStr='tour(''showmatlab'')';
mainHndl(10)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xleftcol Ytoprow-1 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the intro to Simulink demo button 
visitBtnCallbackStr='tour(''showsimulink'')';
mainHndl(11)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xleftcol Yforthrow+4 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%=====================================
% Initialize the data analysis button
visitBtnCallbackStr='tour(''showdat'')';
mainHndl(12)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xrightcol Ytoprow-2 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',visitBtnCallbackStr);

%  ===========================================
%   The BLOCKSET Button 
buttonCallbackStr='tour(''showblkset'')';
mainHndl(15)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xleftcol Ysixthrow+15 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String',' ', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',buttonCallbackStr);

%  ===========================================
%   The BLOCKSET Button
buttonCallbackStr='tour(''showsf'')';
mainHndl(16)=uicontrol(figNumber, ...
    'Style','pushbutton', ...
    'Units','pixels', ...
    'Position',[Xleftcol Ysixthrow-18 20 20], ...
    'BackgroundColor',btnColor, ...
    'ForegroundColor',btnTextColor, ...
    'String','', ...
    'Visible','off', ...
    'Tag', 'firstPage', ...
    'Callback',buttonCallbackStr);

%====================================
% Build listboxes and button for MATLAB, toolbox, simulink, ...
LocalBuildPage(figNumber);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%% Local Functions %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function toolHndl=LocalBuildPage(figNumber) 
%  build buttons and listboxes for each page 


left=0.015;
right=0.75;
bottom=0.25;
labelHt=0.04;
spacing=0.05;
frmBorder=0.04;
listwidth=.41;
listlength=.42;
%===================================
% First, listbox of demos for one toolbox
left1=9.5*left+listwidth;
% build listbox
demoList=' ';


lstPos=[.5325 .27 .41 .42];  

% The right side list box
demoListHndl=LocalBuildUi(lstPos, 'List', 'evalcb(''showdemo'')',...
             demoList, 'tooldemos');
set(demoListHndl, 'Value', 1);

%===================================
% Set up the toolbox list Window

% Then the toolbox list label
% Then the toobbox listbox
tlwPos=[.0553571 .1238 .42321 .56428];
tbxList=' ';
tbxListHndl=LocalBuildUi(tlwPos, 'List', 'evalcb(''showlist'')',...
            tbxList, 'ToolListTag');
%====================================

% Information for all buttons    

%====================================
% The about button
btnNumber=1;

callbackStr='tour(''abouttoolboxes'')';  
abtTbxHndl = uicontrol('style', 'push',...
    'units', 'normalized',...
    'position', [.5857 .1238 .3, .05238],...
    'Tag', 'about', 'callback', callbackStr,...
    'String', ' ',...
    'Visible', 'off');  
%====================================
% The return button

labelStr='Main Window';
callbackStr='evalcb(''back'');';
backHndl=LocalBuildBtn(2, .34, .022, .3, .05, labelStr,...
         callbackStr, 'return');
%====================================
% The run button    
callbackStr='evalcb(''runtool'')';
runHndl=LocalBuildBtn(2, .5857, .20476, .3, .05238, 'Run Demo',...
        callbackStr, 'RunDemo');

%====================================

toolHndl=[demoListHndl, tbxListHndl,...
      abtTbxHndl, backHndl, runHndl];



%=================================================
function uiHandle=LocalBuildUi(uiPos, uiStyle, uiCallback,...
                   promptStr, uitag)
% local function to build an uicontrol
uiHandle=uicontrol( ...
    'Style',uiStyle, ...
    'HorizontalAlignment','left', ...
    'Units','normalized', ...
    'Max',10, ...
    'BackgroundColor',[1 1 1], ...
    'Position',uiPos, ...
    'Callback',uiCallback, ... 
    'Tag', uitag, ...
    'Visible', 'off', ...
    'String',promptStr);

%=================================================
function btHandle=LocalBuildBtn(btnNumber, xpos, ypos,btnWid,...
                  btnHt, labelStr, callbackStr, uitag)
% local function to build a ui button
labelColor=[0.8 0.8 0.8];

% Generic button information
btnPos=[xpos ypos btnWid btnHt];
btHandle=uicontrol( ...
    'Style','pushbutton', ...
    'Units','normalized', ...
    'Position',btnPos, ...
    'String',labelStr, ...
    'Tag', uitag, ...
    'Visible', 'off', ...
    'Callback',callbackStr); 
    
    
    
    


