1010 QUERY_TIMEOUT = 5 ; % Dojo query timeout period, seconds
1111 end
1212
13- methods (Access = public , Static = true )
14- function textAlign(uielement , alignment )
15- % A method for manipulating text alignment.
16- alignment = lower(alignment );
17- mlapptools .validateAlignmentStr(alignment )
18-
19- [win , widgetID ] = mlapptools .getWebElements(uielement );
20-
21- alignSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "textAlign", "%s ")' , widgetID , alignment );
22- win .executeJS(alignSetStr );
23- end % textAlign
24-
25-
26- function fontWeight(uielement , weight )
27- % A method for manipulating font weight, which controls how thick or
28- % thin characters in text should be displayed.
29- weight = mlapptools .validatefontweight(weight );
30-
31- [win , widgetID ] = mlapptools .getWebElements(uielement );
32-
33- fontWeightSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "font-weight", "%s ")' , widgetID , weight );
34- win .executeJS(fontWeightSetStr );
35- end % fontWeight
36-
37-
38- function fontColor(uielement , newcolor )
39- % A method for manipulating text color.
40- newcolor = mlapptools .validateCSScolor(newcolor );
41-
42- [win , widgetID ] = mlapptools .getWebElements(uielement );
43-
44- fontColorSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "color", "%s ")' , widgetID , newcolor );
45- win .executeJS(fontColorSetStr );
46- end % fontColor
47-
48- function varargout = setStyle(varargin )
49- % A method providing an interface for modifying style attributes of uicontrols.
50- %
51- % WARNING: Due to the large amount of available style attributes and
52- % corresponding settings, input checking is not performed. As this
53- % might lead to unexpected results or errors - USE AT YOUR OWN RISK!
54- %
55- % "Overloads":
56- % 3-parameter call:
57- % widgetID = setStyle(hControl, styleAttr, styleValue)
58- % 4-parameter call:
59- % setStyle(hUIFig, styleAttr, styleValue, widgetID)
60-
61- % Unpack inputs:
62- styleAttr = varargin{2 };
63- styleValue = varargin{3 };
64-
65- switch nargin
66- case 3
67- hControl = varargin{1 };
68- % Get a handle to the webwindow
69- [win , widgetID ] = mlapptools .getWebElements(hControl );
70- case 4
71- hUIFig = varargin{1 };
72- widgetID = varargin{4 };
73-
74- % Get a handle to the webwindow
75- win = mlapptools .getWebWindow(hUIFig );
76- end
77-
78- styleSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "%s ", "%s ")' , widgetID , styleAttr , styleValue );
79- % ^ this might result in junk if widgetId=='null'.
80- try
81- win .executeJS(styleSetStr );
82- % ^ this might crash in case of invalid styleAttr/styleValue.
83- catch ME
84- % Test for "Invalid or unexpected token":
85- ME = mlapptools .checkJavascriptSyntaxError(ME , styleSetStr );
86- rethrow(ME );
87- end
88-
89- % Assign outputs:
90- if nargout >= 1
91- varargout{1 } = widgetID ;
92- end
93-
94- end % setStyle
95-
13+ methods (Access = public , Static = true )
14+
9615 function [dojoVersion ] = aboutDojo()
97- % A method for getting version info about the Dojo Toolkit version visible by MATLAB.
16+ % A method for getting version info about the Dojo Toolkit visible by MATLAB.
9817
9918 if ~numel(matlab .internal .webwindowmanager .instance .findAllWebwindows())
10019 f= uifigure ; drawnow ; tmpWindowCreated = true ;
@@ -113,9 +32,30 @@ function fontColor(uielement, newcolor)
11332 dojoVersion = jsondecode(dojoVersion );
11433 end
11534 end % aboutDojo
116-
35+
36+ function fontColor(uielement , newcolor )
37+ % A method for manipulating text color.
38+ newcolor = mlapptools .validateCSScolor(newcolor );
39+
40+ [win , widgetID ] = mlapptools .getWebElements(uielement );
41+
42+ fontColorSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "color", "%s ")' , widgetID , newcolor );
43+ win .executeJS(fontColorSetStr );
44+ end % fontColor
45+
46+ function fontWeight(uielement , weight )
47+ % A method for manipulating font weight, which controls how thick or
48+ % thin characters in text should be displayed.
49+ weight = mlapptools .validatefontweight(weight );
50+
51+ [win , widgetID ] = mlapptools .getWebElements(uielement );
52+
53+ fontWeightSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "font-weight", "%s ")' , widgetID , weight );
54+ win .executeJS(fontWeightSetStr );
55+ end % fontWeight
56+
11757 function [fullHTML ] = getHTML(hUIFig )
118- % A method for dumping the HTML code of a uifigure.
58+ % A method for dumping the HTML code of a uifigure.
11959 % Intended for R2017b (and onward?) where the CEF url cannot be simply opened in a browser.
12060
12161 win = mlapptools .getWebWindow(hUIFig );
@@ -139,7 +79,7 @@ function fontColor(uielement, newcolor)
13979 fclose(fid);
14080 %}
14181 end % getHTML
142-
82+
14383 function varargout = getWidgetInfo(hUIFig ,verbose )
14484 % A method for gathering information about dijit widgets.
14585
@@ -187,10 +127,110 @@ function fontColor(uielement, newcolor)
187127 end % getWidgetInfo
188128
189129 end
130+
131+ function varargout = setStyle(varargin )
132+ % A method providing an interface for modifying style attributes of uicontrols.
133+ %
134+ % WARNING: Due to the large amount of available style attributes and
135+ % corresponding settings, input checking is not performed. As this
136+ % might lead to unexpected results or errors - USE AT YOUR OWN RISK!
137+ %
138+ % "Overloads":
139+ % 3-parameter call:
140+ % widgetID = setStyle(hControl, styleAttr, styleValue)
141+ % 4-parameter call:
142+ % setStyle(hUIFig, styleAttr, styleValue, widgetID)
143+
144+ % Unpack inputs:
145+ styleAttr = varargin{2 };
146+ styleValue = varargin{3 };
147+
148+ switch nargin
149+ case 3
150+ hControl = varargin{1 };
151+ % Get a handle to the webwindow
152+ [win , widgetID ] = mlapptools .getWebElements(hControl );
153+ case 4
154+ hUIFig = varargin{1 };
155+ widgetID = varargin{4 };
156+
157+ % Get a handle to the webwindow
158+ win = mlapptools .getWebWindow(hUIFig );
159+ end
160+
161+ styleSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "%s ", "%s ")' , widgetID , styleAttr , styleValue );
162+ % ^ this might result in junk if widgetId=='null'.
163+ try
164+ win .executeJS(styleSetStr );
165+ % ^ this might crash in case of invalid styleAttr/styleValue.
166+ catch ME
167+ % Test for "Invalid or unexpected token":
168+ ME = mlapptools .checkJavascriptSyntaxError(ME , styleSetStr );
169+ rethrow(ME );
170+ end
171+
172+ % Assign outputs:
173+ if nargout >= 1
174+ varargout{1 } = widgetID ;
175+ end
176+
177+ end % setStyle
178+
179+ function textAlign(uielement , alignment )
180+ % A method for manipulating text alignment.
181+ alignment = lower(alignment );
182+ mlapptools .validateAlignmentStr(alignment )
183+
184+ [win , widgetID ] = mlapptools .getWebElements(uielement );
185+
186+ alignSetStr = sprintf(' dojo.style(dojo.query("#%s ")[0], "textAlign", "%s ")' , widgetID , alignment );
187+ win .executeJS(alignSetStr );
188+ end % textAlign
190189
191190 end % Public Static Methods
192191
193192 methods (Static = true , Access = private )
193+
194+ function ME = checkJavascriptSyntaxError(ME ,styleSetStr )
195+ if (strcmp(ME .identifier ,' cefclient:webwindow:jserror' ))
196+ c = strfind(ME .message ,' Uncaught SyntaxError:' );
197+ if ~isempty(c )
198+ v = str2double(regexp(ME .message(c : end ),' -?\d+\.?\d*|-?\d*\.?\d+' ,' match' ));
199+ msg = [' Syntax error: unexpected token in styleValue: ' styleSetStr(v(1 ),v(2 ))];
200+ causeException = MException(' mlapptools:setStyle:invalidInputs' ,msg );
201+ ME = addCause(ME ,causeException );
202+ end
203+ end
204+ end % checkJavascriptSyntaxError
205+
206+ function eStruct = emptyStructWithFields(fields )
207+ % A convenience method for creating an empty scalar struct with specific field
208+ % names.
209+ % INPUTS:
210+ % fields - cell array of strings representing the required fieldnames.
211+
212+ tmp = [ matlab .lang .makeValidName(fields(: )), cell(numel(fields ),1 )].' ;
213+ eStruct = struct(tmp{: });
214+
215+ end % emptyStructWithFields
216+
217+ function [data_tag ] = getDataTag(uielement )
218+ mlapptools .toggleWarnings(' off' )
219+ data_tag = char(struct(uielement ).Controller.ProxyView.PeerNode.getId);
220+ mlapptools .toggleWarnings(' on' )
221+ end % getDataTag
222+
223+ function [win , widgetID ] = getWebElements(uielement )
224+ % Get a handle to the webwindow
225+ win = mlapptools .getWebWindow(uielement .Parent );
226+
227+ % Find which element of the DOM we want to edit
228+ data_tag = mlapptools .getDataTag(uielement );
229+
230+ % Manipulate the DOM via a JS command
231+ widgetID = mlapptools .getWidgetID(win , data_tag );
232+ end % getWebElements
233+
194234 function [win ] = getWebWindow(uifigurewindow )
195235 mlapptools .toggleWarnings(' off' )
196236 % Test if uifigurewindow is a valid handle
@@ -230,15 +270,7 @@ function fontColor(uielement, newcolor)
230270 mlapptools .QUERY_TIMEOUT );
231271 end
232272 end % getWebWindow
233-
234-
235- function [data_tag ] = getDataTag(uielement )
236- mlapptools .toggleWarnings(' off' )
237- data_tag = char(struct(uielement ).Controller.ProxyView.PeerNode.getId);
238- mlapptools .toggleWarnings(' on' )
239- end % getDataTag
240-
241-
273+
242274 function [widgetID ] = getWidgetID(win , data_tag )
243275 widgetquerystr = sprintf(' dojo.getAttr(dojo.query("[data-tag^=''%s'' ] > div")[0], "widgetid")' , data_tag );
244276
@@ -267,20 +299,7 @@ function fontColor(uielement, newcolor)
267299 mlapptools .QUERY_TIMEOUT );
268300 end
269301 end % getWidgetID
270-
271-
272- function [win , widgetID ] = getWebElements(uielement )
273- % Get a handle to the webwindow
274- win = mlapptools .getWebWindow(uielement .Parent );
275-
276- % Find which element of the DOM we want to edit
277- data_tag = mlapptools .getDataTag(uielement );
278-
279- % Manipulate the DOM via a JS command
280- widgetID = mlapptools .getWidgetID(win , data_tag );
281- end % getWebElements
282-
283-
302+
284303 function toggleWarnings(togglestr )
285304 switch lower(togglestr )
286305 case ' on'
@@ -293,8 +312,22 @@ function toggleWarnings(togglestr)
293312 % Do nothing
294313 end
295314 end % toggleWarnings
315+
316+ function uStruct = unifyStructs(cellOfStructs )
317+ % A method for merging structs having *some* overlapping field names.
318+
319+ fields = cellfun(@fieldnames , cellOfStructs , ' UniformOutput' , false );
320+ uFields = unique(vertcat(fields{: }));
321+ sz = numel(cellOfStructs );
322+ uStruct = repmat(mlapptools .emptyStructWithFields(uFields ),sz ,1 );
323+ for ind1 = 1 : sz
324+ fields = fieldnames(cellOfStructs{ind1 });
325+ for ind2 = 1 : numel(fields )
326+ uStruct(ind1 ).(fields{ind2 }) = cellOfStructs{ind1 }.(fields{ind2 });
327+ end
328+ end
329+ end % unifyStructs
296330
297-
298331 function validateAlignmentStr(alignment )
299332 if ~ischar(alignment )
300333 msgID = ' mlapptools:alignstring:InvalidInputIype' ;
@@ -308,8 +341,11 @@ function validateAlignmentStr(alignment)
308341 error(msgID , ' Invalid string alignment specified: ''%s'' ' , alignment );
309342 end
310343 end % validateAlignmentStr
311-
312-
344+
345+ function [newcolor ] = validateCSScolor(newcolor )
346+ % TODO
347+ end % validateCSScolor
348+
313349 function [weight ] = validateFontWeight(weight )
314350 if ischar(weight )
315351 weight = lower(weight );
@@ -333,53 +369,7 @@ function validateAlignmentStr(alignment)
333369 error(msgID , ' Invalid font weight specified: ''%s'' ' , weight );
334370 end
335371 end % validateFontWeight
336-
337-
338- function [newcolor ] = validateCSScolor(newcolor )
339- % TODO
340- end % validateCSScolor
341-
342-
343- function ME = checkJavascriptSyntaxError(ME ,styleSetStr )
344- if (strcmp(ME .identifier ,' cefclient:webwindow:jserror' ))
345- c = strfind(ME .message ,' Uncaught SyntaxError:' );
346- if ~isempty(c )
347- v = str2double(regexp(ME .message(c : end ),' -?\d+\.?\d*|-?\d*\.?\d+' ,' match' ));
348- msg = [' Syntax error: unexpected token in styleValue: ' styleSetStr(v(1 ),v(2 ))];
349- causeException = MException(' mlapptools:setStyle:invalidInputs' ,msg );
350- ME = addCause(ME ,causeException );
351- end
352- end
353- end % checkJavascriptSyntaxError
354-
355-
356- function eStruct = emptyStructWithFields(fields )
357- % A convenience method for creating an empty scalar struct with specific field
358- % names.
359- % INPUTS:
360- % fields - cell array of strings representing the required fieldnames.
361-
362- tmp = [ matlab .lang .makeValidName(fields(: )), cell(numel(fields ),1 )].' ;
363- eStruct = struct(tmp{: });
364-
365- end % emptyStructWithFields
366-
367-
368- function uStruct = unifyStructs(cellOfStructs )
369- % A method for merging structs having *some* overlapping field names.
370-
371- fields = cellfun(@fieldnames , cellOfStructs , ' UniformOutput' , false );
372- uFields = unique(vertcat(fields{: }));
373- sz = numel(cellOfStructs );
374- uStruct = repmat(mlapptools .emptyStructWithFields(uFields ),sz ,1 );
375- for ind1 = 1 : sz
376- fields = fieldnames(cellOfStructs{ind1 });
377- for ind2 = 1 : numel(fields )
378- uStruct(ind1 ).(fields{ind2 }) = cellOfStructs{ind1 }.(fields{ind2 });
379- end
380- end
381- end % unifyStructs
382-
372+
383373 end % Private Static Methods
384374
385375end % classdef
0 commit comments