Skip to content

Commit 21605db

Browse files
committed
Initial UI Object string alignment method
1 parent 7da63df commit 21605db

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

mlapptools.m

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
classdef mlapptools
2+
% MLAPPTOOLS is a class definition
3+
%
4+
% MLAPPTOOLS methods:
5+
6+
methods
7+
function obj = mlapptools
8+
% Dummy constructor so we don't return an empty class instance
9+
clear obj
10+
end
11+
end
12+
13+
methods (Static)
14+
function alignstring(uielement, alignment)
15+
mlapptools.togglewarnings('off')
16+
drawnow;
17+
rez = '';
18+
while ~strcmp(rez, sprintf('"%s"', alignment))
19+
try
20+
% 1. Get a handle to the webwindow:
21+
win = struct(struct(uielement.Parent).Controller).Container.CEF;
22+
% 2. Find which element of the DOM we want to edit (as before):
23+
data_tag = char(struct(uielement).Controller.ProxyView.PeerNode.getId);
24+
% 3. Manipulate the DOM via a JS command
25+
JSstr = sprintf('dojo.style(dojo.query("[data-tag^=''%s'']")[0],"textAlign","%s")', ...
26+
data_tag, alignment);
27+
rez = win.executeJS(JSstr);
28+
catch
29+
% TODO: See if an infinite loop condition is possible
30+
pause(0.5); % Give the figure (webpage) some more time to load
31+
end
32+
end
33+
mlapptools.togglewarnings('on')
34+
end
35+
end
36+
37+
methods (Static, Access = private)
38+
function togglewarnings(togglestr)
39+
switch lower(togglestr)
40+
case 'on'
41+
warning on MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame
42+
warning on MATLAB:structOnObject
43+
case 'off'
44+
warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame
45+
warning off MATLAB:structOnObject
46+
otherwise
47+
% Do nothing
48+
end
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)