-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabPanel.m
617 lines (584 loc) · 25.2 KB
/
tabPanel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
function [mainTabHandle,tabCardHandles,tabHandles] = tabPanel(parent,tabLabels,varargin)
% tabPanel: Create a uipanel comprising labeled, tiered, and ranked tabbed cards.
%
% tabPanel is different than some of the other submissions by the
% same name in the degree of control it provides (flexibility), and
% in its independence from the GUIDE environment. It also supports
% TOP (default), BOTTOM, LEFT, and RIGHT tabs, with vertical
% labels, and multiple-depth (tiered) panels. (See important REMARK
% under description of TABLABELS for discussion of how tabPanel is
% organized.)
%
% USAGE:
%
% [mainTabHandle,tabCardHandles,tabHandles] = tabPanel(parent,tabLabels,ParameterValuePairs)
%
% tabPanel(parent,tabLabels);
% Creates a uipanel with tabbed labels specified by tabLabels, as a
% child of a valid figure, uipanel, or uibuttongroup. (NOTE: This is
% the minimum required set of arguments.)
%
% [mainTabHandle,tabCardHandles,tabHandles] = tabPanel(parent,tabLabels)
% Returns the handle of the parent uipanel ("tab set"), of the
% individual tab cards (which are themselves uipanels), and of the
% individual tabs (which are pushbuttons).
%
% [mainTabHandle,tabCardHandles] = tabPanel(parent,tabLabels,PVPairs)
% Provides additional support for control of the
% overall tabPanel position, tab position (T,B,L,R), extent, height,
% colors, and tab label properties.
%
% OUTPUT ARGUMENTS:
%
% MAINTABHANDLE: Handle of the parent uipanel.
%
% TABCARDHANDLES: A cell array of handles of the child uipanels.
% The structure of the cell array will reflect the
% manner in which the tabLabels were defined (and thus
% the tier of the cards. For instance, if tabLabels =
% {{'One','Two'},{'Three','Four'},{'Five'}}, the handles
% might be returned in a cell array like this:
% tabCardHandles = {{1 2},{3 4},{5}}.
% (See REMARK under TABLABELS for more discussion.)
%
% TABHANDLES: A cell array of handles of the labeled tabs
% themselves, which are uicontrol pushbuttons. NOTE that
% in the case of 'top' or 'bottom' tabs, the labels are
% captured in the 'string' property of the uicontrols,
% but for 'left' or 'right' tabs, the labels are stored
% in the 'cdata' property (this is a workaround for the
% inability to rotate text on pushbuttons), making them
% less convenient to modify after they are created.
%
% INPUT ARGUMENT:
%
% PARENT: Handle of the parent object (required). Must be a
% valid handle to a figure, a uipanel, or a uibuttongroup.
%
% TABLABELS: A cell array of text strings with which cards are labelled.
%
% EXAMPLE: tabLabels1 = {'One','Two'}
% tabLabels2 = {{'One','Two'}}
% tabLabels3 = {{'One','Two','Three'},{'Four','Five'}}
%
% REMARK:
% The structure of this input determines the creation of
% tab cards, the parsing of subsequent inputs, and
% format of the returned variables!
%
% TIERS: tabLabels must be a cell array, with all
% elements being strings, or with all elements being
% cell arrays of strings. Each sub-cell defines a new
% "TIER" of cards, displayed on a separate level. If all
% elements of tabLabels are strings, then a single TIER
% of tabs will be created. If all elements of tabLabels
% are cells, then each will define a new tier of tabbed
% cards. In the examples above, tabLabels1 and
% tabLabels2 are equivalent, and will produce a single
% TIER of cards. tabLabels3 will produce a three-TIERed
% set of cards, having two cards in each of the first
% two TIERs, and one card in the third TIER.
%
% tabRank: within each tier, cards have a "tabRank," which
% captures the order in which they were specified and
% created. For example, in tabLabels3, the cards labeled
% 'One' and 'Four' will have tabRank 1, cards labeled 'Two'
% and 'Five' will have tabRank 2, and the card labeled
% 'Three' will have tabRank 3.
%
% See TABCARDHANDLE description for a discussion of how
% handles will be mapped to corresponding positions in
% tabLabels.
%
% PARAMETER-VALUE PAIRS:
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PARAMETER VALUE
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TABPOS: A (case-insensitive) string indicating the position of
% the tabs. Valid strings are:
%
% 'Top' (or 'T'): Tabs along top. (DEFAULT)
% 'Bottom' (or 'B'): Tabs along bottom.
% 'Left' (or 'L'): Tabs along left.
% 'Right' (or 'R'): Tabs along right.
%
% PANELPOS: The position (in normalized units) of the main panel
% within the parent. (Default is [0 0 1 1], to occupy
% the entirety of the parent.)
%
% TABEXTENT: A scalar, or an nTiers x 1 vector of numbers that modify the portion of
% the parent spanned by the tab set. (Must be on the interval [0,
% 1];). If a scalar is provide, it is used for all
% tiers. If a vector is provided, each element specifies
% the span of its corresponding tier. Example: for a
% 3-tiered set of tabs, tabExtent = [1 1 0.5] would
% trigger tiers 1 and 2 to span the parent, and tier 1
% to span half the parent.DEFAULT = 1)
%
% TABHEIGHT: The height of the tab (in pixels), if it is top- or
% bottom-positioned, or the width of the tab, otherwise.
% (DEFAULT = 50 pixels.) (Note: different heights for
% different tiers is not supported; tabHeight must be a
% scalar.)
%
% COLORS: A totalTabs x 3 matrix of RGB colors for the tab cards.
% Default is a "boosted" JET colormap, defined by:
% colors = jet(totalTabs+1);
% colors = min(1,colors+0.25);
% (totalTabs is the overall number of tab labels
% provided.)
%
% TABCARDPVS: A cell array or structure of Parameter-Value pairs,
% which will be applied to all individual tab cards.
% (See uipanel properties for valid PVs.)
%
% TABLABELPVS: A cell array or structure of Parameter-Value pairs,
% which will be applied to all tab labels. This allows
% the user to apply non-default text parameters, such as
% fontsize, color, rotation, etc. (See text properties
% for valid PVs.)
%
% HIGHLIGHTCOLOR:A triplet indicating the color in which the
% active panel (and corresponding button)
% should be displayed. (If not provided, no
% color change is implemented.)
%
% TO PROGRAMMATICALLY ACTIVATE A PRE-CONSTRUCTED TAB:
% tabPanel(tabCardHandles,tabHandles{tier}(tabRank,:))
%
% TO PROGRAMMATICALLY DETERMINE WHICH TAB IS ACTIVE:
% [currentTier,currentTabRank,tabName] = tabPanel(mainTabHandle);
%
% Examples:
% tabLabels = {{'One','Two','Three'},{'Four','Five'}};
%
% 1) tabPanel(gcf,tabLabels);
%
% 2) tabPanel(gcf,tabLabels,'tabpos','r','panelpos',[0.2 0.2 0.6 0.6],...
% 'tabextent',0.8,'tabheight',80,'colors',cool(5))
%
% 3) tabPanel(gcf,{{1,2,3},{4},{5,6}},'tabpos','b','tabextent',3/4,...
% 'tabLabelPVs',{'fontweight','b','foregroundcolor','r'})
%
% 4) tabLabels = {{'January','February','March'},{'April','May','June'},...
% {'July','August','September'},{'October','November','December'}};
% tabPanelOpts.fontweight = 'bold';
% tabPanelOpts.fontsize = 14;
% [mth,tch,th] = tabPanel(gcf,tabLabels,'TabPos','Right','TabHeight',60,'Colors',cool(12),...
% 'TabCardPVs',{'bordertype','etchedin','title',''},...
% 'TabLabelPVs',tabPanelOpts,...
% 'TabExtent',[1, 0.8, 1, 0.8])
%
% NOTE ON TEXT ORIENTATION: Text is automatically set to be upright for Top and
% Bottom tabs, and, by default, rotated 90 degrees for Left tabs, and
% 270 degrees for Right tabs. To modify the orientation, the user can
% change the 'rotation' property using the optional TABLABELPVS input
% argument. IMPORTANT: If ANY PVs are provided as inputs for a Left
% or Right tabPanel, uicontrol defaults (rather than TABPANEL
% defaults) will be used for unspecified parameters. (Thus, if you
% want to specify the color of the text, you must also specify the
% rotation if you want other something other than un-rotated text,
% and the backgroundcolor, to match that of the pushbutton.) Also,
% because MATLAB does not currently support rotated text in
% uicontrol strings, labels for L or R tabs will be _images_ of
% rotated text, generated using the function CREATEBUTTONLABEL.
% Creation of Left or Right tabPanels therefore requires the download
% and installation of CREATEBUTTONLABEL from the MATLAB Central File
% Exchange. (Using L or R will briefly expose a temporary figure in
% which the labels are generated.)
%
% NOTE ON PARAMETER VALUE PAIRS FOR TAB PANELS AND LABELS: After creation
% of the tabpanel, use the mainTabHandle output to modify the parent
% tab. (See uipanel properties for valid PV pairs.) Use output
% tabCardHandles to modify the child cards, again with any PV pairs
% valid for uipanels. And use tabHandles to modify the uicontrol
% pushbuttons that comprise the active labels on the cards. (See
% description of tabHandles for details of these handles.) If the
% tabs are left- or right-oriented, use the createButtonLabel command
% to re-generate cdata with different parameters.
%
% See also: createButtonLabel, sliderPanel
% Written by Brett Shoelson, PhD
% 01/21/07
%
% Copyright 2010-2013 The Mathworks Inc
% Modifications:
% 03/11/2013: Changed "highlight" behavior.
% Added capability of determining programmatically which tab is
% active, and note on how to do so.
% 09/22/2014: Modified "highlight" behavior again so that programmatic tab
% selection accurately updates highlights.
persistent p origState allHandles
if nargin == 1
%Note: This just reuses output argument names; it doesn't overwrite
%them in any meaninful sense.
[mainTabHandle,tabCardHandles,tabHandles] = getCurrentTab(parent);
return
end
if nargin == 2 &&...
~isa(tabLabels,'cell') && ...
ishandle(tabLabels) && ...
strcmp(get(tabLabels,'style'),'pushbutton')
% PANEL ACTIVATION REQUESTED
try
highlightColor = [];
tabCardHandles = parent;
nTiers = size(tabCardHandles,2);
changeTabOrder(tabLabels);
fig = ancestor(parent{1}(1),'figure');
mainTabPanel = findall(fig,'tag','mainTabPanel');
tabHandles = getappdata(mainTabPanel,'tabHandles');
for qq = 1:numel(tabHandles)
set(tabHandles{qq},'fontangle',origState.FontAngle,...
'fontweight',origState.FontWeight,...
'fontsize',origState.FontSize,...
'foregroundcolor',origState.ForegroundColor);
end
highlightColor = p.Results.highlightColor;
set(tabHandles{tier}(tabRank),...
'fontangle','italic',...
'fontweight','bold',...
'fontsize',origState.FontSize+1);
if ~isempty(highlightColor)
set(tabHandles{tier}(tabRank),...
'foregroundcolor',highlightColor);
end
return
catch
beep
disp('Activation-by-tab-handle not working!');
return
end
end
% Determine color of parent
parentColor = getParentColor;
% Make sure tabLabels is valid
[nTiers, nTabs, tabCardHandles] = validateParseTabLabels;
totalTabs = sum(nTabs);
% CREATE/INITIALIZE TABCARDS
tabHandles = tabCardHandles;
% PARSE INPUT ARGUMENTS
[colors,highlightColor,panelPos,parent,tabCardPVs,tabExtent,tabHeight,tabLabelPVs,tabLabels,tabPos] = parseInputs(parent,tabLabels,varargin{:});
% Simplify tabPos expression
tabPos = lower(tabPos(1));
if ismember(tabPos,{'l','r'}) && exist('createButtonLabel','file') ~= 2
beep;
s1 = sprintf('\nNOTE:\nTo create left- or right-oriented tabPanels, you you must first download\nand install ');
s2 = sprintf('<a href="matlab: web(''http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=15018&objectType=file'')">createButtonLabel</a> from the MATLAB Central File Exchange.\n\n');
%error(['TABPANEL: Unsupported option.',s1,s2]);
fprintf(['\nTABPANEL: Unsupported option.\n',s1,s2,'Using TOP-oriented labels instead.\n\n'])
tabPos = 't';
end
tp = {'rightbottom','lefttop'};
tp = tp{(strcmp(tabPos,'b')||strcmp(tabPos,'r'))+1};
% Calculate tab positions
rectPosn = calculatePositions;
% CREATE UIPANEL AS PARENT (DEFAULT)
mainTabHandle = uipanel('parent',parent,'backgroundcolor',parentColor,'bordertype',...
'none','units','normalized','pos',panelPos,'tag','mainTabPanel');
% Find characters, convert to lower case
if ~isempty(tabLabelPVs) && iscell(tabLabelPVs)
charpos = find(cellfun('isclass',tabLabelPVs,'char'));
for ii = charpos
tabLabelPVs{ii} = lower(tabLabelPVs{ii});
end
end
setappdata(mainTabHandle,'tabLabels',tabLabels);
incr = 1;
for tier = 1:nTiers
for tabRank = 1:nTabs(tier)
%CHILD TAB PANELS (DEFAULT)
if nTiers > 1
currString = tabLabels{tier}(tabRank);
else
currString = tabLabels{tabRank};
end
if iscell(currString)
currString = currString{1};
end
tabCardHandles{tier}(tabRank) = uipanel('parent',mainTabHandle,'units','normalized',...
'pos',tabCardPosn,'backgroundcolor',colors(incr,:),'bordertype','none',...
'titleposition',tp,'title',currString);
applyPVs(tabCardHandles{tier}(tabRank),tabCardPVs);
tabHandles{tier}(tabRank) = uicontrol('parent',mainTabHandle,...
'style','pushbutton','units','normalized',...
'tag','AutoConstructedTabHandle',...
'pos',rectPosn{tier}(tabRank,:),'backgroundcolor',colors(incr,:),...
'horizontalalignment','l','fontsize',14,'fontweight','bold',...
'callback',@changeTabOrder);
if ismember(tabPos,{'t','b'})
set(tabHandles{tier}(tabRank),'string',currString);
applyPVs(tabHandles{tier}(tabRank),tabLabelPVs);
else %'l' or 'r'
rots = [90,270];% Left: 90; Right: 270
if isempty(tabLabelPVs)
%DEFAULTS FOR L,R
tabLabelPVs = {'fontsize',14,'rotation',rots(strcmp(tabPos,'r')+1),'fontweight','b','backgroundcolor',colors(incr,:)};
else
tabLabelPVs = updateTabLabelPVs(tabLabelPVs,incr);
end
% BUTTONLABEL = CREATEBUTTONLABEL(STRING,PVs,FIGOPT);
% For all but the last call to createButtonLabel, figOpt = 2
% (for figure re-use); for creation of the last cdata label,
% figOpt = 1, triggering deletion of temporary figure.
buttonLabel = createButtonLabel(currString,...
tabLabelPVs,...
2-double(tier == nTiers && tabRank == nTabs(nTiers)));
set(tabHandles{tier}(tabRank),'cdata',buttonLabel);
end
setappdata(tabHandles{tier}(tabRank),'tabRank',tabRank);
setappdata(tabHandles{tier}(tabRank),'tier',tier);
setappdata(tabHandles{tier}(tabRank),'origColor',colors(incr,:));
incr = incr + 1;
end
end
%HIDE ALL BUT FIRST TAB
%toggleCardVisibility([tier,tabRank],visibility)
origState = get(tabHandles{1}(1));
setappdata(mainTabHandle,'tabHandles',tabHandles);%BDS
toggleCardVisibility('all',[],'off');
toggleCardVisibility(1,1,'on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% BEGIN NESTED FUNCTIONS
function [colors,highlightColor,panelPos,parent,tabCardPVs,tabExtent,tabHeight,tabLabelPVs,tabLabels,tabPos] = parseInputs(parent,tabLabels,varargin)
% DEFAULT Colors
colors = jet(totalTabs+1);
%Boost color base so tabs won't be too dark
colors = min(1,colors+0.25);
p = inputParser;
p.addRequired('parent',@(x) ishandle(x) && ismember(get(x,'type'),{'figure','uipanel'}))
p.addRequired('tabLabels',@(x)iscell(x) || ischar(x))
p.addParamValue('tabPos', 't', ...
@(x)any(strcmpi(x,{'t','top','b','bottom','l','left','r','right'}))); %Case insensitive (by default)
p.addParamValue('panelPos', [0 0 1 1], ...
@(x) numel(x)==4);
p.addParamValue('tabExtent',1,@(x) all(x>0) && all(x<=1));
p.addParamValue('tabHeight', 50,@(x) isscalar(x));
p.addParamValue('colors',colors,@(x) size(x,1)>=totalTabs && size(x,2)==3 && all(x(:)>=0) && all(x(:)<=1));
p.addParamValue('tabCardPVs',[]);
p.addParamValue('tabLabelPVs',[]);
p.addParamValue('highlightColor',[], @(x) ischar(x) || all(x>=0) && all(x<=1) && numel(x)==3);
p.parse(parent,tabLabels,varargin{:});
tmp = struct2cell(p.Results);
%Distribute inputs in alphabetical order!
[colors,highlightColor,panelPos,parent,tabCardPVs,tabExtent,tabHeight,tabLabelPVs,tabLabels,tabPos] = ...
deal(tmp{:});
end
% VALIDATE PARENT ARGUMENT
function parentColor = getParentColor
parentType = get(parent,'type');
switch parentType
case 'figure'
parentColor = get(parent,'color');
case {'uipanel','uibuttongroup'}
parentColor = get(parent,'backgroundcolor');
end
end
% VALIDATE TAB LABELS
function [nTiers, nTabs, tabCardHandles] = validateParseTabLabels
% tabLabels must be a cell array. The elements of tabLabel can
% themselves be cell arrays of strings. Each element that is itself
% a cell array increases the depth (number of tiers) of the panels.
% For instance:
% tabLabels = {{'One','Two'},{'Three','Four'},{'Five'}} will create
% three tiers of panels, with two labels in the first ('One' and
% 'Two') and second ('Three' and 'Four') tiers, and one ('Five') in
% the third tier.
class1 = class(tabLabels{1});
% All tab labels must be of the same class
for ii = 2:numel(tabLabels)
if ~strcmp(class(tabLabels{ii}),class1)
error('TABPANEL: Mismatched tab label types.')
end
end
if iscell(tabLabels{1})
nTiers = numel(tabLabels);
nTabs = cellfun('length',tabLabels);
elseif ischar(tabLabels{1})
nTiers = 1;
nTabs = numel(tabLabels);
else
error('TABPANEL: tabLabels declaration appears to be invalid.');
end
% Initialize placeholders for tabCardHandles
tabCardHandles = cell(1,nTiers);
for tier = 1:nTiers
tabCardHandles{tier} = zeros(nTabs(tier),1);
end
end
function rectPosn = calculatePositions
%Calculate positions
tmp = get(0,'screensize');
Wscr = tmp(3);
Hscr = tmp(4);
try
tabLength = tabExtent./nTabs;
catch
error('TABPANEL: Inappropriate value or dimension for tabExtent.')
end
% POSITION = [x,y,W,H]
rectPosn = cell(1,nTiers);
for tier = 1:nTiers
if strcmp(tabPos,'t')
tabCardPosn = [0 0 1 1-nTiers*tabHeight/Hscr];
rectPosn{tier} = repmat([0 1-tier*tabHeight/Hscr tabLength(tier) tabHeight/Hscr],nTabs(tier),1);
rectPosn{tier}(:,1)=((1:nTabs(tier))-1)*tabLength(tier);
elseif strcmp(tabPos,'b')
tabCardPosn = [0 nTiers*tabHeight/Hscr 1 1-nTiers*tabHeight/Hscr];
rectPosn{tier} = repmat([0 (tier-1)*tabHeight/Hscr tabLength(tier) tabHeight/Hscr],nTabs(tier),1);
rectPosn{tier}(:,1)=((1:nTabs(tier))-1)*tabLength(tier);
elseif strcmp(tabPos,'l')
tabCardPosn = [nTiers*tabHeight/Wscr 0 1-nTiers*tabHeight/Wscr,1];
rectPosn{tier} = repmat([(tier-1)*tabHeight/Wscr 0 tabHeight/Wscr tabLength(tier)],nTabs(tier),1);
rectPosn{tier}(:,2)=(0:nTabs(tier)-1)*tabLength(tier);
else %strcmp(tabPos,'r')
tabCardPosn = [0 0 1-nTiers*tabHeight/Wscr 1];
rectPosn{tier} = repmat([1-tier*tabHeight/Wscr 0 tabHeight/Wscr tabLength(tier)],nTabs(tier),1);
rectPosn{tier}(:,2)=1-((1:nTabs(tier))*tabLength(tier));
end
end
end
function changeTabOrder(varargin)
tier = getappdata(varargin{1},'tier');
tabRank = getappdata(varargin{1},'tabRank');
mth = ancestor(varargin{1},'uipanel');%findall(gcf,'tag','mainTabPanel');
setappdata(mth,'currentTier',tier);
setappdata(mth,'currentTabRank',tabRank)
if ~isempty(highlightColor)
reset = true;
else
reset = false;
end
toggleCardVisibility('all',[],'off',reset);
toggleCardVisibility(tier,tabRank,'on',reset);
end
function toggleCardVisibility(tier,tabRank,visibility,varargin)
if ischar(tier)% tier = 'all'
for tier = 1:nTiers
set(tabCardHandles{tier},'visible',visibility);
end
if nargin == 4 && varargin{1} && strcmp(visibility,'off')
allHandles = [];
for ii = 1:nTiers
allHandles = [allHandles;tabHandles{ii}];
end
for ii = 1:numel(allHandles)
origColor = getappdata(allHandles(ii),'origColor');
%set(allHandles(ii),'backgroundcolor',origColor);
%set(allHandles(ii),'fontangle',origFontAngle,'foregroundcolor',origForegroundColor)
set(allHandles(ii),'fontangle',origState.FontAngle,...
'fontweight',origState.FontWeight,...
'fontsize',origState.FontSize,...
'foregroundcolor',origState.ForegroundColor);
end
end
else
set(tabCardHandles{tier}(tabRank),'visible',visibility);
if ~isempty(highlightColor) && ismember(tabPos,{'t','b'})
if strcmp(visibility,'on')
% Note: tabHandles are uicontrol pushbuttons
%set(tabHandles{tier}(tabRank),'backgroundcolor',highlightColor);
set(tabHandles{tier}(tabRank),...
'fontangle','italic',...
'fontweight','bold',...
'fontsize',origState.FontSize+1,...
'foregroundcolor',highlightColor);
end
end
end
end
function applyPVs(obj,pvarray)
if isempty(pvarray)
return;
end
if isstruct(pvarray)
set(obj,pvarray);
else %Cell
if ~isempty(pvarray)
for ii = 1:2:numel(pvarray)
set(obj,pvarray{ii},pvarray{ii+1});
end
end
end
end
function tabLabelPVs = updateTabLabelPVs(tabLabelPVs,incr)
% USE DEFAULTS, FOR VALUES NOT EXPLICITLY DEFINED
%DEFAULTS FOR L,R
%tabLabelPVs = {'fontsize',14,'rotation',rots(strcmp(tabPos,'r')+1),'fontweight','b','backgroundcolor',colors(incr,:)};
if iscell(tabLabelPVs)
% FONTSIZE
if ~any(strcmp(tabLabelPVs,'fontsize'))
[tabLabelPVs{end+1},tabLabelPVs{end+2}] = deal('fontsize',14);
end
% ROTATION
if ~any(strcmp(tabLabelPVs,'rotation'))
[tabLabelPVs{end+1},tabLabelPVs{end+2}] = deal('rotation',rots(strcmp(tabPos,'r')+1));
end
% FONTWEIGHT
if ~any(strcmp(tabLabelPVs,'fontweight'))
[tabLabelPVs{end+1},tabLabelPVs{end+2}] = deal('fontweight','bold');
end
% BACKGROUNDCOLOR (NOTE: YOU CANNOT SPECIFY
% ANYTHING OTHER THAN BACKGROUNDCOLOR OF
% THE PARENT
tmp = find(strcmp(tabLabelPVs,'backgroundcolor'));
if ~isempty(tmp)
tabLabelPVs{tmp+1} = colors(incr,:);
else
[tabLabelPVs{end+1},tabLabelPVs{end+2}] = deal('backgroundcolor',colors(incr,:));
end
elseif isstruct(tabLabelPVs)
fn = fieldnames(tabLabelPVs);
% FONTSIZE
tmp = find(ismember(fn,{'Fontsize','FontSize','fontsize'}));
if isempty(tmp)
tabLabelPVs.fontsize = 14;
end
% ROTATION
tmp = find(ismember(fn,{'Rotation','rotation'}));
if isempty(tmp)
tabLabelPVs.rotation = rots(strcmp(tabPos,'r')+1);
end
% FONTWEIGHT
tmp = find(ismember(fn,{'Fontweight','FontWeight','fontweight'}));
if isempty(tmp)
tabLabelPVs.fontweight = 'bold';
end
% BACKGROUNDCOLOR
tmp = find(ismember(fn,{'Backgroundcolor','BackgroundColor','backgroundcolor'}));
if isempty(tmp)
tabLabelPVs.backgroundcolor = colors(incr,:);
else
eval(['tabLabelPVs.' fn{tmp} '=colors(incr,:);']);
end
end
end
function [currentTier,currentTabRank,tabName] = getCurrentTab(varargin)
currentTier = getappdata(varargin{1},'currentTier');
currentTabRank = getappdata(varargin{1},'currentTabRank');
if isempty(currentTier)
currentTier = 1;currentTabRank = 1;
end
tabLabels = getappdata(varargin{1},'tabLabels');
% if size(tabLabels,1) == 1
% tabName = tabLabels{currentTabRank};
% else
% tabName = tabLabels{currentTier}{currentTabRank};
% end
try
tabName = tabLabels{currentTier}{currentTabRank};
catch
tabName = tabLabels{currentTabRank};
end
% try
% tabName = tabLabels{currentTier}(currentTabRank,:);
% %tabName = tabLabels{currentTier}{currentTabRank};
% catch
% tabName = tabLabels;
% end
if iscell(tabName)
tabName = tabLabels{currentTier}(currentTabRank);
end
end
end