source: MML/trunk/applications/common/uitabdemo.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 12.3 KB
Line 
1function hh = uitabdemo(option)
2
3% UITABDEMO  This script demostrates the use of UITABPANEL.
4
5% Author: Shiying Zhao (zhao@arch.umsl.edu)
6% Version: 1.0
7% First created: May 02, 2006
8% Last modified: May 20, 2006
9
10if nargin<1, option = 1; end
11switch option
12  case 1
13    style1 = 'popup';
14    style2 = 'lefttop';
15    style3 = 'rightbottom';
16  case 2
17    style1 = 'popup';
18    style2 = 'righttop';
19    style3 = 'leftbottom';
20  otherwise
21    style1 = 'popup';
22    style2 = 'centertop';
23    style3 = 'centerbottom';
24end
25
26width = 0;
27hfig = figure(...
28  'Name','uitabpanel demo',...
29  'NumberTitle','off', ...
30  'Menubar','none',...
31  'Toolbar','none');
32
33%--------------------------------------------------------------------------
34% Creating the tabs
35%--------------------------------------------------------------------------
36htab(1) = uitabpanel(...
37  'Parent',hfig,...
38  'Style',style1,...
39  'Units','normalized',...
40  'Position',[0,0,0.3,1],...
41  'FrameBackgroundColor',[0.4314,0.5882,0.8431],...
42  'FrameBorderType','etchedin',...
43  'Title',{'This is popup tab','Click me!','See also','About'},...
44  'PanelHeights',[8,30,10,10],...
45  'HorizontalAlignment','left',...
46  'FontWeight','bold',...
47  'TitleBackgroundColor',[0.9255 0.9490 0.9765],...
48  'TitleForegroundColor',[0.1294,0.3647,0.8510],...
49  'PanelBackgroundColor',[0.7725,0.8431,0.9608],...
50  'PanelBorderType','line',...
51  'CreateFcn',@CreateTab1);
52
53htab(2) = uitabpanel(...
54  'Parent',hfig,...
55  'TabPosition',style2,...
56  'Position',[0.3,0.5,0.7,0.5],...
57  'Margins',{[0,-1,1,0],'pixels'},...
58  'PanelBorderType','line',...
59  'Title',{'Introduction','Syntax','Features','Todo'},...
60  'CreateFcn',@CreateTab2);
61
62htab(3) = uitabpanel(...
63  'Parent',hfig,...
64  'TitlePosition',style3,...
65  'Position',[0.3,0,0.7,0.5],...
66  'Margins',{[0,1,1,0],'pixels'},...
67  'Title',{'The Earth','The Globe','More Styles'},...
68  'CreateFcn',@CreateTab3,...
69  'SelectedItem',3);
70
71if nargout, hh = htab; end
72
73%--------------------------------------------------------------------------
74  function CreateTab1(htab,evdt,hpanel,hstatus)
75    uicontrol(...
76      'Parent',hpanel(1),...
77      'Units','normalized',...
78      'Position',[.1,.1,.9,.8],...
79      'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
80      'HorizontalAlignment','left',...
81      'Style','text',...
82      'String',[...
83      'Popup panel is another   '
84      'type of UITABPANEL       '
85      'with the ''Style''         '
86      'property set to ''Popup''. '
87      'Click on its title bar   '
88      'toggle open/close of the '
89      'popup panel.             ']);
90
91    uicontrol(...
92      'Parent',hpanel(2),...
93      'Units','normalized',...
94      'Position',[.1,.02,.8,.95],...
95      'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
96      'HorizontalAlignment','left',...
97      'Style','text',...
98      'String',[...
99      'Here is a long panel. '
100      'Using the vertical    '
101      'slider to scroll up   '
102      'and down for the rest '
103      'of content in this    '
104      'popup panel.          '
105      '                      '
106      'All popup panels have '
107      'the same vertical     '
108      'layout.               '
109      '                      '
110      'The length of each    '
111      'panel in the group can'
112      'be specified using the'
113      'the property          '
114      '''PanelHeights'' at     '
115      'creation time, which  '
116      'should be a numeric   '
117      'array with the same   '
118      'length of ''Title'' in  '
119      'the unit of           '
120      '''Characters''.         '
121      '                      '
122      'Interactive change of '
123      'the length of a panel '
124      'in the group can only '
125      'be done when it is    '
126      'deactivated.          ']);
127
128    uicontrol(...
129      'Parent',hpanel(3),...
130      'Units','normalized',...
131      'Position',[.1,.1,.8,.82],...
132      'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
133      'HorizontalAlignment','left',...
134      'Style','text',...
135      'String',[...
136      'tabpanel, by Dirk Tenne '
137      'Tab panel example, by   '
138      '  Bill York             '
139      'TabPanel Constructor    '
140      '  v1.3, by Elmar Tarajan'
141      'Tab Panel (Yet another  '
142      '  one), by Laine Berhane'
143      '  Kahsay                '
144      'in File Exchange Site.  ']);
145
146    uicontrol(...
147      'Parent',hpanel(4),...
148      'Units','normalized',...
149      'Position',[.1,.1,.8,.76],...
150      'BackgroundColor',get(hpanel(3),'BackgroundColor'),...
151      'Style','text',...
152      'String',[...
153      '     UITABPANEL     '
154      '     version 1.0    '
155      '                    '
156      '     Created by     '
157      '    Shiying Zhao    '
158      '(zhao@arch.umsl.edu)'
159      '                    '
160      '    May 20, 2006    ']);
161
162    uicontrol(...
163      'Parent',hstatus,...
164      'Units','normalized',...
165      'Position',[0,0,1,.3],...
166      'BackgroundColor',get(hstatus,'BackgroundColor'),...
167      'ForegroundColor',[0.6,1,1],...
168      'HitTest','off',...
169      'Style','text',...
170      'String',[...
171      ' Copyright(c) 2006  '
172      '   Shiying Zhao     '
173      'All rights reserved.']);
174
175    set(htab,'ResizeFcn',@TabResize1);
176  end
177
178%--------------------------------------------------------------------------
179  function CreateTab2(htab,evdt,hpanel,hstatus)
180    uicontrol(...
181      'Parent',hpanel(1),...
182      'Units','normalized',...
183      'Position',[.1,.1,.8,.8],...
184      'BackgroundColor',get(hpanel(1),'BackgroundColor'),...
185      'ForegroundColor','w',...
186      'HorizontalAlignment','left',...
187      'FontSize',12,...
188      'Style','text',...
189      'String',[ ...
190      'UITABPANEL creates a group of tabbed     '
191      'panels with a consistent look and feel to'
192      'the builtin MATLAB UI objects.           '
193      '                                         '
194      'A special type of UITABPANEL is the      '
195      'popup tabpanel as shown on the left-hand '
196      'side of this figure.                     ']);
197
198    uicontrol(...
199      'Parent',hpanel(2),...
200      'Units','normalized',...
201      'Position',[.1,.1,.8,.8],...
202      'BackgroundColor','w',...
203      'HorizontalAlignment','left',...
204      'Style','text',...
205      'String',[...
206      '                                                                '
207      '   The syntax of using UITABPANEL is the same as                '
208      '   UIPANEL except a few property changes. For a complete        '
209      '   description, see the online help of UITABPANEL and the       '
210      '   MATLAB script of this demo. Examples:                        '
211      '                                                                '
212      '     htab = uitabpanel( ''Title'',{''A'',''B'',''C'',''D''} )             '
213      '     htab = uitabpanel( ''Title'',{''A'',''B''},''Style'',''righttop'' )  '
214      '     htab = uitabpanel( ''Title'',{''A'',''B'',''C''},''Position'',my_pos,'
215      '                ''CreateFcn'',@my_fun1,''ResizeFcn'',@my_fun2)      ']);
216   
217    uicontrol(...
218      'Parent',hpanel(3),...
219      'Units','normalized',...
220      'Position',[.1,.1,.8,.8],...
221      'BackgroundColor','w',...
222      'HorizontalAlignment','left',...
223      'Style','text',...
224      'String',[...
225      '                                                             '
226      '   The following is a brief summary of some advanced features'
227      '   of the current implementation of UITABPANEL:              '
228      '   1. UITABPANEL can be resizable if ''ResizeFcn'' is set.     '
229      '   2. A callback routine ''SelectionChangeFcn'' can be defined '
230      '      through ''set/getappdata'', which will be executed when  '
231      '      the selected tab changes.                              '
232      '   3. An empty UICONTAINER in each UITABPANEL is             '
233      '      designed mainly for a functional purpose, but is can be'
234      '      used by users for other purposes in a number of ways.  ']);
235
236    uicontrol(...
237      'Parent',hpanel(4),...
238      'Units','normalized',...
239      'Position',[.1,.1,.8,.8],...
240      'BackgroundColor','w',...
241      'HorizontalAlignment','left',...
242      'Style','text',...
243      'String',[...
244      '                                                            '
245      '   Although the current implementation of UITABPANEL works  '
246      '   well for small number of tabs, many improvements and new '
247      '   features are still desirable.                            '
248      '                                                            '
249      '   An immediate task is to add more styles, such as vertical'
250      '   tabs and multi-row tabs. However, the most desirable     '
251      '   improvement to me is to rewrite UITABPANEL as a          '
252      '   MATLAB class, so that it will behave in the same way as  '
253      '   the builtin MATLAB user interface (UI) objects.          ']);
254
255    uicontrol(...
256      'Parent',hstatus,...
257      'Units','normalized',...
258      'Position',[0,0.1,1,.68],...
259      'BackgroundColor',get(hstatus,'BackgroundColor'),...
260      'ForegroundColor','k',...
261      'HitTest','off',...
262      'Style','text',...
263      'String',['This is ',style2,' tab']);
264    setappdata(htab,'SelectionChangeFcn',@TabStatus2);
265
266    set(htab,'ResizeFcn',{@TabResize2,[0.5,0.5]});
267  end
268
269%--------------------------------------------------------------------------
270  function CreateTab3(htab,evdt,hpanel,hstatus)
271    uicontrol(...
272      'Parent',hpanel(3),...
273      'Units','normalized',...
274      'Position',[.3,.1,.6,.6],...
275      'BackgroundColor',get(hpanel(1),'BackgroundColor'),...
276      'ForegroundColor','w',...
277      'HorizontalAlignment','left',...
278      'FontSize',12,...
279      'Style','text',...
280      'String',[...
281      'Run this demo with the optional '
282      'argument 1, 2, and 3 to view all'
283      'implemented styles.             ']);
284     
285    load('topo.mat','topo','topomap1');
286    axes('Parent',hpanel(1));
287    PlotTheEarth(topo,topomap1);
288
289    axes('Parent',hpanel(2),'Position',[0,.1,.8,.8]);
290    axis square off
291    uicontrol(...
292      'Parent',hpanel(2),...
293      'Units','normalized',...
294      'Position',[0.7,.4,.2,.1],...
295      'Style','pushbutton',...
296      'Callback',{@PlotTheGlobel,topo},...
297      'String','Create it!');
298    uicontrol(...
299      'Parent',hpanel(2),...
300      'Units','normalized',...
301      'Position',[0.7,.2,.2,.1],...
302      'Style','pushbutton',...
303      'Callback','cla',...
304      'String','Remove it!');
305
306    uicontrol(...
307      'Parent',hstatus,...
308      'Units','normalized',...
309      'Position',[0,0.1,1,.68],...
310      'BackgroundColor',get(hstatus,'BackgroundColor'),...
311      'ForegroundColor','k',...
312      'HitTest','off',...
313      'Style','text',...
314      'String',['This is ',style3,' tab']);
315
316    set(htab,'ResizeFcn',{@TabResize2,[0,0.5]});
317  end
318
319%--------------------------------------------------------------------------
320  function TabResize1(hobj,evdt)
321    figpos = get(hfig,'Position');
322    tabpos = get(hobj,'Position');
323    tabpos(4) = figpos(4);
324    set(hobj,'Position',tabpos);
325
326    width = tabpos(3)/figpos(3);
327  end
328
329%--------------------------------------------------------------------------
330  function TabResize2(hobj,evdt,ysiz)
331    figpos = get(hfig,'Position');
332    tabpos = get(hobj,'Position');
333    tabpos([1,3]) = [width,1-width]*figpos(3)+[1,0];
334    tabpos([2,4]) = ysiz*figpos(4)+[1,0];
335    set(hobj,'Position',tabpos);
336  end
337
338%--------------------------------------------------------------------------
339  function TabStatus2(hobj,evdt)
340    set(get(evdt.Status,'Children'),'String',['page ',num2str(evdt.NewValue)]);
341  end
342
343%--------------------------------------------------------------------------
344  function PlotTheEarth(topo,topomap1)
345    contour(0:359,-89:90,topo,[0 0],'b')
346    axis equal
347    box on
348    set(gca,'XLim',[0 360],'YLim',[-90 90], ...
349      'XTick',[0 60 120 180 240 300 360], ...
350      'YTick',[-90 -60 -30 0 30 60 90]);
351    hold on
352    image([0 360],[-90 90],topo,'CDataMapping', 'scaled');
353    colormap(topomap1);
354  end
355
356%--------------------------------------------------------------------------
357  function PlotTheGlobel(hobj,evdt,topo)
358    [x,y,z] = sphere(50);
359    props.AmbientStrength = 0.1;
360    props.DiffuseStrength = 1;
361    props.SpecularColorReflectance = .5;
362    props.SpecularExponent = 20;
363    props.SpecularStrength = 1;
364    props.FaceColor= 'texture';
365    props.EdgeColor = 'none';
366    props.FaceLighting = 'phong';
367    props.Cdata = topo;
368    surface(x,y,z,props);
369    light('position',[-1 0 1]);
370    light('position',[-1.5 0.5 -0.5], 'color', [.6 .2 .2]);
371  end
372
373%--------------------------------------------------------------------------
374
375end
Note: See TracBrowser for help on using the repository browser.