function [fields,values,ui_type] = get_non_default_value( ui_handle )
%
% get_non_default_value - get the list of <field,value> which have different values than the default
%
% format: [fields,values,ui_type] = get_non_default_value( ui_handle )
%
% input: ui_handle - a graphic handle of any type
%
% output: fields,values - pairs of field name and it's content which is not the default value
% ui_type - the type of the graphic handle given to the function
%
% example: [fields,values,h_type] = get_non_default_value( figure('name','mytest','tag','examplefig' ) )
%
% check if input is a handle
if ( nargin == 0 ) | ( isempty( ui_handle) ) | ( ~ishandle( ui_handle ) )
fields = {};
values = {};
ui_type = [];
error( 'invalid handle' );
end
% check the type of the graphic handle
ui_type = get( ui_handle,'type' );
% create the same graphic element (based on the type)
switch lower( ui_type )
case 'figure',
temp_parent = [];
temp_handle = figure( 'visible','off' );
exception_fields = { 'children','visible' };
case 'axes',
temp_parent = figure( 'visible','off' );
temp_handle = axes( 'parent',temp_parent );
exception_fields = { 'parent','children','xlabel','ylabel','zlabel','title' };
case {'uimenu','uicontextmenu'},
temp_parent = [];
temp_handle = feval( ui_type );
exception_fields = { 'parent','children' };
case 'uicontrol',
temp_parent = figure( 'visible','off' );
temp_handle = uicontrol( 'parent',temp_parent,'style',get(ui_handle,'style') );
exception_fields = { 'parent','children','style' };
case 'uitoolbar',
temp_parent = figure( 'visible','off' );
temp_handle = uitoolbar( 'parent',temp_parent );
exception_fields = { 'parent','children' };
case {'uitoggletool','uipushtool'},
temp_parent(1) = figure( 'visible','off' );
temp_parent(2) = uitoolbar( 'parent',temp_parent(1) );
temp_handle = feval( ui_type,'parent',temp_parent(2) );
exception_fields = { 'parent','children' };
case {'line','image','light','patch','rectangle','surface','text'},
temp_parent(1) = figure( 'visible','off' );
temp_parent(2) = axes( 'parent',temp_parent(1) );
temp_handle = feval( ui_type,'parent',temp_parent(2) );
exception_fields = { 'parent','children' };
otherwise,
fields = {};
values = {};
ui_type = [];
error( 'unknown graphic object' );
end
% shared code for all elements
[fields,values] = get_fields_and_values( ui_handle,temp_handle,exception_fields );
close_element( temp_handle,temp_parent );
% ====================================================================================
% I n n e r f u n c t i o n i m p l e m e n t a t i o n
% ====================================================================================
function [fields,values] = get_fields_and_values( ui_handle,temp_handle,exception_fields )
% find all fields which are different from the default values in "temp_handle"
% initialize
fields = {};
values = {};
% get the list of fields in the ui
ui_fields = fieldnames( get( ui_handle ) );
% remove fields which are not meant to be compared
for m = 1:length(exception_fields)
for n = length( ui_fields ):-1:1
if strcmpi( ui_fields{n},exception_fields{m} )
ui_fields = { ui_fields{1:n-1} ui_fields{n+1:end} }.';
break;
end
end
end
% get the list of <field,value> which have different values than the default ones
for m = 1:length( ui_fields )
if ~isequal( get( ui_handle,ui_fields{m} ),get( temp_handle,ui_fields{m} ) )
fields{end+1} = ui_fields{m};
values{end+1} = get( ui_handle,ui_fields{m} );
end
end
% sort as a column vector
fields = fields.';
values = values.';
% -----------------------------------------------------------------------------------
function close_element( temp_handle,temp_parent )
% close all graphic handles which were created in the calling routine
delete( temp_handle );
for m = length(temp_parent):-1:1
delete( temp_parent(m) );
end