4242 end % properties
4343
4444
45+ %% Public dependent properties
4546 properties (AbortSet , Dependent )
4647
4748 % Indices of displayed items that are currently added to the list
5657 end % properties
5758
5859
59- properties (AbortSet , Dependent , SetAccess = private )
60+ properties (AbortSet , Dependent , UsedInUpdate = false )
6061
61- % Indices of the highlighted items
62- HighlightedIndex
62+ % Width of the buttons
63+ ButtonWidth
6364
6465 end % properties
6566
6667
67- properties ( AbortSet , Dependent , Hidden )
68+ methods
6869
69- % Indices of displayed items that are currently added to the list (for backward compatibility - use ValueIndex instead)
70- SelectedIndex (1 ,: )
70+ function value = get .ValueIndex(obj )
71+ value = obj .ListBox .ItemsData ;
72+ end
7173
72- end % properties
74+ function set .ValueIndex(obj ,value )
75+ obj.ListBox.Items = obj .Items(value );
76+ obj.ListBox.ItemsData = value ;
77+ end
7378
79+ function value = get .Value(obj )
80+ if isempty(obj .ItemsData )
81+ value = obj .Items(: ,obj .ListBox .ItemsData );
82+ else
83+ value = obj .ItemsData(: ,obj .ListBox .ItemsData );
84+ end
85+ end
7486
75- properties (AbortSet , Dependent , UsedInUpdate = false )
87+ function set .Value(obj ,value )
88+ if isempty(value )
89+ obj.SelectedIndex = [];
90+ else
91+ if isempty(obj .ItemsData )
92+ [tf , selIdx ] = ismember(value , obj .Items );
93+ else
94+ [tf , selIdx ] = ismember(value , obj .ItemsData );
95+ end
96+ if ~all(tf )
97+ warning(" widgets:ListSelector:InvalidValue" ,...
98+ " Attempt to set an invalid Value to the list." )
99+ selIdx(~tf ) = [];
100+ end
101+ obj.SelectedIndex = selIdx ;
102+ end
103+ end
76104
77- % Width of the buttons
78- ButtonWidth
79105
80- end % properties
106+ function value = get .HighlightedValue(obj )
107+ selIdx = obj .ListBox .Value ;
108+ if isempty(selIdx ) || ~isnumeric(selIdx )
109+ selIdx = [];
110+ end
111+ if isempty(obj .ItemsData )
112+ value = obj .Items(: ,selIdx );
113+ else
114+ value = obj .ItemsData(: ,selIdx );
115+ end
116+ end
117+
118+ function set .HighlightedValue(obj ,value )
119+ if isempty(value )
120+ obj.ListBox.Value = {};
121+ return ;
122+ end
123+ if isempty(obj .ItemsData )
124+ [~ , obj .ListBox .Value ] = ismember(value , obj .Items );
125+ else
126+ [~ , obj .ListBox .Value ] = ismember(value , obj .ItemsData );
127+ end
128+ end
129+
81130
131+ function value = get .ButtonWidth(obj )
132+ value = obj.Grid.ColumnWidth{2 };
133+ end
82134
135+ function set .ButtonWidth(obj ,value )
136+ obj.Grid.ColumnWidth{2 } = value ;
137+ end
83138
84- %% Read-Only properties
85- properties (SetAccess = private )
139+ end % methods
86140
87- % Additional user buttons
88- UserButtons wt.ButtonGrid
141+
142+ %% Read-only dependent properties
143+ properties (AbortSet , Dependent , SetAccess = private )
144+
145+ % Indices of the highlighted items
146+ HighlightedIndex
89147
90148 end % properties
91149
150+ methods
151+
152+ function value = get .HighlightedIndex(obj )
153+ value = obj .ListBox .Value ;
154+ if isempty(value )
155+ value = [];
156+ end
157+ end
158+
159+ end % methods
160+
92161
93162
94163 %% Internal Properties
106175 end % properties
107176
108177
178+ properties (SetAccess = private )
179+
180+ % Additional user buttons may be attached to this ButtonGrid
181+ UserButtons wt.ButtonGrid
182+
183+ end % properties
184+
185+
186+ %% Hidden compatibility properties
187+ properties (AbortSet , Dependent , Hidden )
188+
189+ % Indices of displayed items that are currently added to the list (for backward compatibility - use ValueIndex instead)
190+ SelectedIndex (1 ,: )
191+
192+ end % properties
193+
194+ methods
195+
196+ function value = get .SelectedIndex(obj )
197+ value = obj .ValueIndex ;
198+ end
199+
200+ function set .SelectedIndex(obj ,value )
201+ obj.ValueIndex = value ;
202+ end
203+
204+ end % methods
205+
206+
109207
110208 %% Protected methods
111209 methods (Access = protected )
@@ -385,95 +483,4 @@ function shiftListBoxIndex(obj, shift)
385483
386484 end % methods
387485
388-
389-
390- %% Accessors
391- methods
392-
393- function value = get .SelectedIndex(obj )
394- value = obj .ListBox .ItemsData ;
395- end
396-
397- function set .SelectedIndex(obj ,value )
398- obj.ListBox.Items = obj .Items(value );
399- obj.ListBox.ItemsData = value ;
400- end
401-
402- function value = get .ValueIndex(obj )
403- value = obj .ListBox .ItemsData ;
404- end
405-
406- function set .ValueIndex(obj ,value )
407- obj.ListBox.Items = obj .Items(value );
408- obj.ListBox.ItemsData = value ;
409- end
410-
411- function value = get .Value(obj )
412- if isempty(obj .ItemsData )
413- value = obj .Items(: ,obj .ListBox .ItemsData );
414- else
415- value = obj .ItemsData(: ,obj .ListBox .ItemsData );
416- end
417- end
418-
419- function set .Value(obj ,value )
420- if isempty(value )
421- obj.SelectedIndex = [];
422- else
423- if isempty(obj .ItemsData )
424- [tf , selIdx ] = ismember(value , obj .Items );
425- else
426- [tf , selIdx ] = ismember(value , obj .ItemsData );
427- end
428- if ~all(tf )
429- warning(" widgets:ListSelector:InvalidValue" ,...
430- " Attempt to set an invalid Value to the list." )
431- selIdx(~tf ) = [];
432- end
433- obj.SelectedIndex = selIdx ;
434- end
435- end
436-
437- function value = get .HighlightedValue(obj )
438- selIdx = obj .ListBox .Value ;
439- if isempty(selIdx ) || ~isnumeric(selIdx )
440- selIdx = [];
441- end
442- if isempty(obj .ItemsData )
443- value = obj .Items(: ,selIdx );
444- else
445- value = obj .ItemsData(: ,selIdx );
446- end
447- end
448-
449- function set .HighlightedValue(obj ,value )
450- if isempty(value )
451- obj.ListBox.Value = {};
452- return ;
453- end
454- if isempty(obj .ItemsData )
455- [~ , obj .ListBox .Value ] = ismember(value , obj .Items );
456- else
457- [~ , obj .ListBox .Value ] = ismember(value , obj .ItemsData );
458- end
459- end
460-
461- function value = get .HighlightedIndex(obj )
462- value = obj .ListBox .Value ;
463- if isempty(value )
464- value = [];
465- end
466- end
467-
468- function value = get .ButtonWidth(obj )
469- value = obj.Grid.ColumnWidth{2 };
470- end
471-
472- function set .ButtonWidth(obj ,value )
473- obj.Grid.ColumnWidth{2 } = value ;
474- end
475-
476- end % methods
477-
478-
479486end % classdef
0 commit comments