function highlight(hObject,Descriptor)
%
% highlight brings to front all the elements contained in a panel
% associated to a tab.
%
%
% Call & Parameters:
%
% highlight(hObject,Descriptor)
%
% - hObject : is the handle of the object that calls the function. For
% example the button/tab that the user has pusshed.
%
% - Descriptor: Is the descriptor that identifies the type of
% element. As default, if not defined by the user, the descriptor for
% push buttons is "PB_" and "P_" for panels. The first
% descriptor is used for the panels and the second for
% the push buttons.
% Name scheme:
%
% The function asume that the elements in the GUI are bundled into
% Panels where each panel is related with a tab. For instance, imagine
% that we want two tabs named 'analisys' and 'synthesis'. Each tab will
% have its own panels named 'P_Analysis' and 'P_Synthesis' which would
% include one push button each one. Those push buttons are used for launching
% the corresponding m-file scripts. They will be named 'PB_Analysis' and
% 'PB_Synthesis' respectively. According to this name scheme, 'P_' and
% 'PB_' would be the Descriptors for the panels and push buttons.
%
% Usage:
%
% Push buttons are used to emulate the tabs. Once you push a push
% button, in its callback function you have to use this highlight
% function with hObject the handle of the push button and the
% corresponding descriptor depending on your name scheme.
%
% The main point is to identify and relate every element on the gui by
% the 'UserData' property to identify all the elements belonging to the
% same tab. For instnce in our example environment, we could use number
% '1' for analysis tab and '2' for synthesis. Every element that belongs
% to tab 'anaylsis' will have the value '1' in its 'UserData' property
% while all elements from tab 'synthesis' will be distinguished by
% having the vlue '2' in the 'UserData' property.
% If user hasn't defined the identifiers, the default values are used.
% 'P_' for panels and 'PB_' for push buttons.
if ~exist('Descriptor','var')
Descriptor={'P_','PB_'};
end
% First descriptor is used for panels
panel_desc=Descriptor{1};
% The second descriptor is used for the push buttons.
button_desc=Descriptor{2};
% Get the descriptor's length for the comparisons of the tag's char
% strings.
match_panel=length(panel_desc);
match_button=length(button_desc);
Pare = (get(hObject,'Parent'));
Fills = allchild(Pare);
% Get the descriptors of all the push buttons apart from the one that
% has launched the function (the one that user has pushed).
botons = Fills((strncmp(get(Fills,'Tag'),button_desc,match_button).*~strcmp(get(Fills,'Tag'),get(hObject,'Tag')) == 1));
%Getting the panels descriptors.
panells = Fills((strncmp(get(Fills,'Tag'),panel_desc,match_panel) == 1));
% Generate an array with the groups which belong each panel.
UData=zeros(size(panells));
for index=1:length(panells)
if isempty(get(panells(index),'UserData'))
UData(index)='a'; UData(index)='';
else
UData(index)=get(panells(index),'UserData');
end
end
% Panel that belongs to the same group/tab of the selected button.
panell_principal = panells(((UData == get(hObject,'UserData'))==1));
% Other panels that do not belong to the same group that the selected button.
panells = panells((~(UData == get(hObject,'UserData'))==1));
% Main panel activation and hide all other panels.
set(panells,'Visible','off');
set(panell_principal,'Visible','on');
% Set priority to the pushed button.
uistack(hObject,'top');
uistack(botons,'bottom')
set(hObject,'BackgroundColor',[0.7020 0.7020 0.7020].*0.997)
set(hObject,'ForegroundColor',[0 0 0])
set(hObject,'FontWeight','demi');
set(hObject,'FontAngle','normal');
%set(botons,'BackgroundColor',get(hObject,'BackgroundColor').*0.997)
set(botons,'BackgroundColor',[0.7020 0.7020 0.7020])
set(botons,'ForegroundColor',[0.5 0.5 0.5])
set(botons,'FontWeight','light');
set(botons,'FontAngle','italic');
end