function [c,t] = MIconFactory(p,id)
%MICONFACTORY Creates built-in toolbar components
% MIconFactory
% With no arguments, displays registered toolbar
% components to the command window.
%
% [C] = MIconFactory(H,'GroupName.ComponentName')
% H is the parent toolbar handle.
% 'GroupName' is the name of the toolbar group
% 'ComponentName' is the name of the toolbar component
% C is the toolbar component
%
% [C] = MIconFactory(H,'GroupName')
% Specifying a 'GroupName' without a 'ComponentName' will create
% all the components, C, registered in that group.
%
% NOTE:
% C will return empty if the component is no longer supported as a
% built-in component.
%
% [INFO] = MIconFactory(H,'getinfo')
% Returns a struct containing information on all registered tools.
%
% Example:
%
% % Create a figure with a simple toolbar
% FIG = figure('toolbar','none');
% H = uitoolbar('parent',FIG);
% C = MIconFactory(H,'Standard.EditPlot');
% C = MIconFactory(H,'Exploration.ZoomIn');
% set(C,'Separator','on');
% C = MIconFactory(H,'Exploration.ZoomOut');
% C = MIconFactory(H,'Exploration.Pan');
%
% See also UIGETTOOL.
% Copyright 1984-2005 The MathWorks, Inc.
% $Revision: 1 $ $Date: 3/03/05 4:45p $
if nargin==0
% Pretty print output
info = localGetToolbarComponentInfo;
localPrettyPrint(info);
elseif nargin==1 & nargout==1
info = localGetToolbarComponentInfo;
% Convert cell of structs to structure
for n = 1:length(info)
c(n) = info{n};
end
elseif nargin==2
c = localMainCreate(p,id);
end
%---------------------------------------------------%
function [hComponent] = localMainCreate(p,fullid)
% Creates one or more uitoolbar components
hComponent = [];
% Get group and name from full ID
[idgroup,idname] = strtok(fullid,'.');
if ~isempty(idname)
idname = idname(2:end);
end
% p must be a toolbar
if strcmpi(get(p,'Type'),'uitoolbar')
hToolbar = p;
else
error('uitools:uitoolbarfactory','Handle must be a toolbar');
end
% Get full listing of registered components
dat = localGetToolbarComponentInfo;
% No name specified, so load group of toolbar components
if isempty(idname)
% Cycle through each item and add appropriately
for n = 1:length(dat);
info = dat{n};
if strcmp(info.group,idgroup)
hComponent(end+1) = localCreateToolbarComponent(hToolbar,info);
end
end
% Load individual toolbar components
else
% Cycle through each item
for n = 1:length(dat);
info = dat{n};
if strcmp(info.group,idgroup) && strcmp(info.name,idname);
hComponent = localCreateToolbarComponent(hToolbar,info);
break;
end
end
end
%---------------------------------------------------%
function [h] = localCreateToolbarComponent(p,info)
% Creates individual components (i.e. uitoggletool)
ICONROOT = [getbasedir, '/GUI/icons/'];
props = info.properties;
% Create tag based on group & name. It is better to keep this tag unique as
% we do know. It is used to improve the performance of creating the icon
% from CData in Java Figures. It is used as the key to search for a match
% in a table with Java icons created for component generated by this
% uitoolfactory.
props.tag = [info.group,'.',info.name];
% Load cdata from *.gif file
filename = info.icon;
if length(filename)>3 && strncmp(filename(end-3:end),'.gif',4)
[cdata,map] = imread([ICONROOT,info.icon]);
% Set all white (1,1,1) colors to be transparent (nan)
ind = find(map(:,1)+map(:,2)+map(:,3)==3);
map(ind) = nan;
props.cdata = ind2rgb(cdata,map);
% Load cdata from *.mat file
else
dat = load([ICONROOT,info.icon],'cdata');
props.cdata = dat.cdata;
end
% Specify PARENT property
props.parent = p;
% Create toolbar component
h = feval(info.constructor,props);
% Properties common to all uitool components
set(h,'HandleVisibility','off','Serializable','off');
%---------------------------------------------------%
function localPrettyPrint(uidata)
% Pretty prints toolbar data to command window
% in a similar manner as the PATH command.
% Header
disp(sprintf('\n\t\tTOOLBAR ITEMS\n'))
info = {};
for n = 1:length(uidata)
info{n} = [uidata{n}.group,'.',uidata{n}.name];
end
% Display items
ch= strvcat(info);
tabspace = ones(size(ch,1),1);
tabspace(:) = sprintf('\t');
s = [tabspace, ch];
disp(s)
% Footer
disp(sprintf('\n'))
%---------------------------------------------------%
function [uidata] = localGetToolbarComponentInfo
% Loads all toolbar data
uidata = {};
% EXPLORE TOOLS ------------------------------------------%
% Zoom In
info = [];
info.name = 'ZoomIn';
info.group = 'Exploration';
info.constructor = 'uitoggletool';
info.properties.ClickedCallback = 'putdowntext(''zoomin'',gcbo)';
%info.properties.ClickedCallback = 'zoom inmode';
info.properties.ToolTip = 'Zoom In';
info.icon = 'view_zoom_in.gif';
uidata{end+1} = info;
% Zoom Out
info = [];
info.name = 'ZoomOut';
info.group = 'Exploration';
info.constructor = 'uitoggletool';
info.properties.ClickedCallback = 'putdowntext(''zoomout'',gcbo)';
%info.properties.ClickedCallback = 'zoom outmode';
info.properties.ToolTip = 'Zoom Out';
info.icon = 'view_zoom_out.gif';
uidata{end+1} = info;
% Pan
info = [];
info.name = 'Pan';
info.group = 'Exploration';
info.constructor = 'uitoggletool';
info.properties.ClickedCallback = 'putdowntext(''pan'',gcbo)';
%info.properties.ClickedCallback = 'pan on';
info.properties.ToolTip = 'Pan';
info.icon = 'pan';
uidata{end+1} = info;
% Data Cursor
info = [];
info.name = 'DataCursor';
info.group = 'Exploration';
info.constructor = 'uitoggletool';
info.properties.ClickedCallback = 'putdowntext(''datatip'',gcbo)';
info.properties.ToolTip = 'Data Cursor';
info.icon = 'tool_data_cursor.gif';
uidata{end+1} = info;
% LinkAxes
info = [];
info.name = 'LinkAxes';
info.group = 'Exploration';
info.constructor = 'uitoggletool';
info.properties.ClickedCallback = 'putdowntext(''link axes'',gcbo)';
info.properties.ToolTip = 'Link Axes';
info.icon = 'chain_linked.gif';
uidata{end+1} = info;
% Data Cursor
info = [];
info.name = 'UnlinkAxes';
info.group = 'Exploration';
info.constructor = 'uitoggletool';
info.properties.ClickedCallback = 'putdowntext(''unlink axes'',gcbo)';
info.properties.ToolTip = 'Unlink Axes';
info.icon = 'chain_unlinked.gif';
uidata{end+1} = info;