📄 tabpanel.m
字号:
function tabpanel( figname , tag , action )
%TABPANEL TabPanel Constructor offers the easiest way for creating of tabpanels
% Usage:
% 1. Reserve place for tabpanel with textobject under GUIDE and notice
% the fig-file name and the 'tag'-property of the created textobject.
% 2. Initialize TabPanel Constructor with:
% tabpanel('fig_file','tag_name',{'Tab1' 'Tab2' 'Tab3'})
% 3. Use constructor for creating tabpanels (might be selfexplicatory...)
% 4. ready? update tabpanel, close GUI und restart it.
%
% Options:
% a. activate TabPanel Constructor:
% tabpanel('fig_file','tag_name')
% b. add or remove a panel:
% tabpanel('fig_file','tag_name',{'Tab1' 'NewPanel1' 'Tab3' 'NewPanel2'})
% c. remove tabpanel from GUI
% tabpanel('fig_file','tag_name','delete')
% Version: 1.3 $
% Date: 2005/02/25 21:44:00 $
% (c) 2005 By Elmar Tarajan [MCommander@gmx.de]
%
figname = [strrep(figname,'.fig','') '.fig'];
fig = openfig(figname,'reuse');
handles = guihandles(fig);
%
%
if nargin == 3 & ischar(action)
%
tab = get(handles.(tag)(end),'Userdata');
htabs = handles.(tab.tag)(end-length(tab.names)-1:end-2);
hcurr = findobj(htabs,'String',tab.current);
%
switch action
case 'edit'
%
currfig = figure('NumberTitle','off', ...
'Name',[tab.tag '_' tab.current], ...
'Units','pixels', ...
'Menubar','none', ...
'color',tab.CurrBackColor, ...
'position',tab.pos-[0 0 6 tab.height+tab.outbreak+4], ...
'visible','off');
%
children = get(hcurr,'UserData');
[cancel order] = unique(children);
for j = children(-sort(-order))
tmp = handle2struct(handles.(char(j)));
for i=1:length(tmp)
tmp(i).properties.Position(1:2) = tmp(i).properties.Position(1:2)-tab.pos(1:2)-[ 3 3];
tmp(i).properties.Tag = tmp(i).properties.Tag(max(find(tmp(i).properties.Tag=='_'))+1:end);
end% for
struct2handle(tmp,currfig);
end% for
%
hgS_050200 = handle2struct(currfig);
hgS_050200.properties.Color = tab.CurrBackColor;
save([tab.tag '_' tab.current '.fig'],'hgS_050200','-mat');
delete(currfig);
%
try
result = get(handles.(constructor)(1),'UserData');
result.java.closeWindow(0);
end% try
%
result.java = guide([tab.tag '_' tab.current '.fig']);
result.figname = [tab.tag '_' tab.current '.fig'];
set(handles.(['constructor_' tag])(1),'UserData', result)
return
%
case 'update'
%
figfiles = dir([tab.tag '_*.fig']);
for j={figfiles.name}
tabfile = j{:}(max(find(char(j)=='_'))+1:max(find(char(j)=='.'))-1);
tags=[];
%
children = get(findobj(htabs,'String',tabfile),'UserData');
[cancel order] = unique(children);
for i = children(sort(order))
delete(handles.(char(i)));
end% for
%
hpage = openfig(char(j),'new','invisible');
set(get(hpage,'Children'),'Units','pixels');
for i=get(hpage,'children')'
tmp = get(i,'position');
tags{end+1} = [tab.tag '_' tabfile '_' get(i,'Tag')];
set(i,'Position',[[tmp(1:2)+tab.pos(1:2) + [3 3]] tmp(3:4)],'Tag',tags{end});
%
if strcmp(tab.current,tabfile)
set(i,'Visible','on');
else
set(i,'Visible','off');
end% if
%
try
if isempty(get(i,'callback'))
switch lower(get(i,'Style'))
case {'listbox' 'popupmenu' 'listbox' 'slider' 'edit'}
set(i,'callback','%automatic');
set(i,'CreateFcn','%automatic');
case {'checkbox' 'pushbutton' 'togglebutton' 'radiobutton'}
set(i,'callback','%automatic');
end% switch
end% if
end% try
end% for
set(findobj(htabs,'String',tabfile),'Userdata',tags);
tmp = get(hpage,'children');
copyobj(tmp(end:-1:1),fig)
close(hpage);
delete(char(j));
end% for
try
delete(findobj(get(fig,'children'),'UserData',[tab.tag '_warning']));
end% try
uicontrol('Parent',fig,'Style','text','Tag',tab.tag,'String', ...
{'TABPANEL' '!!! CHANGE NOTHING !!!' '' 'usage for editing tabpanel' ...
'---------------------------------------------------------' ['tabpanel(''' figname ''',''' tag ''')']}, ...
'Enable','inactive', 'units','pixels','position',tab.pos, ...
'BackgroundColor',[.2 .2 .2],'foregroundcolor',[1 .25 0], 'Visible','off','FontSize',8,'UserData',[tab.tag '_warning']);
%
try
result = get(handles.(['constructor_' tag])(1),'UserData');
result.java.closeWindow(0);
end% try
try
tmp = fieldnames(handles);
delete(handles.(tmp{strncmp(tmp,'constructor_',12)}))
end% try
%
setappdata(fig,'UsedByGUIData_m',guihandles(fig));
guidemfile('updateFile',fig, which(figname));
hgsave(fig, figname);
%
%
case {'CurrForeColor' 'CurrBackColor' 'BackColor' 'ForeColor'}
tmpcolor = uisetcolor;
if length(tmpcolor)>1
tab.(action) = tmpcolor;
end% if
%
case 'height'
try
answer = inputdlg({'lateral offset [left right]' 'tab height' 'tab outbreak - as a rule [0...5]'}, ...
'input...',1,{sprintf('%d %d',tab.outlet) sprintf('%d',tab.height) sprintf('%d',tab.outbreak)});
tab.outlet = str2num(char(answer{1}));
tab.height = str2num(char(answer{2}));
tab.outbreak = str2num(char(answer{3}));
sizename = {tab.current tab.height};
end% try
%
case 'size'
try
answer = inputdlg({'Tab name' ...
sprintf('Length in pixels (%d) or ''auto''',tab.dim(strcmp(tab.names,tab.current)))}, ...
'input...',1,{tab.current 'auto'});
tmp = answer{1}(~ismember(answer{1},' .,:;\/+-',''));
if any(ismember(tab.names(~ismember(tab.names,tab.current)),tmp))
warndlg({'tabname already exist' 'please, choose another'},'warning','modal')
uiwait
tabpanel(figname,tab.tag,'size');
return
end% if
tab.names{find(strcmp(tab.names,tab.current))} = tmp;
tab.current = tmp;
if strcmp('auto',answer{2})
tab.dim = [];
for i=tab.names
tab.dim = [tab.dim sum((char(i)<90)*1.5+(char(i)>90))+0.5];
end% for
else
tab.dim(strcmp(tab.names,tab.current)) = str2num(answer{2});
end% if
end% try
%
case 'font'
try
font = uisetfont('choose font');
set(htabs, ...
'FontName' ,font.FontName, ...
'FontUnits',font.FontUnits, ...
'FontSize' ,font.FontSize, ...
'FontAngle',font.FontAngle);
end% try
%
case 'info'
answer = questdlg({'TabPanel Constructor v1.3' ...
'(c) 2005' '' 'by Elmar Tarajan [MCommander@gmx.de]'}, ...
'who says that MATLAB does not support Tabpanels? :)', ...
'look for updates','Bug found?','OK','OK');
switch answer
case 'look for updates'
web('http://www.mathworks.com/matlabcentral/fileexchange/loadAuthor.do?objectId=936824&objectType=author');
case 'Bug found?'
web(['mailto:MCommander@gmx.de?subject=TabPanel-BUG:[Description]-[ReproductionSteps]-[Suggestion(if%20possible)]-[MATLAB%20v' strrep(version,' ','%20') ']-[TabPanel%20v1.3]']);
case 'OK',
end % switch
return
%
case 'delete'
tmp = get(handles.(tab.tag)(end-length(tab.names):end-1),'UserData');
for i=unique([tmp{:}])
delete(handles.(char(i)))
end% for
delete(handles.(tag)(1:end-1))
set(handles.(tag)(end),'UserData',[],'visible','on')
if isfield(handles,['constructor_' tag])
delete(handles.(['constructor_' tag]))
end% if
hgsave(fig, figname);
return
%
end% if
TPConstructor(fig,figname,tab,handles)
return
end% switch
%
%
%
if ~isempty(get(handles.(tag),'Userdata'))
%
tab = get(handles.(tag)(end),'UserData');
if exist('action')
%
%
[cancel order] = unique(action);
action = action(sort(order));
%
for i=1:length(action)
action{i} = action{i}(~ismember(action{i},' .,:;\/<>''~+-_',''));
end% for
%
for i=tab.names(~ismember(tab.names,action))
for j=fieldnames(handles)'
if ~isempty(findstr(char(j),['_' char(i) '_']))
delete(handles.(char(j)))
end% if
end% for
end% for
%
delete(handles.(tab.tag)(1:end-1))
%
handles = guihandles(fig);
tmp = fieldnames(handles);
htmp = [];
for i=tmp(strncmp([tab.tag '_'],tmp,length(tab.tag)+1))'
htmp = [htmp handles.(char(i))];
end% for
set(htmp,'visible','off')
t = handle2struct(htmp);
delete(htmp)
%
% 'tab' aktualisieren
tab.names = action;
tab.current = action{1};
tab.dim = [];
for i=1:length(tab.names)
tmp = tab.names{i}(~ismember(tab.names{i},' .,:;\/<>''~+-',''));
tab.dim = [tab.dim sum((tmp<90)*1.5+(tmp>90))+0.5];
tab.names{i} = tmp;
end% for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -