Skip to content

Commit 9962777

Browse files
committed
Changed ProgressBar and PasswordFields to COmponentcontainer Inheritance
1 parent 1f8df7f commit 9962777

File tree

6 files changed

+66
-42
lines changed

6 files changed

+66
-42
lines changed

widgets/+wt/+mixin/BackgroundColorable.m

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77

88
%% Properties
9-
properties (AbortSet, Abstract)
9+
properties (AbortSet, Abstract, ...
10+
Access = {?matlab.ui.componentcontainer.ComponentContainer})
11+
12+
%BackgroundColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne}
1013

11-
% Background Color
12-
BackgroundColor (1,3) double {wt.validators.mustBeBetweenZeroAndOne}
1314

1415
end %properties
1516

1617

1718

1819
%% Internal properties
1920
properties (AbortSet, Transient, NonCopyable, ...
20-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
21+
Access = {?matlab.ui.componentcontainer.ComponentContainer})
2122

2223
% List of graphics controls to apply to
2324
BackgroundColorableComponents (:,1) matlab.graphics.Graphics
@@ -47,12 +48,26 @@
4748
methods (Access = protected)
4849

4950
function updateBackgroundColorableComponents(obj)
51+
5052

5153
hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor');
5254
wt.utility.fastSet(obj.BackgroundColorableComponents(hasProp),...
5355
"BackgroundColor",obj.BackgroundColor);
5456

5557
end %function
58+
59+
60+
function listenForBackgroundChange(obj)
61+
62+
% Establish Listener for Background Color Change
63+
addlistener(obj,'BackgroundColor','PostSet',...
64+
@(h,e)obj.updateBackgroundColorableComponents());
65+
66+
end
67+
68+
69+
70+
5671

5772
end %methods
5873

widgets/+wt/+mixin/FontStyled.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
%% Internal properties
3030
properties (AbortSet, Transient, NonCopyable, ...
31-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
31+
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest, ?matlab.ui.componentcontainer.ComponentContainer} )
3232

3333
% List of graphics controls to apply to
3434
FontStyledComponents (:,1) matlab.graphics.Graphics

widgets/+wt/+mixin/GridOrganized.m

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
properties (AbortSet, Transient, NonCopyable)
77

88
% GridLayout
9-
Grid (1,1) matlab.ui.container.GridLayout = uigridlayout;
10-
11-
% List of graphics controls that BackgroundColor should apply to
12-
BackgroundColorableComponents (:,1) matlab.graphics.Graphics
9+
Grid (1,1) matlab.ui.container.GridLayout
1310

1411
end
1512

1613

1714
%% Accessors
1815
methods (Access = protected)
1916

20-
function updateBackgroundColorableComponents(obj)
21-
% Update components that are affected by BackgroundColor
22-
23-
hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor');
24-
set(obj.BackgroundColorableComponents(hasProp),...
25-
"BackgroundColor",obj.BackgroundColor);
26-
27-
end %function
17+
function establishGrid(obj)
18+
19+
% Construct Grid Layout to Manage Building Blocks
20+
obj.Grid = uigridlayout(obj);
21+
obj.Grid.ColumnWidth = {'1x'};
22+
obj.Grid.RowHeight = {'1x'};
23+
obj.Grid.RowSpacing = 2;
24+
obj.Grid.ColumnSpacing = 2;
25+
obj.Grid.Padding = 2;
26+
27+
end
28+
2829
end
2930
end

widgets/+wt/PasswordField.m

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef PasswordField < matlab.ui.componentcontainer.ComponentContainer & ...
2-
wt.mixin.ErrorHandling & wt.mixin.GridOrganized
2+
wt.mixin.ErrorHandling & wt.mixin.GridOrganized & wt.mixin.BackgroundColorable
33

44
% A password entry field
55

@@ -12,6 +12,7 @@
1212
% The current value shown
1313
Value (1,1) string
1414

15+
1516
end %properties
1617

1718

@@ -26,22 +27,25 @@
2627

2728

2829
%% Internal Properties
29-
properties ( Transient, NonCopyable)
30+
properties (Transient, NonCopyable)
3031

3132
% Password control
3233
PasswordControl (1,1) matlab.ui.control.HTML
3334

3435
end %properties
3536

3637

37-
3838
%% Protected methods
3939
methods (Access = protected)
4040

4141
function setup(obj)
4242

43-
% Establish Grid for Control
43+
% Establish Grid for Control
4444
obj.establishGrid();
45+
46+
% Establish Background Color Listener
47+
obj.BackgroundColorableComponents = obj.Grid;
48+
obj.listenForBackgroundChange();
4549

4650
% Set default size
4751
obj.Position(3:4) = [100 25];
@@ -64,20 +68,12 @@ function setup(obj)
6468
'Parent',obj.Grid,...
6569
'HTMLSource',html,...
6670
'DataChangedFcn',@(h,e)obj.onPasswordChanged(e) );
67-
68-
end %function
6971

70-
function establishGrid(obj)
7172

72-
% Construct Grid Layout to Manage Building Blocks
73-
obj.Grid = uigridlayout(obj);
74-
obj.Grid.ColumnWidth = {'1x'};
75-
obj.Grid.RowHeight = {'1x'};
76-
obj.Grid.RowSpacing = 2;
77-
obj.Grid.ColumnSpacing = 2;
78-
obj.Grid.Padding = [2];
73+
74+
end %function
7975

80-
end
76+
8177

8278

8379
function update(obj)
@@ -87,6 +83,16 @@ function update(obj)
8783

8884
end %function
8985

86+
% function updateBackgroundColorableComponents(obj)
87+
% % Override Default BGC Update with Additional Components
88+
% obj.Grid.BackgroundColor = obj.BackgroundColor;
89+
% hasProp = isprop(obj.BackgroundColorableComponents,'BackgroundColor');
90+
% set(obj.BackgroundColorableComponents(hasProp),...
91+
% "BackgroundColor",obj.BackgroundColor);
92+
%
93+
% end
94+
95+
9096
end %methods
9197

9298

widgets/+wt/ProgressBar.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
classdef ProgressBar < wt.abstract.BaseWidget & wt.mixin.FontStyled
1+
classdef ProgressBar < matlab.ui.componentcontainer.ComponentContainer & ...
2+
wt.mixin.ErrorHandling & wt.mixin.GridOrganized & wt.mixin.FontStyled
3+
24
% A progress bar with status and cancel button
35

46
% Copyright 2020-2021 The MathWorks Inc.
@@ -69,7 +71,7 @@
6971

7072
%% Internal Properties
7173
properties ( Transient, NonCopyable, ...
72-
Access = {?wt.abstract.BaseWidget, ?wt.test.BaseWidgetTest} )
74+
Access = {?matlab.ui.componentcontainer.ComponentContainer} )
7375

7476
% Progress panel
7577
ProgressPanel (1,1) matlab.ui.container.Panel
@@ -224,7 +226,7 @@ function demo(obj)
224226
function setup(obj)
225227

226228
% Call superclass setup to establish the main grid
227-
obj.setup@wt.abstract.BaseWidget();
229+
obj.establishGrid();
228230

229231
% Set default size
230232
obj.Position(3:4) = [200 30];

widgets/resources/appDesigner.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@
122122
{
123123
"className": "wt.PasswordField",
124124
"componentName": "Password Field",
125-
"description": "A password entry field where the text is hidden as dots.",
125+
"description": "A password entry field where the text is hidden as dots. Derives from ui.componentcontainer.ComponentContainer",
126126
"icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAB3RJTUUH5AwREjotE4Db3QAAAapJREFUSIntlE1IFGEYgJ9vdn5k8bSeFnYhMIggCHElJSVoiQhkO9ScZIOgk3jQhCXpRxQPIjsEXaOjBXuJokuBnQoXWgkykmovwjoHl/RgSbPTzNsh8ahGfnTxOb6H5+H7XnjhiP+NymazxSAItMgdx0GVSiXJ5XJaArVaDTOdTuO6rpaA7/sYURRpkQNEUYShzb7DbiDwa4y6AwzNPOHHzuxXc5mJoXNcvf2IzfjPLN78wtT1PIXxB6yHByiUvfsiEsrD8Utigai2lMy+qotIJI/vXRFbIdjtcvfpsoiIPJsrimMgWEkZm6/KXnieJ4YyDAi/8a76khCQnxssVOvABkuLL2gJ0PrOwuJnYJv3b58TxEC4zes3K7QO+kW6MCSOweqgp/ciFqDaUuR7jwMpuvsGsRVgt5PvOwEk6TpbwDEAK8n5/pPY+wRMJAJMijen+bi6RfP0MCMXOgFwRyb5UG/y9dg1xgqnABi8cYeJT2sspS5zyz2z/xPK5fKei/oXPM8T/TswTVObPJFIYDYaDSqVipaA7/uoTCaj5VwrpXAc59C9R/w9vwGf2g17roftigAAAABJRU5ErkJggg==",
127127
"category": "Widgets Toolbox",
128128
"authorName": "Robyn Jackey - MathWorks Consulting",
129129
"authorEmail": "",
130-
"version": "2.1",
131-
"avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAZCAIAAABIPBwcAAAAB3RJTUUH5AwREjoxB4GHkgAAAG9JREFUWIXt0DEOgCAABMHDyAP4Cf//GgUWJvZbGNDsNNdeNpHeUO4ZY6z9sblaa55Yc86lZ3ZXSklyrL7xJcYCjAUYCzAWYCzAWICxAGMBxgKMBRgLMBZgLMBYgLEAYwHGAowFnElaa7331U/0Lxe5Kwbwb3BHfQAAAABJRU5ErkJggg==",
130+
"version": "3.0",
131+
"avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAZCAIAAABIPBwcAAAAB3RJTUUH5QwOEwsZNo3WgQAAAJRJREFUWIXt2bEJwzAURVE7eJr3Kk2nibSWZtAIKRwSQ4r4VVLgnsYCN5/Lx4W8jzE23POYPcA/Oc5HKWXuHCuT1Frb2KyfJNk+z8f1Re99xjxLq7W+z2xWgFgBYgWIFSBWgFgBYgWIFSBWgFgBYgWIFSBWgFgBYgWIFfhc/tm+XnTh22uzbEuaO8r6dn6F3cc3K/AE7UoQuvgib+gAAAAASUVORK5CYII=",
132132
"defaultPosition": [
133133
1,
134134
1,
@@ -139,13 +139,13 @@
139139
{
140140
"className": "wt.ProgressBar",
141141
"componentName": "Progress Bar",
142-
"description": "A progress bar that can optionally display time remaining, status message, and cancel button. It can also be made indeterminate to show \"busy\" status.",
142+
"description": "A progress bar that can optionally display time remaining, status message, and cancel button. It can also be made indeterminate to show \"busy\" status. Inherits from UI Component Container + Mixins.",
143143
"icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAB3RJTUUH5AwREiAHeBbo0AAAAN1JREFUSIntlLFKxEAURc8bJ9ktoojICmu5aUTETmwE/8zOPxDsV/YPAv6M5BM2MbsKknnPYgUJVhMJIuTANLe4Z5p3YeSvESAbWhAGFUynB3Z4dI2RABZdEIJxcZ5xOp908qqqKIoCmZ2c2eXVE2r7gEYL3t6V+7sFtzdpJy/LkjzP8WZK225Qk16C0Crb7Stw3MmbpgHARTdGMgpGwT8Q+N0c7X096VHhSJLJjzRNd5ftTdfoxzOqGfGX7Ehsw+PDC6vl91SICHVd471HRCid6/t7ACOEQQd55Jd8AujXQbk6YnXJAAAAAElFTkSuQmCC",
144144
"category": "Widgets Toolbox",
145145
"authorName": "Robyn Jackey - MathWorks Consulting",
146146
"authorEmail": "",
147-
"version": "2.1",
148-
"avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAAeCAIAAADmXcb7AAAAB3RJTUUH5AwREiALcaCk+wAAAGxJREFUeJzt0kENACEQwMDj/ItdCZigISEzCvrompkPTvtvB/AmY5EwFgljkTAWCWORMBYJY5EwFgljkTAWCWORMBYJY5EwFgljkTAWCWORMBYJY5EwFgljkTAWCWORMBYJY5EwFgljkTAWiQ2jJAMMhsTjyAAAAABJRU5ErkJggg==",
147+
"version": "3.0",
148+
"avatar": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAAAeCAIAAADmXcb7AAAAB3RJTUUH5QwOExwLwLcjXwAAAGxJREFUeJzt0kENACEQwMDj/ItdCZigISEzCvrompkPTvtvB/AmY5EwFgljkTAWCWORMBYJY5EwFgljkTAWCWORMBYJY5EwFgljkTAWCWORMBYJY5EwFgljkTAWCWORMBYJY5EwFgljkTAWiQ2jJAMMhsTjyAAAAABJRU5ErkJggg==",
149149
"defaultPosition": [
150150
1,
151151
1,
@@ -222,6 +222,6 @@
222222
]
223223
}
224224
],
225-
"schema": 1,
225+
"schema": 2,
226226
"MATLABRelease": "R2021b"
227227
}

0 commit comments

Comments
 (0)