function dopOSCCIgui(varargin)
% dopOSCCI Mark II: dopOSCCIgui ~ 17-Jan-2012 (last edit)
%
% graphical user interface to interact with a functional Transcranial
% Doppler Ultrasonography summary tool, dopOSCCI (see dopOSCCI).
%
% consists of a series of selectable tabs to modify the dopOSCCI inputs.
% for more information see dopOSCCIdef - the task definition function to
% dopOSCCI.
%
% contains a series of embedded functions...

% note:
% setting UserData field of objects to be default values...
% - best if there is a reset.
%
% -------------------------------------------------------------------------
%     'dopOSCCI' summarises functional transcranial Doppler ultrasonography
%     (fTCD) data.  The primary function of the software is to assess the
%     hemispheric lateralization of cognitive function.
%
%     Copyright (C) 2011 the Chancellor, Masters and Scholars of the
%     University of Oxford.
% 
%     This program is free software: you can redistribute it and/or modify
%     it under the terms of the GNU General Public License as published by
%     the Free Software Foundation, either version 3 of the License, or
%     (at your option) any later version.
% 
%     This program is distributed in the hope that it will be useful,
%     but WITHOUT ANY WARRANTY; without even the implied warranty of
%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%     GNU General Public License for more details.
% 
%     You should have received a copy of the GNU General Public License
%     along with this program.  If not, see <http://www.gnu.org/licenses/> 
%     or write to the Free Software Foundation, Inc., 51 Franklin Street,
%     Fifth Floor, Boston, MA 02110-1301, USA.
%
%     Authors: Nic Badcock, Georgina Holt, Anneka Holden, & Dorothy Bishop.
%       contact: nicholas.badcock@gmail.com
%
%     Type 'dopOSCCIlicense' for license details or see dopOSCCIlicense.txt
%

% 2.1.1 2-June-2011: ready for sharing
% 2.1.2 14-Sep-2011: quality selection update
% 2.1.3 03-Nov-2011: extra index popup handles
% 2.2.3 04-Nov-2011: created 'gen' version, works on Mac (+win with any luck)
% 2.2.4 06-Dec-2011: various superficial bugs + behavioural mismatch
% 2.2.5 05-Jan-2012: fixed dopRawChEqual finding poi markers for multiple
% events when there's a mismatch between the number of base and poi
% markers...
% 2.2.6 11-Jan-2012 included test graph button
% 2.3.6 12-Jan-2012 included inidividual data save options + Graph Data save button
% 2.3.7 13-Jan-2012 save directory tweaks
% 2.3.8 17-Jan-2012 included dopDownsample & epoch rejection save
% 2.3.9 18-Jan-2012 dopDownsample in dopEventStack
% 2.3.10 19-Jan-2012 corrected individual graph data epochs horz vs vert

%% open the figure
global dg inputs % want to avoid this if I can...
% might be possible if data is simply entered or collect at end...
commandwindow; % puts matlab command window to front - gui on top
fprintf('%s\n',['Running ',mfilename]);

if isfield(dg,'fig') && isfield(dg.fig,'h')
    try % matlab orange info is fine here
        dg.tmp.warn=sprintf('%s\n%s\n',...
            'dopOSCCI figure already open or global variable ''dg'' available,',...
            'Attempting to close - please try again');
        disp(dg.tmp.warn); warndlg(dg.tmp.warn,'dopOSCCI variable found:');
        dgCloseGui;
        return;
    end
end
%% > check inputs
inputs.varargin=[];
if ~isempty(varargin)
    if numel(varargin)==1
        if isfield(varargin{1},'inputs')
            inputs.varargin=varargin{1}.inputs;
        end
    else
        inputs.varargin=varargin;
    end
end
inputs.turnOn={}; % 'stitch'
inputs.turnOff={};
inputs.defaults=struct('taskName',[],...
    'defFileNameLoc',[]);
dg.inputs=setGetInputsStruct(inputs);

%% > colours
dg=dgColours(dg);
%% > font
dg.font.h=[]; % collect font handles so we can easily adjust
dg.font.values=[-1 1];
dg.font.sets={'Decrease','Increase'};

%% > enable
% series of gui functionality that are locked until a definition file is
% found/created.
dg.enable.variables={'list','h','import','style'};
for i=1:numel(dg.enable.variables)
    dg.enable.(dg.enable.variables{i})=[];
end
% dg.enable.list=[];
% dg.enable.h=[];
dg.enable.on=0; % set this to one when done so don't repeat
% dg.enable.import=[];
% dg.enable.style=[];

%% -> Tab ? Info
% rollover/tooltipstring question mark to describe tab - general settings
dg.info.abb='q';
dg.info.txt='?';
dg.info.txtBreak='---------------------------------------';
dg.info.align='Left';
dg.info.pos=[.01 .94 .05 .05];

%% > figure setup
dg.fig.name='dopOSCCI - fTCD summary suite';
dg.fig.pos=[.01 .45 .5 .5]; % start it in the top left hand corner
dg.fig.h=figure('units','normalized','position',dg.fig.pos,...
    'NumberTitle','off','Toolbar','none','MenuBar','none',...
    'name',dg.fig.name,'color',dg.col.bg,'visible','off',...
    'ResizeFcn',@dgResize,'DeleteFcn',@dgDeleteGui);

%% > run (bottom) panel
dg.run.h=uipanel('Parent',dg.fig.h,'Tag','run_panel',...%'Title','Run','FontSize',12,...
    'Position',[.11 .01 .88 .1],'BackgroundColor',dg.col.wait);
dg.run.but.abb={'run','save','reset','close'};
dg.run.but.n=numel(dg.run.but.abb);
dg.run.but.title={'Run','Save','Reset','Close'};
% dg.run.but.callback={'@dgRun','@dgSave','@dgClose'};
dg.run.but.pos=dgPositions([1 dg.run.but.n],[.1 .1]); % columns row, x gap, y gap
dg.run.but.tts={'Start the summary','Save Defintion File',...
    'Revert setting to opening state','Close gui'};
for i=1:numel(dg.run.but.abb)
    dg.run.but.h(i)=uicontrol('Parent',dg.run.h,'Tag',dg.run.but.abb{i},...
        'String',dg.run.but.title{i},'Style','pushbutton',...
        'units','normalized',...
        'Callback',eval(['@dg',dg.run.but.title{i},'Gui']),...
        'Position',dg.run.but.pos(i,:),...
        'ToolTipString',dg.run.but.tts{i});
    dg.font.h(end+1)=dg.run.but.h(i);
    %         'BackgroundColor',get(dg.run.h,'BackgroundColor'));
    switch dg.run.but.abb{i}
        case {'run','save','reset'}
            set(dg.run.but.h(i),'Enable','off');
            dg.enable.list{end+1}=dg.run.but.abb{i};
            dg.enable.h(end+1)=dg.run.but.h(i);
            dg.enable.import(end+1)=0;
            dg.enable.style{end+1}='push';
            % can't do this until we have a taskName or definition
    end
end
%% > font size buttons
% [.88 .11 .1 .89]
dg.extra.h=uipanel('Parent',dg.fig.h,'Tag','extra_panel',...%'Title','Run','FontSize',12,...
    'Position',[.01 .01 .1 .1],'BackgroundColor',dg.col.go);
dg.extra.but.abb={'Decrease','Increase'};
dg.extra.but.n=numel(dg.extra.but.abb);
dg.extra.but.title={'-','+'};
% dg.extra.but.key={'-','+'};
% dg.extra.but.callback={'@dgRun','@dgSave','@dgClose'};
dg.extra.but.pos=dgPositions([1 dg.extra.but.n],[.1 .1]); % columns row, x gap, y gap
dg.extra.but.tts={'Decrease font size','Increase font size'};
for i=1:numel(dg.extra.but.abb)
    dg.extra.but.h(i)=uicontrol('Parent',dg.extra.h,'Tag',dg.extra.but.abb{i},...
        'String',dg.extra.but.title{i},'Style','pushbutton',...
        'units','normalized',...
        'Callback',eval('@fontAdjust'),...
        'KeyPressFcn',eval('@fontAdjust'),...
        'Position',dg.extra.but.pos(i,:),...
        'ToolTipString',dg.extra.but.tts{i});
    dg.font.h(end+1)=dg.extra.but.h(i);
    %         'BackgroundColor',get(dg.extra.h,'BackgroundColor'));
    %     switch dg.extra.but.abb{i}
    %         case {'run','save','reset'}
    %             set(dg.extra.but.h(i),'Enable','off');
    %             dg.enable.list{end+1}=dg.extra.but.abb{i};
    %             dg.enable.h(end+1)=dg.extra.but.h(i);
    %             dg.enable.import(end+1)=0;
    %             dg.enable.style{end+1}='push';
    %             % can't do this until we have a taskName or definition
    %     end
end

%% > tabs
dg.tab.pos=[.01 .11 .98 .89];
dg.tab.h=uitabgroup('v0','parent',dg.fig.h,'position',dg.tab.pos,...
    'BackgroundColor',dg.col.bg);
dg.tab.abb={'def','dat','event','graph','sav','spec','misc','about'};%,'graphp','savp',
dg.tab.title={'Definition','Data','Event','Graphs','Save','Special','Misc','About'};%,'Graphs+','Save+''Events','Special','Save Options','About'};
dg.tab.name={'Definition','Data','Event','Graphs','Save','Special','Misc','About'};%,'GraphsPlus','SavePlus''Events','Special','Save Options','About'};
dg.tab.pan.pos=[0 0 1 1];
dg.tab.pan.col=dg.col.pb;
% create each tab
for i=1:length(cellfun('size',dg.tab.title,1))
    dg.tmp.tabAbb=dg.tab.abb{i};
    dg.tmp.tabTitle=dg.tab.title{i};
    if strcmp(dg.tab.abb,'event')
        dg.tmp.tabAbb=[dg.tab.abb{i},'1'];
        dg.tmp.tabTitle=[dg.tab.title{i},'1'];
    end
    dg.tab.(dg.tmp.tabAbb).h = uitab('v0', dg.tab.h,...
        'title', dg.tab.title{i},'tag',dg.tmp.tabAbb);
    if strcmp(dg.tab.abb{i},'event')
        dg=feval(['dg',dg.tab.name{i}],dg,dg.tab.(dg.tmp.tabAbb).h,1);
    else
        dg=feval(['dg',dg.tab.name{i}],dg,dg.tab.(dg.tmp.tabAbb).h);
    end
    
end
%% > any inputted settings?
if ~isempty(dg.inputs.taskName)
    set(dg.def.taskName.edit.h,'String',dg.inputs.taskName);
    feval(char(get(dg.def.taskName.edit.h,'CallBack')),dg.def.taskName.edit.h);
elseif ~isempty(dg.inputs.defFileNameLoc)
    dg.tmp.fnl=[dg.inputs.defFileNameLoc];
    %     set(varargin{1},'UserData',dg.tmp.fnl); % set user data for save
    %     keeping
    checkTaskDefFile;
end
%% take to about tab
% don't think this is really sensible - better to be at task definition
% set(dg.tab.h,'SelectedIndex',...
%     find(strcmp(get(get(dg.tab.h,'Children'),'Tag'),'about')));

%% set tooltip display times
% from:
% http://undocumentedmatlab.com/blog/additional-uicontrol-tooltip-hacks/
% tm = javax.swing.ToolTipManager.sharedInstance; %static method to get ToolTipManager object
% initialDelay = javaMethodEDT('getInitialDelay',tm); %get the delay before display in milliseconds (=750 on my system)
% javaMethodEDT('setInitialDelay',tm,0); %set tooltips to appear immediately
%  
% dismissDelay = javaMethodEDT('getDismissDelay',tm); %get the delay before the tooltip disappears (=10000 (10 sec) on my system)
% javaMethodEDT('setDismissDelay',tm,2000); %set the dismiss delay to 2 seconds
%  
% javaMethodEDT('setEnabled',tm,false); %turns off all tooltips in system (including the Matlab desktop)
% javaMethodEDT('setEnabled',tm,true);
%  
% javaMethodEDT('setInitialDelay',tm,initialDelay);
% javaMethodEDT('setDismissDelay',tm,dismissDelay);
dg.tt.translation = 'tt = tool tip';
dg.tt.tm = javax.swing.ToolTipManager.sharedInstance; %static method to get ToolTipManager object
dg.tt.initialDelay = javaMethodEDT('getInitialDelay',dg.tt.tm); %get the delay before display in milliseconds (=750 on my system)
% javaMethodEDT('setInitialDelay',tm,0); %set tooltips to appear immediately
%  
dg.tt.dismissDelay = javaMethodEDT('getDismissDelay',dg.tt.tm); %get the delay before the tooltip disappears (=10000 (10 sec) on my system)
dg.tt.wait=60000; % one minute
javaMethodEDT('setDismissDelay',dg.tt.tm,dg.tt.wait); %set the dismiss delay to 2 seconds
%  
% javaMethodEDT('setEnabled',tm,false); %turns off all tooltips in system (including the Matlab desktop)
% javaMethodEDT('setEnabled',tm,true);

% reset:
% javaMethodEDT('setInitialDelay',dg.tt.tm,dg.tt.initialDelay);
% javaMethodEDT('setDismissDelay',dg.tt.tm,dg.tt.dismissDelay);

%% make visible
set(dg.fig.h,'visible','on');

end
%% -----------------------------------------------------------------------
%% Run Callbacks
% dg.run.but.callback={'dgRun','dgSave','dgClose'};
%% > dgRunGui
function dgRunGui(varargin) % matlab orange info is fine here
global dg
dg.tmp.info=dbstack;
fprintf('%s\n',[dg.tmp.info.name,' has been called:']);
if ~isempty(dg.dopdef.dataDir)
    dgSaveGui; % save the data
    taskName = dg.dopdef.taskName;
    defFNL = dg.dopdef.defFileNameLoc; % this is important if the defintion is away from the default directory
    saveDirBase = dg.dopdef.saveDirBase;
    if dg.dopdef.closeGui
        dgCloseGui; % this may be annoying but it's safe and saves on memory
    else
        % make the run button red...
        set(dg.run.h,'Backgroundcolor',dg.col.Off);
        set(dg.run.but.h(1),'Enable','Off');
    end
    drawnow;
    commandwindow;
    fprintf('%s\n','Running dopOSCCI:');
    dopOSCCI('nogui','taskName',taskName,'defFileNameLoc',defFNL,'saveDirBase',saveDirBase); % probably a list here would be best...
    clear taskName defFNL saveDir
    try
        set(dg.run.h,'Backgroundcolor',dg.col.On);
        set(dg.run.but.h(1),'Enable','On');
    end
else
    dop.tmp.warn=sprintf('%s\n%s\n','A data directory must selected (see Data tab).',...
        ' - not possible to summarise data without some files.');
    disp(dop.tmp.warn);
    warndlg(dop.tmp.warn,'No data directory:')
end
end
%% > dgSaveGui
function dgSaveGui(varargin) % matlab orange info is fine here
global dg
dg.tmp.info=dbstack;
if size(dg.tmp.info,1) 
    dg.tmp.info = dg.tmp.info(1);
end
fprintf('%s\n',[dg.tmp.info.name,' has been called:']);
fprintf('%s\n','Saving definition:')
if isfield(dg,'dopdef') && isfield(dg.dopdef,'defFileNameLoc')
    dop.def=dg.dopdef;
    save(dg.dopdef.defFileNameLoc,'dop');
    clear dop
    fprintf('\t%s\n','Done.')
else
    fprintf('\t%s\n\t%s\n','dg.dopdef variable does not exist',...
        ' - can''t save it.');
end
end
%% > dgResetGui
function dgResetGui(varargin) % matlab orange info is fine here
global dg
dg.tmp.info=dbstack;
fprintf('%s\n',[dg.tmp.info.name,' has been called:']);
fprintf('%s\n','Resetting dopOSCCIgui to original state.');
enableSet('Off');
% remove extra event tabs = if exist
dgEventNumberAdjust('reset');
% if isfield(dg,'dopdef') && dg.dopdef.evNum>1
%     for i=1:dg.dopdef.evNum-1
%         dgEventNumberCheck(dg.dat.evNum.push.h(1));
%     end
% end
setGuiData('reset');


fprintf('\t%s\n\t\t%s\n\n','Setting tab selection to Definition Tab',...
    '(adjust in ''dgResetGui'' embedded function within ''dopOSCCIgui'' mfile)');
set(dg.tab.h,'SelectedIndex',...
    find(strcmp(get(get(dg.tab.h,'Children'),'Tag'),'def')));
end
%% > dgCloseGui
% this is a pushbutton function - not called if figure is closed by other
% means - dgDeleteGui is called under these circumstances
function dgCloseGui(varargin) % matlab orange info is fine here
global dg


commandwindow;
try
     % reset the defatul tooltip display times using java
    javaMethodEDT('setInitialDelay',dg.tt.tm,dg.tt.initialDelay);
    javaMethodEDT('setDismissDelay',dg.tt.tm,dg.tt.dismissDelay);
    dg.tmp.info=dbstack;
    fprintf('%s\n%s\n',...
        [dg.tmp.info(1).name,' has been called:'],'Closing dopOSCCIgui.');
    for i=1:numel(dg.sav.popfig.abb)
        if ~isempty(findobj('Tag',dg.sav.popfig.abb{i}));
            try
                close(dg.([dg.sav.popfig.abb{i},'Fig']).h);
            end
        end
    end
    close(dg.fig.h); % this then calls below
    % clear global dg inputs
    % clear dg inputs
    
catch err
    close all;
    delete(gcf)
    rethrow(err)
end
end
%% > dgDeleteGui
function dgDeleteGui(varargin) % matlab orange info is fine here
global dg
try
    % reset the defatul tooltip display times using java
    javaMethodEDT('setInitialDelay',dg.tt.tm,dg.tt.initialDelay);
    javaMethodEDT('setDismissDelay',dg.tt.tm,dg.tt.dismissDelay);
    dg.tmp.info=dbstack;
    fprintf('%s\n%s\n',...
        [dg.tmp.info(1).name,' has been called:'],'Deleting dopOSCCIgui.');
    for i=1:numel(dg.sav.popfig.abb)
        if ~isempty(findobj('Tag',dg.sav.popfig.abb{i}));
            try
                delete(dg.([dg.sav.popfig.abb{i},'Fig']).h);
            end
        end
    end
    delete(dg.fig.h);
    clear global dg inputs
    clear dg inputs
catch err
    delete(gcf)
    rethrow(err)
end
end
%% -----------------------------------------------------------------------
%% tab callbacks
%% > About
function dg=dgAbout(dg,tmp_handle) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;

dg.(dg.tmp.abb).head.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).head.abb={'name','OSCCI','version','author','matlab','licence'}; %'institution',
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.txt={
    'dopOSCCI Functional Transcranial Doppler Summary Suite',...
    '(Oxford Study of Children''s Communication Impairments)',...
    'Version: 2.3.10, Thursday 19th January 2012',...
    'Author: Nic Badcock, University of Oxford',...
    'Written in Matlab version 7.9.0.529 (R2009b)',...
    'The software is freely available under the GNU  Public  License www.gnu.org'};

dg.(dg.tmp.abb).head.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],[0 .01],[0 .05 1 .5],'opposite');

dg.(dg.tmp.abb).pic.name='OSCCI logo blue.jpg';
dg.(dg.tmp.abb).pic.loc=[fileparts(which(mfilename)),'/']; % same folder as mfile
dg.(dg.tmp.abb).pic.nameLoc=[dg.about.pic.loc,dg.about.pic.name];
dg.(dg.tmp.abb).pic.data=imread(dg.about.pic.nameLoc,'jpg');
dg.(dg.tmp.abb).pic.size=size(dg.(dg.tmp.abb).pic.data); % rows columns col
dg.(dg.tmp.abb).pic.size=dg.(dg.tmp.abb).pic.size([2 1]); % switch this to be 1 = x axis, 2 = y axis
dg.(dg.tmp.abb).pic.panSize=.3; % image within a .3 square
dg.(dg.tmp.abb).pic.ratio=[dg.(dg.tmp.abb).pic.size(1)/dg.(dg.tmp.abb).pic.size(2) 1];

dg.(dg.tmp.abb).pic.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).pic.pos=dgOSCCIimagePos(dg);

dg.(dg.tmp.abb).pic.h=axes('parent',dg.(dg.tmp.abb).pan.h,...
    'position',dg.(dg.tmp.abb).pic.pos,......
    'color',dg.col.w,'Tag',dg.(dg.tmp.abb).pic.name,...
    'Ycolor',dg.col.pb,'Xcolor',dg.col.pb,'XTick',[],'YTick',[]);%[.05 .5 .5 .2]);%);dg.col.txtOnBlue
image(dg.(dg.tmp.abb).pic.data); axis off;hold;


dg.(dg.tmp.abb).el={'head'};%{'head','check'};%,'edit','push','pop','check'}; % elements
dg.(dg.tmp.abb).styles={'text'};%{'text','checkbox'};%,'edit','pushbutton','popupmenu','checkbox'};
for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).(dg.tmp.el).par,...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
            'units','normalized','HorizontalAlign','center',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
    end
end
end
%% >> dgOSCCIimagePos
% dg.fig.pos needs to be updated before calling
function pos=dgOSCCIimagePos(dg)

set(dg.about.pic.par,'Units','Pixels');
dg.about.pic.parPos=get(dg.about.pic.par,'Position');
set(dg.about.pic.par,'Units','Normalized');
dg.about.pic.parXYpix=dg.about.pic.parPos([3 4]);
% dg.fig.posRatio=[dg.fig.pos(3)/dg.fig.pos(4) 1];

dg.about.pic.parRatio=[dg.about.pic.parXYpix(1)/dg.about.pic.parXYpix(2) 1];

dg.about.pic.panSizeXY=dg.about.pic.ratio./dg.about.pic.parRatio*dg.about.pic.panSize;%((dg.about.pic.parRatio*dg.about.pic.panSize)*dg.about.pic.panSize).*dg.about.pic.ratio;
% need to adjust for figure x y ratio dg.fig.pos

% while sum(dg.about.pic.panSizeXY>1)
%     dg.about.pic.panSizeXY=dg.about.pic.panSizeXY-.01;
% end
% dg.about.pic.panSizeXY=dg.about.pic.panSizeXY*dg.about.pic.panSize;
pos=dgPositions([1 1],[0 0],...
    [.5-(dg.about.pic.panSizeXY(1)/2) .8-(dg.about.pic.panSizeXY(2)/2) ...
    dg.about.pic.panSizeXY]);
end
%% > Definition
% task name editable area and pushbutton selection (.mat)
% notes field
function dg=dgDefinition(dg,tmp_handle) % matlab orange info is fine here
% dg.tmp.info=dbstack;
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;

%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
    'dopOSCCI Task Definition:',...
    ['This is the starting point of the dopOSCCI summary - creating ',...
    'a task definition file which houses the settings for the summary'],...
    dg.info.txtBreak,...
    ['> Start by typing a task name Or by selecting a pre-existing task ',...
    'definition ''.mat'' file using the pushbutton to the right'],...
    ['This will import the default (see the dopOSCCIdef function) or ',...
    ' pre-existing setting from the ''.mat'' file'],...
    dg.info.txtBreak,'Notes:',...
    'This provides a text based record of the task details',...
    'It is not required but is very useful for later reference.',...
    dg.info.txtBreak);
dg=dgTabInfo(dg);

% headings
dg.(dg.tmp.abb).head.abb={'taskName','notes'};
dg.(dg.tmp.abb).head.txt={'Task Name','Notes'};
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.pos=[.05 .8 .2 .1;...
    .05 .7 .2 .1];
% editable
dg.(dg.tmp.abb).edit.pos=[.25 .82 .5 .08;...
    .1 .05 .8 .65];

dg.(dg.tmp.abb).edit.txt={'type task name','notes'};
dg.tmp.fill='-----------------------------------';
dg.(dg.tmp.abb).edit.notes=sprintf('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n',...
    'For example,','Date: (of data collection)',...
    'Experimenter/s:','Task Description:','Sample Description:',...
    dg.tmp.fill,...
    'Timing:',' > baseline = ',' > stim = ',' > response ? ',...
    ' > normalization = ',dg.tmp.fill);
dg.(dg.tmp.abb).edit.callback={'@compileTaskDefFile','@getTxtEdit'};
dg.(dg.tmp.abb).edit.tts={'Type in task name','Type task descritive info'};

dg.(dg.tmp.abb).push.pos=[.85 .82 .1 .08];
dg.(dg.tmp.abb).push.txt={'...'};
dg.(dg.tmp.abb).push.tts={'Browse for Task Definition file'}; % tooltip string
dg.(dg.tmp.abb).push.callback={'@browseTaskDefFile'};

dg.(dg.tmp.abb).el={'head','edit','push'}; % elements
dg.(dg.tmp.abb).styles={'text','edit','pushbutton'};

for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        if  i<dg.(dg.tmp.abb).head.n || ...
                and(i==dg.(dg.tmp.abb).head.n,j<find(strcmp(dg.(dg.tmp.abb).el,'push')))
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
            switch dg.tmp.style
                case 'edit'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'Callback',eval(dg.(dg.tmp.abb).edit.callback{i}),...
                        'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i},...
                        'UserData',dg.(dg.tmp.abb).edit.txt{1});
                    switch dg.tmp.h_abb
                        case 'taskName'
                            set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                                'HorizontalAlign','center');
                        case 'notes'
                            set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,'Max',100,...
                                'String',dg.(dg.tmp.abb).edit.notes,...
                                'UserData',dg.(dg.tmp.abb).edit.notes)
                            dg=enableObject(dg,1);
                    end
                case 'pushbutton'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'Callback',eval(dg.(dg.tmp.abb).push.callback{i}),...
                        'BackgroundColor',dg.col.go,'ForegroundColor',dg.col.gt,...
                        'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
            end
        end
    end
end

end
% >> callbacks
%% >> browseTaskDefFile
function browseTaskDefFile(varargin) % matlab orange info is fine here
global dg
dg.tmp.cur_dir=pwd; % current dir
dg.tmp.td_dir=[fileparts(which('dopOSCCI')),'/taskData/'];
cd(dg.tmp.td_dir); % now uigetfile will start here
[dg.tmp.fn,dg.tmp.dir]=uigetfile('*.mat','Browse for task definition file:');
if numel(dg.tmp.fn)>1
    dg.tmp.fnl=[dg.tmp.dir,dg.tmp.fn];
    checkTaskDefFile;
end
cd(dg.tmp.cur_dir); % change back
end
%% >> compileTaskDefFile
function compileTaskDefFile(varargin) % matlab orange info is fine here
global dg
% typed name found - see if it is a file
dg.tmp.editString=get(varargin{1},'String');
if ~isempty(dg.tmp.editString)
    if exist(dg.tmp.editString,'file')==2
        % path to full file
        dg.tmp.fnl=dg.tmp.editString;
    else % might just be name
        % see if it's in the regular folder:
        dg.tmp.fnl=[fileparts(which('dopOSCCI')),'/taskData/',...
            dg.tmp.editString,'.mat'];
    end
    checkTaskDefFile;
    if ~isempty(dg.tmp.err) % error
        set(varargin{1},'String',dg.def.edit.txt{1});
    end
else
    set(varargin{1},'String',get(varargin{1},'UserData'));
end
end
%% >> checkTaskDefFile
function checkTaskDefFile
% requires dg.tmp.fnl before call
global dg
dg.tmp.err=[];
if isfield(dg,'tmp') && isfield(dg.tmp,'fnl')
    fprintf('%s\n\t%s\n','Checking definition file:',dg.tmp.fnl);
    [dg.tmp.dd dg.tmp.taskName dg.tmp.ext]=fileparts(dg.tmp.fnl);
    
    if isfield(dg,'enable') && isfield(dg.enable,'setting') && strcmp(dg.enable.setting,'On')
        dg.tmp.warn=sprintf('%s\n%s\n%s\n',...
            'dopOSCCgui data already set',...
            'Currently settings will be saved in new file',dg.tmp.fnl);
        disp(dg.tmp.warn);
        warndlg(dg.tmp.warn,'New Definition File:');
        dg.tmp.new=0;
        if  exist(dg.tmp.fnl,'file')==2 && ...
                strcmp('Yes',questdlg(sprintf('%s\n%s\n%s\n',...
                'File already exists:',dg.tmp.fnl,'Overwrite?'),...
                'Definition File Exists: Overwrite?','Yes','No','Yes'))
            dg.tmp.new=1;
        else
            dg.tmp.new=1;
        end
        if dg.tmp.new
            fprintf('\t%s\n','Saving...');
            dg.dopdef.taskName=dg.tmp.taskName;
            dop.def=dg.dopdef;
            save(dg.tmp.fnl,'dop'); clear dop;
            dop=dopOSCCIdef('defFileNameLoc',dg.tmp.fnl); % 2-jan-11
            dg.dopdef=dop.def; clear dop;
            %             okayTaskDefFile;
        else
            fprintf('\t%s\n','Not saved');
            set(dg.def.taskName.edit.h,'String',get(dg.def.taskName.edit.h,'UserData'));
        end
    elseif exist(dg.tmp.fnl,'file')==2
        fprintf('\t%s\n','Definition file exists, loading...');
        dop=dopOSCCIdef('defFileNameLoc',dg.tmp.fnl); % 2-jan-11
        %         load(dg.tmp.fnl,'dop');  % import dop structure
        if isfield(dop,'def')
            dg.dopdef=dop.def; % def structure imported
            set(dg.def.taskName.edit.h,'String',dg.tmp.taskName);
            okayTaskDefFile;
        else
            dg.tmp.err=sprintf('%s\n%s\n%s\n',...
                'Definition structure not found in file',...
                dg.tmp.fnl,'Try another file.');
            disp(dg.tmp.err);
            warndlg(dg.tmp.err,'Def stucture not found:');
        end
        clear dop;
    elseif strfind(dg.tmp.fnl,'.mat')
        fprintf('\t%s\n','Definition file does not exists, creating...');
        dop=dopOSCCIdef('defFileNameLoc',dg.tmp.fnl);
        dg.dopdef=dop.def;
        clear dop;
        okayTaskDefFile;
    else
        dg.tmp.err=sprintf('%s\n%s\n%s\n',...
            'Definition file not found',...
            dg.tmp.fnl,'Check full file path.');
        disp(dg.tmp.err);
        warndlg(dg.tmp.err,'Def stucture not found:');
    end
else
    dg.tmp.err=sprintf('%s\n%s\n',...
        'dop.tmp.fnl variable was not found.',...
        'Check when function is being called.');
    disp(dg.tmp.err);
    warndlg(dg.tmp.err,'Missing variable:');
end
end
%% >> okayTaskDefFile
function okayTaskDefFile
enableSet('On');
setGuiData('import');
end
%% > Data
function dg=dgData(dg,tmp_handle) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);

dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% separator panel
dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',[.05 .625 .9 .01],'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf(...
    '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
    'dopOSCCI Data Tab:',...
    ['The Data Tab allows access to settings that dictate which data ',...
    'will be summarised and the general way it will be processed'],...
    dg.info.txtBreak,'Data Directory:',...
    ['It is critical to have a Data Directory which can be typed or ',...
    'browsed for using the pushbutton to the right'],...
    ['After a directory is defined some notes will appear reporting on ',...
    'the files that were found in the directory'],...
    dg.info.txtBreak,'File Selection:',...
    'An individual file can be selected for summary if desired',...
    dg.info.txtBreak,'Settings:',...
    'Various important settings can be found in the lower section of the Tab',...
    ' - These include the Left and Right signal channels (data columns for ''.EXP'' files)',...
    ' - The number of Event Markers to be used (increases the number of Event Tabs)',...
    ' - Marker height to search for in the data files = values below this are ignored',...
    ' - Downsample rate = rate in Hertz at which data will be summarised',...
    ' - Activation Rejection range = epochs with values outside range will be screened',...
    ' - Activation Separation = acceptable difference between left & right activation values',...
    ' - Epoch Trim = cuts off the start and end of a data file based upon Epoch settings and Event Markers',...
    ' - Epoch Norm = normalisation of data is conducted for each epoch (standard = overall)',...
    [' - Include Short = sometimes the available data might be inadequate for ',...
    'the selected epoch settings (see Event Tab).'],...
    ['The data will be extrapolated ',...
    'from what is available but this is not accurate and should be excluded'],...
    dg.info.txtBreak);
dg=dgTabInfo(dg);

% headings
dg.(dg.tmp.abb).head.abb={'dataDir','dataDirInfo','fileSel','dopChs','evNum',...
    'markHeight','downHertz','actRej','actSep','trim','epochNorm','inShort'};
dg.(dg.tmp.abb).head.txt={'Data Directory','','File Selection','Signal Channels',...
    'Number of Events','Marker Height','Down Sample','Act. Rej.','Act. Sep.','Epoch Trim','Epoch Norm','Include Short'};
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.dim=[8 2]; %[dg.(dg.tmp.abb).head.n-4 2];
dg.(dg.tmp.abb).head.pos=dgPositions(dg.(dg.tmp.abb).head.dim,[0 .05],...
    [.05 0 .9 1],'opposite','down');
% more positions than I need but want to push the second column down by 3
% & ignore the last row of the first column (delete)
% dg.(dg.tmp.abb).head.pos(1+dg.(dg.tmp.abb).head.dim(1):1+dg.(dg.tmp.abb).head.dim(1)+3,:)=...
%     dg.(dg.tmp.abb).head.pos(end-3:end,:);
dg.(dg.tmp.abb).head.pos(dg.(dg.tmp.abb).head.dim(1):1+dg.(dg.tmp.abb).head.dim(1)+3,:)=...
    dg.(dg.tmp.abb).head.pos(end-4:end,:);
dg.(dg.tmp.abb).head.pos(:,3)=.2; % shorten everything
dg.(dg.tmp.abb).head.pos(2,[1 2 3 4])=[.2 dg.(dg.tmp.abb).head.pos(2,2)-.075 ...
    .5 dg.(dg.tmp.abb).head.pos(2,4)+.1]; % indent report & make wider
dg.(dg.tmp.abb).head.pos(3,[1 2])=[dg.(dg.tmp.abb).head.pos(3,1)+.05 ...
    dg.(dg.tmp.abb).head.pos(3,2)+.025]; % indent file selection
dg.(dg.tmp.abb).head.use=[1 1 1 1 1 1 1 1 1 1 1 1];
dg.(dg.tmp.abb).head.tts={...
    'Type or Browse for the Doppler Data directory','',...
    'Select a specific file to be summarised',...
    'Specify the left and right Doppler signal channels',...
    'Specify the number of Event Markers to be used',...
    'Specify the value above which Event Markers will be searched for in the raw data',...
    'Specify the rate at which the data should be summarised/processed at',...
    'Specify the Activation Rejection ranged - epochs with values outside range can be screened',...
    ['Specify the acceptable % blood flow different between left and right channels: ',...
    'epochs with large descrepancies will be screened.'],...
    'Trim the raw data based upon epoch settings (see Event Tab)',...
    'Normalised the raw data within each epoch',...
    'Include epochs with inadequate data in summary (not recommended)',...
    };
% editable
dg.(dg.tmp.abb).edit.use=[1 0 0 1 0 1 1 1 1 0 0 0];
dg.(dg.tmp.abb).edit.pos=dg.(dg.tmp.abb).head.pos;
dg.(dg.tmp.abb).edit.pos(:,1)=dg.(dg.tmp.abb).edit.pos(:,1)+.2;
dg.(dg.tmp.abb).edit.pos(:,3)=.05;
dg.(dg.tmp.abb).edit.pos(:,[2 4])=[dg.(dg.tmp.abb).edit.pos(:,2)+.025 ...
    dg.(dg.tmp.abb).edit.pos(:,4)-.025];
% dgPositions([dg.(dg.tmp.abb).head.n-4 2],[0 .05],...
%     [.25 .05 .9 .9],'opposite','down');
dg.(dg.tmp.abb).edit.pos(1,[2 3 4])=[dg.(dg.tmp.abb).edit.pos(1,2)-.025 ...
    .5 dg.(dg.tmp.abb).edit.pos(1,4)+.025]; % adjust wider edits & taller
dg.(dg.tmp.abb).edit.pos(6,3)=.1; % marker needs to be a bit wider too

dg.(dg.tmp.abb).edit.txt={'type data directory','','','','','','','','','','','',''};
dg.(dg.tmp.abb).edit.callback={'@getTxtEdit'};
dg.(dg.tmp.abb).edit.to=[0 0 0 1 0 0 0 1 0 0 0 0];
dg.(dg.tmp.abb).edit.toTxt={'','','','&','','','','to','','','',''};
dg.(dg.tmp.abb).edit.tts={'Type in the directory of your raw doppler files',...
    '','','Doppler signal','Adjust the number of event markers',...
    'Type raw event marker height','Type down sample value in hertz',...
    'Activation Rejection value','Left Right Activation separatation value'};
dg.(dg.tmp.abb).edit.dopChs={'Left','Right'};
dg.(dg.tmp.abb).edit.actRej={'Lower','Upper'};
% % pushbutton
dg.(dg.tmp.abb).push.pos=dg.(dg.tmp.abb).head.pos;
dg.(dg.tmp.abb).push.pos(1,[1 3])=[dg.(dg.tmp.abb).push.pos(1,1)+.8 .1];
dg.(dg.tmp.abb).push.txt={'...','','','','1','','','','','','','+'};
dg.(dg.tmp.abb).push.use=[1 0 0 0 1 0 0 0 0 0 0 0];
dg.(dg.tmp.abb).push.two=[0 0 0 0 1 0 0 0 0 0 0 0];
dg.(dg.tmp.abb).push.twoTxt={'','','','',{'-','','+'}};
dg.(dg.tmp.abb).push.twoCallback={'@dgEventNumberCheck'};
dg.(dg.tmp.abb).push.tts={'Browse for data directory','','','',...
    'number of events'}; % tooltip string
dg.(dg.tmp.abb).push.twotts={'','','','',{'Decrease','Increase'}};
dg.(dg.tmp.abb).push.callback={'@browseDirectory','','','','','','','','','','','@browseDirectory'};
dg.(dg.tmp.abb).push.startDir={fileparts(which('dopOSCCI')),'','','','','','','','','','',''};
%
% popupmenu
dg.(dg.tmp.abb).pop.pos=dg.(dg.tmp.abb).head.pos;
dg.(dg.tmp.abb).pop.pos(3,[1 3])=[dg.(dg.tmp.abb).pop.pos(3,1)+.25 .5];
dg.(dg.tmp.abb).pop.txt={'','','all files'};
dg.(dg.tmp.abb).pop.use=[0 0 1 0 0 0 0 0 0 0 0 0];
dg.(dg.tmp.abb).pop.tts={'','','select a single file to summarise',''}; % tooltip string
dg.(dg.tmp.abb).pop.callback={'','','@getPopEdit'};

% checkbox
dg.(dg.tmp.abb).check.use=[0 0 0 0 0 0 0 0 0 1 1 1];
dg.(dg.tmp.abb).check.pos=dg.(dg.tmp.abb).edit.pos;
% dg.(dg.tmp.abb).check.pos(:,1)=dg.(dg.tmp.abb).edit.pos(:,1)+.2;

dg.(dg.tmp.abb).check.txt={'','','','','','','','','','','',''};
dg.(dg.tmp.abb).check.tts={'','','','','','','','','',...
    'Trim raw data by epoch seetings',...
    'Normalise data by epoch settings',...
    'Include epochs with inadequate data in screened summary'}; % tooltip string
dg.(dg.tmp.abb).check.callback={'@getCheckbox'};
dg.(dg.tmp.abb).check.options={'','','','','','','','','',...
    {'Data will not be trimmed by epoch','Data will be trimmed by epoch'},...
    {'Data will not be normalised by epoch','Data will be normalised by epoch'},...
    {'Inadequate epochs will not be included in screened summary',...
    'Inadequate epochs will be included in screened summary'},...
    };

dg.(dg.tmp.abb).el={'head','edit','push','pop','check'}; % elements
dg.(dg.tmp.abb).styles={'text','edit','pushbutton','popupmenu','checkbox'};

for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        
        if dg.(dg.tmp.abb).(dg.tmp.el).use(i)
            %              fprintf('\t%u\t%u\t%s\t%s\t%s\n',i,j,dg.tmp.el,dg.tmp.style,['(',dg.tmp.h_abb,')']);
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
            
            %             if ~strcmp(dg.tmp.style,'text')
            %                 set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
            %                     'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
            %             end
            switch dg.tmp.style
                case 'edit'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{1}),...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                        'HorizontalAlign','center');
                    dg=enableObject(dg,1);
                    if dg.(dg.tmp.abb).(dg.tmp.el).to(i)
                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                            'ToolTipString',['type ',dg.(dg.tmp.abb).(dg.tmp.style).(dg.tmp.h_abb){1},...
                            ' ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                            'UserData',[1 1]);%,...
                        for jj=1:2
                            dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
                            dg.tmp.pos(1,1)=dg.tmp.pos(1,1)+.05*jj;
                            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj)=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
                                'units','normalized','HorizontalAlign','center',...
                                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
                                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
                            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj);
                            switch jj
                                case 1 % 'to' text
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj),...
                                        'Style','text','String',dg.(dg.tmp.abb).(dg.tmp.el).toTxt{i});
                                case 2 % second edit box
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj),...
                                        'Style',dg.tmp.style,...
                                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{1}),...
                                        'ToolTipString',['type ',dg.(dg.tmp.abb).(dg.tmp.el).(dg.tmp.h_abb){2},...
                                        ' ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                                        'UserData',[1 2]);
                                    dg=enableObject(dg,1);
                            end
                        end
                        
                    end
                case 'text'
                    if strfind(dg.tmp.h_abb,'Info')
                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                            'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
                        dg=enableObject(dg,0);
                    end
                case 'pushbutton'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'Callback',eval(dg.(dg.tmp.abb).push.callback{1}),...
                        'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
                        'UserData',dg.(dg.tmp.abb).push.startDir{i});
                    dg=enableObject(dg,0);
                    if dg.(dg.tmp.abb).(dg.tmp.el).two(i) % num events
                        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
                        dg.tmp.pos(1,[1 2 3 4])=[dg.tmp.pos(1,1)+.2 ...
                            dg.tmp.pos(1,2)+.025 .05 .05];
                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                            'Position',dg.tmp.pos,...
                            'String',dg.(dg.tmp.abb).(dg.tmp.el).twoTxt{i}{1},...
                            'ToolTipString',['Push to ',dg.(dg.tmp.abb).push.twotts{i}{1},' ',...
                            dg.(dg.tmp.abb).push.tts{i}],'UserData',-1,...
                            'Callback',eval(dg.(dg.tmp.abb).push.twoCallback{1}));%,...);
                        %                         set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        %                             'ToolTipString',['type ',dg.(dg.tmp.abb).(dg.tmp.style).(dg.tmp.h_abb){1},...
                        %                             ' ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                        %                             'UserData',[1 1]);%,...
                        %
                        for jj=1:2
                            dg.tmp.pos(1,1)=dg.tmp.pos(1,1)+.05;
                            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj)=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
                                'units','normalized','HorizontalAlign','center',...
                                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                                'String',dg.(dg.tmp.abb).(dg.tmp.el).twoTxt{i}{1+jj});
                            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj);
                            switch jj
                                case 1 % 'to' text
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj),...
                                        'Style','text','UserData','',...
                                        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);%,'String',dg.(dg.tmp.abb).(dg.tmp.el).twoTxt{i,2});
                                    dg.enable.styleAdj='text';
                                    dg=enableObject(dg,1); dg.enable=rmfield(dg.enable,'styleAdj');
                                case 2 % second edit box
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj),...
                                        'Style',dg.tmp.style,...'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{1}),...
                                        'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
                                        'ToolTipString',['Push to ',dg.(dg.tmp.abb).push.twotts{i}{1},...
                                        dg.(dg.tmp.abb).push.tts{i}],'UserData',1,...
                                        'Callback',eval(dg.(dg.tmp.abb).push.twoCallback{1}));%,...);
                                    %                                         'ToolTipString',['type ',dg.(dg.tmp.abb).(dg.tmp.el).(dg.tmp.h_abb){1},...
                                    %                                         ' ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                                    %                                         'UserData',[1 2]);
                                    dg=enableObject(dg,0);
                            end
                        end
                    end
                case 'popupmenu'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'HorizontalAlign','right',...
                        'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
                    dg=enableObject(dg,1); % might not want this...
                case 'checkbox'
                    %                     xisp(dg.tmp.el)
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                        'value',1,'UserData',dg.(dg.tmp.abb).(dg.tmp.el).options{i},...
                        'callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{1}));
                    %                     set(dg.(dg.tmp.abb).([dg.tmp.h_abb,'Info']).head.h,...
                    %                         dg.(dg.tmp.abb).(dg.tmp.el).options{i}{2});
                    dg=enableObject(dg,1); % might not want this...
                    
            end
        end
    end
end

% % headings
% dg.(dg.tmp.abb).head.par=dg.(dg.tmp.abb).pan.h;
% dg.(dg.tmp.abb).head.abb={'scrnFile','grpFile','behFile','sesFile'};
% % if abbreviations are altered, must also be changed at getCheckbox & set
% % guiData functions.
% dg.(dg.tmp.abb).head.txt={'Screen','Group','Behaviour','Session'};
% dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
% dg.(dg.tmp.abb).head.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],[0 .05],[.05 .25 .15 .7],'opposite');
% % [columns row], [x gap y gap],[x y corner x y dimensions]
%
% % % editable
%
% % dg.(dg.tmp.abb).edit.pos=[.3 .82 .5 .08; 0 0 0 0; ...
% %     0 0 0 0; .3 .32 .5 .08; 0 0 0 0;0 0 0 0];
% %
% % dg.(dg.tmp.abb).edit.txt={'type data directory','','','type save directory','',''};
% %
% % dg.(dg.tmp.abb).edit.callback={'@getTxtEdit','','','@getTxtEdit','',''};
% % dg.(dg.tmp.abb).edit.tts={'Type in the directory of your raw doppler files',...
% %     '','','Type in the directory where the data will be saved to','',''};
%
% % % pushbutton
% % dg.(dg.tmp.abb).push.pos=[.85 .82 .1 .08;0 0 0 0; 0 0 0 0;.85 .32 .1 .08;...
% %     0 0 0 0;0 0 0 0];
% % dg.(dg.tmp.abb).push.txt={'...','...','...','...','',''};
% % dg.(dg.tmp.abb).push.tts={'Browse for data directory','','',...
% %     'Browse for save directory','',''}; % tooltip string
% % dg.(dg.tmp.abb).push.callback={'@browseDirectory','','','@browseDirectory','',''};
% % dg.(dg.tmp.abb).push.startDir={fileparts(which('dopOSCCI')),'','',fileparts(which('dopOSCCI')),'',''};
%
% % % popupmenu
% % dg.(dg.tmp.abb).pop.pos=[0 0 0 0;0 0 0 0; .3 .57 .5 .08;0 0 0 0;0 0 0 0;0 0 0 0];
% % dg.(dg.tmp.abb).pop.txt={'','','all files','','',''};
% % dg.(dg.tmp.abb).pop.tts={'','','select a single file to summarise',...
% %     '','',''}; % tooltip string
% % dg.(dg.tmp.abb).pop.callback={'','','@getPopEdit','','',''};
%
%
% % save check panel
% % dg.(dg.tmp.abb).check.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...
% %     'Title','Save','TitlePosition','CenterTop',...%'FontSize',12,...
% %     'Position',[.25 .25 .1 .73],...
% %     'ForegroundColor',dg.col.pt,'BackgroundColor',dg.tab.pan.col);
% % dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% % display check panel
%
% % checkbox headers...
% % Save and Display titles
% % dg.(dg.tmp.abb).chkHead.par=dg.(dg.tmp.abb).pan.h;
% % dg.(dg.tmp.abb).chkHead.abb={'save','disp'};
% % dg.(dg.tmp.abb).chkHead.title={'(Save','Display)'};
% % dg.(dg.tmp.abb).chkHead.pos=dgPositions([2 1],[0 0],[0 .2 .23 .08]);
% % for i=1:numel(dg.(dg.tmp.abb).chkHead.abb)
% %     dg.(dg.tmp.abb).chkHead.h(i)=uicontrol('Parent',dg.(dg.tmp.abb).chkHead.par,...
% %         'Style','text','String',dg.(dg.tmp.abb).chkHead.title{i},...
% %         'units','normalized','HorizontalAlign','center',...
% %         'tag',[dg.(dg.tmp.abb).chkHead.abb{i},'_title'],...
% %         'Position',dg.(dg.tmp.abb).chkHead.pos(i,:),...
% %         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
% %     dg.font.h(end+1)=dg.(dg.tmp.abb).chkHead.h(i);
% % end
%
%
% % checkbox
% % dg.(dg.tmp.abb).checkFuncs={'Save','Display'};
% % for i=1:2
% %     dg.tmp.chkAbb=['check',num2str(i)];
% %     dg.tmp.chkFunc=dg.(dg.tmp.abb).checkFuncs{i};
% %     dg.(dg.tmp.abb).(dg.tmp.chkAbb).par=dg.(dg.tmp.abb).pan.h;
% %     dg.(dg.tmp.abb).(dg.tmp.chkAbb).pos=dgPositions([1 dg.(dg.tmp.abb).head.n],[0 .05],...
% %         [.05+.1*(i-1) .25 .15*i .7],'opposite');
% dg.(dg.tmp.abb).check.pos=dgPositions([1 dg.(dg.tmp.abb).head.n],...
%     [.15 .15],[0 0 .3 1],'opposite');
%
% dg.(dg.tmp.abb).edit.pos=dgPositions([1 dg.(dg.tmp.abb).head.n],...
%     [0 .15],[.25 0 .5 1],'opposite');
%
% dg.(dg.tmp.abb).text.pos=dgPositions([1 dg.(dg.tmp.abb).head.n],...
%     [0 .15],[.2 -.1 .8 1],'opposite');
%
% dg.(dg.tmp.abb).push.pos=dgPositions([1 dg.(dg.tmp.abb).head.n],...
%     [0 .15],[.8 0 .1 1],'opposite');
%
% % end
% % % editable
%
% % dg.(dg.tmp.abb).edit.pos=[.3 .82 .5 .08; 0 0 0 0; ...
% %     0 0 0 0; .3 .32 .5 .08; 0 0 0 0;0 0 0 0];
% %
% % dg.(dg.tmp.abb).edit.txt={'type data directory','','','type save directory','',''};
% %
% % dg.(dg.tmp.abb).edit.callback={'@getTxtEdit','','','@getTxtEdit','',''};
% % dg.(dg.tmp.abb).edit.tts={'Type in the directory of your raw doppler files',...
% %     '','','Type in the directory where the data will be saved to','',''};
%
%
% dg.(dg.tmp.abb).el={'check','edit','push','text'};%{'head','check'};%,'edit','push','pop','check'}; % elements
% dg.(dg.tmp.abb).styles={'checkbox','edit','pushbutton','text'};%{'text','checkbox'};%,'edit','pushbutton','popupmenu','checkbox'};
% for i=1:dg.(dg.tmp.abb).head.n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
%     for j=1:numel(dg.(dg.tmp.abb).el);
%         dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
%
%         dg.(dg.tmp.abb).(dg.tmp.el).par=dg.(dg.tmp.abb).pan.h;
%         switch dg.tmp.el
%             case 'check'
%                 dg.(dg.tmp.abb).(dg.tmp.el).txt{i}=dg.(dg.tmp.abb).head.txt{i};
%                 dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=...
%                     ['Select to run ',dg.(dg.tmp.abb).head.txt{i},' function']; % tooltip string
%                 dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@getCheckbox';
%                 dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i},'Chk'];
%                 dg.(dg.tmp.abb).(dg.tmp.el).values(i)=0; % default is don't save or display
%             case 'edit'
%                 dg.(dg.tmp.abb).(dg.tmp.el).txt{i}=['type ',dg.(dg.tmp.abb).head.txt{i},' file function path'];
%                 dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=dg.(dg.tmp.abb).(dg.tmp.el).txt{i};
%                 %                     ['Type in ',dg.(dg.tmp.abb).head.txt{i},' file function path']; % tooltip string
%                 dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@getTxtEdit';
%                 dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i},'NameLoc'];
%             case 'text'
%                 dg.(dg.tmp.abb).(dg.tmp.el).txt{i}=[];'visualise...';
%                 dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i},'NameLoc'];
%             case 'push'
%                 dg.(dg.tmp.abb).(dg.tmp.el).txt{i}='...';
%                 dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=['Browse for ',dg.(dg.tmp.abb).head.txt{i},' file'];
%                 %                     ['Type in ',dg.(dg.tmp.abb).head.txt{i},' file function path']; % tooltip string
%                 dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@browseSpecialFuncFile';
%                 dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i}];
%                 dg.(dg.tmp.abb).(dg.tmp.el).startDir{i}=[fileparts(which('dopOSCCI')),'/taskData/'];
%         end
%
%
%         if sum(dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:)) % then we have something to place
%             %             fprintf('\t%u\t%u\t%s\t%s\n',i,j,dg.tmp.el,dg.tmp.style);
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).(dg.tmp.el).par,...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%             if ~strcmp(dg.tmp.style,'text')
%                 set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                     'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
%             end
%             switch dg.tmp.style
%                 case 'edit'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
%                         'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
%                         'tag',dg.(dg.tmp.abb).(dg.tmp.el).tag{i},...
%                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
%                         'HorizontalAlign','center');
%                     dg.enable.listAdj=dg.(dg.tmp.abb).(dg.tmp.el).tag{i};
%                     dg=enableObject(dg,1);
%                     dg.enable=rmfield(dg.enable,'listAdj');
%                 case 'text'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'UserData',[]);%,'FontSize',7); % empty
%                     dg=enableObject(dg,0);
%                 case 'pushbutton'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
%                         'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
%                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).startDir{i},...
%                         'HorizontalAlign','center');
%                     dg=enableObject(dg,0);
%                     %                 case 'popupmenu'
%                     %                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                     %                         'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
%                     %                         'HorizontalAlign','right',...
%                     %                         'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
%                     %                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
%                     %                     dg=enableObject(dg,1); % might not want this...
%                 case 'checkbox'
%                     %                     disp(dg.tmp.el)
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                         'value',dg.(dg.tmp.abb).(dg.tmp.el).values(i),...
%                         'tag',dg.(dg.tmp.abb).(dg.tmp.el).tag{i},...
%                         'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
%                         'UserData',0);%dg.(dg.tmp.abb).(dg.tmp.el).options{i});%,...
%                     dg.enable.styleAdj=[dg.tmp.h_abb,'Chk']; % don't want this to be 1 & 2 anymore
%                     %                     dg.enable.listAdj=dg.(dg.tmp.abb).(dg.tmp.el).tag{i};
%                     %                         'callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}));
%                     %                     set(dg.(dg.tmp.abb).([dg.tmp.h_abb,'Info']).head.h,...
%                     %                         dg.(dg.tmp.abb).(dg.tmp.el).options{i}{2});
%                     dg=enableObject(dg,1); % might not want this...
%                     dg.enable=rmfield(dg.enable,'styleAdj');
%
%             end
%         end
%     end
% end

end
%% >> dgCheckDataDir
% when we have a directory, check what's in it and update dataDirInfo &
% file selection list
function dg=dgCheckDataDir(dg)
[dg.data.files dg.data.report dg.dopdef.fileType]=dopOSCCIgetFileList(dg.dopdef.dataDir,1);

if ~isempty(dg.data.files)
    set(dg.dat.fileSel.pop.h,'String',...
        {get(dg.dat.fileSel.pop.h,'UserData'),dg.data.files{1:end}});
    set(dg.dat.dataDirInfo.head.h,'String',dg.data.report);
    %     set(dg.dat.dataDir.edit.h,'String',dg.dopdef.dataDir);
else
    set(dg.dat.dataDir.edit.h,'String',get(dg.dat.dataDir.edit.h,'UserData'))
end


end
%% >> dgCheckSaveDir
% when we have a directory, check what's in it and update dataDirInfo &
% file selection list
function dg=dgCheckSaveDir(dg)
dop.def = dg.dopdef; % dopSaveDirBase requires dop.def structure as dop.def
[dg.dopdef.saveDir dg.dopdef.sumDescrip dg.dopdef.saveDirBase]=dopSaveDirBase(dop);
set(dg.sav.saveDir.edit.h,'String',dg.dopdef.saveDirBase,...
    'Tooltipstring',sprintf('dopOSCCI summary description folder will be added to the end of this:\n\te.g., %s',dg.dopdef.sumDescrip));
clear dop

% if ~isempty(dg.data.files)
%     set(dg.dat.fileSel.pop.h,'String',...
%         {get(dg.dat.fileSel.pop.h,'UserData'),dg.data.files{1:end}});
%     set(dg.dat.dataDirInfo.head.h,'String',dg.data.report);
%     %     set(dg.dat.saveDir.edit.h,'String',dg.dopdef.saveDir);
% else
%     set(dg.dat.saveDir.edit.h,'String',get(dg.dat.saveDir.edit.h,'UserData'))
% end


end
%% >> dgEventNumberCheck
function dgEventNumberCheck(varargin)
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'Tag');
dg.tmp.field=strtok(dg.tmp.tag,'_');
% disp(dg.tmp.field);
% dg.tmp.evnt=varargin{2};
dg.tmp.import=0;
if numel(varargin)==2 && ~isempty(varargin{2})
    dg.tmp.evNum=varargin{2};
    dg.tmp.import=1;
    if ~isnumeric(dg.tmp.evNum)
        dg.tmp.evNum=str2double(dg.tmp.evNum);
    end
else
%     dg.tmp.evNum=str2double(get(dg.dat.evNum.push.h(2),'String'))+get(dg.tmp.h,'UserData');
    dg.tmp.evNum=str2double(get(dg.event.evNum.push.h(1,2),'String'))+get(dg.tmp.h,'UserData');
    
end
if dg.tmp.evNum>0
    if ~dg.tmp.import%numel(varargin)~=2
        disp(dg.tmp.field)
        dg.dopdef.(dg.tmp.field)=dg.tmp.evNum;
    end
    %     disp(dg.dopdef.(dg.tmp.field))
    %     set(dg.dat.evNum.push.h(2),'String',dg.tmp.evNum)
    if or(numel(dg.tab.event.h)<dg.dopdef.(dg.tmp.field),... % add new tab
            dg.tmp.import)
        
        i=dg.dopdef.(dg.tmp.field);
        if dg.tmp.import %numel(varargin)==2 && ~isempty(varargin{2})
            i=dg.tmp.evNum;
        end
        fprintf('%s%i%s\n','Creating New Event Tab (',i,')');
        dg.tmp.enables=numel(dg.enable.list); % find the number of these so we know how many are created, then enable them
        dg.tab.event.h(end+1) = uitab('v0', dg.tab.h,...
            'title', ['Event',num2str(i)],...
            'tag','event'); %['event',num2str(i)]
        dg=feval('dgEvent',dg,dg.tab.event.h(end),i);
        dg.tmp.enable=dg.tmp.enables+1:numel(dg.enable.list);
        dg=dgEventGraph(dg,i);
        dg=dgSetEventMatchList(dg);%,dg.event.evMatch.pop.h(i));
        set(dg.tab.h,'SelectedIndex',numel(get(dg.tab.h,'Children'))); % set selected as the new one
        %             set(dg.enable.h(dg.tmp.enable),'Enable','On');
        % & import data from previous event tab...
        %             for j=1:numel(dg.tmp.enable)
        %                 disp(dg.enable.list{dg.tmp.enable(j)});
        %                 try
        %                     set(dg.enable.h(dg.tmp.enable(j)),'Enable','On');
        %                 end
        %                 dg.tmp.ef=strtok(get(dg.enable.h(dg.tmp.enable(j)),'tag'),'_'); % enable field
        %                 dg.tmp.eud=get(dg.enable.h(dg.tmp.enable(j)),'UserData'); % enable user data
        %                 switch dg.tmp.ef
        %                     case 'evType'
        %                         set(dg.enable.h(dg.tmp.enable(j)),'Value',2);
        %                     otherwise
        %                         set(dg.enable.h(dg.tmp.enable(j)),'String',dg.dopdef.(dg.tmp.ef)(dg.tmp.eud(1)-1,dg.tmp.eud(2)));
        %                 end
        %             end
        
    elseif numel(dg.tab.event.h)>dg.dopdef.(dg.tmp.field) % remove tab...
        fprintf('\t%s %i\n','Deleting event tab',numel(dg.tab.event.h));
        % if on tab being removed, move back one
        if get(dg.tab.h,'SelectedIndex')==numel(get(dg.tab.h,'Children'))
            set(dg.tab.h,'SelectedIndex',get(dg.tab.h,'SelectedIndex')-2);
        end
        delete(dg.tab.event.h(end));
        
%         dg.enable.h(end-2:end)=[]; % remove from enable list as well...
%         dg.enable.list(end-2:end)=[]; % remove the labels as well
%         dg.enable.import(end-2:end)=[]; % remove the import details
        
        dg.tab.event.h(end)=[];
        dg.enable.remove=[];
        for i=1:numel(dg.enable.import)
            if ~ishandle(dg.enable.h(i)) || dg.enable.h(i)==0 
                dg.enable.remove(end+1)=i;
            end
        end
        if numel(dg.enable.remove)
            for i=1:numel(dg.enable.variables)
                dg.enable.(dg.enable.variables{i})(dg.enable.remove)=[];
            end
        end
        % clear handle collection for tab
        %         dg.event.evNames.edit.h(1:dg.tmp.evNum);
        %         dg.event.evType.radio.h=dg.event.evType.radio.h(1:dg.tmp.evNum,:);
        %         dg.event.evMatch.pop.h=dg.event.evMatch.pop.h(1:dg.tmp.evNum);
        
        %         dg.tmp.evList={dg.event.head.abb{1:end},'evType'};
        dg.event.pan.h=dg.event.pan.h(1:dg.tmp.evNum);
        dg.tmp.evList={dg.event.head.abb{1:end},'evType'};
        %         dg.tmp.names={'evType','evNames','evChs','epochs','sep','actWin',...
        %             'epoch','base','poi','evMatch'};
        dg.tmp.styles={'edit','edit','edit','edit','edit',...
            'edit','edit','edit','pop','push','radio'};
        for i=1:numel(dg.tmp.evList)
            if size(dg.event.(dg.tmp.evList{i}).(dg.tmp.styles{i}).h,2)==1
                dg.event.(dg.tmp.evList{i}).(dg.tmp.styles{i}).h=...
                    dg.event.(dg.tmp.evList{i}).(dg.tmp.styles{i}).h(1:dg.tmp.evNum);
            else
                dg.event.(dg.tmp.evList{i}).(dg.tmp.styles{i}).h=...
                    dg.event.(dg.tmp.evList{i}).(dg.tmp.styles{i}).h(1:dg.tmp.evNum,:);
            end
            if ~strcmp(dg.tmp.evList{i},'evNum')
                if sum(numel(dg.dopdef.(dg.tmp.evList{i}))==size(dg.dopdef.(dg.tmp.evList{i})))
                    % single row or column
                    dg.dopdef.(dg.tmp.evList{i})=dg.dopdef.(dg.tmp.evList{i})(1:dg.tmp.evNum);
                else
                    dg.dopdef.(dg.tmp.evList{i})=dg.dopdef.(dg.tmp.evList{i})(1:dg.tmp.evNum,:);
                end
            end
        end
    end
    dg=dgEventEnableSet(dg);
    %     if dg.tmp.evNum==1
    %         set(dg.event.evType.radio.h,'Enable','Off');
    %         set(dg.event.evMatch.pop.h,'Enable','Off');
    %     else
    %         fprintf('\t%s\n','Turning Event Radio & Popups On');
    %         set(dg.event.evType.radio.h,'Enable','On');
    %         set(dg.event.evMatch.pop.h,'Enable','On');
    %     end
    set(dg.dat.evNum.push.h(2),'String',dg.tmp.evNum)
    set(dg.event.evNum.push.h(:,2),'String',dg.tmp.evNum)
else
    dg.tmp.warn=sprintf('%s\n%s\n',...
        'Number of events must be numeric and greater than 0',...
        'Setting to 1');
    disp(dg.tmp.warn);
    warndlg(dg.tmp.warn,'Number of Events:');
    set(dg.tmp.h,'String','1');
end
% dg=rmfield(dg,'tmp');
end
%% >> dgEventNumberAdjust
% upon reset we need to reduce number of event tabs (if more than one)
% upon import we need to increase number of event tabs (if more than one
% required)
function dgEventNumberAdjust(setting)
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);

if isfield(dg,'dopdef') && dg.dopdef.evNum>1
    switch setting
        case 'import'
            for i=2:dg.dopdef.evNum
                % add extra event tabs
                dgEventNumberCheck(dg.dat.evNum.push.h(3),i);
                dg.tmp.ch=get(dg.event.pan.h(end),'Children');
                for j=1:numel(dg.tmp.ch)
                    try
                        set(dg.tmp.ch(j),'Enable','On');
                    end
                end
            end
        case 'reset'
            % remove extra event tabs
            for i=1:dg.dopdef.evNum-1
                dgEventNumberCheck(dg.dat.evNum.push.h(1));
            end
    end
end
end
%% > Event
function dg=dgEvent(dg,tmp_handle,k) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s %i\n',['Setting up ', dg.tmp.abb,' Tab:'],k);
dg.tmp.k=k; % keep a record in the dg structure

% dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%
% % separator panel
% dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.6 .2 .01 .75],'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;

dg.(dg.tmp.abb).n=1; % number of event tabs within tab, for different events or event types

% just going with single and creating new tabs for extra


% headings
dg.(dg.tmp.abb).head.use=[1 1 1 1 1 1 1 1 1 1];
dg.(dg.tmp.abb).head.abb={'evNames','evChs','epochs',...
    'sep','actWin','epoch','base','poi','evMatch','evNum'};%,'evType',
dg.(dg.tmp.abb).head.txt={'Event Name','Channel','Epochs','Separation',...
    'Act. Window','Epoch','Baseline','POI','Event Match:','Number of Events:'};
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.pos=dgPositions([dg.(dg.tmp.abb).head.n-2 1],[0 .05],[.1 .2 .2 .75],'opposite');
dg.(dg.tmp.abb).head.pos(9:10,:)=dg.(dg.tmp.abb).head.pos(7:8,:);
% colour square
dg.(dg.tmp.abb).col.pos=dgPositions([dg.(dg.tmp.abb).head.n-2 1],[.05 .05],[.025 .2 .05 .75],'opposite'); % for colour blocks
dg.(dg.tmp.abb).col.use=[0 0 0 1 1 1 1 1 0 0]; % logical have colour code for graph
dg.(dg.tmp.abb).col.code={'','','','m','y','b','k','g',''}; % matlab colour code
dg.(dg.tmp.abb).col.tts='colour code for below event timing schematic';
% edit
dg.(dg.tmp.abb).edit.pos=dgPositions([dg.(dg.tmp.abb).head.n-2 1],[.05 .05],[.3 .2 .05 .75],'opposite');
dg.(dg.tmp.abb).edit.pos(9:10,:)=dg.(dg.tmp.abb).edit.pos(7:8,:);
dg.(dg.tmp.abb).edit.use=[1 1 1 1 1 1 1 1 0 0];
dg.(dg.tmp.abb).edit.to=[0 0 0 0 0 1 1 1 0 0]; % 2 boxes with 'to' between
dg.(dg.tmp.abb).edit.callback={'@getTxtEdit'};
dg.(dg.tmp.abb).edit.pos(1,3)=dg.(dg.tmp.abb).edit.pos(1,3)*3;

dg.(dg.tmp.abb).edit.tts={'type event name - used for labelling',...
    'type event channel number - data file reference',...
    'type the number of expected epochs in data file',...
    'type the minimum separation (seconds) between markers (less will be ignored)',...
    'type the duration (seconds) of the activation window for LI calculation',...
    'epoch value (in seconds)',...
    'baseline value (in seconds)',...
    'period of interest value (in seconds)',...
    'if base or period of interest only, select matching event - data file reference','number of event'};

% event type radio
dg.(dg.tmp.abb).radio.abb={'both','poi','base'};%,'not'};
dg.(dg.tmp.abb).radio.txt={'Base & POI','Base Only','POI Only','Not in use'};
dg.(dg.tmp.abb).radio.tts={...
    'Select as Baseline & Period of Interest event marker(regular)',...
    'Select as Baseline Only event marker (requires matching Period of Interest marker)',...
    'Select as Period of Interest Only event marker (requires matching Baseline only marker)',...
    'Event maker Not in use'};
dg.(dg.tmp.abb).radio.code=[2 0 1 -1]; % user data
dg.(dg.tmp.abb).radio.n=numel(dg.(dg.tmp.abb).radio.abb);
dg.(dg.tmp.abb).radio.pos=dgPositions([dg.(dg.tmp.abb).radio.n 1],[.05 0],'opposite');
dg.(dg.tmp.abb).radio.chFunc='@dgEventTypeCheck';

dg.(dg.tmp.abb).pop.use=[0 0 0 0 0 0 0 0 1 0];
dg.(dg.tmp.abb).pop.pos=dg.(dg.tmp.abb).edit.pos;
dg.(dg.tmp.abb).pop.callback='@getPopEdit';
dg.(dg.tmp.abb).pop.default={'No Match (0)'};

dg.(dg.tmp.abb).push.use=[0 0 0 0 0 0 0 0 0 1];
dg.(dg.tmp.abb).push.pos=dg.(dg.tmp.abb).edit.pos;
dg.(dg.tmp.abb).push.callback='@dgEventNumberCheck';%'@getPopEdit';
dg.(dg.tmp.abb).push.default={'No Match (0)'};
dg.(dg.tmp.abb).push.twoTxt={'','','','','','','','','',{'-','','+'}};
% dg.(dg.tmp.abb).push.twoCallback={'@dgEventNumberCheck'};
dg.(dg.tmp.abb).push.tts={'','','','','','','','','',...
    'number of events'}; % tooltip string
dg.(dg.tmp.abb).push.twotts={'','','','','','','','','',{'Decrease','Increase'}};

dg.(dg.tmp.abb).el={'col','head','edit','pop','push'}; % elements
dg.(dg.tmp.abb).styles={'text','text','edit','popupmenu','pushbutton'};

% create tab:
%     dg.(dg.tmp.abb).tab.par.h=uitabgroup('v0','parent',dg.tmp.h,'position',[.01 .01 1 1],...
%     'BackgroundColor',dg.col.bg,'Units','Normalized');%dg.tab.pan.col);

% for k=1:dg.(dg.tmp.abb).n % each event
% create each tab
%     dg.(dg.tmp.abb).tab.h(k) = uitab('v0', dg.(dg.tmp.abb).tab.par.h,...
%         'title', ['Event',num2str(k)],'tag',['event',num2str(k)],...
%         'Units','Normalized');
dg.(dg.tmp.abb).pan.par(k)=dg.tmp.h;
dg.(dg.tmp.abb).pan.h(k)=uipanel('Parent',dg.(dg.tmp.abb).pan.par(k),'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h(k);

% separator panel
dg.(dg.tmp.abb).pan.sepH(k)=uipanel('Parent',dg.(dg.tmp.abb).pan.h(k),'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',[.6 .2 .01 .75],'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h(k);

% radio panel first
dg.tmp.h_abb='evType';dg.tmp.el='radio';
dg.(dg.tmp.abb).radio.pan.h(k)=uibuttongroup('parent',dg.(dg.tmp.abb).pan.h(k),...
    'Title','Event Type',...'ToolTipString','Select event Type',...
    'tag',dg.tmp.h_abb,'UserData',k,...
    'Units','Normalized','Position',[.65 .45 .3 .3],...
    'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
    'SelectionChangeFcn',eval(dg.(dg.tmp.abb).radio.chFunc));
dg.font.h(end+1)=dg.(dg.tmp.abb).radio.pan.h(k);

for i=1:dg.(dg.tmp.abb).radio.n
    dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,i)=uicontrol(...
        'Parent',dg.(dg.tmp.abb).(dg.tmp.el).pan.h(k),...
        'Units','Normalized','tag',[dg.tmp.h_abb,'_',dg.tmp.el],...
        'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).code(i),...
        'ToolTipString',dg.(dg.tmp.abb).radio.tts{i},...
        'Style','Radio','String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i});
    dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,i);
    dg=enableObject(dg,1,i);%dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,i);
end
if isfield(dg.enable,'setting') && strcmp(dg.enable.setting,'On')
    if numel(dg.dopdef.(dg.tmp.h_abb))<k
        dg.dopdef.(dg.tmp.h_abb)(k)=dg.dopdef.(dg.tmp.h_abb)(1);
    end
    dg.tmp.col=find(dg.dopdef.(dg.tmp.h_abb)(k)==dg.(dg.tmp.abb).radio.code,1,'first');
    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,dg.tmp.col),'Value',1);
    fprintf('\t%s\n',get(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,dg.tmp.col),'String'));
    dg=dgEventEnableSet(dg);
end



for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        if dg.(dg.tmp.abb).(dg.tmp.el).use(i);
            
            
            if i==dg.(dg.tmp.abb).head.n % set right position
                dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:)=dg.(dg.tmp.abb).(dg.tmp.el).pos(5,:); % same level as this
                dg.(dg.tmp.abb).(dg.tmp.el).pos(i,1)=.625+.2*(j-2);
            end
            % h (k, 1) here so we can add (k,2) etc. for epoch, base, & poi
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1)=...
                uicontrol('Parent',dg.(dg.tmp.abb).pan.h(k),...%dg.(dg.tmp.abb).pan.h,...
                'Style',dg.tmp.style,...
                'units','normalized','HorizontalAlign','center',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1);
            switch dg.tmp.style
                case 'text'
                    switch dg.tmp.el
                        case 'col'
                            if ~isempty(dg.(dg.tmp.abb).(dg.tmp.el).code{i})
                                set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                                    'BackgroundColor',dg.(dg.tmp.abb).(dg.tmp.el).code{i},...
                                    'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts)
                                % could resize this...
                            end
                        case 'head'
                            set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                                'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                                'HorizontalAlign','Left',...
                                'ToolTipString',dg.(dg.tmp.abb).edit.tts{i});
                            %                             dg=enableObject(dg,0);
                    end
                case 'edit'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                        'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i},...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{1}),...
                        'UserData',[k,1])
                    dg=enableObject(dg,1,1);
                    if isfield(dg.enable,'setting') && strcmp(dg.enable.setting,'On')
                        switch dg.tmp.h_abb
                            case 'evName'
                                if numel(dg.dopdef.(dg.tmp.h_abb))<k
                                    dg.dopdef.(dg.tmp.h_abb){k}=dg.dopdef.(dg.tmp.h_abb){1};
                                end
                                set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                                    'String',dg.dopdef.(dg.tmp.h_abb){k});
                            otherwise
                                if size(dg.dopdef.(dg.tmp.h_abb),1)<k
                                    dg.dopdef.(dg.tmp.h_abb)(k,:)=dg.dopdef.(dg.tmp.h_abb)(1,:);
                                end
                                set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                                    'String',dg.dopdef.(dg.tmp.h_abb)(k,1));
                        end
                    end
                    if dg.(dg.tmp.abb).(dg.tmp.el).to(i)
                        
                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                            'ToolTipString',['type Lower ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}]);%,...
                        for jj=1:2
                            dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
                            dg.tmp.pos(1,1)=dg.tmp.pos(1,1)+.1*jj;
                            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj)=uicontrol('Parent',dg.(dg.tmp.abb).pan.h(k),...
                                'units','normalized','HorizontalAlign','center',...
                                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
                                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
                            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj);
                            switch jj
                                case 1 % 'to' text
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj),...
                                        'Style','text','String','to');
                                case 2 % second edit box
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj),...
                                        'Style',dg.tmp.style,...
                                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{1}),...
                                        'ToolTipString',['type Upper ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                                        'UserData',[k,2]);
                                    dg=enableObject(dg,1,3);% 3?
                                    if isfield(dg.enable,'setting') && strcmp(dg.enable.setting,'On')
                                        %                                         if size(dg.dopdef.(dg.tmp.h_abb),1)<k
                                        %                                             dg.dopdef.(dg.tmp.h_abb)(k,2)=dg.dopdef.(dg.tmp.h_abb)(1,2);
                                        %                                         end
                                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj),...
                                            'String',dg.dopdef.(dg.tmp.h_abb)(k,2));
                                    end
                            end
                        end
                    end
                    
                case 'popupmenu'
                    
                    dg.(dg.tmp.abb).(dg.tmp.el).pos(i,[1 2 3])=[.725 .275 .2];
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k),...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                        'String',dg.(dg.tmp.abb).pop.default,...
                        'HorizontalAlign','right',...
                        'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback),...
                        'UserData',[k,1]); % empty
                    dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
                    dg.tmp.pos([1 2])=[.65 .35];
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).head.h(k),'Position',dg.tmp.pos);
                    dg=enableObject(dg,1); % might not want this...
                    if isfield(dg.enable,'setting') && strcmp(dg.enable.setting,'On') && numel(dg.dopdef.(dg.tmp.h_abb))<k
                        dg.dopdef.(dg.tmp.h_abb)(k)=dg.dopdef.(dg.tmp.h_abb)(1);
                    end
                case 'pushbutton'
                        dg.(dg.tmp.abb).(dg.tmp.el).pos(i,[1 2 3])=[.525 .8 .1];
                        
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                        'Callback',eval(dg.(dg.tmp.abb).push.callback),...
                        'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt);
                    dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
                    dg.tmp.pos([1 2 3])=[.65 .9 .35];
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).head.h(k),'Position',dg.tmp.pos)
                    
                    dg=enableObject(dg,0);
%                     if dg.(dg.tmp.abb).(dg.tmp.el).two(i) % num events
                        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
                        dg.tmp.pos(1,[1 2 3 4])=[dg.tmp.pos(1,1)+.2 ...
                            dg.tmp.pos(1,2)+.025 .05 .05];
                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1),...
                            'Position',dg.tmp.pos,...
                            'String',dg.(dg.tmp.abb).(dg.tmp.el).twoTxt{i}{1},...
                            'ToolTipString',['Push to ',dg.(dg.tmp.abb).push.twotts{i}{1},' ',...
                            dg.(dg.tmp.abb).push.tts{i}],'UserData',-1);%,...
%                             'Callback',eval(dg.(dg.tmp.abb).push.twoCallback{1}));%,...);
                        %                         set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        %                             'ToolTipString',['type ',dg.(dg.tmp.abb).(dg.tmp.style).(dg.tmp.h_abb){1},...
                        %                             ' ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                        %                             'UserData',[1 1]);%,...
                        %
                        for jj=1:2
                            dg.tmp.pos(1,1)=dg.tmp.pos(1,1)+.05;
                            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj)=...
                                uicontrol('Parent',dg.(dg.tmp.abb).pan.h(k),...
                                'units','normalized','HorizontalAlign','center',...
                                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                                'String',dg.(dg.tmp.abb).(dg.tmp.el).twoTxt{i}{1+jj});
                            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(1+jj);
                            switch jj
                                case 1 % 'number' text
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj),...
                                        'Style','text','UserData','',...
                                        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);%,'String',dg.(dg.tmp.abb).(dg.tmp.el).twoTxt{i,2});
                                    dg.enable.styleAdj='text';
                                    dg=enableObject(dg,1); dg.enable=rmfield(dg.enable,'styleAdj');
                                    if k>1
                                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj),...
                                            'Enable','On','String',num2str(k));
                                    end
                                case 2 % second edit box
                                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(k,1+jj),...
                                        'Style',dg.tmp.style,...'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback),...
                                        'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
                                        'ToolTipString',['Push to ',dg.(dg.tmp.abb).push.twotts{i}{1},...
                                        dg.(dg.tmp.abb).push.tts{i}],'UserData',1);%,...
%                                         'Callback',eval(dg.(dg.tmp.abb).push.twoCallback{1}));%,...);
                                    %                                         'ToolTipString',['type ',dg.(dg.tmp.abb).(dg.tmp.el).(dg.tmp.h_abb){1},...
                                    %                                         ' ',dg.(dg.tmp.abb).(dg.tmp.el).tts{i}],...
                                    %                                         'UserData',[1 2]);
                                    dg=enableObject(dg,0);
                            end
                        end
%                     end
            end
        end
    end
end
%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf(...
    '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
    'dopOSCCI Event Tab:',...
    'The Event Tab contains information defining individual event markers: ',...
    ['The Name, data channel, number of epochs, marker separation, ',...
    'activation window size, upper and lower epoch values, '],...
    'upper and lower baseline values, and upper and lower period of interest values.',...
    ['If using 2 or more event markers, the type of event can also be defined ',...
    'along with the matching event if appropriate (Base or Stim Only Event Types)'],...
    'Additional events can be added using the Data Tab',...
    dg.info.txtBreak,'Example Design:',...
    'The graph at the bottom displays a schematic of the event timings',...
    ['It allows you to see how the epoch, base, period of interest, and activation window ',...
    'relate to each other'],...
    'note: the dotted lines represent theoretical placement of parameters',...
    '> the actual placement of these values is dependent upon:',...
    ' * activation window = peak left - right difference in period of interest',...
    [' * 2nd event marker = actual separation of event markers, ',...
    ' the separation setting is just the minmum that will be used - values may be greater'],...
    ' * 2nd baseline = actual position of event maker (same as 2nd event marker)',...
    dg.info.txtBreak);
dg=dgTabInfo(dg);
% end
%% -> Event Figure/Graph
dg.event.fig.pos=[.05 .075 .85 .1];

dg.event.fig.lw=2;% linewidth
dg.event.fig.yLim=[0 1];
dg.event.fig.yepoch=[.75 .75];
dg.event.fig.ybase=[.5 .5];
dg.event.fig.ywin=[.35 .35];
dg.event.fig.ypoi=[.25 .25];
dg.event.fig.xLabel='(seconds)';
dg.event.fig.xLabelPos=[1.05 -.2 0]; % right level with numbers...

dg.event.fig.h(k)=axes('parent',dg.(dg.tmp.abb).pan.h(k),'position',dg.event.fig.pos,......
    'Ycolor',dg.col.pb,'Xcolor',dg.col.pb,'color',dg.col.pb,...
    'YTick',[],'XTickLabelMode','auto','Units','Normalized',...
    'Tag',['Event Axes ',num2str(k)]);
dg.event.fig.XTick=get(dg.event.fig.h(k),'XTick');
% set(dg.event.fig.h(k),'XTick',[]); % clear it before opened properly
dg.font.h(end+1)=dg.event.fig.h(k);
set(get(dg.event.fig.h(k),'XLabel'),'String',dg.event.fig.xLabel,...
    'Units','Normalized','Position',dg.event.fig.xLabelPos,...
    'BackgroundColor',dg.col.pb,'Visible','Off'); % will cover up numbers... a bit
dg.font.h(end+1)=get(dg.event.fig.h(k),'XLabel');

% dg=dgEventGraph(dg,k);
end
%% >> dgEventTypeCheck
function dgEventTypeCheck(varargin)
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['!!!! Running ', dg.tmp.dbstack(1).name,':']);
dg.tmp.h=varargin{1};
dg.tmp.evt=varargin{2}; % event information (from & to change handles);
dg.tmp.tag=get(dg.tmp.h,'tag');
% get first part e.g., from notes_edit
% just want 'notes'
dg.tmp.field=strtok(dg.tmp.tag,'_');
dg.tmp.ud=get(dg.tmp.h,'UserData');
dg.dopdef.(dg.tmp.field)(dg.tmp.ud)=get(dg.tmp.evt.NewValue,'UserData');
dg=dgEventMatchCheck(dg,dg.event.evMatch.pop.h(dg.tmp.ud),...
    dg.dopdef.(dg.tmp.field)(dg.tmp.ud));
dg=dgEventTypeFreeze(dg,dg.tmp.ud(1));
% dg.tmp.basePoi={'On','On'}; % enable settings
% switch dg.dopdef.(dg.tmp.field)(dg.tmp.ud)
%     case 1 % hold base
%         dg.tmp.basePoi{1}='Off';
%     case 0 % hold poi
%     dg.tmp.basePoi{2}='Off';
% end
% set(dg.event.base.edit.h(dg.tmp.ud,[1 3]),'Enable',dg.tmp.basePoi{1});
% set(dg.event.poi.edit.h(dg.tmp.ud,[1 3]),'Enable',dg.tmp.basePoi{2});

dg=dgEventGraph(dg);
end
%% >> dgEventTypeFreeze
function dg=dgEventTypeFreeze(dg,k)
dg.tmp.basePoi={'On','On'}; % enable settings
switch dg.dopdef.evType(k)
    case 1 % hold base
        dg.tmp.basePoi{1}='Off';
    case 0 % hold poi
        dg.tmp.basePoi{2}='Off';
end
set(dg.event.base.edit.h(k,[1 3]),'Enable',dg.tmp.basePoi{1});
set(dg.event.poi.edit.h(k,[1 3]),'Enable',dg.tmp.basePoi{2});
end
%% >> dgEventGraph
function dg=dgEventGraph(dg,varargin)

% which event?
if ~isempty(varargin)
    dg.tmp.k=varargin{1};
else
    dg.tmp.ud=get(dg.tmp.h,'UserData');
    dg.tmp.k=dg.tmp.ud(1);
end
k=dg.tmp.k;
fprintf('%s %i\n','Setting Event Graph',k);
dg.tmp.tab='event';
% if k>1; dg.tmp.tab=[dg.tmp.tab,num2str(k)];end

if ishold(dg.event.fig.h(k))
    hold(dg.event.fig.h(k)); % release
end
% set(dg.event.fig.h(k),'XTick',dg.event.fig.XTick)
cla(dg.event.fig.h(k));
set(dg.event.fig.h(k),'XTickLabel',[]);%drawnow;
% dg.event.fig.h
% dg.col.fbg=[.65 .65 .65]; % light grey
set(dg.event.fig.h(k),'color',dg.col.fbg,'Ycolor',dg.col.fbg,...
    'Xcolor',dg.col.pt);
% set(get(dg.event.fig.h(k),'XLabel'),'String',dg.event.fig.xLabel);

% dg.event.fig.lw=2;% linewidth
% dg.event.fig.yLim=[0 1];
% dg.event.fig.yepoch=[.75 .75];
% dg.event.fig.ybase=[.5 .5];
% dg.event.fig.ywin=[.35 .35];
% dg.event.fig.ypoi=[.25 .25];

%% ~> axis dimensions
% dg.event.fig.xLim=[-dg.data.base(2) dg.data.trialSeparation];
% dg.event.fig.xLim=[dg.data.base(1) dg.data.trialSeparation]; % 26-2-10
dg.event.fig.xLim=[dg.dopdef.epoch(k,1) dg.dopdef.sep(k)]; % 1-3-10
dg.event.fig.xAbs=length(dg.event.fig.xLim(1):dg.event.fig.xLim(2));
dg.event.fig.xExt=dg.event.fig.xAbs*.1; % extend the axes a little each way
% dg.event.fig.xLim=[-dg.data.base(2)-dg.event.fig.xExt dg.data.trialSeparation+dg.event.fig.xExt];
dg.event.fig.xLim=[dg.dopdef.epoch(k,1)-dg.event.fig.xExt dg.dopdef.sep(k)+dg.event.fig.xExt];

% dg.event.fig.tmpX=ceil(dg.event.fig.xLim(1)/10):floor(dg.event.fig.xLim(2)/10);
% set(dg.event.fig.h,'XTickLabel',get(dg.event.fig.h,'XTick'));

% dg.event.fig.yLim=[0 1];
% dg.event.fig.yepoch=[.75 .75];
% dg.event.fig.ybase=[.5 .5];
% dg.event.fig.ywin=[.35 .35];
% dg.event.fig.ypoi=[.25 .25];

dg.event.fig.axis=[dg.event.fig.xLim dg.event.fig.yLim];
axis(dg.event.fig.h(k),dg.event.fig.axis);
% if ~ishold(dg.event.fig.h(k))
hold(dg.event.fig.h(k)); % hold
% end

set(dg.event.fig.h(k),'XTickLabel',get(dg.event.fig.h(k),'XTick'));
set(get(dg.event.fig.h(k),'XLabel'),'Visible','On');
% dg.event.col.code={'','','','m','y','b','k','g',''}; % matlab colour code
% dg.(dg.tmp.abb).head.txt={'Name','Channel','Epochs','Separation',...
%     'Act. Window','Epoch','Baseline','POI','Event Match'};

%% ~> onsets
dg.event.fig.xonset=[0 dg.dopdef.sep(k)];
dg.event.fig.yonset=dg.event.fig.yLim;

plot(dg.event.fig.h(k),[dg.event.fig.xonset(1) dg.event.fig.xonset(1)],...
    dg.event.fig.yonset,dg.event.col.code{4},'LineWidth',dg.event.fig.lw);
plot(dg.event.fig.h(k),[dg.event.fig.xonset(2) dg.event.fig.xonset(2)],...
    dg.event.fig.yonset,dg.event.col.code{4},'LineWidth',dg.event.fig.lw,...
    'LineStyle',':');

%% ~> epoch or trial length
% dg.event.fig.xepoch=[0 dg.data.epoch(2)]; old
dg.event.fig.xepoch=dg.dopdef.epoch(k,:); %[dg.data.epoch(1) dg.data.epoch(2)]; % 1-3-10
% dg.event.fig.yepoch=[.75 .75];
% dg.event.fig.ybase=[.5 .5];
% dg.event.fig.ywin=[.35 .35];
% dg.event.fig.ypoi=[.25 .25];
plot(dg.event.fig.h(k),dg.event.fig.xepoch,dg.event.fig.yepoch,dg.event.col.code{6},'LineWidth',dg.event.fig.lw);

if sum(dg.dopdef.evType(k)==[0 2])
    %% ~> baseline 1
    dg.event.fig.xbase1=dg.dopdef.base(k,:); %[-dg.data.base(2) -dg.data.base(1)];
    % dg.event.fig.ybase=[.5 .5];
    % dg.event.fig.ywin=[.35 .35];
    % dg.event.fig.ypoi=[.25 .25];
    plot(dg.event.fig.h(k),dg.event.fig.xbase1,dg.event.fig.ybase,dg.event.col.code{7},'LineWidth',dg.event.fig.lw);
    
    %% ~> baseline 2
    dg.event.fig.xbase2=dg.dopdef.sep(k)+dg.dopdef.base(k,:); %[dg.data.trialSeparation-dg.data.base(2)  dg.data.trialSeparation-dg.data.base(1)];
    plot(dg.event.fig.h(k),dg.event.fig.xbase2,dg.event.fig.ybase,dg.event.col.code{7},...
        'LineWidth',dg.event.fig.lw,'LineStyle',':');
end
if sum(dg.dopdef.evType(k)==[1 2])
    %% ~> activation window
    % dg.event.fig.ywin=[.35 .35];
    % dg.event.fig.ypoi=[.25 .25];
    dg.event.fig.poiCentre=dg.dopdef.poi(k,1)+diff(dg.dopdef.poi(k,:))*.5;
    dg.event.fig.actWin=[-dg.dopdef.actWin(k)*.5 dg.dopdef.actWin(k)*.5]+dg.event.fig.poiCentre;
    plot(dg.event.fig.h(k),dg.event.fig.actWin,dg.event.fig.ywin,dg.event.col.code{5},...
        'LineWidth',dg.event.fig.lw,'LineStyle',':');
    
    %% ~> period of interest
    dg.event.fig.xpoi=[dg.dopdef.poi(k,1) dg.dopdef.poi(k,2)];
    % dg.event.fig.ypoi=[.25 .25];
    plot(dg.event.fig.h(k),dg.event.fig.xpoi,dg.event.fig.ypoi,dg.event.col.code{8},'LineWidth',dg.event.fig.lw);
end
end
%% >> dgSetEventMatchList
% requires object handle
function dg=dgSetEventMatchList(dg) %,h)
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
% dg.tmp.ud=get(h,'UserData');
for i=1:numel(dg.event.evMatch.pop.h);%dg.dopdef.evNum
    if numel(dg.event.evMatch.pop.h)>=i % list handle exists
        dg.tmp.evMatchList=dg.event.pop.default; % is cell
        for j=1:numel(dg.event.evMatch.pop.h)%dg.dopdef.evNum
            if j~=i%dg.tmp.ud(i)
                if iscell(dg.dopdef.evNames{j})
                    dg.dopdef.evNames{j}=dg.dopdef.evNames{j}{1};
                end
                dg.tmp.evMatchList{end+1}=...
                    [dg.dopdef.evNames{j},' (',num2str(j),')'];
            end
        end
        dg.tmp.data=1; % no match
        if dg.dopdef.evMatch(i)
            if isfield(dg.dopdef,'evNames') && numel(dg.dopdef.evNames)>=i && numel(dg.dopdef.evMatch)>=i
                
                for j=1:numel(dg.tmp.evMatchList)
                    [dg.tmp.evName dg.tmp.num]=dgGetMatchListInfo(dg.tmp.evMatchList{j});
                    if strcmp(dg.dopdef.evNames{dg.dopdef.evMatch(i)},dg.tmp.evName) && dg.dopdef.evMatch(i)==dg.tmp.num
                        dg.tmp.data=j;
                    end
                end
            end
        end
        %             dg.tmp.row=find(dg.dopdef.evType(k)==dg.tmp.evTypes);
        %     set(dg.event.evType.radio.h(k,dg.tmp.data),'Value',1);
        %         disp(dg.tmp.evMatchList); disp(dg.tmp.data)
        set(dg.event.evMatch.pop.h(i),'String',dg.tmp.evMatchList);%,...
        set(dg.event.evMatch.pop.h(i),'value',dg.tmp.data)
    end
    %     set(h,'String',dg.tmp.evMatchList)
end
% clear h
end
% %% >> dgEventMatchPop
% function dgEventMatchPop(varargin)
%
% end
%% >> dgEventMatchCheck
% dg = gui structure
% h = radio handle
% varargin = setting, if import, don't want to check values - use imported
function dg=dgEventMatchCheck(dg,h,varargin)
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
eventType=[];

dg.tmp.h=h;
dg.tmp.data=get(dg.tmp.h,'String'); % get selected string
dg.tmp.data=dg.tmp.data{get(dg.tmp.h,'Value')}; % get selected string
[dg.tmp.evName dg.tmp.num]=dgGetMatchListInfo(dg.tmp.data);
%     [dg.tmp.evName dg.tmp.remain]=strtok(dg.tmp.data,'(');
%     dg.tmp.num=str2double(strrep(strtok(dg.tmp.remain,')'),'(',''));
dg.tmp.ud=get(dg.tmp.h,'UserData');
dg.dopdef.evMatch(dg.tmp.ud(1))=dg.tmp.num;
% else
%     dg.tmp.num
% end
% if size(dg.dopdef.evMatch,2)>1 % if 2 columns, clear second - shouldn't be there
%     dg.dopdef.evMatch=dg.dopdef.evMatch(:,1);
% end

    
if isempty(varargin)
    if dg.tmp.num==0 && dg.dopdef.evType(dg.tmp.ud(1))~=2
        % can't be stim & base
        set(dg.event.evType.radio.h(dg.tmp.ud(1),1),'Value',1);
        dg.dopdef.evType(dg.tmp.ud(1))=2;  dg.dopdef.evMatch(dg.tmp.ud(1))=0;
        dg.tmp.warn=sprintf('%s\n%s\n',...
            'For event matching, non-matched events must be ''Base Only'' or ''POI Only''',...
            'Set event type to ''Base & POI'' setting');
        disp(dg.tmp.warn);
        warndlg(dg.tmp.warn,'Event Match ~ Event Type:','modal');
    elseif dg.tmp.num>0 && dg.dopdef.evType(dg.tmp.ud(1))==2
        % can't be stim & base
        set(dg.event.evType.radio.h(dg.tmp.ud(1),2),'Value',1);
        dg.dopdef.evType(dg.tmp.ud(1))=1; dg.dopdef.evMatch(dg.tmp.ud(1))=dg.tmp.adjNum;
        dg.tmp.warn=sprintf('%s\n%s\n',...
            'For event matching, matched events must be ''Base Only'' or ''POI Only''',...
            'Set event type OFF ''Base & POI'' setting');
        disp(dg.tmp.warn);
        warndlg(dg.tmp.warn,'Event Match ~ Event Type:','modal');
    end
else
    eventType=varargin{1};
    eventStrings=get(dg.event.evMatch.pop.h(dg.tmp.ud(1)),'String');
    eventMatch=eventStrings{1};
    if numel(eventStrings)>1;eventMatch=eventStrings{2}; end
    [dg.tmp.adjName dg.tmp.adjNum]=dgGetMatchListInfo(eventMatch);
    if eventType==2 && dg.tmp.num~=0 %dg.dopdef.evType(dg.tmp.ud(1))~=2
        % must be no match
        %         set(dg.event.evType.radio.h(dg.tmp.ud(1),1),'Value',1);
        %         dg.dopdef.evType(dg.tmp.ud(1))=2;
        set(dg.event.evMatch.pop.h(dg.tmp.ud(1)),'Value',1);
            dg.dopdef.evMatch(dg.tmp.ud(1))=0;
        dg.tmp.warn=sprintf('%s\n%s\n',...
            'For event matching, non-matched events must be ''Base & POI''',...
            'Set event match to ''No Match (0)'' setting');
        disp(dg.tmp.warn);
        warndlg(dg.tmp.warn,'Event Match ~ Event Type:','modal');
    elseif eventType<2 && dg.tmp.num==0
        set(dg.event.evMatch.pop.h(dg.tmp.ud(1)),'Value',2);
        eventStrings=get(dg.event.evMatch.pop.h(dg.tmp.ud(1)),'String');
        eventMatch=eventStrings{2};
        [dg.tmp.adjName dg.tmp.adjNum]=dgGetMatchListInfo(eventMatch);
        dg.dopdef.evMatch(dg.tmp.ud(1))=dg.tmp.adjNum;
        dg.tmp.warn=sprintf('%s\n%s\n',...
            'For event matching, matched events must be ''Base Only'' or ''POI Only''',...
            ['Set event match to ',eventMatch]);
        disp(dg.tmp.warn);
        warndlg(dg.tmp.warn,'Event Match ~ Event Type:','modal');
    end
    
end

end
%% ~ dgGetMatchListInfo
function [name num]=dgGetMatchListInfo(listName)
dg.tmp.dbstack=dbstack;
% fprintf('%s\n\t\n',['Running ', dg.tmp.dbstack(1).name,':'],...
%     ['List name = ',listName]);

[name remain]=strtok(listName,'(');
num=str2double(strrep(strtok(remain,')'),'(',''));
name=strrep(name,' ','');
% fprintf('\t%s\n\t\t%s\t%s\n\t\t%s\t%i\n','Found',...
%     'Name',name,'Number',num);

end
%% ~ dgEventEnableSet
function dg=dgEventEnableSet(dg)
if sum(size(dg.event.evType.radio.h)==1)
%     set(get(dg.event.pan.h,'Children'),'Enable','On');
    set([dg.event.base.edit.h dg.event.poi.edit.h],'Enable','On');
    set(dg.event.evType.radio.h,'Enable','Off');
    set(dg.event.evType.radio.h(1),'Value',1);
        dg.dopdef.evType=2;
    set(dg.event.evMatch.pop.h,'Enable','Off','Value',1);
        dg.dopdef.evMatch=0;
        
elseif strcmp(dg.enable.setting,'On')
    fprintf('\t%s\n','Turning Event Radio & Popups On');
    set(dg.event.evType.radio.h,'Enable','On');
    set(dg.event.evMatch.pop.h,'Enable','On');
end
end
%% > Graphs
function dg=dgGraphs(dg,tmp_handle) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% % separator panel
% dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .5 .9 .01],'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;

%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf(...
    '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
    'dopOSCCI Graph Tab:',...
    ['The dopOSCCI summary allows for the creation of a series of graphs ',...
    'which are useful for visualising different stages of data processing'],...
    'The graphs can be saved as images files for later examination (left check boxes)',...
    'Or the graphs can be displayed as the summary is carried out (right check boxes)',...
    ['The Display setting requires a key-press or mouse click for each graph ',...
    'and is therefore not recommended for large data sets as it is time consuming'],...
    dg.info.txtBreak,'Graphs:',...
    'Raw = depicts the imported raw data: left, right, and event markers',...
    'Norm = depicts the normalised left and right data along with the raw and to-be-used event markers',...
    ['Individual = left, right, and difference data averaged across selected epochs ',...
    'which are used for the laterality index calculation based on individual data files'],...
    'Epoch = left, right, and difference data for each epoch (usually very noisy)',...
    ['Behavioural = same as individual graph but epochs selected based on ',...
    'behavioural settings (see Special Tab, Behavioural)'],...
    'Overall = same as individual graph but averaged across all available data files',...
    dg.info.txtBreak);
dg=dgTabInfo(dg);

% headings
dg.(dg.tmp.abb).head.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).head.abb={'raw','norm','ind','epoch','beh','grp'};
% if abbreviations are altered, must also be changed at getCheckbox & set
% guiData functions.
dg.(dg.tmp.abb).head.txt={'Raw','Normed','Individual','Epoch','Behavioural','Overall'};
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],[0 .05],[.05 .05 .2 .85],'opposite');
% [columns row], [x gap y gap],[x y corner x y dimensions]

% info
dg.(dg.tmp.abb).info.txt={'Depicts the imported raw data: left, right, and event markers',...
    'Depicts the normalised left and right data along with the raw and to-be-used event markers',...
    ['Depicts the left, right, and difference data averaged across selected epochs ',...
    'based on individual data files'],...
    'Depicts left, right, and difference data for each epoch (usually very noisy)',...
    ['Is the same as individual graph but epochs are selected/divided based on ',...
    'behavioural settings (see Special Tab, Behavioural)'],...
    'Is the same as individual graph but averaged across all available data files'};

% checkbox headers...
% Save and Display titles
dg.(dg.tmp.abb).chkHead.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).chkHead.abb={'save','disp'};
dg.(dg.tmp.abb).chkHead.title={'(Save','Display)'};
dg.(dg.tmp.abb).chkHead.tts={'Select to save an image file of the graph',...
    'Select to Display graph during summary - requires interaction (mouse-click or keypress), not recommended'};
dg.(dg.tmp.abb).chkHead.pos=dgPositions([1 2],[0 0],[.01 .88 .17 .07]);
for i=1:numel(dg.(dg.tmp.abb).chkHead.abb)
    dg.(dg.tmp.abb).chkHead.h(i)=uicontrol('Parent',dg.(dg.tmp.abb).chkHead.par,...
        'Style','text','String',dg.(dg.tmp.abb).chkHead.title{i},...
        'units','normalized','HorizontalAlign','center',...
        'tag',[dg.(dg.tmp.abb).chkHead.abb{i},'_title'],...
        'Position',dg.(dg.tmp.abb).chkHead.pos(i,:),...
        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
        'ToolTipString',dg.(dg.tmp.abb).chkHead.tts{i});
    dg.font.h(end+1)=dg.(dg.tmp.abb).chkHead.h(i);
end


% checkbox
dg.(dg.tmp.abb).checkFuncs={'Save','Display'};
for i=1:2
    dg.tmp.chkAbb=['check',num2str(i)];
    dg.tmp.chkFunc=dg.(dg.tmp.abb).checkFuncs{i};
    dg.(dg.tmp.abb).(dg.tmp.chkAbb).par=dg.(dg.tmp.abb).pan.h;
    dg.(dg.tmp.abb).(dg.tmp.chkAbb).pos=dgPositions([dg.(dg.tmp.abb).head.n 1],[0 .05],...
        [.05+.05*(i-1) .15 .15*i .79],'opposite');
    for j=1:dg.(dg.tmp.abb).head.n
        if i==1
            dg.(dg.tmp.abb).(dg.tmp.chkAbb).txt{j}='';%,'','','','',''};
        else
            dg.(dg.tmp.abb).(dg.tmp.chkAbb).txt{j}=dg.(dg.tmp.abb).head.txt{j};
        end
        dg.(dg.tmp.abb).(dg.tmp.chkAbb).tts{j}=...
            ['Select to ',dg.tmp.chkFunc,' ',dg.(dg.tmp.abb).head.txt{j},' graph']; % tooltip string
        dg.(dg.tmp.abb).(dg.tmp.chkAbb).callback{j}='@getCheckbox';
        dg.(dg.tmp.abb).(dg.tmp.chkAbb).options{j}=[i j]; % dop.def.graph row column coordinates
        dg.(dg.tmp.abb).(dg.tmp.chkAbb).values(j)=0; % default is don't save or display
        dg.(dg.tmp.abb).(dg.tmp.chkAbb).tag{j}=['graphs_',...
            dg.(dg.tmp.abb).head.txt{j},'_',dg.tmp.chkAbb]; % default is don't save or display
    end
end

dg.(dg.tmp.abb).el={'check1','check2'};%{'head','check'};%,'edit','push','pop','check'}; % elements
dg.(dg.tmp.abb).styles={'checkbox','checkbox'};%{'text','checkbox'};%,'edit','pushbutton','popupmenu','checkbox'};
for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        
        if sum(dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:)) % then we have something to place
            %             fprintf('\t%u\t%u\t%s\t%s\n',i,j,dg.tmp.el,dg.tmp.style);
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).(dg.tmp.el).par,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
            
            if ~strcmp(dg.tmp.style,'text')
                set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                    'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
            end
            switch dg.tmp.style
                case 'checkbox'
                    %                     disp(dg.tmp.el)
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                        'value',dg.(dg.tmp.abb).(dg.tmp.el).values(i),...
                        'tag',dg.(dg.tmp.abb).(dg.tmp.chkAbb).tag{i},...
                        'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.chkAbb).callback{i}),...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).options{i});%,...
                    dg.enable.styleAdj='check'; % don't want this to be 1 & 2 anymore
                    dg=enableObject(dg,1); % might not want this...
                    dg.enable=rmfield(dg.enable,'styleAdj');
                    
            end
        end
        if j==2 % place the graph info text
            dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:);
            dg.tmp.pos([1 2 3])=[dg.tmp.pos(1)+.16 dg.tmp.pos(2)-0.02 .7];
            %             if i==1;dg.tmp.pos(3)=.45; end % fit in the image selection
            dg.(dg.tmp.abb).(dg.tmp.h_abb).info.h(i)=uicontrol('Parent',dg.(dg.tmp.abb).(dg.tmp.el).par,...
                'Style','text','String',dg.(dg.tmp.abb).info.txt{i},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_graphInfo'],'Position',dg.tmp.pos,...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).info.h(i);
            
            % & test graph button
            if i < 3 % just for the raw & norm at this stage
                dg.tmp.butPos = dg.tmp.pos;
                dg.tmp.butPos([1 2 3]) = [sum(dg.tmp.pos([1 3])) dg.tmp.pos(2)+.025 .025];
                dg.(dg.tmp.abb).(dg.tmp.h_abb).test.h(i)=uicontrol('Parent',dg.(dg.tmp.abb).(dg.tmp.el).par,...
                    'Style','pushbutton','String','*',...
                    'units','normalized','HorizontalAlign','Left',...
                    'tag',[dg.tmp.h_abb,'_graphTest'],'Position',dg.tmp.butPos,...
                    'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.y,...
                    'Tooltipstring','click to test/see graph for selected file or first in list',...
                    'callback',eval('@dgGraphTest'),'UserData',i);
                dg.tmp.el = 'test';
                dg=enableObject(dg,1);
                dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).test.h(i);
            end
        end
    end
end
%% -> Graph File Type
dg.(dg.tmp.abb).pop.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).pop.abb={'graphFileType'};
% if abbreviations are altered, must also be changed at getCheckbox & set
% guiData functions.
% dg.(dg.tmp.abb).head.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).head.abb={'raw','norm','ind','epoch','beh','grp'};
dg.(dg.tmp.abb).pop.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).pop.pos=dgPositions([1 2],[.1 0],[.01 .01 .3 .08],'across');
%     dg.(dg.tmp.abb).graphFileType={'jpg'};
dg.(dg.tmp.abb).pop.txt={'Image Type',{'jpg','fig','tif','bmp','eps','png'}}; % save figures as
dg.(dg.tmp.abb).pop.tts={'select graph image file type'};
% could be any of these formats: see matlab saveas function
% ai	- Adobe® Illustrator `88
% bmp	- Windows bitmap
% emf	- Enhanced metafile
% eps	- EPS Level 1
% fig	- MATLAB figure (invalid for Simulink block diagrams)
% jpg	- JPEG image (invalid for Simulink block diagrams)
% m	- MATLAB M-file (invalid for Simulink block diagrams)
% pbm	- Portable bitmap
% pcx	- Paintbrush 24-bit
% pdf	- Portable Document Format
% pgm	- Portable Graymap
% png	- Portable Network Graphics
% ppm	- Portable Pixmap
% tif - TIFF image, compressed
dg.tmp.h_abb=dg.(dg.tmp.abb).pop.abb{1};
dg.(dg.tmp.abb).pop.el={'head','pop'};
dg.(dg.tmp.abb).pop.styles={'text','popupmenu'};
dg.tmp.pan=[dg.tmp.h_abb,'Pop'];
for i=1:2
    dg.tmp.el=dg.(dg.tmp.abb).pop.el{i};dg.tmp.style=dg.(dg.tmp.abb).pop.styles{i};
    switch i
        case 1
            dg.(dg.tmp.abb).pan.pop=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
                'Position',[.025 .025 .25 .15],'BackgroundColor',dg.tab.pan.col,...
                'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
                'Title',dg.(dg.tmp.abb).pop.txt{i},'units','normalized');
            dg.font.h(end+1)=dg.(dg.tmp.abb).pan.pop;
        case 2
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.pop,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).pop.txt{i},...
                'units','normalized','HorizontalAlign','Right',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',[.1 0 .8 .9],...dg.(dg.tmp.abb).pop.pos(i,:),...'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).pop.tts{1},...); %set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                'UserData',dg.(dg.tmp.abb).pop.txt{i},'callback',eval('@getPopEdit'));
            dg=enableObject(dg,1);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
    end
    
end

%% -> Graph Epoch Selection
dg.(dg.tmp.abb).pop2.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).pop2.abb={'graphEpochSel'};
% if abbreviations are altered, must also be changed at getCheckbox & set
% guiData functions.
% dg.(dg.tmp.abb).head.par=dg.(dg.tmp.abb).pan.h;
% dg.(dg.tmp.abb).head2.abb={'all','length','activation','manual','combined'};
% dg.(dg.tmp.abb).pop2.n=numel(dg.(dg.tmp.abb).head.abb);
% dg.(dg.tmp.abb).pop2.pos=dgPositions([1 2],[.1 0],[.41 .01 .3 .08],'across');
%     dg.(dg.tmp.abb).graphFileType={'jpg'};
dg.(dg.tmp.abb).pop2.txt={'Epoch Selection',{'all','length','activation','manual','combined'}}; % save figures as
dg.(dg.tmp.abb).pop2.tts={'select which epochs will be used for Individual, Behavioural, & Overall graphs'};
dg.tmp.note=['Individual, Behavioural (if used), and Overall graphs will ',...
    ' use £ '];
dg.(dg.tmp.abb).pop2.notes={...
    strrep(dg.tmp.note,'£','all available epochs.'),...
    [strrep(dg.tmp.note,'£','length appropriate epochs.'),' If the first or last ',...
    'epochs are short, these will not be included.'],...
    [strrep(dg.tmp.note,'£','activation appropriate epochs.'),' If normed ',...
    'activation values are outside set limits (see Data Tab), these will not be inlcuded.'],...
    [strrep(dg.tmp.note,'£','manually selected epochs.'),' If the Manual function ',...
    'is selected (see Special Tab), only manually selected epochs will be included.'],...
     [strrep(dg.tmp.note,'£',''),'length appropriate, activation appropriate, ',...
    'and manually selected epochs (recommended).']};
% could be any of these formats: see matlab saveas function
% ai	- Adobe® Illustrator `88
% bmp	- Windows bitmap
% emf	- Enhanced metafile
% eps	- EPS Level 1
% fig	- MATLAB figure (invalid for Simulink block diagrams)
% jpg	- JPEG image (invalid for Simulink block diagrams)
% m	- MATLAB M-file (invalid for Simulink block diagrams)
% pbm	- Portable bitmap
% pcx	- Paintbrush 24-bit
% pdf	- Portable Document Format
% pgm	- Portable Graymap
% png	- Portable Network Graphics
% ppm	- Portable Pixmap
% tif - TIFF image, compressed
dg.tmp.h_abb=dg.(dg.tmp.abb).pop2.abb{1};
dg.(dg.tmp.abb).pop2.el={'head','pop','note',};
dg.(dg.tmp.abb).pop2.styles={'text','popupmenu','text'};
dg.tmp.pan=[dg.tmp.h_abb,'Pop2'];
for i=1:3
    dg.tmp.el=dg.(dg.tmp.abb).pop2.el{i};dg.tmp.style=dg.(dg.tmp.abb).pop2.styles{i};
    switch i
        case 1
            dg.(dg.tmp.abb).pan.pop2=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
                'Position',[.3 .025 .25 .15],'BackgroundColor',dg.tab.pan.col,...
                'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
                'Title',dg.(dg.tmp.abb).pop2.txt{i},'units','normalized');
            dg.font.h(end+1)=dg.(dg.tmp.abb).pan.pop2;
        case 2
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.pop2,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).pop2.txt{i},...
                'units','normalized','HorizontalAlign','Right',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',[.1 0 .8 .9],...dg.(dg.tmp.abb).pop.pos(i,:),...'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).pop2.tts{1},...); %set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                'UserData',dg.(dg.tmp.abb).pop2.txt{i},'callback',eval('@getPopEdit'));
            dg=enableObject(dg,1);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        case 3
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
                'Style',dg.tmp.style,'String','',...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',[.56 0.01 .43 .15],...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'UserData',dg.(dg.tmp.abb).pop2.notes,'FontSize',7,...
                'Tooltipstring','Epoch Selection notes - make a selection');
            
    end
    
end
end
%% >> dgGraphDataChCheck
function dg=dgGraphDataChCheck(dg)
switch dg.tmp.field
    case {'graphs','saveGraphDataChs'} % ,'saveIndBalGraph'
        if and(strcmp(dg.tmp.field,'saveGraphDataChs'),sum(dg.dopdef.graphs(:,6))) || ...
                and(dg.tmp.userdata(2)==6, dg.dopdef.(dg.tmp.field)(dg.tmp.userdata(1),6)==1);% || ...
            %                 ~strcmp(dg.tmp.field,'saveIndBalGraph') && ...
            
            %             if dg.tmp.userdata(2)==6 && dg.dopdef.(dg.tmp.field)(dg.tmp.userdata(1),6)==1
            if sum(dg.dopdef.saveGraphDataChs(1:3))<3
                %                 set(dg.graph.saveGraphDataChs.check.h(1:3),'Value',1);
                dg.dopdef.saveGraphDataChs(1:3)=1;
                dg.tmp.warn=sprintf('%s\n%s\n',...
                    'Overall graphs required Left, Right, & Dif Graph Data to be saved.',...
                    'Settings have been adjusted');
                disp(dg.tmp.warn);
                warndlg(dg.tmp.warn,'Save Graph Data Adjust:');
                if strmatch('save',get(dg.tmp.h,'tag'))
                    set(dg.tmp.h,'Value',1); % reset checkbox
                end
            end
        end
        
if sum(dg.dopdef.graphs(1,:)) % saving anything
    set(dg.graph.graphFileType.pop.h,'Enable','On');
else
    set(dg.graph.graphFileType.pop.h,'Enable','Off');
end
if sum(sum(dg.dopdef.graphs(:,[3 5 6]))) % saving or viewing anything that matters
    set(dg.graph.graphEpochSel.pop.h,'Enable','On');
else
    set(dg.graph.graphEpochSel.pop.h,'Enable','Off');
end
end

end
%% >> dopGraphEpochSel
% adjusts the popedit box and accompanying notes
% - varargin just indicates that it's done from popEdit function
function dg=dopGraphEpochSel(dg,varargin)
dg.tmp.h=dg.graph.graphEpochSel.pop.h;
dg.tmp.list=get(dg.tmp.h,'String');
if ~isempty(varargin)
    dg.tmp.value=get(dg.tmp.h,'Value');
else
    dg.tmp.value=find(dg.dopdef.saveEpochSelectionGraph(1:end-1));
    if isempty(dg.tmp.value)
        dg.tmp.value=5;
    end
    set(dg.tmp.h,'Value',dg.tmp.value)
end
dg.tmp.notes=get(dg.graph.graphEpochSel.note.h,'UserData');
dg.tmp.tts=textwrap(dg.graph.graphEpochSel.note.h,dg.tmp.notes(dg.tmp.value));
set(dg.graph.graphEpochSel.note.h,'String',...
    dg.tmp.notes{dg.tmp.value},...
    'Tooltipstring',sprintf('%s\n%s\n%s\n%s\n%s\n%s\n',dg.tmp.tts{1:end}));%,dg.graph.pop2.notes)
end
% %% > Graphs+
% function dg=dgGraphsPlus(dg,tmp_handle) % matlab orange info is fine here
% dg.tmp.h=tmp_handle;
% dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
% fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
% dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% % % separator panel
% % dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
% %     'Position',[.05 .5 .9 .01],'BackgroundColor',dg.tab.pan.col);
% % dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% 
% %% -> ? Info
% % rollover/tooltipstring question mark to describe tab
% % dg.info.abb='q';
% % dg.info.txt='?';
% % dg.info.txtBreak='---------------------------------------';
% % dg.info.align='Left';
% % dg.info.pos=[.01 .94 .05 .05];
% dg.(dg.tmp.abb).info.tts=sprintf(...
%     '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
%     'dopOSCCI Graphs+ Tab:',...
%     ['The dopOSCCI summary allows for the creation of a series of graphs ',...
%     '(see Graphs Tab)'],...
%     ['The Graphs+ Tab houses settings that dictate which aspects of the ',...
%     'Overall data summaries will be saved'],...
%     dg.info.txtBreak,'Save Overall Graph Data:',...
%     'Series of settings to save the Overall data for later graphing',...
%     dg.info.txtBreak,'Overall Channel indices:',...
%     'Series of settings to save summary indices from Overall data files',...
%     dg.info.txtBreak,'Overall laterality indices:',...
%     ['Series of settings to save Laterality information calculated ',...
%     'for the Overall data files'],...
%     dg.info.txtBreak);
% dg=dgTabInfo(dg);
% 
% %% -> Graph Data Panel
% dg.tmp.pan='graphData';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .75 .9 .2],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Save Overall Graph Data');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
% 
% % 'saveEpochSelectionGraph','saveGraphDataChs','saveGraphDataVert'
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveEpochSelectionGraph',...[0 0 0 0 1 1],... % save graph data [all dat act man scrn bal] balanced for session summary
%     'saveGraphDataChs',...[1 1 1 1],... % left right, diff, avg (left right)
%     'saveGraphDataVert'};%1,... % save a vertical arrangment of graph data files
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[6 4 1];% 2]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Epoch Selection',...
%     'Data Selection','Vertical File'};%,'LI Selection'};
% dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%     'If none are selected, data will not be saved',...
%     'If none are selected, data will not be saved (left, right, & dif required for Overall graphs)',...
%     'Save a vertically aligned data file as well as horizontal'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'all','data','act','man','comb','bal'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'all available epochs',...
%     'length appropriate epochs (i.e., not including short epochs)',...
%     'epochs with data values within activation rejection range (see Data tab)',...
%     'manually selected epochs (see Special, Screen)',...
%     'combined epochs = length appropriate + activation appropriate + manually selected epochs',...
%     'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'left','right','dif','avg'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Save Left Channel data',...
%     'Save Right Channel data','Save Left - Right data',...
%     'Save Left Right average data'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'save'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'check to save vertical file'};
% % dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'mean','peak'}; % different order to regular LI
% % dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={...
% %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
% %         'Time of peak left - right difference (in seconds)'};
% 
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%     
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% %% -> Overall Channel Indices Panel
% dg.tmp.pan='chIndOver';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .475 .9 .225],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Overall Channel Indices');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChsOverall',...[1 1 0],... % on/off save left, right, difference indices
%     'saveIndexFiltOverall',...[0 1 1],... % filter = epoch, base, poi
%     'saveIndicesOverall'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 3 5]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Data Selection',...
%     'Filter Selection','Statistic Selection'};
% dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%     'If none are selected, below selections will not save',...
%     'Data filter for statistical calculation',...
%     'Static for data based upon channel and filter selections'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
%     'Save Right Channel Indicies','Save Left - Right Indicies'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
%     'Indicies based upon baseline data','Indicies based upon Period of Interest data'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','min','max','rms'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
%     'Minimum value','Maximum value','Root Mean Squared'};
% 
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%     
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% %% -> LI Indices Panel
% dg.tmp.pan='liIndOver';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.01 .05 .98 .375],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Overall Laterality Indices');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescripOverall',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%     'save1sampleOverall',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save2sampleOverall',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%     'saveRankOverall',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save1normOverall',...[1 0 0 0],... % save normality test info for difference LI distribution
%     'save2normOverall'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
% 
% %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
%     'Time/Latency of peak left - right difference (in seconds)',...
%     'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     };
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','95% confidence interval of mean difference',...
%     't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
%     'p value of test','Jarque-Bera value','critical value for test'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
%     'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%     'Normality of right channel data: 0 = normal, 1 = different',...
%     'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
% 
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.01 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%     
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% end

%% >> dgGraphTest
% allows individual graph to be examined within all dopOSCCI
% processing/functions - just minimal required to get to graph
function dgGraphTest(varargin)
global dg

dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
dg.tmp.field=strtok(dg.tmp.tag,'_'); % graph abbreviation


dg.tmp.graphTestFile = dg.data.files{1};
if exist(dg.dopdef.fileSel{1},'file')==2
    dg.tmp.graphTestFile = dg.dopdef.fileSel{1};
end
dopGraphTest(dg.tmp.graphTestFile,'def',dg.dopdef,'graphName',dg.tmp.field)

end
%% > Special
function dg=dgSpecial(dg,tmp_handle) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% % separator panel
% dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .5 .9 .01],'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;

%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf(...
    '%s\n%s\n%s\n%s\n%s\n%s',...
    'dopOSCCI Special Tab:',...
    'The Special Tab houses a series of options which control additional functions: ',...
    ['Manual Epoch Selection, Group Data summaries, Behavioural Epoch Divisions, ',...
    'and Session File concatenation.'],...
    'Each of these can be turned on or off using the check boxes to the left',...
    ['In order to run each requires a custom made ''.txt'' file, the path to which ',...
    'can be typed or browsed for using the pushbuttons to the right.'],...
    dg.info.txtBreak);
dg=dgTabInfo(dg);

% headings
dg.(dg.tmp.abb).head.par=dg.(dg.tmp.abb).pan.h;
dg.(dg.tmp.abb).head.abb={'scrnFile','grpFile','behFile','sesFile'};
% if abbreviations are altered, must also be changed at getCheckbox & set
% guiData functions.
dg.(dg.tmp.abb).head.txt={'Manual','Group','Behaviour','Session'};
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],[0 .05],[.05 .25 .15 .7],'opposite');
% [columns row], [x gap y gap],[x y corner x y dimensions]

% % editable

% dg.(dg.tmp.abb).edit.pos=[.3 .82 .5 .08; 0 0 0 0; ...
%     0 0 0 0; .3 .32 .5 .08; 0 0 0 0;0 0 0 0];
%
% dg.(dg.tmp.abb).edit.txt={'type data directory','','','type save directory','',''};
%
% dg.(dg.tmp.abb).edit.callback={'@getTxtEdit','','','@getTxtEdit','',''};
% dg.(dg.tmp.abb).edit.tts={'Type in the directory of your raw doppler files',...
%     '','','Type in the directory where the data will be saved to','',''};

% % pushbutton
% dg.(dg.tmp.abb).push.pos=[.85 .82 .1 .08;0 0 0 0; 0 0 0 0;.85 .32 .1 .08;...
%     0 0 0 0;0 0 0 0];
% dg.(dg.tmp.abb).push.txt={'...','...','...','...','',''};
% dg.(dg.tmp.abb).push.tts={'Browse for data directory','','',...
%     'Browse for save directory','',''}; % tooltip string
% dg.(dg.tmp.abb).push.callback={'@browseDirectory','','','@browseDirectory','',''};
% dg.(dg.tmp.abb).push.startDir={fileparts(which('dopOSCCI')),'','',fileparts(which('dopOSCCI')),'',''};

% % popupmenu
% dg.(dg.tmp.abb).pop.pos=[0 0 0 0;0 0 0 0; .3 .57 .5 .08;0 0 0 0;0 0 0 0;0 0 0 0];
% dg.(dg.tmp.abb).pop.txt={'','','all files','','',''};
% dg.(dg.tmp.abb).pop.tts={'','','select a single file to summarise',...
%     '','',''}; % tooltip string
% dg.(dg.tmp.abb).pop.callback={'','','@getPopEdit','','',''};


% save check panel
% dg.(dg.tmp.abb).check.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...
%     'Title','Save','TitlePosition','CenterTop',...%'FontSize',12,...
%     'Position',[.25 .25 .1 .73],...
%     'ForegroundColor',dg.col.pt,'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% display check panel

% checkbox headers...
% Save and Display titles
% dg.(dg.tmp.abb).chkHead.par=dg.(dg.tmp.abb).pan.h;
% dg.(dg.tmp.abb).chkHead.abb={'save','disp'};
% dg.(dg.tmp.abb).chkHead.title={'(Save','Display)'};
% dg.(dg.tmp.abb).chkHead.pos=dgPositions([2 1],[0 0],[0 .2 .23 .08]);
% for i=1:numel(dg.(dg.tmp.abb).chkHead.abb)
%     dg.(dg.tmp.abb).chkHead.h(i)=uicontrol('Parent',dg.(dg.tmp.abb).chkHead.par,...
%         'Style','text','String',dg.(dg.tmp.abb).chkHead.title{i},...
%         'units','normalized','HorizontalAlign','center',...
%         'tag',[dg.(dg.tmp.abb).chkHead.abb{i},'_title'],...
%         'Position',dg.(dg.tmp.abb).chkHead.pos(i,:),...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).chkHead.h(i);
% end


% checkbox
% dg.(dg.tmp.abb).checkFuncs={'Save','Display'};
% for i=1:2
%     dg.tmp.chkAbb=['check',num2str(i)];
%     dg.tmp.chkFunc=dg.(dg.tmp.abb).checkFuncs{i};
%     dg.(dg.tmp.abb).(dg.tmp.chkAbb).par=dg.(dg.tmp.abb).pan.h;
%     dg.(dg.tmp.abb).(dg.tmp.chkAbb).pos=dgPositions([1 dg.(dg.tmp.abb).head.n],[0 .05],...
%         [.05+.1*(i-1) .25 .15*i .7],'opposite');
dg.(dg.tmp.abb).check.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],...
    [.15 .15],[0 0 .3 1],'opposite');

dg.(dg.tmp.abb).edit.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],...
    [0 .15],[.25 0 .5 1],'opposite');

dg.(dg.tmp.abb).text.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],...
    [0 .15],[.2 -.1 .8 1],'opposite');

dg.(dg.tmp.abb).push.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],...
    [0 .15],[.8 0 .1 1],'opposite');

dg.(dg.tmp.abb).push2.pos=dgPositions([dg.(dg.tmp.abb).head.n 1],...
    [0 .15],[.925 0 .05 1],'opposite');
% dg.(dg.tmp.abb).push2.pos(3:4,:)=0; % clear these, just want first 2
% end
% % editable

% dg.(dg.tmp.abb).edit.pos=[.3 .82 .5 .08; 0 0 0 0; ...
%     0 0 0 0; .3 .32 .5 .08; 0 0 0 0;0 0 0 0];
%
% dg.(dg.tmp.abb).edit.txt={'type data directory','','','type save directory','',''};
%
% dg.(dg.tmp.abb).edit.callback={'@getTxtEdit','','','@getTxtEdit','',''};
% dg.(dg.tmp.abb).edit.tts={'Type in the directory of your raw doppler files',...
%     '','','Type in the directory where the data will be saved to','',''};


dg.(dg.tmp.abb).el={'check','edit','push','push2','text'};%{'head','check'};%,'edit','push','pop','check'}; % elements
dg.(dg.tmp.abb).styles={'checkbox','edit','pushbutton','pushbutton','text'};%{'text','checkbox'};%,'edit','pushbutton','popupmenu','checkbox'};
for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        
        dg.(dg.tmp.abb).(dg.tmp.el).par=dg.(dg.tmp.abb).pan.h;
        switch dg.tmp.el
            case 'check'
                dg.(dg.tmp.abb).(dg.tmp.el).txt{i}=dg.(dg.tmp.abb).head.txt{i};
                dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=...
                    ['Select to run ',dg.(dg.tmp.abb).head.txt{i},' function']; % tooltip string
                dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@getCheckbox';
                dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i},'Chk'];
                dg.(dg.tmp.abb).(dg.tmp.el).values(i)=0; % default is don't save or display
            case 'edit'
                dg.(dg.tmp.abb).(dg.tmp.el).txt{i}=['type ',dg.(dg.tmp.abb).head.txt{i},' file function path'];
                dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=dg.(dg.tmp.abb).(dg.tmp.el).txt{i};
                %                     ['Type in ',dg.(dg.tmp.abb).head.txt{i},' file function path']; % tooltip string
                dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@getTxtEdit';
                dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i},'NameLoc'];
            case 'text'
                dg.(dg.tmp.abb).(dg.tmp.el).txt{i}=[];'visualise...';
                dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i},'NameLoc'];
            case 'push'
                dg.(dg.tmp.abb).(dg.tmp.el).txt{i}='...';
                dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=['Browse for ',dg.(dg.tmp.abb).head.txt{i},' file'];
                %                     ['Type in ',dg.(dg.tmp.abb).head.txt{i},' file function path']; % tooltip string
                dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@browseSpecialFuncFile';
                dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i}];
                dg.(dg.tmp.abb).(dg.tmp.el).startDir{i}=[fileparts(which('dopOSCCI')),'/taskData/'];
            case 'push2'
                dg.(dg.tmp.abb).(dg.tmp.el).txt{i}='...';
                dg.(dg.tmp.abb).(dg.tmp.el).tts{i}=sprintf('%s\n%s\n%s\n',...
                    ['Create basic ',dg.(dg.tmp.abb).head.txt{i},' file'],...
                    'It will need to be edited to do the job',...
                    'A hyperlink to its folder will appear at the commandline');
                %                     ['Type in ',dg.(dg.tmp.abb).head.txt{i},' file function path']; % tooltip string
                dg.(dg.tmp.abb).(dg.tmp.el).callback{i}='@createSpecialFuncFile';
                dg.(dg.tmp.abb).(dg.tmp.el).tag{i}=[dg.(dg.tmp.abb).head.abb{i}];
                dg.(dg.tmp.abb).(dg.tmp.el).startDir{i}=[];
        end
        
        
        if sum(dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:)) % then we have something to place
            %             fprintf('\t%u\t%u\t%s\t%s\n',i,j,dg.tmp.el,dg.tmp.style);
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).(dg.tmp.el).par,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
            
            if ~strcmp(dg.tmp.style,'text')
                set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                    'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
            end
            switch dg.tmp.style
                case 'edit'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                        'tag',dg.(dg.tmp.abb).(dg.tmp.el).tag{i},...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                        'HorizontalAlign','center');
                    dg.enable.listAdj=dg.(dg.tmp.abb).(dg.tmp.el).tag{i};
                    dg=enableObject(dg,1);
                    dg.enable=rmfield(dg.enable,'listAdj');
                case 'text'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'UserData',[]);%,'FontSize',7); % empty
                    dg=enableObject(dg,0);
                case 'pushbutton'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                        'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).startDir{i},...
                        'HorizontalAlign','center');
                    dg=enableObject(dg,0);
                    %                 case 'popupmenu'
                    %                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                    %                         'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                    %                         'HorizontalAlign','right',...
                    %                         'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                    %                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
                    %                     dg=enableObject(dg,1); % might not want this...
                    if strcmp(dg.tmp.el,'push2')
                        set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                            'BackgroundColor',dg.col.y);
                    end
                case 'checkbox'
                    %                     disp(dg.tmp.el)
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                        'value',dg.(dg.tmp.abb).(dg.tmp.el).values(i),...
                        'tag',dg.(dg.tmp.abb).(dg.tmp.el).tag{i},...
                        'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                        'UserData',0);%dg.(dg.tmp.abb).(dg.tmp.el).options{i});%,...
                    dg.enable.styleAdj=[dg.tmp.h_abb,'Chk']; % don't want this to be 1 & 2 anymore
                    %                     dg.enable.listAdj=dg.(dg.tmp.abb).(dg.tmp.el).tag{i};
                    %                         'callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}));
                    %                     set(dg.(dg.tmp.abb).([dg.tmp.h_abb,'Info']).head.h,...
                    %                         dg.(dg.tmp.abb).(dg.tmp.el).options{i}{2});
                    dg=enableObject(dg,1); % might not want this...
                    dg.enable=rmfield(dg.enable,'styleAdj');
                    
            end
        end
    end
end

end
%% >> browseSpecialFunctionFile
function browseSpecialFuncFile(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
dg.tmp.field=strtok(dg.tmp.tag,'_');

dg.tmp.cur_dir=pwd; % current dir
dg.tmp.td_dir=get(dg.tmp.h,'UserData');%[fileparts(which('dopOSCCI')),'/taskData/'];
cd(dg.tmp.td_dir); % now uigetfile will start here
[dg.tmp.fn,dg.tmp.dir]=uigetfile('*.txt',['Browse for ',' file:']);
if numel(dg.tmp.fn)>1
    dg.tmp.fnl=[dg.tmp.dir,dg.tmp.fn];
    dg=checkSpecialFile(dg);
end
cd(dg.tmp.cur_dir); % change back
end
%% >> checkSpecialFile
function dg=checkSpecialFile(dg)
dg.tmp.fileType=strtok(dg.tmp.field,'F');
dg.tmp.func=['dop',upper(dg.tmp.fileType(1)),dg.tmp.fileType(2:end),'Chk'];
if ~isempty(dg.dopdef.dataDir) && exist(dg.dopdef.dataDir,'dir')==7
    dg.tmp.chkData=feval(dg.tmp.func,dg.tmp.fnl,'dataDir',dg.dopdef.dataDir);
else
    dg.tmp.chkData=feval(dg.tmp.func,dg.tmp.fnl);
end
if isfield(dg.tmp,'chkData')
    if isfield(dg.tmp.chkData,'report')
        disp(dg.tmp.chkData.report);
    end
    if dg.tmp.chkData.okay % update edit & defintion info
        dg.tmp.fileType=strtok(dg.tmp.field,'F');
        dg.tmp.field_adj=[dg.tmp.fileType,'File'];
        dg.dopdef.([dg.tmp.field_adj,'NameLoc'])=dg.tmp.fnl;
        set(dg.spec.(dg.tmp.field_adj).edit.h,'String',dg.tmp.fnl,...
            'ToolTipString',dg.tmp.chkData.report);
        set(dg.spec.(dg.tmp.field_adj).text.h,'String',dg.tmp.chkData.guiReport);
        %         dg.dopdef.([dg.tmp.fileType,'FileChk'])=1;
        %         set(dg.spec.(dg.tmp.field_adj).check.h,'value',1);
    else
        dg.tmp.rep=[];
        if isfield(dg.tmp.chkData,'report')
            dg.tmp.rep=dg.tmp.chkData.report;
        end
        warndlg(sprintf('%s\n%s\n%s\n%s\n',dg.tmp.rep,...
            'Check that a data directory has been selected',...
            'This is used to check if the files are available',...
            'Or file information has no affect on summary'),[dg.tmp.field,' issue:']);
    end
else
    fprintf('%s\n',['Import error: ',dg.tmp.fileType]);
end
end
%% >> createSpecialFunctionFile
function createSpecialFuncFile(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
dg.tmp.field=strtok(dg.tmp.tag,'_');

dg.tmp.cur_dir=pwd; % current dir
dg.tmp.td_dir=get(dg.tmp.h,'UserData');%[fileparts(which('dopOSCCI')),'/taskData/'];
% cd(dg.tmp.td_dir); % now uigetfile will start here
dg.tmp.([dg.tmp.field,'Report'])=feval(['dop',dg.tmp.field,'Create'],...
    dg.dopdef.dataDir,'taskName',dg.dopdef.taskName);
% [dg.tmp.fn,dg.tmp.dir]=uigetfile('*.txt',['Browse for ',' file:']);
% if numel(dg.tmp.fn)>1
%     dg.tmp.fnl=[dg.tmp.dir,dg.tmp.fn];
%     dg=checkSpecialFile(dg);
% end
% cd(dg.tmp.cur_dir); % change back
end
%% > Save OLD
% function dg=dgSave(dg,tmp_handle) % matlab orange info is fine here
% dg.tmp.h=tmp_handle;
% dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
% fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
%
% dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% % separator panel
% % dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag','sep_panel',...%'Title','Run','FontSize',12,...
% %     'Position',[.05 .65 .9 .01],'BackgroundColor',dg.tab.pan.col);
% % dg.font.h(end+1)=dg.(dg.tmp.abb).pan.sepH;
%
% %% -> ? Info
% % rollover/tooltipstring question mark to describe tab
% % dg.info.abb='q';
% % dg.info.txt='?';
% % dg.info.txtBreak='---------------------------------------';
% % dg.info.align='Left';
% % dg.info.pos=[.01 .94 .05 .05];
% dg.(dg.tmp.abb).info.tts=sprintf(...
%     ['%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
%     '%s\n%s\n%s\n%s\n%s\n%s\n%s'],...
%     'dopOSCCI Save Tab:',...
%     'The Save Tab contains information defining where and which data will be saved',...
%     ['A default data location will be provided but this can be changed by typing, ',...
%     'or browsing using the pushbutton to the right.'],...
%     '> One critical feature is the ''Save Data'' check box:',...
%     'This toggles between saving and not saving the summary data',...
%     '...there are lots of checkboxes...',...
%     dg.info.txtBreak,'Epoch Save Selection Panel:',...
%     'This allows you to save variables pertaining to difference groups of epochs:',...
%     '* all = all available epochs',...
%     '* data = data appropriate epochs (short epochs will not be included)',...
%     '* act = activation appropriate epochs (see Data Tab, Activation Rejection)',...
%     '* man = manually selected epochs (see Special Tab, Screen)',...
%     '* scrn = data + activation + manually selected appropriate epochs (Recommended)',...
%     '* bal = applies to Session special function (see Special Tab, Session)',...
%     ' > balances the number of epochs used from each session',...
%     dg.info.txtBreak,'Channel Indices',...
%     'Selects descriptive statistics for the Left, Right, and Differences Channels, ',...
%     ' - the statistics are calculated within filters:',...
%     ' whole epoch, baseline period, and/or period of interest',...
%     dg.info.txtBreak,'Laterality Indices',...
%     'Selects descriptive and inferential statistics for the Laterality Index Calculation',...
%     'Choices include a range of descriptives statistics as well as ',...
%     'Parameteric and non-parametric tests for left right differences, and ',...
%     'Normality tests of the LI indices calculated for each epoch.',...
%     dg.info.txtBreak);
% dg=dgTabInfo(dg);
%
% % headings
% dg.(dg.tmp.abb).head.abb={'saveDir','saveData','saveDataInfo'};
% dg.(dg.tmp.abb).head.txt={'Save Directory','',''};
% dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
% dg.(dg.tmp.abb).head.pos=[.05 .86 .25 .1;0 0 0 0;.35 .8 .5 .08];
%
% % editable
% dg.(dg.tmp.abb).edit.pos=[.3 .9 .5 .07; 0 0 0 0;0 0 0 0];
%
% dg.(dg.tmp.abb).edit.txt={'type save directory','',''};
%
% dg.(dg.tmp.abb).edit.callback={'@getTxtEdit','',''};
% dg.(dg.tmp.abb).edit.tts={'Type in the directory where the data will be saved to','',''};
%
% % pushbutton
% dg.(dg.tmp.abb).push.pos=[.85 .89 .1 .08;0 0 0 0;0 0 0 0];
% dg.(dg.tmp.abb).push.txt={'...','',''};
% dg.(dg.tmp.abb).push.tts={'Browse for save directory','',''}; % tooltip string
% dg.(dg.tmp.abb).push.callback={'@browseDirectory','',''};
% dg.(dg.tmp.abb).push.startDir={fileparts(which('dopOSCCI')),'','',fileparts(which('dopOSCCI')),'',''};
%
% % checkbox
% dg.(dg.tmp.abb).check.pos=[0 0 0 0;.1 .82 .2 .08;0 0 0 0];
% dg.(dg.tmp.abb).check.txt={'','Save Individual Data',''};
% dg.(dg.tmp.abb).check.tts={'','check box and data will be saved',''}; % tooltip string
% dg.(dg.tmp.abb).check.callback={'','@getCheckbox',''};
% dg.(dg.tmp.abb).check.options={'',...
%     {'(Individual summary data will not be saved)','(Individual summary data will be saved)'},...
%     ''};
%
% dg.(dg.tmp.abb).el={'head','edit','push','check'}; % elements
% dg.(dg.tmp.abb).styles={'text','edit','pushbutton','checkbox'};
%
% for i=1:dg.(dg.tmp.abb).head.n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
%     for j=1:numel(dg.(dg.tmp.abb).el);
%
%         dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
%
%         if sum(dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:)) % then we have something to place
%             %             fprintf('\t%u\t%u\t%s\t%s\n',i,j,dg.tmp.el,dg.tmp.style);
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%             if ~strcmp(dg.tmp.style,'text')
%                 set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                     'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
%             end
%             switch dg.tmp.style
%                 case 'edit'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
%                         'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
%                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
%                         'HorizontalAlign','center');
%                     dg=enableObject(dg,1);
%                 case 'text'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
%                     dg=enableObject(dg,0);
%                 case 'pushbutton'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'Callback',eval(dg.(dg.tmp.abb).push.callback{i}),...
%                         'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
%                         'UserData',dg.(dg.tmp.abb).push.startDir{i});
%                     dg=enableObject(dg,0);
%                 case 'popupmenu'
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
%                         'HorizontalAlign','right',...
%                         'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
%                         'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
%                     dg=enableObject(dg,1); % might not want this...
%                 case 'checkbox'
%                     %                     disp(dg.tmp.el)
%                     set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
%                         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                         'value',1,'UserData',dg.(dg.tmp.abb).(dg.tmp.el).options{i},...
%                         'callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}));
%                     %                     set(dg.(dg.tmp.abb).([dg.tmp.h_abb,'Info']).head.h,...
%                     %                         dg.(dg.tmp.abb).(dg.tmp.el).options{i}{2});
%                     dg=enableObject(dg,1); % might not want this...
%
%             end
%         end
%     end
% end
% %% -> epoch selection panel
% dg.tmp.pan='epSel';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .7 .9 .1],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Epoch Save Selection');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','data','act','man','comb','bal'};
% dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
% dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
%     'data appropriate epochs (i.e., not including short epochs)',...
%     'epochs with data values within activation rejection range (see Data tab)',...
%     'manually selected epochs (see Special, Screen)',...
%     'combined epochs = data appropriate + activation appropriate + manually selected epochs',...
%     'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
%
% dg.tmp.h_abb='saveEpochSelection'; % dop.def. abbreviation
% dg.tmp.el='check'; dg.tmp.style='checkbox';
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',['Save data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
%         'value',0,'UserData',[1 i],...
%         'callback',eval('@getCheckbox'));
%     dg=enableObject(dg,1); % might not want this...
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
% end
%
% %% -> Channel Indices Panel
% dg.tmp.pan='chInd';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .45 .9 .225],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Channel Indices');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChs',...[1 1 0],... % on/off save left, right, difference indices
%     'saveIndexFilt',...[0 1 1],... % filter = epoch, base, poi
%     'saveIndices'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 3 5]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Data Selection',...
%     'Filter Selection','Statistic Selection'};
% dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%     'If none are selected, below selections will not save',...
%     'Data filter for statistical calculation',...
%     'Static for data based upon channel and filter selections'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
%     'Save Right Channel Indicies','Save Left - Right Indicies'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
%     'Indicies based upon baseline data','Indicies based upon Period of Interest data'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','min','max','rms'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
%     'Minimum value','Maximum value','Root Mean Squared'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% %% -> LI Indices Panel
% dg.tmp.pan='liInd';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.01 .05 .98 .375],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Laterality Indices');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescrip',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%     'save1sample',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save2sample',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%     'saveRank',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save1norm',...[1 0 0 0],... % save normality test info for difference LI distribution
%     'save2norm'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
%
% %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
%
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
%     'Time of peak left - right difference (in seconds)',...
%     'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     };
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','95% confidence interval of mean difference',...
%     't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
%     'p value of test','Jarque-Bera value','critical value for test'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
%     'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%     'Normality of right channel data: 0 = normal, 1 = different',...
%     'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.01 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% end
%% > Save
function dg=dgSave(dg,tmp_handle) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);

dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% separator panel
% dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag','sep_panel',...%'Title','Run','FontSize',12,...
%     'Position',[.05 .65 .9 .01],'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.sepH;

%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf(...
    '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n',...
    'dopOSCCI Save Tab:',...
    'The Save Tab contains information defining where and which data will be saved',...
    ['A default data location will be provided but this can be changed by typing, ',...
    'or browsing using the pushbutton to the right.'],...
    '> One critical feature is the ''Save Data'' check box:',...
    'This toggles between saving and not saving the summary data',...
    dg.info.txtBreak,'Pushbuttons:',...
    ['Each of the pushbuttons opens a separate matlab figure, each of which ',...
    'houses a series of checkboxes'],...
    'These checkboxes can be used to specify the data which is saved.',...
    'Explanations can be found within each figure.',...
    dg.info.txtBreak);
dg=dgTabInfo(dg);

% headings
dg.(dg.tmp.abb).head.abb={'saveDir','saveData','saveDataInfo'};
dg.(dg.tmp.abb).head.txt={'Save Directory','',''};
dg.(dg.tmp.abb).head.n=numel(dg.(dg.tmp.abb).head.abb);
dg.(dg.tmp.abb).head.pos=[.05 .8 .25 .1;0 0 0 0;.4 .74 .5 .08];

% editable
dg.(dg.tmp.abb).edit.pos=[.3 .84 .5 .07; 0 0 0 0;0 0 0 0];

dg.(dg.tmp.abb).edit.txt={'type save directory','',''};

dg.(dg.tmp.abb).edit.callback={'@getTxtEdit','',''};
dg.(dg.tmp.abb).edit.tts={'Type in the directory where the data will be saved to','',''};

% pushbutton
dg.(dg.tmp.abb).push.pos=[.85 .83 .1 .08;0 0 0 0;0 0 0 0];
dg.(dg.tmp.abb).push.txt={'...','',''};
dg.(dg.tmp.abb).push.tts={'Browse for save directory','',''}; % tooltip string
dg.(dg.tmp.abb).push.callback={'@browseDirectory','',''};
dg.(dg.tmp.abb).push.startDir={fileparts(which('dopOSCCI')),'','',fileparts(which('dopOSCCI')),'',''};

% checkbox
dg.(dg.tmp.abb).check.pos=[0 0 0 0;.1 .76 .3 .08;0 0 0 0];
dg.(dg.tmp.abb).check.txt={'','Save Summary Data',''};
dg.(dg.tmp.abb).check.tts={'','check box and data will be saved',''}; % tooltip string
dg.(dg.tmp.abb).check.callback={'','@getCheckbox',''};
dg.(dg.tmp.abb).check.options={'',...
    {'(Summary data will not be saved)','(Summary data will be saved)'},...
    ''};

dg.(dg.tmp.abb).el={'head','edit','push','check'}; % elements
dg.(dg.tmp.abb).styles={'text','edit','pushbutton','checkbox'};

for i=1:dg.(dg.tmp.abb).head.n
    dg.tmp.h_abb=dg.(dg.tmp.abb).head.abb{i};
    for j=1:numel(dg.(dg.tmp.abb).el);
        
        dg.tmp.el=dg.(dg.tmp.abb).el{j}; dg.tmp.style=dg.(dg.tmp.abb).styles{j};
        
        if sum(dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:)) % then we have something to place
            %             fprintf('\t%u\t%u\t%s\t%s\n',i,j,dg.tmp.el,dg.tmp.style);
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.el).pos(i,:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
            
            if ~strcmp(dg.tmp.style,'text')
                set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                    'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.el).tts{i});
            end
            switch dg.tmp.style
                case 'edit'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'Callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i},...
                        'HorizontalAlign','center');
                    dg=enableObject(dg,1);
                case 'text'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
                    dg=enableObject(dg,0);
                case 'pushbutton'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'Callback',eval(dg.(dg.tmp.abb).push.callback{i}),...
                        'BackgroundColor',dg.col.bg,'ForegroundColor',dg.col.gt,...
                        'UserData',dg.(dg.tmp.abb).push.startDir{i});
                    dg=enableObject(dg,0);
                case 'popupmenu'
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.et,'BackgroundColor',dg.col.eb,...
                        'HorizontalAlign','right',...
                        'CallBack',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}),...
                        'UserData',dg.(dg.tmp.abb).(dg.tmp.el).txt{i}); % empty
                    dg=enableObject(dg,1); % might not want this...
                case 'checkbox'
                    %                     disp(dg.tmp.el)
                    set(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h,...
                        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                        'value',1,'UserData',dg.(dg.tmp.abb).(dg.tmp.el).options{i},...
                        'callback',eval(dg.(dg.tmp.abb).(dg.tmp.el).callback{i}));
                    %                     set(dg.(dg.tmp.abb).([dg.tmp.h_abb,'Info']).head.h,...
                    %                         dg.(dg.tmp.abb).(dg.tmp.el).options{i}{2});
                    dg=enableObject(dg,1); % might not want this...
                    
            end
        end
    end
end
%% -> pushbuttons...
% put all the save options into popup figures...
dg.(dg.tmp.abb).popfig.abb={'EpochSave','IndividualSaveLI',...'EpochSaveSelect',
    'IndividualSaveExtra','SplitHalf',...
    'OverallStatsLI','OverallStatsExtra'...'GraphData',
    'NotesSave','DataQual','GraphData'};
dg.(dg.tmp.abb).popfig.n=numel(dg.(dg.tmp.abb).popfig.abb);
dg.(dg.tmp.abb).popfig.title={'Epoch Stats','Individual LI','Individual Extra',...
    'Split-Half','Overall LI','Overall Extra',...'Epoch Inclusion',
    'Notes Save','Data Quality','Graph Data'};
dg.(dg.tmp.abb).popfig.name={...'Epoch Inclusion:',...
    'Epoch Statistics: (independent epoch summaries)',...
    'Individual LI Statistics: (collections of epochs summaries)',...
    'Individual Extra Statistics: (collections of epochs summaries)',...
    'Split-Half Reliability Save:',...
    'Overall LI Statistics: (collections of averaged individual summaries)',...
    'Overall Extra Statistics: (collections of averaged individual summaries)',...
    'Notes Save',...
    'Data Quality Save:',...
    'Graph Data Save:'};
dg.(dg.tmp.abb).popfig.tts={...'epoch collection save options (used for Individual Stats)',...
    'independent epoch save options: produces summaries for each epoch',...
    'individual data file save options: produces LI summaries for selected collections of epochs',...
    'individual data file save options: produces extra summaries for selected collections of epochs',...
    'split-half reliability save options: produces summaries for independent halves of available epochs',...'graph data save options',...
    'Overall Laterality Index summary statistics save options',...
    'Overall Extra summary statistics save options',...
    'summary note save options',...
    'Save data drop out and Goodness of Recording statistics',...
    'Save graph data to output files'};

dg.(dg.tmp.abb).popfig.pos=dgPositions([3 3],[.1 .1],[.05 .1 .9 .6],'opposite');
dg.tmp.h_abb = 'popfig';dg.tmp.el ='push';
for i=1:numel(dg.(dg.tmp.abb).popfig.abb)
    dg.(dg.tmp.abb).popfig.push.h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.h,'Tag',dg.(dg.tmp.abb).popfig.abb{i},...
        'String',dg.(dg.tmp.abb).popfig.title{i},'Style','pushbutton',...
        'units','normalized',...
        'Callback',eval(['@dg',dg.(dg.tmp.abb).popfig.abb{i},'Fig']),...
        'Position',dg.(dg.tmp.abb).popfig.pos(i,:),...
        'ToolTipString',dg.(dg.tmp.abb).popfig.tts{i},...
        'UserData',dg.(dg.tmp.abb).popfig.name{i});
    dg=enableObject(dg,0);
    dg.font.h(end+1)=dg.(dg.tmp.abb).popfig.push.h(i);
end
% %% -> epoch selection panel
% dg.tmp.pan='epSel';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .7 .9 .1],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Epoch Save Selection');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','data','act','man','comb','bal'};
% dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
% dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
%     'data appropriate epochs (i.e., not including short epochs)',...
%     'epochs with data values within activation rejection range (see Data tab)',...
%     'manually selected epochs (see Special, Screen)',...
%     'combined epochs = data appropriate + activation appropriate + manually selected epochs',...
%     'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
%
% dg.tmp.h_abb='saveEpochSelection'; % dop.def. abbreviation
% dg.tmp.el='check'; dg.tmp.style='checkbox';
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',['Save data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
%         'value',0,'UserData',[1 i],...
%         'callback',eval('@getCheckbox'));
%     dg=enableObject(dg,1); % might not want this...
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
% end
%
% %% -> Channel Indices Panel
% dg.tmp.pan='chInd';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .45 .9 .225],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Channel Indices');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChs',...[1 1 0],... % on/off save left, right, difference indices
%     'saveIndexFilt',...[0 1 1],... % filter = epoch, base, poi
%     'saveIndices'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 3 5]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Data Selection',...
%     'Filter Selection','Statistic Selection'};
% dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%     'If none are selected, below selections will not save',...
%     'Data filter for statistical calculation',...
%     'Static for data based upon channel and filter selections'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
%     'Save Right Channel Indicies','Save Left - Right Indicies'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
%     'Indicies based upon baseline data','Indicies based upon Period of Interest data'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','min','max','rms'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
%     'Minimum value','Maximum value','Root Mean Squared'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% %% -> LI Indices Panel
% dg.tmp.pan='liInd';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.01 .05 .98 .375],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Laterality Indices');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescrip',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%     'save1sample',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save2sample',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%     'saveRank',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save1norm',...[1 0 0 0],... % save normality test info for difference LI distribution
%     'save2norm'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
%
% %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
%
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
%     'Time of peak left - right difference (in seconds)',...
%     'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     };
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','95% confidence interval of mean difference',...
%     't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
%     'p value of test','Jarque-Bera value','critical value for test'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
%     'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%     'Normality of right channel data: 0 = normal, 1 = different',...
%     'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.01 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
end
%% >> saveEnable
function dg=saveEnable(dg)
set(dg.sav.saveDataInfo.head.h,'String',...
    dg.tmp.userdata{dg.dopdef.(dg.tmp.field)+1});
dg.tmp.saveEnable='Off';
if dg.dopdef.(dg.tmp.field)
    dg.tmp.saveEnable='On';
end
% dg.tmp.pans={'chInd','epSel','liInd','indEpochCh','indEpochLI','split','chIndOver','liIndOver'};%,'graphFileType'};'graphData',
% dg.tmp.parPans={'sav','sav','sav','savp','savp','savp','graphp','graphp'};%,'graphp'};'graphp',
% for i=1:numel(dg.tmp.pans)
%     set(get(dg.(dg.tmp.parPans{i}).pan.(dg.tmp.pans{i}),'Children'),'Enable',dg.tmp.saveEnable)
% end

% for i=1:3
%dg.sav.popfig.abb = 'EpochSave','IndividualSave','OverallStats','SplitHalf','NotesSave'
% set(dg.sav.popfig.push.h([1 2 4]),'Enable',dg.tmp.saveEnable);
set(dg.sav.popfig.push.h(1:end-1),'Enable',dg.tmp.saveEnable);
% end-1 here to avoid the Graph Data Save: want this to be independent

end
%% > Save+
% function dg=dgSavePlus(dg,tmp_handle) % matlab orange info is fine here
% dg.tmp.h=tmp_handle;
% dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
% fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);
%
% dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%
% %% -> ? Info
% % rollover/tooltipstring question mark to describe tab
% % dg.info.abb='q';
% % dg.info.txt='?';
% % dg.info.txtBreak='---------------------------------------';
% % dg.info.align='Left';
% % dg.info.pos=[.01 .94 .05 .05];
% dg.(dg.tmp.abb).info.tts=sprintf(...
%     '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
%     'dopOSCCI Save+ Tab:',...
%     'The Save+ Tab contains information defining which additional data will be saved',...
%     dg.info.txtBreak,'Individual Epoch - Channel & Laterality Indicies:',...
%     'This allows data for each indidual epoch to be saved',...
%     'Channel indicies refer to the left, right, and difference data for each epoch',...
%     'Laterality Indicies refer to the peak Left - Right difference activation window',...
%     dg.info.txtBreak,'Split-Half',...
%     'The Split-Half Panels defines which data is saved for split-half comparisons',...
%     '> this can be used to estimate the internal reliability of your task.',...
%     'Options include:',...
%     '* Displaying and Saving the data, ',...
%     '* Different epoch splits - odd versus even epochs Or randomly selected halves',...
%     '* Balancing the number of trials in each half',...
%     'And a series of descriptives and inferential descriptives for the Laterality Index Calculation :',...
%     'Choices include a range of descriptives statistics as well as ',...
%     'Parameteric and non-parametric tests for left right differences, and ',...
%     'Normality tests of the LI indices calculated for each epoch.',...
%     dg.info.txtBreak);
% dg=dgTabInfo(dg);
%
% %% -> Individual Epoch - Channel & Laterality Indicies Panel
% dg.tmp.pan='indEpochCh';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .75 .9 .2],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Individual Epoch - Channel Indicies');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% %     'saveEpochIndCh','saveEpochIndFilter','saveEpochInd','saveEpochLI'
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveEpochIndCh',...[1 1 0],... % on/off save left, right, difference indices
%     'saveEpochIndFilter',...[1 0 0],... % epoch, base, poi
%     'saveEpochInd'};%,...};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
% %         'saveEpochLI'};%,[1 0],... % indices to be saved for each epoch LI (mean) LI latency
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 3 5];% 2]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Data Selection',...
%     'Filter Selection','Statistic Selection'};%,'LI Selection'};
% dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%     'If none are selected, below selections will not save',...
%     'Data filter for statistical calculation',...
%     'Static for data based upon channel and filter selections'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
%     'Save Right Channel Indicies','Save Left - Right Indicies'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
%     'Indicies based upon baseline data','Indicies based upon Period of Interest data'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','min','max','rms'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
%     'Minimum value','Maximum value','Root Mean Squared'};
% % dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'mean','peak'}; % different order to regular LI
% % dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={...
% %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
% %         'Time of peak left - right difference (in seconds)'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% %% -> Individual Epoch - Laterality Indicies Panel
% dg.tmp.pan='indEpochLI';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .625 .9 .1],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Individual Epoch - Laterality Indicies');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% %     'saveEpochIndCh','saveEpochIndFilter','saveEpochInd','saveEpochLI'
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
%     'saveEpochLI'};%,[1 0],... % indices to be saved for each epoch LI (mean) LI latency
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=8; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'LI Selection'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'across'); % top to bottom
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'peak','mean','std','sem','95%','min','max','med','iqr'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
%     'Time of peak left - right difference (in seconds)',...
%     'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard error of the mean (same as standard deviation for single epoch)',...
%     '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     };
% % dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'mean','peak'}; % different order to regular LI
% % dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
% %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
% %         'Time of peak left - right difference (in seconds)'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% %% -> Split Half LI Indices Panel
% dg.tmp.pan='split';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.01 .05 .98 .55],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Split-Half');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
%     'splitCalcSave',...[1 1],...); % actually do the calculation & save data
%     'splitOptions',...[1 1],...); % Split half odd v even, random selection
%     'splitBal',...1,...); % balance the number of epochs in the split
%     'saveDescripSplit',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%     'save1sampleSplit',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save2sampleSplit',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%     'saveRankSplit',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%     'save1normSplit',...[1 0 0 0],... % save normality test info for difference LI distribution
%     'save2normSplit'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
%
% %     'splitCalcSave','splitOptions','splitBal',...
% %     'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
% %         'save1normSplit','save2normSplit',
%
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[2 2 1 10 7 7 5 4 8]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={...
%     'Disp/Save','Options','Balance',...
%     'Descriptives',...
%     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'disp','save'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
%     'Display Split-Half values at the commandline',...
%     'Save Split-Half values in data summary file'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'O v E','rand'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
%     'Halves based upon odd and even epochs',...
%     'Halves based upon random split of epochs'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'bal'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={...
%     'Balance number of epochs in each half (drop epochs if more in one half)'};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Number of included epochs',...
%     'Time of peak left - right difference (in seconds)',...
%     'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%     };
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'sig','p','ci','t','df','sd','d'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','95% confidence interval of mean difference',...
%     't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{5};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{5};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{7}={'sig','p','rank','Z','r'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{7}={'Significance of test: 1 = dif, 0 = not',...
%     'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{8}={'norm','p','stat','crit'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{8}={'Normality of data: 0 = normal, 1 = different',...
%     'p value of test','Jarque-Bera value','critical value for test'};
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{9}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{9}={'Normality of left channel data: 0 = normal, 1 = different',...
%     'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%     'Normality of right channel data: 0 = normal, 1 = different',...
%     'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.01 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
% end
%% > Misc
function dg=dgMisc(dg,tmp_handle) % matlab orange info is fine here
dg.tmp.h=tmp_handle;
dg.tmp.abb=get(dg.tmp.h,'tag'); % temp abbreviation
fprintf('%s\n',['Setting up ', dg.tmp.abb,' Tab:']);

dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;

%% -> ? Info
% rollover/tooltipstring question mark to describe tab
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
dg.(dg.tmp.abb).info.tts=sprintf(...
    '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',... \n%s\n%s\n%s\n%s\n%s
    'dopOSCCI Misc Tab:',...
    'Miscellaneous dopOSCCI features and settings',...
    dg.info.txtBreak,'Admin Extras:',...
    'Save ''dop'' variable = allows the dopOSCCI summary data structure to be saved for later inspection',...
    'Finish Sound = by default dopOSCCI will announce the end of the summary with a little trumpet fanfare...',...
    'If this becomes annoying, you can turn it off!',...
    ['(you could also select your own ''.wav'' file if you wanted to: ',...
    '(see ~dopOSCCIm2\dopTools\genTools\finishSound.wav)'],...
    'Short Warn = toggles between displaying and not displaying dialog boxes, indicating that a file is short',...
    ' > short refers to data recordings started late or finished early relative to the specified summary epoch',...
    dg.info.txtBreak,'Session: Individual Balanced Graph:',...
    'For the special session function, this option controls the creation of balanced epoch graphs',...
    'These graphs are based upon a balanced or equated number of epochs from each session',...
    dg.info.txtBreak);
% ,'Overall Graph Data:',...
%     'The vertical option creates additional Overall Graph Data files which are',...
%     'Vertically aligned (participant across the top, time down the side) ',...
%     'as opposed to the regular files (participants down the side, time across the top)',...
%     dg.info.txtBreak);
dg=dgTabInfo(dg);

%% -> Admin Panel
dg.tmp.pan='admin';
dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',[.05 .7 .8 .25],'BackgroundColor',dg.tab.pan.col,...
    'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
    'Title','Admin Extras');
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);

dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDop','finishSound','closeGui','shortWarn'};

%     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'

% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[9 7 7 5 4 8]; % number of check
% boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
    [2 2],...%[1 dg.(dg.tmp.abb).(dg.tmp.pan).n],...
    [0 0],[.05 0 .95 1],'across','opposite'); % [.05 0 .5 1]
dg.(dg.tmp.abb).(dg.tmp.pan).txt={'Save ''dop'' variable','Finish Sound','Close Gui','Short Warn'};
dg.(dg.tmp.abb).(dg.tmp.pan).tts={...
    'Save ''dop'' structure of summary for offline examination',...
    'Play a sound to announce end of summary (see ~dopOSCCIm2\dopTools\genTools\finishSound.wav)',...
    'Close the dopOSCCI graphical user interface when the summary starts',...
    'Display pop dialog boxes to indicate available data is short'};
for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
    dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
    %     dg.tmp.el='head'; dg.tmp.style='text';
    %     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
    %     dg.tmp.pos([1 3])=[.01 .2];
    %     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
    %         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
    %         'units','normalized','HorizontalAlign','Left',...
    %         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
    %         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
    %     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
    
    %     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
    j=1;
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
        'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i},...
        'units','normalized','HorizontalAlign','Left',...
        'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
        'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i},...
        'value',0,'UserData',[1 j],...
        'callback',eval('@getCheckbox'));
    dg=enableObject(dg,1); % might not want this...
    dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
    %     end
end
%% -> Session Balance panel
dg.tmp.pan='grd';
dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
    'Position',[.05 .5 .5 .15],'BackgroundColor',dg.tab.pan.col,...
    'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
    'Title','Session: Individual Balanced Graph');
dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);

dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndBalGraph'};%,'viewIndBalGraph'};

%     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'

% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[9 7 7 5 4 8]; % number of check
% boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
    [1 dg.(dg.tmp.abb).(dg.tmp.pan).n],...
    [0 0],[.1 0 .9 1],'across'); % [.05 0 .5 1]
dg.(dg.tmp.abb).(dg.tmp.pan).txt={'Save Balanced Graph','View Graph'};
dg.(dg.tmp.abb).(dg.tmp.pan).tts={...
    sprintf('%s\n%s\n%s',...
'For Session Special function:',... 
' > SAVE an Individual graph with equal number of epochs per session (balanced)',...
'(Only operates if Individual Graph Save is selected on Graph Tab)'),...
    sprintf('%s\n%s\n',...
'For Session Special function',... 
'VIEW an Individual graph with equal number of epochs per session (balanced).')};
for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
    dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
    %     dg.tmp.el='head'; dg.tmp.style='text';
    %     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
    %     dg.tmp.pos([1 3])=[.01 .2];
    %     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
    %         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
    %         'units','normalized','HorizontalAlign','Left',...
    %         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
    %         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
    %     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
    
    %     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
    j=1;
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
        'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i},...
        'units','normalized','HorizontalAlign','Left',...
        'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
        'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
        'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i},...
        'value',0,'UserData',[1 i],...
        'callback',eval('@getCheckbox'));
    dg=enableObject(dg,0); % might not want this...
    dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
    %     end
end
%% -> epoch selection panel
    dg.tmp.pan='rejEpSel';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .3 .9 .15],'BackgroundColor',dg.tab.pan.col,... 'Position',[.05 .7 .9 .1]
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which collections of rejected epochs (if any) will be saved in the Individual Summary File)');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','length','activation','manual','combined','balanced'};
    dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
    dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
        'length appropriate epochs (i.e., not including short epochs)',...
        'epochs with data values within activation rejection range (see Data tab)',...
        'manually selected epochs (see Special, Screen)',...
        'combined epochs = length appropriate + activation appropriate + manually selected epochs',...
        'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
    
    dg.tmp.h_abb='saveRejEpochs'; % dop.def. abbreviation
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',['Save record of rejected epochs for ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
            'UserData',[1 i],'value', 0,...
            'callback',eval('@getCheckbox'));
            dg=enableObject(dg,1); % might not want this...
        
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
    end
% %% -> Graph Data Panel
% dg.tmp.pan='grd';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .3 .3 .15],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Overall Graph Data');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
% 
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveGraphDataVert'};
% 
% %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
% 
% % dg.(dg.tmp.abb).(dg.tmp.pan).checks=[9 7 7 5 4 8]; % number of check
% % boxes per line
% % dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
% %     '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
% %     '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [1 dg.(dg.tmp.abb).(dg.tmp.pan).n],...
%     [0 0],[.1 0 .9 1],'across'); % [.05 0 .5 1]
% dg.(dg.tmp.abb).(dg.tmp.pan).txt={'Vertical file'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts={...
%     'Save verticallly alligned overall graph data file.'};
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     %     dg.tmp.el='head'; dg.tmp.style='text';
%     %     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     %     dg.tmp.pos([1 3])=[.01 .2];
%     %     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%     %         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%     %         'units','normalized','HorizontalAlign','Left',...
%     %         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%     %         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%     %     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%     
%     %     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%     j=1;
%     dg.tmp.el='check'; dg.tmp.style='checkbox';
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i},...
%         'value',0,'UserData',[1 j],...
%         'callback',eval('@getCheckbox'));
%     dg=enableObject(dg,1); % might not want this...
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%     %     end
% end
% %% -> Notes Panel
% dg.tmp.pan='notes';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .5 .6 .25],'BackgroundColor',dg.tab.pan.col,...
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Summary Notes');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
%
% % 'saveNotes','defFileNotes'
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
%     'saveNotes',...[1 1 1],... % [overall and inidividual & skip] running notes - requires dop.def.saveData=1 (see dopSaveNotes)
%     'defFileNotes'};%,[1 1],... % move view only and mat defintion files to notes
% dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 2]; % number of check boxes per line
% dg.(dg.tmp.abb).(dg.tmp.pan).title={'Save Notes','Copy Definition'};
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%     [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%     [0 0],[.25 0 .75 1],'across','opposite'); % top to bottom
%
% dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%     ['Save notes which are text files of information printed to ',...
%     'the matlab command window during the summary'],...
%     ['Defintion files hold a copy of all the dopOSCCI settings for ',...
%     'a particular task']};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'Overall','Individual','Skip'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
%     'Save Overall notes - includes setup and individual notes (if saved) in single file',...
%     'Save Individual data file notes',...
%     'Save text file record of which files skipped from summary and why'};
%
% dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'View Only ''.txt'' file','Matlab ''.mat'' file'};
% dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
%     'Copy View Only text file to notes directory - will be included in Overall notes file',...
%     'Copy ''.mat'' definition file to notes directory'};
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%     dg.tmp.el='head'; dg.tmp.style='text';
%     dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%     dg.tmp.pos([1 3])=[.025 .2];
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%     for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%         dg.tmp.el='check'; dg.tmp.style='checkbox';
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%             'value',0,'UserData',[1 j],...
%             'callback',eval('@getCheckbox'));
%         dg=enableObject(dg,1); % might not want this...
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%     end
% end
end
%% -----------------------------------------------------------------------
%% dgTabInfo ?
% dg.info.abb='q';
% dg.info.txt='?';
% dg.info.txtBreak='---------------------------------------';
% dg.info.align='Left';
% dg.info.pos=[.01 .94 .05 .05];
function dg=dgTabInfo(dg)
dg.(dg.tmp.abb).info.h=uicontrol('Parent',dg.(dg.tmp.abb).pan.h(end),...
    'Style','text','String',dg.info.txt,...
    'units','normalized','HorizontalAlign',dg.info.align,...
    'tag',[dg.tmp.abb,'_info'],'Position',dg.info.pos,...
    'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
    'ToolTipString',dg.(dg.tmp.abb).info.tts);
dg.font.h(end+1)=dg.(dg.tmp.abb).info.h;
end
%% -----------------------------------------------------------------------
%% getTxtEdit
% try to make this generic if I can
function getTxtEdit(varargin) % matlab orange info is fine here
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
% get first part e.g., from notes_edit
% just want 'notes'
dg.tmp.field=strtok(dg.tmp.tag,'_');
dg.tmp.dat=get(dg.tmp.h,'String');

if isfield(dg.dopdef,dg.tmp.field)
    switch dg.tmp.field
        case 'dataDir'
            dg.dopdef.(dg.tmp.field)=dg.tmp.dat;
            disp(dg.dopdef.(dg.tmp.field)(1));%
            dg=dgCheckDataDir(dg);
        case 'saveDir'
            dg.dopdef.(dg.tmp.field)=dg.tmp.dat;
            disp(dg.dopdef.(dg.tmp.field)(1));%
            dg=dgCheckSaveDir(dg);
        case {'epoch','base','poi',...
                'evChs','epochs','sep','actWin',...
                'evMatch'}
            dg.tmp.dat=strrep(dg.tmp.dat,' ',''); % no spaces
            dg.tmp.ud=get(dg.tmp.h,'UserData');
            dg.dopdef.(dg.tmp.field)(dg.tmp.ud(1),dg.tmp.ud(2))=str2double(dg.tmp.dat);
            dg.dopdef=dopOSCCIeventCheck(dg.dopdef,dg);% dg=dgEventCheck(dg);
            dg=dgEventGraph(dg);
            switch dg.tmp.field
                case {'actWin','sep'}
                    dg.dopdef=dopOSCCIeventCheck(dg.dopdef,dg);% dg=dgEventCheck(dg);
                    dg=dgEventGraph(dg);
            end
        case {'dopChs','actRej'}
            dg.tmp.dat=strrep(dg.tmp.dat,' ',''); % no spaces
            dg.tmp.ud=get(dg.tmp.h,'UserData');
            dg.dopdef.(dg.tmp.field)(dg.tmp.ud(1),dg.tmp.ud(2))=str2double(dg.tmp.dat);
        case 'evNames'
            dg.tmp.dat=strrep(dg.tmp.dat,' ',''); % no spaces
            dg.tmp.ud=get(dg.tmp.h,'UserData');
            dg.dopdef.(dg.tmp.field){dg.tmp.ud(1),dg.tmp.ud(2)}=dg.tmp.dat;
            set(dg.tmp.h,'String',dg.tmp.dat);
            dg=dgSetEventMatchList(dg);
        case {'downHertz','markHeight','actSep'} % numbers
            dg.tmp.dat=strrep(dg.tmp.dat,' ',''); % no spaces
            if ~isnan(str2double(dg.tmp.dat))
                dg.dopdef.(dg.tmp.field)=str2double(dg.tmp.dat);
                disp(dg.dopdef.(dg.tmp.field)(1));%
            else
                % must be numeric
                set(dg.tmp.h,'String',dg.dopdef.setGet.defaults.(dg.tmp.field));
                dg.tmp.warn=sprintf('%s\n%s\n',[dg.tmp.field,' must be numeric'],...
                    'Reset to default');
                disp(dg.tmp.warn);
                warndlg(dg.tmp.warn,'Must be Numeric:');
            end
        otherwise
            dg.dopdef.(dg.tmp.field)={dg.tmp.dat};
            disp(dg.dopdef.(dg.tmp.field){1});%
            
    end
else
    fprintf('\t%s\n',[dg.tmp.field,' is not a definition field.']);
end
switch dg.tmp.field
    case {'scrnFileNameLoc','grpFileNameLoc','behFileNameLoc','sesFileNameLoc'};
        dg.tmp.fnl=dg.dopdef.(dg.tmp.field);%[dg.tmp.dir,dg.tmp.fn];
        dg=checkSpecialFile(dg);
end
end
%% browseDirectory
function browseDirectory(varargin)
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
% get first part e.g., from notes_edit
% just want 'notes'
dg.tmp.field=strtok(dg.tmp.tag,'_');
dg.tmp.dataDir=uigetdir(get(dg.tmp.h,'UserData'),...
    ['Browse for ',dg.tmp.tag]);
if numel(dg.tmp.dataDir)>1;
    dg.tmp.dataDir=[dg.tmp.dataDir,'/'];
    set(dg.tmp.h,'UserData',dg.tmp.dataDir); % update location
    dg.dopdef.(dg.tmp.field)=dg.tmp.dataDir;

    switch dg.tmp.field
        case 'dataDir'
                set(dg.dat.(dg.tmp.field).edit.h,'String',dg.tmp.dataDir);
            dg=dgCheckDataDir(dg);
        case 'saveDir'
%                 set(dg.sav.(dg.tmp.field).edit.h,'String',dg.tmp.dataDir);
             dg=dgCheckSaveDir(dg);
    end
end
end
%% getCheckbox
function getCheckbox(varargin)
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
% get first part e.g., from notes_edit
% just want 'notes'
dg.tmp.field=strtok(dg.tmp.tag,'_');

dg.tmp.userdata=get(dg.tmp.h,'UserData');
switch dg.tmp.field
    case 'saveData'
        dg.dopdef.(dg.tmp.field)=get(dg.tmp.h,'Value');
        dg=saveEnable(dg);
        %         set(dg.sav.saveDataInfo.head.h,'String',...
        %             dg.tmp.userdata{dg.dopdef.(dg.tmp.field)+1});
        %         dg.tmp.saveEnable='Off';
        %         if dg.dopdef.(dg.tmp.field)
        %             dg.tmp.saveEnable='On';
        %         end
        %         dg.tmp.pans={'chInd','epSel','LIind'};
        %         for i=1:numel(dg.tmp.pans)
        %             set(get(dg.sav.pan.(dg.tmp.pans{i}),'Children'),'Enable',dg.tmp.saveEnable)
        %         end
    case 'graphs' %{'raw','norm','ind','epoch','beh','grp'}
        dg.dopdef.(dg.tmp.field)(dg.tmp.userdata(1),dg.tmp.userdata(2))=get(dg.tmp.h,'Value');
        dg=dgGraphDataChCheck(dg);
        %         if dg.tmp.userdata(2)==6 && dg.dopdef.(dg.tmp.field)(dg.tmp.userdata(1),6)==1
        %             if sum(dg.dopdef.saveGraphDataChs(1:3))<3
        %                 set(dg.graph.saveGraphDataChs.check.h(1:3),'Value',1);
        %                 dg.dopdef.saveGraphDataChs(1:3)=1;
        %                 dg.tmp.warn=sprintf('%s\n%s\n',...
        %                     'Overall graphs required Left, Right, & Dif Graph Data to be saved.',...
        %                     'Settings have been adjusted (see Save+ tab,Graph Data, Data Selection)');
        %                 disp(dg.tmp.warn);
        %                 warndlg(dg.tmp.warn,'Save Graph Data Adjust:');
        %             end
        %         end
    case {'saveEpochSelection',...
            'saveIndexChs','saveIndexFilt','saveIndices',...
            'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm',...
            'saveEpochIndCh','saveEpochIndFilter','saveEpochInd','saveEpochLI',...
            'saveEpochSelectionGraph','saveGraphDataChs','saveGraphDataVert',...
            'splitCalcSave','splitOptions','splitBal',...
            'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
            'save1normSplit','save2normSplit','saveRankSplit',...
            'saveNotes','defFileNotes',...
            'saveIndexChsOverall',...
            'saveIndexFiltOverall','saveIndicesOverall',...
            'saveDescripOverall','save1sampleOverall',...
            'save2sampleOverall','saveRankOverall',...
            'save1normOverall','save2normOverall',...
            'saveDescripSplitOverall','save1sampleSplitOverall',...
            'save2sampleSplitOverall','saveRankSplitOverall',...
            'save1normSplitOverall','save2normSplitOverall',...
            'saveIndexExtraChs','saveIndexExtraChFilt',...[0 1 1],... % filter = epoch, base, poi
        'saveIndexExtraTypeFilt','saveIndicesExtra',...
        'saveEpochSelQual',...
        'saveDropInd','saveDropChs','saveDropFilt','saveDropSelEp',...
        'saveGorInd','saveGorChs','saveGorFilt','saveGorSelEp',...
        'saveGraphData',...
        'saveGraphDataInd','saveRejEpochs'}
        dg.dopdef.(dg.tmp.field)(dg.tmp.userdata(1),dg.tmp.userdata(2))=get(dg.tmp.h,'Value');
        dg=dgGraphDataChCheck(dg);
    case 'saveIndBalGraph'
%         dg.dopdef.graphs(dg.tmp.userdata(2),end)=get(dg.tmp.h,'Value');
%         dg=dgGraphDataChCheck(dg);
        dg.dopdef.saveEpochSelectionGraph(end)=get(dg.tmp.h,'Value');
    otherwise
        dg.dopdef.(dg.tmp.field)=get(dg.tmp.h,'Value');
end
end
%% getPopEdit
% try to make this generic if I can
function getPopEdit(varargin) % matlab orange info is fine here
global dg
dg.tmp.dbstack=dbstack;
fprintf('%s\n',['Running ', dg.tmp.dbstack(1).name,':']);
dg.tmp.h=varargin{1};
dg.tmp.tag=get(dg.tmp.h,'tag');
% get first part e.g., from notes_edit
% just want 'notes'
dg.tmp.field=strtok(dg.tmp.tag,'_');
if isfield(dg.dopdef,dg.tmp.field) || strcmp(dg.tmp.field,'graphEpochSel')
    dg.tmp.data=get(dg.tmp.h,'String');
    switch dg.tmp.field
        case {'fileSel','graphFileType'}
            dg.dopdef.(dg.tmp.field)={dg.tmp.data{get(dg.tmp.h,'value')}};
            disp(dg.dopdef.(dg.tmp.field){1});
        case 'evMatch'
            dg=dgEventMatchCheck(dg,dg.tmp.h);
        case 'graphEpochSel'
            dg.dopdef.saveEpochSelectionGraph(1:end-1)=0;
            dg.dopdef.saveEpochSelectionGraph(get(dg.tmp.h,'Value'))=1;
            
            dg=dopGraphEpochSel(dg,dg.tmp.h);
            
%             disp(dg.tmp.data{get(dg.tmp.h,'Value')});
%             dg.tmp.notes=get(dg.graph.graphEpochSel.note.h,'UserData');
%             dg.tmp.tts=textwrap(dg.graph.graphEpochSel.note.h,dg.tmp.notes(get(dg.tmp.h,'Value')));
%             set(dg.graph.graphEpochSel.note.h,'String',...
%                 dg.tmp.notes{get(dg.tmp.h,'Value')},...
%                 'Tooltipstring',sprintf('%s\n%s\n%s\n%s\n%s\n%s\n',dg.tmp.tts{1:end}));%,dg.graph.pop2.notes)
%             set(dg.graph.
%             dg.(dg.tmp.abb).pop2.notes
            %             dg.tmp.data=dg.tmp.data{get(dg.tmp.h,'Value')}; % get selected string
            %             [dg.tmp.evName dg.tmp.remain]=strtok(dg.tmp.data,'(');
            %             dg.tmp.num=str2double(strrep(strtok(dg.tmp.remain,')'),'(',''));
            %             dg.tmp.ud=get(dg.tmp.h,'UserData');
            %             dg.dopdef.(dg.tmp.field)(dg.tmp.ud(1))=dg.tmp.num;
            %             switch dg.tmp.num
            %                 case 0 % no match
            %                     if dg.dopdef.evType(dg.tmp.ud(1))~=2
            %                         % can't be stim & base
            %                         set(dg.event.evType.radio.h(dg.tmp.ud(1),1),'Value',1);
            %                         dg.dopdef.evType(dg.tmp.ud(1))=2;
            %                         dg.tmp.warn=sprintf('%s\n%s\n',...
            %                             'For event matching, non-matched events must be ''Stim & Base''',...
            %                             'Set event type to ''Stim & Base'' setting');
            %                         disp(dg.tmp.warn);
            %                         warndlg(dg.tmp.warn,'Event Match ~ Event Type:');
            %                     end
            %                 otherwise
            %                     if dg.dopdef.evType(dg.tmp.ud(1))==2
            %                         % can't be stim & base
            %                         set(dg.event.evType.radio.h(dg.tmp.ud(1),2),'Value',1);
            %                         dg.dopdef.evType(dg.tmp.ud(1))=1;
            %                         dg.tmp.warn=sprintf('%s\n%s\n',...
            %                             'For event matching, matched events must be ''Stim-'' or ''Base Only''',...
            %                             'Set event type OFF ''Stim & Base'' setting');
            %                         disp(dg.tmp.warn);
            %                         warndlg(dg.tmp.warn,'Event Match ~ Event Type:');
            %                     end
            %             end
    end 
else
    
    fprintf('\t%s\n',[dg.tmp.field,' is not a definition field.']);
end
end
%% -----------------------------------------------------------------------
%% set gui data
% function that imports the defintion data into the gui fields...
% starting small and working up as we go
function setGuiData(setting) % import or reset
global dg
dg.tmp.dbstack=dbstack;
fprintf('\n%s\n%s\n','****************************************',...
    ['Running ', dg.tmp.dbstack(1).name,': ',setting]);
dg.data.setting=setting;
dg.tmp.print = 0; % print progress details to command window
% task name editable
if strcmp(dg.data.setting,'reset');
    set(dg.def.taskName.edit.h,'String',get(dg.def.taskName.edit.h,'UserData'));
end
if isempty(dg.inputs.taskName)
    dg.wait.h=waitbar(0,['dopOSCCI ',dg.data.setting]);
end
for i=1:numel(dg.enable.import)
    if dg.enable.import(i)
        if dg.tmp.print; fprintf('\t%s %s%i%s\n',dg.enable.list{i},'(',i,')'); end
        switch dg.enable.style{i}
            case 'edit'
                switch dg.data.setting
                    case 'import'
                        if isfield(dg,'dopdef') && isfield(dg.dopdef,(dg.enable.list{i})) && ~isempty(dg.dopdef.(dg.enable.list{i}))
                            switch dg.enable.list{i}
                                case {'epoch','base','poi','dopChs','actRej',...
                                        'evChs','epochs','sep','actWin',...
                                        'evNames'};%,'evMatch'} % multiple numbers
                                    dg.tmp.ud=get(dg.enable.h(i),'UserData');
                                    if sum(size(dg.dopdef.(dg.enable.list{i}))==dg.tmp.ud)==numel(dg.tmp.ud)
                                        dg.tmp.dat=dg.dopdef.(dg.enable.list{i})(dg.tmp.ud(1),dg.tmp.ud(2));
                                    else % looking for 2nd event data but doesn't exist...
                                        dg.tmp.dat=dg.dopdef.(dg.enable.list{i})(1,dg.tmp.ud(2));
                                    end
                                    if strcmp(dg.enable.list{i},'evNames')
                                        dg.tmp.dat=dg.tmp.dat{1};
                                    end
                                    set(dg.enable.h(i),'String',dg.tmp.dat);
                                case 'notes'
                                    set(dg.enable.h(i),'String',dg.dopdef.(dg.enable.list{i}){1});
                                otherwise
                                    set(dg.enable.h(i),'String',dg.dopdef.(dg.enable.list{i}));
                                    switch dg.enable.list{i}
                                        case 'dataDir'
                                            dg=dgCheckDataDir(dg);
                                        case 'saveDir'
                                            dg=dgCheckSaveDir(dg);
                                        case {'scrnFileNameLoc','grpFileNameLoc','behFileNameLoc','sesFileNameLoc'}
                                            dg.tmp.field=dg.enable.list{i};
                                            dg.tmp.fnl=dg.dopdef.(dg.tmp.field);
                                            dg=checkSpecialFile(dg);
                                    end
                            end
                        else
                            set(dg.enable.h(i),'String',get(dg.enable.h(i),'UserData'))
                            switch dg.enable.list{i}
                                case {'scrnFileNameLoc','grpFileNameLoc','behFileNameLoc','sesFileNameLoc'}
                                    set(dg.enable.h(i),'ToolTipString',get(dg.enable.h(i),'UserData'))
                                    dg.tmp.field_adj=strtok(dg.enable.list{i},'N');
                                    set(dg.spec.(dg.tmp.field_adj).text.h,'String',...
                                        get(dg.spec.(dg.tmp.field_adj).text.h,'UserData'));
                            end
                        end
                        
                    case 'reset'
                        switch dg.enable.list{i}
                            case {'evNames','evChs','epochs','sep',...
                                    'actWin','epoch','base','poi',...
                                    'evNum','evMatch','dopChs','actRej'}
                                set(dg.enable.h(i),'String','');
                            otherwise
                                set(dg.enable.h(i),'String',get(dg.enable.h(i),'UserData'));
                        end
                end
            case 'pop'
                switch dg.data.setting
                    case 'import'
                        switch dg.enable.list{i}
                            case 'fileSel'
                                set(dg.enable.h(i),'value',1);
                                if isfield(dg,'dopdef') && isfield(dg.dopdef,'dataDir') && ~isempty(dg.dopdef.dataDir) ...
                                        && isfield(dg,'data') && isfield(dg.data,'files') && ~isempty(dg.data.files)
                                    set(dg.enable.h(i),'String',...
                                        {get(dg.enable.h(i),'UserData'),dg.data.files{1:end}});
                                    
                                else
                                    set(dg.enable.h(i),'String','No Files');%{get(dg.enable.h(i),'UserData')});
                                end
                                dg.dopdef.(dg.enable.list{i})={get(dg.enable.h(i),'UserData')};
                            case 'graphFileType'
                                set(dg.enable.h(i),'value',1);
                                dg.tmp.data=get(dg.enable.h(i),'UserData');
                                set(dg.enable.h(i),'String',get(dg.enable.h(i),'UserData'),...
                                    'Value',find(strcmp(dg.dopdef.(dg.enable.list{i}){1},dg.tmp.data)));
                            case 'evMatch'
                                if isfield(dg,'dopdef') && isfield(dg.dopdef,'evNum') && dg.dopdef.evNum>1
                                    dg=dgSetEventMatchList(dg);%dg=dgSetEventMatchList(dg,dg.enable.h(i));
                                    %                                     dg.tmp.ud=get(dg.enable.h(i),'UserData');
                                    %                                     dg.tmp.evMatchList=dg.event.pop.default; % is cell
                                    %                                     for j=1:dg.dopdef.evNum
                                    %                                         if j~=dg.tmp.ud(1)
                                    %                                             dg.tmp.evMatchList{end+1}=...
                                    %                                                 [dg.dopdef.evNames{j},' (',num2str(j),')'];
                                    %                                         end
                                    %                                     end
                                    %                                     set(dg.enable.h(i),'String',dg.tmp.evMatchList)
                                end
                            case 'graphEpochSel'
%                                 set(dg.graph.graphEpochSel.pop.h,'Value',5);
                                dg=dopGraphEpochSel(dg);
                                
                        end
                    case 'reset'
                        set(dg.enable.h(i),'value',1);
                        dg.tmp.data=[];
                        dg.tmp.data{1}=get(dg.enable.h(i),'UserData');
                        switch dg.enable.list{i}
                            case 'evMatch'
                                dg.tmp.data=dg.event.pop.default;
                            case {'graphFileType','graphEpochSel'}
                                dg.tmp.data=dg.tmp.data{1};
                        end
                        set(dg.enable.h(i),'String',dg.tmp.data);
                end
            case 'check'
                switch dg.data.setting
                    case 'import'
                        switch dg.enable.list{i}
                            case {'raw','norm','ind','epoch','beh','grp'}
                                if dg.tmp.print;fprintf('\t\t%s\n',' - graph');end
                                dg.tmp.dat=get(dg.enable.h(i),'UserData');
                                set(dg.enable.h(i),'value',...
                                    dg.dopdef.graphs(dg.tmp.dat(1),dg.tmp.dat(2)));
                            case    {'saveEpochSelection',...
                                    'saveIndexChs','saveIndexFilt','saveIndices',...
                                    'saveDescrip','save1sample','save2sample',...
                                    'saveRank','save1norm','save2norm',...
                                    'saveEpochIndCh','saveEpochIndFilter','saveEpochInd','saveEpochLI',...
                                    'saveEpochSelectionGraph','saveGraphDataChs','saveGraphDataVert',...
                                    'splitCalcSave','splitOptions','splitBal',...
                                    'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
                                    'save1normSplit','save2normSplit','saveRankSplit',...
                                    'saveNotes','defFileNotes',...
                                    'saveIndexChsOverall',...
                                    'saveIndexFiltOverall','saveIndicesOverall',...
                                    'saveDescripOverall','save1sampleOverall',...
                                    'save2sampleOverall','saveRankOverall',...
                                    'save1normOverall','save2normOverall',...
                                    'saveDescripSplitOverall','save1sampleSplitOverall',...
                                    'save2sampleSplitOverall','saveRankSplitOverall',...
                                    'save1normSplitOverall','save2normSplitOverall',...
                                    'saveRejEpochs'}
                                try
                                    dg.tmp.dat=get(dg.enable.h(i),'UserData');
                                    set(dg.enable.h(i),'value',...
                                        dg.dopdef.(dg.enable.list{i})(dg.tmp.dat(1),dg.tmp.dat(2)));
                                end
                            otherwise
                                try
                                    set(dg.enable.h(i),'value',dg.dopdef.(dg.enable.list{i}));
                                catch err
                                    fprintf('\t%s (%i): Error = %s\n',dg.enable.list{i},i,err.message);
                                end
                                switch dg.enable.list{i}
                                    case 'saveData'
                                        dg.tmp.userdata=get(dg.enable.h(i),'UserData');
                                        set(dg.sav.saveDataInfo.head.h,'String',...
                                            dg.tmp.userdata{dg.dopdef.(dg.enable.list{i})+1});
                                        dg.tmp.field=dg.enable.list{i};
                                        dg=saveEnable(dg);
                                end
                        end
                    case 'reset'
                        try
                            set(dg.enable.h(i),'value',0); % off
                        end
                end
            case {'scrnFileChk','grpFileChk','behFileChk','sesFileChk'}
                switch dg.data.setting
                    case 'import'
                        set(dg.enable.h(i),'value',dg.dopdef.(dg.enable.style{i}));
                    case 'reset'
                        set(dg.enable.h(i),'value',0);
                end
            case 'text'
                switch dg.data.setting
                    case 'import'
                        set(dg.enable.h(i),'String',dg.dopdef.(dg.enable.list{i}));
                    case 'reset'
                        try
                        set(dg.enable.h(i),'String',get(dg.enable.h(i),'UserData'));
                        end
                end
        end
        
    else
        switch dg.data.setting
            case 'reset'
                switch dg.enable.style{i}
                    case {'head','text'}
                        set(dg.enable.h(i),'String',get(dg.enable.h(i),'UserData'))
                end
                
        end
    end
    if isempty(dg.inputs.taskName)
        waitbar(i/numel(dg.enable.import),dg.wait.h);
    end
end
%% ~ Events
switch dg.data.setting
    case 'import'
        dgEventNumberAdjust('import');
        %         dg=dgSetEventMatchList(dg);
        %         dg.tmp.evTypes=[2 0 0];% ... % evTypes (S&B, S, B)
        for k=1:dg.dopdef.evNum
            if numel(dg.dopdef.evType)<k
                dg.tmp.data=1;
            else
                dg.tmp.data=find(dg.dopdef.evType(k)==dg.event.radio.code);
            end
            %             dg.tmp.row=find(dg.dopdef.evType(k)==dg.tmp.evTypes);
            set(dg.event.evType.radio.h(k,dg.tmp.data),'Value',1);
            dg=dgEventMatchCheck(dg,dg.event.evMatch.pop.h(k));%,'import');
            dg=dgEventTypeFreeze(dg,k);
            dg=dgEventGraph(dg,k);
        end
        
end
if isempty(dg.inputs.taskName)
    close(dg.wait.h);
end
end
%%  enableSet
function enableSet(setting)
global dg
% if isfield(dg.enable,'setting')
%     if strcmp(dg.enable.setting,'On') && strcmp(setting,'On')
%         disp('!!!!');
%         dgResetGui;
%        return;
%     end
% end
dg.enable.setting=setting;
% if ~dg.enable.on
%     dg.enable.on=1; % now it's on
% else
%     dg.enable.on=0;
% end
fprintf('%s\n',['Enable gui functionality: ',dg.enable.setting])
for i=1:length(dg.enable.h); %disp(i);
    try
        set(dg.enable.h(i),'Enable',dg.enable.setting);
    end
end
% set(dg.enable.h,'Enable',dg.enable.setting);
if numel(dg.tab.event.h)==1
    set(dg.event.evType.radio.h,'Enable','Off');
    set(dg.event.evMatch.pop.h,'Enable','Off');
end
switch dg.enable.setting
    case 'On'
        set(dg.def.taskName.push.h,'BackgroundColor',dg.col.Off,...
            'Enable','Off');
    case 'Off'
        set(dg.def.taskName.push.h,'BackgroundColor',dg.col.On,...
            'Enable','On');
end
set(dg.run.h,'BackgroundColor',dg.col.(dg.enable.setting));

fprintf('\t%s\n','Done');

end
%% enableObject
function dg=enableObject(dg,import,varargin)

if numel(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h)==1
    %     xisp('one')
    dg.enable.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
else
    
    [i j]=size(dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h);
    %      xisp([dg.tmp.abb,' ',dg.tmp.h_abb,' ',dg.tmp.el,': ',num2str([i j ])]);
    if ~isempty(varargin)
        j=varargin{1};
        %         xisp(j);
    end
    dg.enable.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i,j);
end
if ishandle(dg.enable.h(end))
    dg.enable.list{end+1}=dg.tmp.h_abb;
    if isfield(dg.enable,'listAdj')
        dg.enable.list{end}=dg.enable.listAdj; % done for special tab - check & edit
    end
    
    dg.enable.import(end+1)=import;
    dg.enable.style{end+1}=dg.tmp.el;
    if isfield(dg.enable,'styleAdj')
        dg.enable.style{end}=dg.enable.styleAdj; % done for graph checkboxes currently
    end
    if isfield(get(dg.enable.h(end)),'Enable')
        set(dg.enable.h(end),'Enable','Off');
        % but adjust if new event tab
        if isfield(dg,'dat') && isfield(dg.dat,'evNum') && ... % have data tab & event number field
                numel(dg.dat.evNum.push.h)>1 && isfield(dg,'dopdef') && ... % we have evNum push buttons & definition info
                numel(dg.event.evType.radio.h)>1
            %                 str2double(get(dg.dat.evNum.push.h(2),'String'))<dg.dopdef.evNum
            
            %             dg.tmp.ef=strtok(get(dg.enable.h(end),'tag'),'_'); % enable field
            %             dg.tmp.eud=get(dg.enable.h(end),'UserData'); % enable user data
            %
            % %             dg.tmp.k=numel(dg.event.evType.radio.h);
            %             if isfield(dg.dopdef,dg.tmp.ef) && sum(dg.tmp.eud)
            %                 if iscell(dg.dopdef.(dg.tmp.ef)) % cell array to play with
            %
            %                 else
            %                 end
            %                 if sum(size(dg.tmp.eud)==1) % if one of the dimension is 1
            %                     if iscell(dg.dopdef.(dg.tmp.ef))
            %                         dg.dopdef.(dg.tmp.ef){dg.tmp.eud}=...
            %                             dg.dopdef.(dg.tmp.ef){dg.tmp.k};
            %                     else
            %                         dg.dopdef.(dg.tmp.ef)(dg.tmp.eud)=...
            %                             dg.dopdef.(dg.tmp.ef)(dg.tmp.k);
            %                     end
            %                 else
            %                     dg.dopdef.(dg.tmp.ef)(dg.tmp.eud(1),dg.tmp.eud(2))=...
            %                         dg.dopdef.(dg.tmp.ef)(dg.tmp.k,dg.tmp.eud(2));
            %                 end
            %             end
            set(dg.enable.h(end),'Enable','On');
            %             switch dg.tmp.ef
            %                 case 'evType'
            %                     set(dg.enable.h(end),'Value',1);
            %                 otherwise
            %                     set(dg.enable.h(end),'String',dg.dopdef.(dg.tmp.ef)(1,dg.tmp.eud(2)));
            %             end
        end
    end
end
% if ~strcmp(dg.tmp.abb,'def') && strcmp(dg.tmp.el,'push')
%     set(dg.enable.h(end),'BackgroundCol',dg.col.wait);
% end
end
%% fontAdjust
% dg.font.values=[-1 1];
% dg.font.sets=['Decrease','Increase'];
function fontAdjust(varargin)
global dg
dg.tmp.h=varargin{1};
dg.tmp.evnt=varargin{2};
dg.font.adjTxt=[];
if ~isempty(dg.tmp.evnt) && ~isfield(dg.tmp.evnt,'modifier')
    if dg.tmp.evnt.Character == '-'
        dg.font.adjTxt=dg.font.sets{1}; % Decrease
    elseif dg.tmp.evnt.Character == '='
        dg.font.adjTxt=dg.font.sets{2}; % Increase
    else
        dg.font.adjTxt='no_adjust';
    end
end
if isempty(dg.font.adjTxt)
    dg.font.adjTxt=strtok(get(varargin{1},'Tag'),'_');
end
if ~strcmp(dg.font.adjTxt,'no_adjust')
    fprintf('%s\n',['Adjusting font size: ',dg.font.adjTxt])
    dg.font.adj=dg.font.values(strcmp(dg.font.sets,dg.font.adjTxt));
    for i=1:numel(dg.font.h)
        try %if sum(strcmpi(fieldnames(dg.font.h(i)),'FontSize'))
            set(dg.font.h(i),'FontSize',...
                get(dg.font.h(i),'FontSize')+1*dg.font.adj);
        catch err
            disp(err)
        end
    end
end
end
%% -----------------------------------------------------------------------
%% dgColours
function dg=dgColours(dg)
dg.col.k=[0 0 0]; % black
dg.col.w=[1 1 1]; % white
dg.col.grey=[.9 .9 .9];
dg.col.r=[.7 0 0]; % red
dg.col.g=[0 .7 0]; % green
dg.col.b=[0 .6 .95]; % blue
dg.col.greyLight=[.65 .65 .65]; % light grey
dg.col.y=[.95 .85 0];

dg.col.bg=dg.col.grey;
dg.col.wait=dg.col.r;
dg.col.go=dg.col.g;
dg.col.gt=dg.col.k; % go text
dg.col.pb=dg.col.b; % panel back
dg.col.pt=dg.col.w; % panel text
dg.col.eb=dg.col.w; % edit back
dg.col.et=dg.col.k; % edit txt

dg.col.fbg=dg.col.greyLight; %  figure background

% enable settings
dg.col.On=dg.col.g;
dg.col.Off=dg.col.r;

end
%% dgPositions
% row_col = number of elements columns rows (just to be confusing)
% xy_gap = x y gap between elements and also from outside of parent pos
% [xy_pos] = xy points and xy portions for elements to fit within
function pos=dgPositions(row_col,xy_gap,varargin)
% finfo=dbstack;
order='standard'; % left to right, bottom to top
direction='down';
xy_size=(1-(row_col([2 1])+1).*xy_gap)./row_col([2 1]); % gap spacing 1./row_col([2 1])-xy_gap;%
xy_pos=[0 0 1 1]; % full
if ~isempty(varargin)
    for i=1:numel(varargin)
        if isnumeric(varargin{i})
            % make sure the position is okay
            %             if sum(varargin{i}(1:2)<0)
            %                 varargin{i}(varargin{i}(1:2)<0)=0;
            %             end
            if varargin{i}(1)+varargin{i}(3)>1
                varargin{i}(1)=1-varargin{i}(3);
            end
            if varargin{i}(2)+varargin{i}(4)>1
                varargin{i}(2)=1-varargin{i}(4);
            end
            xy_pos=varargin{i};
            
        else
            switch varargin{i}
                case {'standard','opposite'}
                    order=varargin{i};
                case {'down','across'}
                    direction=varargin{i};
            end
        end
    end
end
% if numel(xy_size)==4
%     xy_pos=xy_size(3:4);
%     xy_size=xy_size(1:2);
% end
pos=zeros(row_col(1)*row_col(2),4);
k=0;
rows=row_col(1); % number of y (rows)
cols=row_col(2); % number of x (columns)
% if strcmp(direction,'across')
%     % switch these
%     cols=row_col(1); % number of x (columns)
%     rows=row_col(2); % number of y (rows)
% end
for i=1:cols
    for j=1:rows
        k=k+1;
        pos(k,:)=[xy_gap(1)*i+xy_size(1)*(i-1) xy_gap(2)*j+xy_size(2)*(j-1) ...
            xy_size];
        %         pos
    end
end
switch order
    case 'opposite'
        if sum(row_col>1)==2
            % flip in parts
            tmp=pos; pos=[];
            %             switch direction
            %                 case 'down'
            for i=1:row_col(2) % for each column
                pos=vertcat(pos,tmp(flipdim(row_col(1)*(i-1)+1:row_col(1)*i,2),:));
            end
            %                 case 'across'
            %                     for i=1:row_col(1) % for each row
            %                         pos=vertcat(pos,tmp(flipdim(row_col(2)*(i-1)+1:row_col(2)*i,2),:));
            %                     end
            %             end
        else
            pos=pos(flipdim(1:size(pos,1),2),:);
        end
end

for i=1:size(pos,1)
    pos(i,:)=(pos(i,:).*[xy_pos(3:4) xy_pos(3:4)])+[xy_pos(1:2) 0 0];
end

switch direction
    case 'across'
        tmp=pos; pos=[]; k=0;
        for i=1:rows
            for j=1:cols
                k=k+1;
                pos(k,:)=tmp(i+rows*(j-1),:);
            end
        end
end
clear tmp order direction xy_pos xy_size row_col i j k
end

%% dgResize
function dgResize(varargin)
global dg
% OSCCI image position
dg.about.pic.pos=dgOSCCIimagePos(dg);
set(dg.about.pic.h,'position',dg.about.pic.pos);

end

%% dgPopPos
% determine position of popup figure
%
% don't want it to be off the bottom of screen
%
% should have written more comments here....
%
% dg = dgPopPos(dg,[index],[size (portion)]);
%
function dg=dgPopPos(dg,varargin)
dg.tmp.pos=dg.tmp.dopPos;
if ~isempty(varargin)
    dg.tmp.i=varargin{1}; dg.tmp.v=varargin{2};
    for i=1:numel(dg.tmp.i)
        ii=dg.tmp.i(i); % actual index
        switch ii
            case 3
                if dg.tmp.pos(ii)+dg.tmp.v(i)<1; % if adjustment won't cause it to be full screen
                    dg.tmp.pos(ii)=dg.tmp.dopPos(ii)+dg.tmp.v(i);
                else
                    dg.tmp.pos(ii)=1; % full width of screen
                end
            otherwise
                if dg.tmp.v(i)>=0
                    dg.tmp.pos(ii)=dg.tmp.v(i);%dg.tmp.dopPos(2)-dg.tmp.pos(2);
                else
                    % coded with negative number, absolute value of which
                    % is index of value to subtract:
                    % eg i = 2, v = -4
                    % pos(2)=pos(2)-value(4);
                    % always relative to position 2 that this happens...
                    dg.tmp.pos(ii)=dg.tmp.dopPos(2)-dg.tmp.v(dg.tmp.i==abs(dg.tmp.v(i)));
                end
        end
    end
end
% make sure it's not off the screen
if dg.tmp.pos(2)<.05; dg.tmp.pos(2)=.05;end%abs(dg.tmp.pos(2)); end
if dg.tmp.pos(1)+dg.tmp.pos(3)>1; dg.tmp.pos(1)=0; end
end
%% ------------------------------------------------------------------------
%% popup figures
%% --------------------
%% > Epoch Inclusion/EpochSaveSelectFig
% function dgEpochSaveSelectFig(varargin) % matlab orange info is fine here
% global dg
% dg.tmp.h=varargin{1};
% dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
% dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
% dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
% dg.tmp.pos=dg.tmp.dopPos;
% if dg.tmp.pos(3)+.1<1
%     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.1;
% end
% dg.tmp.pos(4)=.15;
% dg.tmp.pos(2)=dg.tmp.dopPos(2)-dg.tmp.pos(4);
% % dg.tmp.pos(4)=.1;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
% if isempty(findobj('name',dg.tmp.name))
%     %     figure(dg.(dg.tmp.abb).h); % bring to front
%     % else
%     fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
%     dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
%         'NumberTitle','off','Toolbar','none','MenuBar','none',...
%         'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
%     dg.tmp.h=dg.(dg.tmp.abb).h;
%     dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%     %% -> epoch selection panel
% dg.tmp.pan='epSel';
% dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%     'Position',[.05 .1 .9 .8],'BackgroundColor',dg.tab.pan.col,... 'Position',[.05 .7 .9 .1]
%     'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%     'Title','Choose which collections of epochs will be used for index calculations (& saved in Individual Summary File)');
% dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
% dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','data','act','man','comb','bal'};
% dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
% dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
% dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
% dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
%     'data appropriate epochs (i.e., not including short epochs)',...
%     'epochs with data values within activation rejection range (see Data tab)',...
%     'manually selected epochs (see Special, Screen)',...
%     'combined epochs = data appropriate + activation appropriate + manually selected epochs',...
%     'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
%
% dg.tmp.h_abb='saveEpochSelection'; % dop.def. abbreviation
% dg.tmp.el='check'; dg.tmp.style='checkbox';
%
% for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%     dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%         'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%         'units','normalized','HorizontalAlign','Left',...
%         'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
%         'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%         'ToolTipString',['Save data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
%         'value',dg.dopdef.(dg.tmp.h_abb)(1,i),'UserData',[1 i],... % 'value', 0
%         'callback',eval('@getCheckbox'));
% %     dg=enableObject(dg,1); % might not want this...
%
%     dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
% end
%
% end
% figure(dg.(dg.tmp.abb).h); % bring to front
% end
%% --------------------
%% > dgIndividualSaveLIFig
function dgIndividualSaveLIFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position

dg=dgPopPos(dg,[2 3 4],[.05 .3 .4]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.3<1;dg.tmp.pos(3)=dg.tmp.dopPos(3)+.3; end
% dg.tmp.pos(2)=.05;
% dg.tmp.pos(4)=.4;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
% if dg.tmp.pos(2)<0; dg.tmp.pos(2)=abs(dg.tmp.pos(2)); end
% if dg.tmp.pos(1)+dg.tmp.pos(3)>1; dg.tmp.pos(1)=0; end

if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    %% -> epoch selection panel
    dg.tmp.pan='epSel';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .8 .9 .15],'BackgroundColor',dg.tab.pan.col,... 'Position',[.05 .7 .9 .1]
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which collections of epochs will be used for index calculations (& saved in Individual Summary File)');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','length','activation','manual','combined','balanced'};
    dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
    dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
        'length appropriate epochs (i.e., not including short epochs)',...
        'epochs with data values within activation rejection range (see Data tab)',...
        'manually selected epochs (see Special, Screen)',...
        'combined epochs = length appropriate + activation appropriate + manually selected epochs',...
        'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
    
    dg.tmp.h_abb='saveEpochSelection'; % dop.def. abbreviation
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',['Save data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
            'value',dg.dopdef.(dg.tmp.h_abb)(1,i),'UserData',[1 i],... % 'value', 0
            'callback',eval('@getCheckbox'));
        %     dg=enableObject(dg,1); % might not want this...
        
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
    end
    
%     %% -> Channel Indices Panel
%     dg.tmp.pan='chInd';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.01 .6 .98 .2],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Choose which FIXED PERIOD descriptive statistics will be saved in Individual Summary File');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChs',...[1 1 0],... % on/off save left, right, difference indices
%         'saveIndexFilt',...[0 1 1],... % filter = epoch, base, poi
%         'saveIndices'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[4 3 9]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Data Selection',...
%         'Filter Selection','Statistic Selection'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         'If none are selected, below selections will not save',...
%         'Data filter for statistical calculation',...
%         'Static for data based upon channel and filter selections'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
%         'Save Right Channel Indicies','Save Left - Right Indicies',...
%         'Save average(Left Right) Indicies'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};%,'absMax','absMaxPOI'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
%         'Indicies based upon baseline data','Indicies based upon Period of Interest data'};%,...
% %         'Indicies based upon absolute maximum filter',...
% %         'Indicies based upon absoluate maximum filter within Period of Interest'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','sem','95%','min','max','rms','median','iqr'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
%         'Standard Error of the Mean','95% Confidence Interval',...
%         'Minimum value','Maximum value','Root Mean Squared',...
%         'Median','Inter-quartile Range'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.025 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',...
%                 dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
    %% -> LI Indices Panel
    dg.tmp.pan='liInd';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .05 .98 .7],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Individual Summary File: Choose which Laterality descriptive & inferential statistics will be saved in Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescrip',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
        'save1sample',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
        'save2sample',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
        'saveRank',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
        'save1norm',...[1 0 0 0],... % save normality test info for difference LI distribution
        'save2norm'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
    
    %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
        '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
        '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
        'Time/Latency of peak left - right difference (in seconds)',...
        'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        };
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
        'p value of test','95% confidence interval of mean difference',...
        't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
        'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
        'p value of test','Jarque-Bera value','critical value for test'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
        'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
        'Normality of right channel data: 0 = normal, 1 = different',...
        'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% -----------------------------
%% > dgIndividualSaveExtraFig
function dgIndividualSaveExtraFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 3 4],[.05 .4 .4]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.4<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.4; end
% dg.tmp.pos(2)=.05;
% dg.tmp.pos(4)=.4;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    %% -> epoch selection panel
    dg.tmp.pan='epSel';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .8 .9 .15],'BackgroundColor',dg.tab.pan.col,... 'Position',[.05 .7 .9 .1]
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which collections of epochs will be used for index calculations (& saved in Individual Summary File)');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','length','activation','manual','combined','balanced'};
    dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
    dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
        'length appropriate epochs (i.e., not including short epochs)',...
        'epochs with data values within activation rejection range (see Data tab)',...
        'manually selected epochs (see Special, Screen)',...
        'combined epochs = length appropriate + activation appropriate + manually selected epochs',...
        'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
    
    dg.tmp.h_abb='saveEpochSelection'; % dop.def. abbreviation
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',['Save data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
            'value',dg.dopdef.(dg.tmp.h_abb)(1,i),'UserData',[1 i],... % 'value', 0
            'callback',eval('@getCheckbox'));
        %     dg=enableObject(dg,1); % might not want this...
        
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
    end
    
    %% -> Channel Indices Panel
    dg.tmp.pan='chInd';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .475 .98 .3],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which FIXED PERIOD descriptive statistics will be saved in Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChs',...[1 1 0],... % on/off save left, right, difference indices
        'saveIndexFilt',...[0 1 1],... % filter = epoch, base, poi
        'saveIndices'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[4 3 9]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Channel Selection',...
        'Fixed Period Selection','General Statistic Selection'};
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s\n','Selected channel/s data will be reported in output summary',...
        '> If none are selected, below selections will not operate'),...
        sprintf('%s\n%s','Fixed period within which statistical calculation is made',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s\n%s\n%s','Statistic based upon channel and fixed period selections',...
        'For example:','- mean of left channel activation during baseline period',...
        '- mean of difference (left - right) activation during period of interest')};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
        'Save Right Channel Indicies','Save Left - Right Indicies',...
        'Save average(Left Right) Indicies'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};%,'absMax','absMaxPOI'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
        'Indicies based upon baseline data','Indicies based upon Period of Interest data'};%,...
%         'Indicies based upon absolute maximum filter',...
%         'Indicies based upon absoluate maximum filter within Period of Interest'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','sem','95%','min','max','rms','median','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
        'Standard Error of the Mean','95% Confidence Interval',...
        'Minimum value','Maximum value','Root Mean Squared',...
        'Median','Inter-quartile Range'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',...
                dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
    
%     inputs.defaults.saveIndexExtraChFiltLabels={'left', 'right', 'dif','avg'};%difference indices, average
%     inputs.defaults.saveIndexExtraTypeFiltLabels={'AbsMaxPOI','AbsMax','MaxPOI','Max','AbsMinPOI','AbsMin','Min','MinPOI'};
      %% -> Extra Indices Panel
    dg.tmp.pan='extraInd';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .025 .98 .4],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which CALCULATED PERIOD descriptive statistics will be saved in the Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexExtraChs',...[1 1 0],... % on/off save left, right, difference indices
        'saveIndexExtraChFilt',...[0 1 1],... % filter = epoch, base, poi
        'saveIndexExtraTypeFilt',...[0 1 1],... % filter = epoch, base, poi
        'saveIndicesExtra'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[4 4 8 10]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Channel Selection',...
        'Calculation Period Channel','Calculated Period Selection','General Statistic Selection'};
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s\n','Selected channel/s data will be reported in output summary',...
        '> If none are selected, below selections will not operate'),...
        sprintf('%s\n%s\n%s\n%s','Channel/s used in order to calculate periods (below).',...
        'For example:',...
        '- left selection & min Calculated period selection (below) = minimum value of left activation within whole epoch',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s\n%s','Calculated period within which statistical calculation is made,',...
        ' based upon activation window period (Event Tab) surrounding calculated value.',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s\n%s\n%s\n%s\n%s\n%s',...
        'Statistic based upon channel, calculated data, & calculated period selections',...
        'For example:',...
        '- mean of difference data at minimum of left activation, where:',...
        '* difference = Selected Channel',...
        '* left = calculation period channel',...
        '* minimum = calculation period seleciton',...
        '* mean = general statistic selection')};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
        'Save Right Channel Indicies','Save Left - Right Indicies',...
        'Save average(Left Right) Indicies'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'left','right','dif','avg'};%,'absMax','absMaxPOI'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tmp{2}='Calculations based on £ data';
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
        strrep(dg.(dg.tmp.abb).(dg.tmp.pan).tmp{2},'£',dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}{1}),...
        strrep(dg.(dg.tmp.abb).(dg.tmp.pan).tmp{2},'£',dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}{1}),...
        strrep(dg.(dg.tmp.abb).(dg.tmp.pan).tmp{2},'£','Left minus Right Difference'),...
        strrep(dg.(dg.tmp.abb).(dg.tmp.pan).tmp{2},'£','Left Right Average')};
     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'AbsMaxPOI','AbsMax','MaxPOI','Max','AbsMinPOI','AbsMin','MinPOI','Min'};%,'absMax','absMaxPOI'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={...
        'Filter based around Absolute Maximum value within Period of Interest',...
        'Filter based around Absolute Maximum value across whole epoch',...
        'Filter based around Maximum value within Period of Interest',...
        'Filter based around Maximum value across whole epoch',...
        'Filter based around Absolute Minimum value within Period of Interest',...
        'Filter based around Absolute Minimum value across whole epoch',...
        'Filter based around Minimum value within Period of Interest',...
        'Filter based around Minimum value across whole epoch',...
            };   
%         'Indicies based upon absolute maximum filter',...
%         'Indicies based upon absoluate maximum filter within Period of Interest'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'time','mean','std','sem','95%','min','max','rms','median','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'peak time point in seconds','Mean','Standard Deviation',...
        'Standard Error of the Mean','95% Confidence Interval',...
        'Minimum value','Maximum value','Root Mean Squared',...
        'Median','Inter-quartile Range'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',...
                dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end  
%     %% -> LI Indices Panel
%     dg.tmp.pan='liInd';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.01 .05 .98 .7],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Individual Summary File: Choose which Laterality descriptive & inferential statistics will be saved in Individual Summary File');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescrip',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%         'save1sample',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%         'save2sample',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%         'saveRank',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%         'save1norm',...[1 0 0 0],... % save normality test info for difference LI distribution
%         'save2norm'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
%     
%     %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%         '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%         '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
%         'Time/Latency of peak left - right difference (in seconds)',...
%         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         };
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
%         'p value of test','95% confidence interval of mean difference',...
%         't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
%         'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
%         'p value of test','Jarque-Bera value','critical value for test'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
%         'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%         'Normality of right channel data: 0 = normal, 1 = different',...
%         'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.01 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% --------------------
%% > EpochSaveFig - epoch by epoch
function dgEpochSaveFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 3 4],[-4 .4 .4]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.3<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.3; end
% dg.tmp.pos(4)=.25;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
% dg.tmp.pos(2)=dg.tmp.dopPos(2)-dg.tmp.pos(4);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    %% -> Individual Epoch - Channel & Laterality Indicies Panel
    dg.tmp.pan='indEpochCh';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .35 .98 .6],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which General descriptive statistics for each Epoch will be saved in the Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    %     'saveEpochIndCh','saveEpochIndFilter','saveEpochInd','saveEpochLI'
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveEpochIndCh',...[1 1 0],... % on/off save left, right, difference indices
        'saveEpochIndFilter',...[1 0 0],... % epoch, base, poi
        'saveEpochInd'};%,...};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
    %         'saveEpochLI'};%,[1 0],... % indices to be saved for each epoch LI (mean) LI latency
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[4 3 9];% 2]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Channel Selection',...
        'Fixed Period Selection','General Statistic Selection'};%,'LI Selection'};
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s\n','Selected channel/s data will be reported in output summary',...
        '> If none are selected, below selections will not operate'),...
        sprintf('%s\n%s','Fixed period within which statistical calculation is made',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s\n%s\n%s','Statistic based upon channel and fixed period selections',...
        'For example:','- mean of left channel activation during baseline period',...
        '- mean of difference (left - right) activation during period of interest')};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
        'Save Right Channel Indicies','Save Left - Right Indicies','Save average(Left Right) Indicies'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
        'Indicies based upon baseline data','Indicies based upon Period of Interest data'};%,...
%         'Indicies based upon absolute maximum filter',...
%         'Indicies based upon absoluate maximum filter within Period of Interest'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','sem','95%','min','max','rms','median','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
        'Standard Error of the Mean','95% Confidence Interval',...
        'Minimum value','Maximum value','Root Mean Squared',...
        'Median','Inter-quartile Range'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'mean','peak'}; % different order to regular LI
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={...
    %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
    %         'Time of peak left - right difference (in seconds)'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
    %% -> Individual Epoch - Laterality Indicies Panel
    dg.tmp.pan='indEpochLI';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .05 .98 .3],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which Laterality descriptive statistics for each Epoch will be saved in the Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    %     'saveEpochIndCh','saveEpochIndFilter','saveEpochInd','saveEpochLI'
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
        'saveEpochLI'};%,[1 0],... % indices to be saved for each epoch LI (mean) LI latency
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=9; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Laterality Statistic Selection'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s',...
        'LI statistic selection for each epoch, always based on:',...
        ' > left - right difference within activation window (see Event Tab) surrounding peak difference within period of interest.')};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'time','mean','std','sem','95%','min','max','med','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
        'Time/Latency of peak left - right difference (in seconds)',...
        'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard error of the mean (same as standard deviation for single epoch)',...
        '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'minimum of the left - right difference over peak time interval (see Act. Window, Event tab)',...
        'maximum of the left - right difference over peak time interval (see Act. Window, Event tab)',...
        'median of the left - right difference over peak time interval (see Act. Window, Event tab)',...
        'inter-quartile range of the left - right difference over peak time interval (see Act. Window, Event tab)',...
        };
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'mean','peak'}; % different order to regular LI
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
    %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
    %         'Time of peak left - right difference (in seconds)'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'Tooltipstring',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{1});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end

%% --------------------
%% > SplitHalfFig
function dgSplitHalfFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 3 4],[.05 .25 .5]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.25<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.25; end
% dg.tmp.pos(2)=.05;
% dg.tmp.pos(4)=dg.tmp.dopPos(2)-dg.tmp.pos(2);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    %% -> Split Half Disp Save
    dg.tmp.pan='splitSave';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .825 .5 .15],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose Split-Half Display in Notes &/or Save in Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
        'splitCalcSave'};%,...[1 1],...); % actually do the calculation & save data
    %     'splitOptions',...[1 1],...); % Split half odd v even, random selection
    %     'splitBal',...1,...); % balance the number of epochs in the split
    %     };%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
    
    %     'splitCalcSave','splitOptions','splitBal',...
    %     'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
    %         'save1normSplit','save2normSplit',
    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=2; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={...
        'Disp/Save'};%,'Options','Balance',...
    %     };%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'disp','save'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
        'Display Split-Half values at the commandline',...
        'Save Split-Half values in data summary file'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'O v E','rand'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
    %     'Halves based upon odd and even epochs',...
    %     'Halves based upon random split of epochs'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'bal'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={...
    %     'Balance number of epochs in each half (drop epochs if more in one half)'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
    %% -> Split Half Epoch selection
    dg.tmp.pan='splitEp';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .60 .5 .2],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose Split-Half epoch collections');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={...'splitCalcSave',...[1 1],...); % actually do the calculation & save data
        'splitOptions',...[1 1],...); % Split half odd v even, random selection
        'splitBal',...1,...); % balance the number of epochs in the split
        };%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
    
    %     'splitCalcSave','splitOptions','splitBal',...
    %     'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
    %         'save1normSplit','save2normSplit',
    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[2 1]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={...'Disp/Save',
        'Options','Balance Havles',...
        };%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.3 0 .7 1],'opposite','across'); % top to bottom
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'disp','save'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
    %     'Display Split-Half values at the commandline',...
    %     'Save Split-Half values in data summary file'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'O v E','rand'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
        'Halves based upon odd and even epochs',...
        'Halves based upon random split of epochs'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={''};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
        'Balance number of epochs in each half (drop epochs if more in one half)'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
    
    %% -> Split Half LI Indices Panel
    dg.tmp.pan='splitLI';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .05 .98 .5],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Individual Summary File: Choose which Split-Half Laterality descriptive & inferential statistics will be saved in Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
        %     'splitCalcSave',...[1 1],...); % actually do the calculation & save data
        %     'splitOptions',...[1 1],...); % Split half odd v even, random selection
        %     'splitBal',...1,...); % balance the number of epochs in the split
        'saveDescripSplit',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
        'save1sampleSplit',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
        'save2sampleSplit',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
        'saveRankSplit',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
        'save1normSplit',...[1 0 0 0],... % save normality test info for difference LI distribution
        'save2normSplit'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
    
    %     'splitCalcSave','splitOptions','splitBal',...
    %     'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
    %         'save1normSplit','save2normSplit',
    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={...
        %     'Disp/Save','Options','Balance',...
        'Descriptives',...
        '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
        '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'disp','save'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
    %     'Display Split-Half values at the commandline',...
    %     'Save Split-Half values in data summary file'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'O v E','rand'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
    %     'Halves based upon odd and even epochs',...
    %     'Halves based upon random split of epochs'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'bal'};
    % dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={...
    %     'Balance number of epochs in each half (drop epochs if more in one half)'};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','time','mean','std','sem','95%','min','max','med','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
        'Time of peak left - right difference (in seconds)',...
        'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        };
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
        'p value of test','95% confidence interval of mean difference',...
        't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
        'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
        'p value of test','Jarque-Bera value','critical value for test'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
        'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
        'Normality of right channel data: 0 = normal, 1 = different',...
        'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
% %% > dgGraphDataFig
% function dgGraphDataFig(varargin) % matlab orange info is fine here
% global dg
% dg.tmp.h=varargin{1};
% dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
% dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
% dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.1<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.1; end
% dg.tmp.pos(4)=.2;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
% dg.tmp.pos(2)=dg.tmp.dopPos(2)-dg.tmp.pos(4);
% if isempty(findobj('name',dg.tmp.name))
% %     figure(dg.(dg.tmp.abb).h); % bring to front
% % else
%     fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
%     dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
%         'NumberTitle','off','Toolbar','none','MenuBar','none',...
%         'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
%     dg.tmp.h=dg.(dg.tmp.abb).h;
%     dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%     % % separator panel
%     % dg.(dg.tmp.abb).pan.sepH=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%     %     'Position',[.05 .5 .9 .01],'BackgroundColor',dg.tab.pan.col);
%     % dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%
%     %% -> ? Info
%     % rollover/tooltipstring question mark to describe tab
%     % dg.info.abb='q';
%     % dg.info.txt='?';
%     % dg.info.txtBreak='---------------------------------------';
%     % dg.info.align='Left';
%     % dg.info.pos=[.01 .94 .05 .05];
% %     dg.(dg.tmp.abb).info.tts=sprintf(...
% %         '%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s',...
% %         'dopOSCCI Graphs+ Tab:',...
% %         ['The dopOSCCI summary allows for the creation of a series of graphs ',...
% %         '(see Graphs Tab)'],...
% %         ['The Graphs+ Tab houses settings that dictate which aspects of the ',...
% %         'Overall data summaries will be saved'],...
% %         dg.info.txtBreak,'Save Overall Graph Data:',...
% %         'Series of settings to save the Overall data for later graphing',...
% %         dg.info.txtBreak,'Overall Channel indices:',...
% %         'Series of settings to save summary indices from Overall data files',...
% %         dg.info.txtBreak,'Overall laterality indices:',...
% %         ['Series of settings to save Laterality information calculated ',...
% %         'for the Overall data files'],...
% %         dg.info.txtBreak);
% %     dg=dgTabInfo(dg);
%
%     %% -> Graph Data Panel
%     dg.tmp.pan='graphData';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.1 .1 .8 .8],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Choose which data will be saved in Overall Graph Data files');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%
%     % 'saveEpochSelectionGraph','saveGraphDataChs','saveGraphDataVert'
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveEpochSelectionGraph',...[0 0 0 0 1 1],... % save graph data [all dat act man scrn bal] balanced for session summary
%         'saveGraphDataChs',...[1 1 1 1],... % left right, diff, avg (left right)
%         'saveGraphDataVert'};%1,... % save a vertical arrangment of graph data files
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[6 4 1];% 2]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Epoch Selection',...
%         'Data Selection','Vertical File'};%,'LI Selection'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         'If none are selected, data will not be saved',...
%         'If none are selected, data will not be saved (left, right, & dif required for group graphs)',...
%         'Save a vertically aligned data file as well as horizontal'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
%
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'all','data','act','man','comb','bal'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'all available epochs',...
%         'data appropriate epochs (i.e., not including short epochs)',...
%         'epochs with data values within activation rejection range (see Data tab)',...
%         'manually selected epochs (see Special, Screen)',...
%         'combined epochs = data appropriate + activation appropriate + manually selected epochs',...
%         'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
%
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'left','right','dif','avg'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Save Left Channel data',...
%         'Save Right Channel data','Save Left - Right data',...
%         'Save Left Right average data'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'save'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'check to save vertical file'};
%     % dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'mean','peak'}; % different order to regular LI
%     % dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={...
%     %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     %         'Time of peak left - right difference (in seconds)'};
%
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.025 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
%
% end
% figure(dg.(dg.tmp.abb).h); % bring to front
% end

%% --------------------
%% > OverallStatsLIFig
function dgOverallStatsLIFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 3 4],[-4 .3 .3]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.3<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.3; end
% dg.tmp.pos(4)=.3;
% dg.tmp.pos(2)=dg.tmp.dopPos(2)-dg.tmp.pos(4);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%     %% -> Graph Data Panel
%     dg.tmp.pan='graphData';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.1 .75 .8 .2],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Overall Graph Data: Choose which data will be saved in Overall Graph Data files');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     % 'saveEpochSelectionGraph','saveGraphDataChs','saveGraphDataVert'
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveEpochSelectionGraph',...[0 0 0 0 1 1],... % save graph data [all dat act man scrn bal] balanced for session summary
%         'saveGraphDataChs',...[1 1 1 1],... % left right, diff, avg (left right)
%         'saveGraphDataVert'};%1,... % save a vertical arrangment of graph data files
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[6 4 1];% 2]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Epoch Selection',...
%         'Data Selection','Vertical File'};%,'LI Selection'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         'If none are selected, data will not be saved',...
%         'If none are selected, data will not be saved (left, right, & dif required for Overall graphs)',...
%         'Save a vertically aligned data file as well as horizontal'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'all','data','act','man','comb','bal'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'all available epochs',...
%         'data appropriate epochs (i.e., not including short epochs)',...
%         'epochs with data values within activation rejection range (see Data tab)',...
%         'manually selected epochs (see Special, Screen)',...
%         'combined epochs = data appropriate + activation appropriate + manually selected epochs',...
%         'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'left','right','dif','avg'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Save Left Channel data',...
%         'Save Right Channel data','Save Left - Right data',...
%         'Save Left Right average data'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'save'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'check to save vertical file'};
%     % dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'mean','peak'}; % different order to regular LI
%     % dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={...
%     %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     %         'Time of peak left - right difference (in seconds)'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.025 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             %             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
%     %% -> Overall Channel Indices Panel
%     dg.tmp.pan='chIndOver';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.05 .65 .9 .3],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Overall Summary File: Choose which descriptive statistics will be saved in Overall Summary File');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChsOverall',...[1 1 0],... % on/off save left, right, difference indices
%         'saveIndexFiltOverall',...[0 1 1],... % filter = epoch, base, poi
%         'saveIndicesOverall'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[4 3 5]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Data Selection',...
%         'Filter Selection','Statistic Selection'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         'If none are selected, below selections will not save',...
%         'Data filter for statistical calculation',...
%         'Static for data based upon channel and filter selections'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
%         'Save Right Channel Indicies','Save Left minus Right Indicies','Save Average Left Right Indicies'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
%         'Indicies based upon baseline data','Indicies based upon Period of Interest data'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','min','max','rms'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
%         'Minimum value','Maximum value','Root Mean Squared'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.025 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             %             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
    %% -> Overall LI Indices Panel
    dg.tmp.pan='liIndOver';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .025 .98 .9],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title',['Overall Summary File: Choose which Laterality descriptive & ',...
        'inferential statistics will be saved in Overall Summary File']);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescripOverall',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
        'save1sampleOverall',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
        'save2sampleOverall',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
        'saveRankOverall',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
        'save1normOverall',...[1 0 0 0],... % save normality test info for difference LI distribution
        'save2normOverall'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
    
    %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
        '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
        '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# files','time','mean','std','sem','95%','min','max','med','iqr'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of data files included in calculations',...
        'Time of peak left - right difference (in seconds)',...
        'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
        };
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
        'p value of test','95% confidence interval of mean difference',...
        't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
        'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
        'p value of test','Jarque-Bera value','critical value for test'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
        'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
        'Normality of right channel data: 0 = normal, 1 = different',...
        'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% --------------------
%% > OverallStatsExtraFig
function dgOverallStatsExtraFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 3 4],[-4 .3 .2]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.3<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.3; end
% dg.tmp.pos(4)=.2;
% dg.tmp.pos(2)=dg.tmp.dopPos(2)-dg.tmp.pos(4);
%dg.tmp.dopPos(2)-dg.tmp.pos(2);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
%     %% -> Graph Data Panel
%     dg.tmp.pan='graphData';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.1 .75 .8 .2],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Overall Graph Data: Choose which data will be saved in Overall Graph Data files');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     % 'saveEpochSelectionGraph','saveGraphDataChs','saveGraphDataVert'
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveEpochSelectionGraph',...[0 0 0 0 1 1],... % save graph data [all dat act man scrn bal] balanced for session summary
%         'saveGraphDataChs',...[1 1 1 1],... % left right, diff, avg (left right)
%         'saveGraphDataVert'};%1,... % save a vertical arrangment of graph data files
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[6 4 1];% 2]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Epoch Selection',...
%         'Data Selection','Vertical File'};%,'LI Selection'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         'If none are selected, data will not be saved',...
%         'If none are selected, data will not be saved (left, right, & dif required for Overall graphs)',...
%         'Save a vertically aligned data file as well as horizontal'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'all','data','act','man','comb','bal'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'all available epochs',...
%         'data appropriate epochs (i.e., not including short epochs)',...
%         'epochs with data values within activation rejection range (see Data tab)',...
%         'manually selected epochs (see Special, Screen)',...
%         'combined epochs = data appropriate + activation appropriate + manually selected epochs',...
%         'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'left','right','dif','avg'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Save Left Channel data',...
%         'Save Right Channel data','Save Left - Right data',...
%         'Save Left Right average data'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'save'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'check to save vertical file'};
%     % dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'mean','peak'}; % different order to regular LI
%     % dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={...
%     %         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%     %         'Time of peak left - right difference (in seconds)'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.025 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%             'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             %             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
    %% -> Overall Channel Indices Panel
    dg.tmp.pan='chIndOver';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .05 .9 .9],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Overall Summary File: Choose which descriptive statistics will be saved in Overall Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveIndexChsOverall',...[1 1 0],... % on/off save left, right, difference indices
        'saveIndexFiltOverall',...[0 1 1],... % filter = epoch, base, poi
        'saveIndicesOverall'};%, [1 1 0 0 1],...% mean, std, min, max, & rms % selection, saveIndexChs required also};
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[4 3 5]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Channel Selection',...
        'Fixed Period Selection','General Statistic Selection'};
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s\n','Selected channel/s data will be reported in output summary',...
        '> If none are selected, below selections will not operate'),...
        sprintf('%s\n%s','Fixed period within which statistical calculation is made',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s\n%s\n%s','Statistic based upon channel and fixed period selections',...
        'For example:','- mean of left channel activation during baseline period',...
        '- mean of difference (left - right) activation during period of interest')};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
        'Save Right Channel Indicies','Save Left minus Right Indicies','Save Average Left Right Indicies'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'epoch','base','poi'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Indicies based upon whole epoch',...
        'Indicies based upon baseline data','Indicies based upon Period of Interest data'};
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'mean','std','min','max','rms'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'Mean','Standard Deviation',...
        'Minimum value','Maximum value','Root Mean Squared'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
%     %% -> Overall LI Indices Panel
%     dg.tmp.pan='liIndOver';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.01 .025 .98 .6],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title',['Overall Summary File: Choose which Laterality descriptive & ',...
%         'inferential statistics will be saved in Overall Summary File']);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescripOverall',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%         'save1sampleOverall',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%         'save2sampleOverall',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%         'saveRankOverall',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%         'save1normOverall',...[1 0 0 0],... % save normality test info for difference LI distribution
%         'save2normOverall'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
%     
%     %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%         '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%         '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# files','time','mean','std','sem','95%','min','max','med','iqr'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of data files included in calculations',...
%         'Time of peak left - right difference (in seconds)',...
%         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         };
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
%         'p value of test','95% confidence interval of mean difference',...
%         't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
%         'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
%         'p value of test','Jarque-Bera value','critical value for test'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
%         'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%         'Normality of right channel data: 0 = normal, 1 = different',...
%         'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.01 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             %             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% --------------------
%% > NotesSaveFig
function dgNotesSaveFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 4],[-4 .2]);
% dg.tmp.pos=dg.tmp.dopPos; %if dg.tmp.pos(3)+.1<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.1; end
% dg.tmp.pos(4)=.2;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
% dg.tmp.pos(2)=dg.tmp.dopPos(2)-dg.tmp.pos(4);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    %% -> Notes Panel
    dg.tmp.pan='notes';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .05 .9 .9],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Summary Notes');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    
    % 'saveNotes','defFileNotes'
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
        'saveNotes',...[1 1 1],... % [overall and inidividual & skip] running notes - requires dop.def.saveData=1 (see dopSaveNotes)
        'defFileNotes'};%,[1 1],... % move view only and mat defintion files to notes
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 2]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Save Notes','Copy Definition'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'across','opposite'); % top to bottom
    
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        ['Save notes which are text files of information printed to ',...
        'the matlab command window during the summary'],...
        ['Defintion files hold a copy of all the dopOSCCI settings for ',...
        'a particular task']};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'All notes','File notes','Skip record'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
        'Save All notes - includes setup and individual file notes (if saved) in single file',...
        'Save individual data file notes',...
        'Save text file record of which files skipped from summary and why'};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'View Only ''.txt'' file','Matlab ''.mat'' file'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={...
        'Copy View Only text file to notes directory - will be included in Overall notes file',...
        'Copy ''.mat'' definition file to notes directory'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% --------------------
%% > dgDataQualFig
function dgDataQualFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
dg=dgPopPos(dg,[2 4],[.05 .4]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.4<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.4; end
% dg.tmp.pos(2)=.05;
% dg.tmp.pos(4)=.4;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    %% -> epoch selection panel
    dg.tmp.pan='epSel';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .8 .9 .15],'BackgroundColor',dg.tab.pan.col,... 'Position',[.05 .7 .9 .1]
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which collections of epochs will be used for quality calculations (& saved in Individual Summary File)');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','length','activation','manual','combined','balanced'};
    dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
    dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
        'length appropriate epochs (i.e., not including short epochs)',...
        'epochs with data values within activation rejection range (see Data tab)',...
        'manually selected epochs (see Special, Screen)',...
        'combined epochs = length appropriate + activation appropriate + manually selected epochs',...
        'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
    
    dg.tmp.h_abb='saveEpochSelQual'; % dop.def. abbreviation
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',['Save data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
            'value',dg.dopdef.(dg.tmp.h_abb)(1,i),'UserData',[1 i],... % 'value', 0
            'callback',eval('@getCheckbox'));
        %     dg=enableObject(dg,1); % might not want this...
        
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
    end
    
    %% -> Drop Out Indices Panel
    dg.tmp.pan='dropInd';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .4 .98 .35],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which Drop Out descriptive statistics will be saved in Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     'saveDropChs',...[1 1 0 0],... % left right dif average channels - probably not necessary but option is there
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDropFilt',...[0 1 0],... % epoch, base, poi
        'saveDropInd',...[0 0],... % save count percent dropout - left and right channels
        'saveDropSelEp'};%,0,... % save dropout all epochs yes/no
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 2 1]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Fixed Period Selection',...
        'Statistic Selection','All Epochs'};
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s','Fixed period within which statistical calculation is made',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s','Statistic based upon fixed period selections',...
        'count = total number of dropouts, pct = percentage dropouts'),...
        'Select if you want above statistics for each individual epoch.'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'epoch','base','poi'};%,'absMax','absMaxPOI'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Indicies based upon whole epoch',...
        'Indicies based upon baseline data','Indicies based upon Period of Interest data'};%,...
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'count','pct'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Count','Percentage'};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'epochs'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'indices save for all epochs'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',...
                dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
    
%     inputs.defaults.saveIndexExtraChFiltLabels={'left', 'right', 'dif','avg'};%difference indices, average
%     inputs.defaults.saveIndexExtraTypeFiltLabels={'AbsMaxPOI','AbsMax','M
%     axPOI','Max','AbsMinPOI','AbsMin','Min','MinPOI'};
    
    %% -> GOR Out Indices Panel
    dg.tmp.pan='gorInd';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.01 .05 .98 .3],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which Goodness of Recording descriptive statistics will be saved in Individual Summary File');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     'saveDropChs',...[1 1 0 0],... % left right dif average channels - probably not necessary but option is there
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveGorFilt',...[0 1 0],... % epoch, base, poi
        'saveGorInd'};%,...[0 0],... % save count percent dropout - left and right channels
%         'saveGorSelEp'};%,0,... % save dropout all epochs yes/no
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=[3 2]; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).title={'Fixed Period Selection',...
        'Statistic Selection'};%,'All Epochs'};
    dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
        sprintf('%s\n%s','Fixed period within which statistical calculation is made',...
        '> If none are selected, above & below selections will not operate'),...
        sprintf('%s\n%s','Statistic based upon fixed period selections',...
        'Mean = Mean root mean square, Max = Max root mean square'),...
        'Select if you want above statistics for each individual epoch.'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.25 0 .75 1],'opposite','across'); % top to bottom
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'epoch','base','poi'};%,'absMax','absMaxPOI'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Indicies based upon whole epoch',...
        'Indicies based upon baseline data','Indicies based upon Period of Interest data'};%,...
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'mean','max'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'root mean square of mean activation during above period',...
        'root mean square of maximum activation during above period'};
    
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}={'epochs'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}={'indices save for all epochs'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.025 .2];
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS{i});
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',...
                dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
%     %% -> LI Indices Panel
%     dg.tmp.pan='liInd';
%     dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',[.01 .05 .98 .7],'BackgroundColor',dg.tab.pan.col,...
%         'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
%         'Title','Individual Summary File: Choose which Laterality descriptive & inferential statistics will be saved in Individual Summary File');
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveDescrip',...ones(1,9),... % save descriptives (see saveDescripLabels below & dopDataLIcalc function)
%         'save1sample',...[1 0 0 0 0 0 1],... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%         'save2sample',...[0 0 0 0 0 0 0],... % save paired-sample t-test sig & effect size (see dopDataLIcalc)
%         'saveRank',...[1 0 0 0 1],...);%,... % save one-sample t-test sig & effect size (see dopDataLIcalc)
%         'save1norm',...[1 0 0 0],... % save normality test info for difference LI distribution
%         'save2norm'};%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
%     
%     %     'saveDescrip','save1sample','save2sample','saveRank','save1norm','save2norm'
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).checks=[10 7 7 5 4 8]; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={'Descriptives',...
%         '1 Sample t-test','2 Sample t-test','Wilcoxon Ranksum',...
%         '1 Sample norm','2 Sample norm'};%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
%     dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
%         [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
%         [0 0],[.2 0 .8 1],'opposite','across'); % top to bottom
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'# ep.','peak','mean','std','sem','95%','min','max','med','iqr'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Number of included epochs',...
%         'Time/Latency of peak left - right difference (in seconds)',...
%         'Laterality Index = mean left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'standard deviation of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'standard error of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         '95% confidence interval of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'minimum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'maximum of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'median of the mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         'inter-quartile range of mean of left - right difference over peak time interval (see Act. Window, Event tab)',...
%         };
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{2}={'sig','p','ci','t','df','sd','d'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{2}={'Significance of test: 1 = dif, 0 = not',...
%         'p value of test','95% confidence interval of mean difference',...
%         't value of test','degrees of freedom','standard deviation','Cohen''s D value (effect size)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{3}=dg.(dg.tmp.abb).(dg.tmp.pan).txt{2};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{3}=dg.(dg.tmp.abb).(dg.tmp.pan).tts{2};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{4}={'sig','p','rank','Z','r'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{4}={'Significance of test: 1 = dif, 0 = not',...
%         'p value of test','ranksum value','Z value of ranksum','Z conversion to r (effect size)'};
%     
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{5}={'norm','p','stat','crit'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{5}={'Normality of data: 0 = normal, 1 = different',...
%         'p value of test','Jarque-Bera value','critical value for test'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).txt{6}={'norm(L)','p(L)','stat(L)','crit(L)','norm(R)','p(R)','stat(R)','crit(R)'};
%     dg.(dg.tmp.abb).(dg.tmp.pan).tts{6}={'Normality of left channel data: 0 = normal, 1 = different',...
%         'p value of left channel test','Jarque-Bera value for left channel','critical value for left channel test',...
%         'Normality of right channel data: 0 = normal, 1 = different',...
%         'p value of right channel test','Jarque-Bera value for right channel','critical value for right channel test'};
%     
%     for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
%         dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
%         dg.tmp.el='head'; dg.tmp.style='text';
%         dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
%         dg.tmp.pos([1 3])=[.01 .2];
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
%         
%         for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
%             dg.tmp.el='check'; dg.tmp.style='checkbox';
%             dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%                 'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
%                 'units','normalized','HorizontalAlign','Left',...
%                 'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
%                 'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
%                 'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
%                 'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
%                 'callback',eval('@getCheckbox'));
%             dg=enableObject(dg,1); % might not want this...
%             dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
%         end
%     end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% --------------------
%% > dgSaveGraphDataFig
function dgGraphDataFig(varargin) % matlab orange info is fine here
global dg
dg.tmp.h=varargin{1};
dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position

dg=dgPopPos(dg,[2 4],[.05 .4]);
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.3<1;dg.tmp.pos(3)=dg.tmp.dopPos(3)+.3; end
% dg.tmp.pos(2)=.05;
% dg.tmp.pos(4)=.4;%dg.tmp.dopPos(2)-dg.tmp.pos(2);
% if dg.tmp.pos(2)<0; dg.tmp.pos(2)=abs(dg.tmp.pos(2)); end
% if dg.tmp.pos(1)+dg.tmp.pos(3)>1; dg.tmp.pos(1)=0; end

if isempty(findobj('name',dg.tmp.name))
    %     figure(dg.(dg.tmp.abb).h); % bring to front
    % else
    fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
    dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
        'NumberTitle','off','Toolbar','none','MenuBar','none',...
        'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
    dg.tmp.h=dg.(dg.tmp.abb).h;
    dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
    
    %% -> Save Graph Data selection
    dg.tmp.pan='graphSave';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .775 .5 .2],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose whether graph data will be saved');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={...
        'saveGraphData'};%,...[1 1],...); % actually do the calculation & save data
    %     'splitOptions',...[1 1],...); % Split half odd v even, random selection
    %     'splitBal',...1,...); % balance the number of epochs in the split
    %     };%...[0 0 0 0 0 0 0 0]};%,... % save normality test info for left & right LI distribution %
    
    %     'splitCalcSave','splitOptions','splitBal',...
    %     'saveDescripSplit','save1sampleSplit','save2sampleSplit',...
    %         'save1normSplit','save2normSplit',
    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=2; % number of check boxes per line
%     dg.(dg.tmp.abb).(dg.tmp.pan).title={...
%         'Disp/Save'};%,'Options','Balance',...
%     %     };%'Jarque-Bera test (1)','Jarque-Bera test (2)'};
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [dg.(dg.tmp.abb).(dg.tmp.pan).n max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.2 0 .8 1],'across'); % top to bottom'opposite',
    dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'Horizontal','Vertical'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={...
        'Time is horizontal in data file: individual cases (or epochs) are vertical (as well as channels)',...
        'Time is vertical in data file: individual cases (or epochs) are horizontal (as well as channels)'};
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        % title (not used here)
%         dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
%             'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
%             'units','normalized','HorizontalAlign','Left',...
%             'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.tmp.pos,...
%             'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb);
%         dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h;
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
    end
    %% -> epoch selection Graph panel
    dg.tmp.pan='epSelGr';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .525 .9 .2],'BackgroundColor',dg.tab.pan.col,... 'Position',[.05 .7 .9 .1]
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which collections of epochs will be saved into graph data files (& saved in Individual graph data files if selected)');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'all','length','activation','manual','combined','balanced'};
    dg.(dg.tmp.abb).(dg.tmp.pan).title=dg.(dg.tmp.abb).(dg.tmp.pan).abb; % same as abbreviations for these
    dg.(dg.tmp.abb).(dg.tmp.pan).n=numel(dg.(dg.tmp.abb).(dg.tmp.pan).abb);
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions([1 dg.(dg.tmp.abb).(dg.tmp.pan).n],[0 0],[.05 0 .95 1]);
    dg.(dg.tmp.abb).(dg.tmp.pan).tts={'all available epochs',...
        'length appropriate epochs (i.e., not including short epochs)',...
        'epochs with data values within activation rejection range (see Data tab)',...
        'manually selected epochs (see Special, Screen)',...
        'combined epochs = length appropriate + activation appropriate + manually selected epochs',...
        'balanced epochs, for Session summary only = screened epochs & equal number of epochs for each session (see Special, Session)'};
    
    dg.tmp.h_abb='saveEpochSelectionGraph'; % dop.def. abbreviation
    dg.tmp.el='check'; dg.tmp.style='checkbox';
    
    for i=1:dg.(dg.tmp.abb).(dg.tmp.pan).n
        dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
            'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).title{i},...
            'units','normalized','HorizontalAlign','Left',...
            'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(i,:),...
            'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
            'ToolTipString',['Graph data based on ',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}],...
            'value',dg.dopdef.(dg.tmp.h_abb)(1,i),'UserData',[1 i],... % 'value', 0
            'callback',eval('@getCheckbox'));
        %     dg=enableObject(dg,1); % might not want this...
        
        dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(i);
    end
    %% -> Channel selection
    dg.tmp.pan='graphChSave';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .275 .5 .2],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which channels will be saved in graph data');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    %     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         sprintf('%s\n%s\n','Selected channel/s data will be reported in output summary',...
%         '> If none are selected, below selections will not operate')};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveGraphDataChs'};    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=4; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [1 max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.05 0 .9 1],'across'); % top to bottom'opposite',
        dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'left','right','dif','avg'};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save Left Channel Indicies',...
        'Save Right Channel Indicies','Save Left - Right Indicies',...
        'Save average(Left Right) Indicies'};
    
        i = 1;
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
        %% -> Individual Panel
        dg.tmp.pan='graphIndSave';
    dg.(dg.tmp.abb).pan.(dg.tmp.pan)=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.pan,'_panel'],...%'Title','Run','FontSize',12,...
        'Position',[.05 .025 .5 .2],'BackgroundColor',dg.tab.pan.col,...
        'ForegroundColor',dg.col.k,'TitlePosition','lefttop',...'centertop',...
        'Title','Choose which INDIVIDUAL graph data will be saved');
    dg.font.h(end+1)=dg.(dg.tmp.abb).pan.(dg.tmp.pan);
    
    %     dg.(dg.tmp.abb).(dg.tmp.pan).titleTTS={...
%         sprintf('%s\n%s\n','Selected channel/s data will be reported in output summary',...
%         '> If none are selected, below selections will not operate')};
    
    dg.(dg.tmp.abb).(dg.tmp.pan).abb={'saveGraphDataInd'};    
    dg.(dg.tmp.abb).(dg.tmp.pan).checks=3; % number of check boxes per line
    dg.(dg.tmp.abb).(dg.tmp.pan).pos=dgPositions(...
        [1 max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)],...
        [0 0],[.05 0 .9 1],'across'); % top to bottom'opposite',
        dg.(dg.tmp.abb).(dg.tmp.pan).txt{1}={'raw','normalized','individual',};
    dg.(dg.tmp.abb).(dg.tmp.pan).tts{1}={'Save raw imported graph data (relatively large files)',...
        'Save normalized graph data',...
        'Save individual graph data (each epoch, not averaged as in group file)'};
    
        i = 1;
        dg.tmp.h_abb=dg.(dg.tmp.abb).(dg.tmp.pan).abb{i};
        dg.tmp.el='head'; dg.tmp.style='text';
        dg.tmp.pos=dg.(dg.tmp.abb).(dg.tmp.pan).pos(1+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:); % select appropriate row
        dg.tmp.pos([1 3])=[.01 .2];
        
        for j=1:dg.(dg.tmp.abb).(dg.tmp.pan).checks(i)
            dg.tmp.el='check'; dg.tmp.style='checkbox';
            dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j)=uicontrol('Parent',dg.(dg.tmp.abb).pan.(dg.tmp.pan),...
                'Style',dg.tmp.style,'String',dg.(dg.tmp.abb).(dg.tmp.pan).txt{i}{j},...
                'units','normalized','HorizontalAlign','Left',...
                'tag',[dg.tmp.h_abb,'_',dg.tmp.el],'Position',dg.(dg.tmp.abb).(dg.tmp.pan).pos(j+(max(dg.(dg.tmp.abb).(dg.tmp.pan).checks)*(i-1)),:),...
                'ForegroundColor',dg.col.pt,'BackgroundColor',dg.col.pb,...
                'ToolTipString',dg.(dg.tmp.abb).(dg.tmp.pan).tts{i}{j},...
                'value',dg.dopdef.(dg.tmp.h_abb)(1,j),'UserData',[1 j],...
                'callback',eval('@getCheckbox'));
            %         dg=enableObject(dg,1); % might not want this...
            dg.font.h(end+1)=dg.(dg.tmp.abb).(dg.tmp.h_abb).(dg.tmp.el).h(j);
        end
end
figure(dg.(dg.tmp.abb).h); % bring to front
end
%% --------------------
%% spare popfigure
% %% > EpochSaveSelectFig
% function dgEpochSaveSelectFig(varargin) % matlab orange info is fine here
% global dg
% dg.tmp.h=varargin{1};
% dg.tmp.abb=[get(dg.tmp.h,'tag'),'Fig'];%'graphDataFig'; % graget(dg.tmp.h,'tag'); % temp abbreviation
% dg.tmp.name=get(dg.tmp.h,'UserData');%'Graph Data Save Selection:';
% dg.tmp.dopPos=get(dg.fig.h,'outerposition'); % dopOSCCI position
% dg.tmp.pos=dg.tmp.dopPos; if dg.tmp.pos(3)+.1<1;     dg.tmp.pos(3)=dg.tmp.dopPos(3)+.1; end
% dg.tmp.pos(2)=.05;
% dg.tmp.pos(4)=dg.tmp.dopPos(2)-dg.tmp.pos(2);
% if isempty(findobj('name',dg.tmp.name))
%     %     figure(dg.(dg.tmp.abb).h); % bring to front
%     % else
%     fprintf('%s\n',['Setting up ', dg.tmp.abb,' Figure:']);
%     dg.(dg.tmp.abb).h=figure('units','normalized','outerposition',dg.tmp.pos,...
%         'NumberTitle','off','Toolbar','none','MenuBar','none',...
%         'name',dg.tmp.name,'color',dg.col.bg,'visible','on');
%     dg.tmp.h=dg.(dg.tmp.abb).h;
%     dg.(dg.tmp.abb).pan.h=uipanel('Parent',dg.tmp.h,'Tag',[dg.tmp.abb,'_panel'],...%'Title','Run','FontSize',12,...
%         'Position',dg.tab.pan.pos,'BackgroundColor',dg.tab.pan.col);
%     dg.font.h(end+1)=dg.(dg.tmp.abb).pan.h;
% end
% figure(dg.(dg.tmp.abb).h); % bring to front
% end