function initializeTimePanel(h)
% INITIALIZETIMEPANEL initializes the 'Define Time Vector' panel

% Author: Rong Chen 
% Revised: 
% Copyright 1986-2004 The MathWorks, Inc.

% -------------------------------------------------------------------------
%% Build time panel
% -------------------------------------------------------------------------
h.DefaultPos.TimePanelDefaultColor=h.DefaultPos.FigureDefaultColor;
h.Handles.PNLtime = uipanel('Parent',h.Figure,...
    'Units','Pixels',...
    'FontUnits','normalized',...
    'FontSize',9,...
    'FontWeight','bold', ...
    'BackgroundColor',h.DefaultPos.TimePanelDefaultColor,...
    'Title','2. Define Time Vector',...
    'Position',[h.DefaultPos.leftoffsetpnl ...
                h.DefaultPos.bottomoffsetTimepnl ...
                h.DefaultPos.widthpnl ...
                h.DefaultPos.heightTimepnl], ...
    'Visible','off'...
);

% create sheet combobox controls whose values are based on the rawdata
h.Handles.TXTtimeSheet = uicontrol('Parent',h.Handles.PNLtime,...
    'style','text', ...
    'Units','Pixels',...
    'BackgroundColor',h.DefaultPos.TimePanelDefaultColor,...
    'String','Time is from : ',...
    'HorizontalAlignment','Right', ...
    'Position',[h.DefaultPos.TXTtimeSheetleftoffset ...
                h.DefaultPos.TXTtimeSheetbottomoffset ...
                h.DefaultPos.TXTtimeSheetwidth ...
                h.DefaultPos.heighttxt] ...
    );
h.Handles.COMBtimeSource = uicontrol('Parent',h.Handles.PNLtime,...
    'style','popupmenu',...
    'Units', 'Pixels',...
    'BackgroundColor',[1 1 1], ...
    'String',[{'current sheet'},{'entering it manually'},{'MATLAB workspace'}], ...
    'Value',1,...
    'TooltipString','The time vector can be obtained from different sources.  Use this drop-down list the select the type of source and configure the source below',...
    'Position',[h.DefaultPos.COMBtimeSheetleftoffset ...
                h.DefaultPos.TXTtimeSheetbottomoffset+4 ...
                h.DefaultPos.COMBtimeSheetwidth ...
                h.DefaultPos.heightcomb], ...
    'Callback',{@localSwitchSource h} ...
    );
% create dynamic panels
h.dynamicPanel_CurrentSheet;
h.dynamicPanel_ManualInput;
h.dynamicPanel_Workspace;
% initialize dynamic panels
if  ~isempty(h.Handles.ActiveX)
    % activex
    if h.IOData.formatcell.columnIsAbsTime>=0
        % the first column contains absolute time format
        set(h.Handles.COMBdataSample,'Value',1);
        h.TimePanelUpdate('column');
    elseif h.IOData.formatcell.rowIsAbsTime>=0
        % the first row contains absolute time format
        set(h.Handles.COMBdataSample,'Value',2);
        h.TimePanelUpdate('row');
    elseif h.IOData.formatcell.columnIsAbsTime==-1
        % the first column contains doubles which can be relative time
        set(h.Handles.COMBdataSample,'Value',1);
        h.TimePanelUpdate('column');
    elseif h.IOData.formatcell.rowIsAbsTime==-1
        % the row column contains doubles which can be relative time
        set(h.Handles.COMBdataSample,'Value',2);
        h.TimePanelUpdate('row');
    else 
        % no time or number detected in either the first row or column
        % set column as default and bring up the manual input
        set(h.Handles.COMBdataSample,'Value',1);
        h.TimePanelUpdate('column');
        set(h.Handles.COMBtimeSource,'Value',2);
        set(h.Handles.PNLtimeCurrentSheet,'Visible','off');
        set(h.Handles.PNLtimeManual,'Visible','on');
    end        
end
if  ~isempty(h.Handles.tsTable)
    % no time or number detected in either the first row or column
    % set column as default and bring up the manual input
    set(h.Handles.COMBdataSample,'Value',1);
    h.TimePanelUpdate('column');
end


% -------------------------------------------------------------------------
%% time vector source selection callbacks
% -------------------------------------------------------------------------
function localSwitchSource(eventSrc, eventData, h)
% callback for the sheet combobox in the time panel
ind = get(eventSrc,'Value');
if ind==3
    % from workspace
    set(h.Handles.PNLtimeCurrentSheet,'Visible','off');
    set(h.Handles.PNLtimeManual,'Visible','off');
    set(h.Handles.PNLtimeWorkspace,'Visible','on');
elseif ind==2
    % manual input
    set(h.Handles.PNLtimeCurrentSheet,'Visible','off');
    set(h.Handles.PNLtimeManual,'Visible','on');
    set(h.Handles.PNLtimeWorkspace,'Visible','off');
elseif ind==1
    % currentsheet
    set(h.Handles.PNLtimeCurrentSheet,'Visible','on');
    set(h.Handles.PNLtimeManual,'Visible','off');
    set(h.Handles.PNLtimeWorkspace,'Visible','off');
end


