0001 function hh = uitabdemo(option)
0002
0003
0004
0005
0006
0007
0008
0009
0010 if nargin<1, option = 1; end
0011 switch option
0012 case 1
0013 style1 = 'popup';
0014 style2 = 'lefttop';
0015 style3 = 'rightbottom';
0016 case 2
0017 style1 = 'popup';
0018 style2 = 'righttop';
0019 style3 = 'leftbottom';
0020 otherwise
0021 style1 = 'popup';
0022 style2 = 'centertop';
0023 style3 = 'centerbottom';
0024 end
0025
0026 width = 0;
0027 hfig = figure(...
0028 'Name','uitabpanel demo',...
0029 'NumberTitle','off', ...
0030 'Menubar','none',...
0031 'Toolbar','none');
0032
0033
0034
0035
0036 htab(1) = uitabpanel(...
0037 'Parent',hfig,...
0038 'Style',style1,...
0039 'Units','normalized',...
0040 'Position',[0,0,0.3,1],...
0041 'FrameBackgroundColor',[0.4314,0.5882,0.8431],...
0042 'FrameBorderType','etchedin',...
0043 'Title',{'This is popup tab','Click me!','See also','About'},...
0044 'PanelHeights',[8,30,10,10],...
0045 'HorizontalAlignment','left',...
0046 'FontWeight','bold',...
0047 'TitleBackgroundColor',[0.9255 0.9490 0.9765],...
0048 'TitleForegroundColor',[0.1294,0.3647,0.8510],...
0049 'PanelBackgroundColor',[0.7725,0.8431,0.9608],...
0050 'PanelBorderType','line',...
0051 'CreateFcn',@CreateTab1);
0052
0053 htab(2) = uitabpanel(...
0054 'Parent',hfig,...
0055 'TabPosition',style2,...
0056 'Position',[0.3,0.5,0.7,0.5],...
0057 'Margins',{[0,-1,1,0],'pixels'},...
0058 'PanelBorderType','line',...
0059 'Title',{'Introduction','Syntax','Features','Todo'},...
0060 'CreateFcn',@CreateTab2);
0061
0062 htab(3) = uitabpanel(...
0063 'Parent',hfig,...
0064 'TitlePosition',style3,...
0065 'Position',[0.3,0,0.7,0.5],...
0066 'Margins',{[0,1,1,0],'pixels'},...
0067 'Title',{'The Earth','The Globe','More Styles'},...
0068 'CreateFcn',@CreateTab3,...
0069 'SelectedItem',3);
0070
0071 if nargout, hh = htab; end
0072
0073
0074 function CreateTab1(htab,evdt,hpanel,hstatus)
0075 uicontrol(...
0076 'Parent',hpanel(1),...
0077 'Units','normalized',...
0078 'Position',[.1,.1,.9,.8],...
0079 'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
0080 'HorizontalAlignment','left',...
0081 'Style','text',...
0082 'String',[...
0083 'Popup panel is another '
0084 'type of UITABPANEL '
0085 'with the ''Style'' '
0086 'property set to ''Popup''. '
0087 'Click on its title bar '
0088 'toggle open/close of the '
0089 'popup panel. ']);
0090
0091 uicontrol(...
0092 'Parent',hpanel(2),...
0093 'Units','normalized',...
0094 'Position',[.1,.02,.8,.95],...
0095 'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
0096 'HorizontalAlignment','left',...
0097 'Style','text',...
0098 'String',[...
0099 'Here is a long panel. '
0100 'Using the vertical '
0101 'slider to scroll up '
0102 'and down for the rest '
0103 'of content in this '
0104 'popup panel. '
0105 ' '
0106 'All popup panels have '
0107 'the same vertical '
0108 'layout. '
0109 ' '
0110 'The length of each '
0111 'panel in the group can'
0112 'be specified using the'
0113 'the property '
0114 '''PanelHeights'' at '
0115 'creation time, which '
0116 'should be a numeric '
0117 'array with the same '
0118 'length of ''Title'' in '
0119 'the unit of '
0120 '''Characters''. '
0121 ' '
0122 'Interactive change of '
0123 'the length of a panel '
0124 'in the group can only '
0125 'be done when it is '
0126 'deactivated. ']);
0127
0128 uicontrol(...
0129 'Parent',hpanel(3),...
0130 'Units','normalized',...
0131 'Position',[.1,.1,.8,.82],...
0132 'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
0133 'HorizontalAlignment','left',...
0134 'Style','text',...
0135 'String',[...
0136 'tabpanel, by Dirk Tenne '
0137 'Tab panel example, by '
0138 ' Bill York '
0139 'TabPanel Constructor '
0140 ' v1.3, by Elmar Tarajan'
0141 'Tab Panel (Yet another '
0142 ' one), by Laine Berhane'
0143 ' Kahsay '
0144 'in File Exchange Site. ']);
0145
0146 uicontrol(...
0147 'Parent',hpanel(4),...
0148 'Units','normalized',...
0149 'Position',[.1,.1,.8,.76],...
0150 'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
0151 'Style','text',...
0152 'String',[...
0153 ' UITABPANEL '
0154 ' version 1.0 '
0155 ' '
0156 ' Created by '
0157 ' Shiying Zhao '
0158 '(zhao@arch.umsl.edu)'
0159 ' '
0160 ' May 20, 2006 ']);
0161
0162 uicontrol(...
0163 'Parent',hstatus,...
0164 'Units','normalized',...
0165 'Position',[0,0,1,.3],...
0166 'BackgroundColor',get(hstatus,'BackgroundColor'),...
0167 'ForegroundColor',[0.6,1,1],...
0168 'HitTest','off',...
0169 'Style','text',...
0170 'String',[...
0171 ' Copyright(c) 2006 '
0172 ' Shiying Zhao '
0173 'All rights reserved.']);
0174
0175 set(htab,'ResizeFcn',@TabResize1);
0176 end
0177
0178
0179 function CreateTab2(htab,evdt,hpanel,hstatus)
0180 uicontrol(...
0181 'Parent',hpanel(1),...
0182 'Units','normalized',...
0183 'Position',[.1,.1,.8,.8],...
0184 'BackgroundColor',get(hpanel(1),'BackgroundColor'),...
0185 'ForegroundColor','w',...
0186 'HorizontalAlignment','left',...
0187 'FontSize',12,...
0188 'Style','text',...
0189 'String',[ ...
0190 'UITABPANEL creates a group of tabbed '
0191 'panels with a consistent look and feel to'
0192 'the builtin MATLAB UI objects. '
0193 ' '
0194 'A special type of UITABPANEL is the '
0195 'popup tabpanel as shown on the left-hand '
0196 'side of this figure. ']);
0197
0198 uicontrol(...
0199 'Parent',hpanel(2),...
0200 'Units','normalized',...
0201 'Position',[.1,.1,.8,.8],...
0202 'BackgroundColor','w',...
0203 'HorizontalAlignment','left',...
0204 'Style','text',...
0205 'String',[...
0206 ' '
0207 ' The syntax of using UITABPANEL is the same as '
0208 ' UIPANEL except a few property changes. For a complete '
0209 ' description, see the online help of UITABPANEL and the '
0210 ' MATLAB script of this demo. Examples: '
0211 ' '
0212 ' htab = uitabpanel( ''Title'',{''A'',''B'',''C'',''D''} ) '
0213 ' htab = uitabpanel( ''Title'',{''A'',''B''},''Style'',''righttop'' ) '
0214 ' htab = uitabpanel( ''Title'',{''A'',''B'',''C''},''Position'',my_pos,'
0215 ' ''CreateFcn'',@my_fun1,''ResizeFcn'',@my_fun2) ']);
0216
0217 uicontrol(...
0218 'Parent',hpanel(3),...
0219 'Units','normalized',...
0220 'Position',[.1,.1,.8,.8],...
0221 'BackgroundColor','w',...
0222 'HorizontalAlignment','left',...
0223 'Style','text',...
0224 'String',[...
0225 ' '
0226 ' The following is a brief summary of some advanced features'
0227 ' of the current implementation of UITABPANEL: '
0228 ' 1. UITABPANEL can be resizable if ''ResizeFcn'' is set. '
0229 ' 2. A callback routine ''SelectionChangeFcn'' can be defined '
0230 ' through ''set/getappdata'', which will be executed when '
0231 ' the selected tab changes. '
0232 ' 3. An empty UICONTAINER in each UITABPANEL is '
0233 ' designed mainly for a functional purpose, but is can be'
0234 ' used by users for other purposes in a number of ways. ']);
0235
0236 uicontrol(...
0237 'Parent',hpanel(4),...
0238 'Units','normalized',...
0239 'Position',[.1,.1,.8,.8],...
0240 'BackgroundColor','w',...
0241 'HorizontalAlignment','left',...
0242 'Style','text',...
0243 'String',[...
0244 ' '
0245 ' Although the current implementation of UITABPANEL works '
0246 ' well for small number of tabs, many improvements and new '
0247 ' features are still desirable. '
0248 ' '
0249 ' An immediate task is to add more styles, such as vertical'
0250 ' tabs and multi-row tabs. However, the most desirable '
0251 ' improvement to me is to rewrite UITABPANEL as a '
0252 ' MATLAB class, so that it will behave in the same way as '
0253 ' the builtin MATLAB user interface (UI) objects. ']);
0254
0255 uicontrol(...
0256 'Parent',hstatus,...
0257 'Units','normalized',...
0258 'Position',[0,0.1,1,.68],...
0259 'BackgroundColor',get(hstatus,'BackgroundColor'),...
0260 'ForegroundColor','k',...
0261 'HitTest','off',...
0262 'Style','text',...
0263 'String',['This is ',style2,' tab']);
0264 setappdata(htab,'SelectionChangeFcn',@TabStatus2);
0265
0266 set(htab,'ResizeFcn',{@TabResize2,[0.5,0.5]});
0267 end
0268
0269
0270 function CreateTab3(htab,evdt,hpanel,hstatus)
0271 uicontrol(...
0272 'Parent',hpanel(3),...
0273 'Units','normalized',...
0274 'Position',[.3,.1,.6,.6],...
0275 'BackgroundColor',get(hpanel(1),'BackgroundColor'),...
0276 'ForegroundColor','w',...
0277 'HorizontalAlignment','left',...
0278 'FontSize',12,...
0279 'Style','text',...
0280 'String',[...
0281 'Run this demo with the optional '
0282 'argument 1, 2, and 3 to view all'
0283 'implemented styles. ']);
0284
0285 load('topo.mat','topo','topomap1');
0286 axes('Parent',hpanel(1));
0287 PlotTheEarth(topo,topomap1);
0288
0289 axes('Parent',hpanel(2),'Position',[0,.1,.8,.8]);
0290 axis square off
0291 uicontrol(...
0292 'Parent',hpanel(2),...
0293 'Units','normalized',...
0294 'Position',[0.7,.4,.2,.1],...
0295 'Style','pushbutton',...
0296 'Callback',{@PlotTheGlobel,topo},...
0297 'String','Create it!');
0298 uicontrol(...
0299 'Parent',hpanel(2),...
0300 'Units','normalized',...
0301 'Position',[0.7,.2,.2,.1],...
0302 'Style','pushbutton',...
0303 'Callback','cla',...
0304 'String','Remove it!');
0305
0306 uicontrol(...
0307 'Parent',hstatus,...
0308 'Units','normalized',...
0309 'Position',[0,0.1,1,.68],...
0310 'BackgroundColor',get(hstatus,'BackgroundColor'),...
0311 'ForegroundColor','k',...
0312 'HitTest','off',...
0313 'Style','text',...
0314 'String',['This is ',style3,' tab']);
0315
0316 set(htab,'ResizeFcn',{@TabResize2,[0,0.5]});
0317 end
0318
0319
0320 function TabResize1(hobj,evdt)
0321 figpos = get(hfig,'Position');
0322 tabpos = get(hobj,'Position');
0323 tabpos(4) = figpos(4);
0324 set(hobj,'Position',tabpos);
0325
0326 width = tabpos(3)/figpos(3);
0327 end
0328
0329
0330 function TabResize2(hobj,evdt,ysiz)
0331 figpos = get(hfig,'Position');
0332 tabpos = get(hobj,'Position');
0333 tabpos([1,3]) = [width,1-width]*figpos(3)+[1,0];
0334 tabpos([2,4]) = ysiz*figpos(4)+[1,0];
0335 set(hobj,'Position',tabpos);
0336 end
0337
0338
0339 function TabStatus2(hobj,evdt)
0340 set(get(evdt.Status,'Children'),'String',['page ',num2str(evdt.NewValue)]);
0341 end
0342
0343
0344 function PlotTheEarth(topo,topomap1)
0345 contour(0:359,-89:90,topo,[0 0],'b')
0346 axis equal
0347 box on
0348 set(gca,'XLim',[0 360],'YLim',[-90 90], ...
0349 'XTick',[0 60 120 180 240 300 360], ...
0350 'YTick',[-90 -60 -30 0 30 60 90]);
0351 hold on
0352 image([0 360],[-90 90],topo,'CDataMapping', 'scaled');
0353 colormap(topomap1);
0354 end
0355
0356
0357 function PlotTheGlobel(hobj,evdt,topo)
0358 [x,y,z] = sphere(50);
0359 props.AmbientStrength = 0.1;
0360 props.DiffuseStrength = 1;
0361 props.SpecularColorReflectance = .5;
0362 props.SpecularExponent = 20;
0363 props.SpecularStrength = 1;
0364 props.FaceColor= 'texture';
0365 props.EdgeColor = 'none';
0366 props.FaceLighting = 'phong';
0367 props.Cdata = topo;
0368 surface(x,y,z,props);
0369 light('position',[-1 0 1]);
0370 light('position',[-1.5 0.5 -0.5], 'color', [.6 .2 .2]);
0371 end
0372
0373
0374
0375 end