You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 25, 2018. It is now read-only.
Conversion of App Designer uielements to "regular ones" #6
It is no secret that designing a UI in App Designer is much more convenient (one might even say fun) than using GUIDE. However, this comes at the price of lower customizability among other things.
It would be very useful to be able to design a UI in App Designer and then export it using "regular" elements (uicontrol).
This functionality can conceptually be achieved by mapping various App Designer Component names to their corresponding uicontrol/figure/axes counterparts.
A caveat to this conversion is that the GUIs will still likely require R2014b or newer. The App Designer makes extensive use of dot notation to access properties of UI objects rather than set or get. A warning to this effect will be included for users running mlapp2classdef in MATLAB versions prior to R2014b.
Though a fun project idea on its own, creating a parser to robustly handle these compatibility issues is beyond the scope of this project.
Another consideration is that a lot of the object properties and callbacks are new to R2016a, which isn't something that can be reliably caught without significant effort
For posterity: it may be possible to convert some App Designer elements to Java Swing components, e.g.:
%% List of JComponents:
% https://docs.oracle.com/javase/8/docs/api/javax/swing/JComponent.html
%% Spinner - https://docs.oracle.com/javase/8/docs/api/javax/swing/JSpinner.html
jSp = javaObjectEDT('javax.swing.JSpinner');
% Get available methods & fields:
M = methods(jSp);
F = fields(jSp); % fields often contain the allowable settings for methods.
% Set some properties:
jSp.setAlignmentX(jSp.LEFT_ALIGNMENT);
% Display component
[jSpinner, hSpContainer] = javacomponent(jSp,'South');
% https://docs.oracle.com/javase/8/docs/api/javax/swing/SwingConstants.html
%% Scrollbar (example based on Altman-2012)
% Create and initialize a JScrollBar object
jSb = javaObjectEDT('javax.swing.JScrollBar');
% Set some properties:
jSb.setOrientation(jSb.HORIZONTAL);
% Display component
[jScrollbar, hSbContainer] = javacomponent(jSb,'North');
Here's a better demo of how to make a spinner and attach a callback to it:
functionhFig=spinnerDemo%%javacomponent "docs": Delete lines 2-3 from javacomponent.m to get access to docs using F1 (help browser)%%Spinner - https://docs.oracle.com/javase/8/docs/api/javax/swing/JSpinner.html
hFig = figure();
% Create a spinner (w/o model):
jJSpinnerNM = javacomponent(javax.swing.JSpinner,[50,40,80,30],hFig);
jJSpinnerNM.StateChangedCallback = @(hObject,eventdata)onSpinnerValueChanged(hObject,eventdata);
% Create a spinner (w/ model):
spModel =javax.swing.SpinnerListModel({'item1','item2','item3'});
% https://docs.oracle.com/javase/8/docs/api/javax/swing/SpinnerModel.html
jJSpinnerM = javacomponent(javax.swing.JSpinner(spModel),[50,80,80,30],hFig);
jJSpinnerM.StateChangedCallback = @(hObject,eventdata)onSpinnerValueChanged(hObject,eventdata);
%%Get available methods & fields, and set some properties:
M = methods(jJSpinnerM);
F = fields(jJSpinnerM); % fields often contain the allowable settings for methods.% Set some arbitrary property:jJSpinnerNM.getEditor.getTextField.setHorizontalAlignment(javax.swing.JTextField.LEFT);
% https://docs.oracle.com/javase/8/docs/api/javax/swing/SwingConstants.htmljJSpinnerM.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
% Crazier demo: http://www.mathworks.com/matlabcentral/fileexchange/26970-spinnerdemoendfunction onSpinnerValueChanged(hObject, eventdata)
disp(['Spinner value is now: ' num2str(hObject.Value)]);
end
For the record, HG1 (R2014a and older) also supports dot-notation, if you simply ensure that all the relevant GUI/graphic handles are handle() objects rather than numeric. For example, the following code runs ok on HG1:
hFig = handle(gcf); % trick to enable dot-notation on GUI/graphic objects
hFig.Color ='w';
hFig.CloseRequestFcn = @myCallback;
The nice thing about this is that it's fully backward-compatible, meaning that hFig=handle(gcf) is transparent to HG2 and meaningful to HG1, so it can be used in Matlab code on both HG1 and HG2.
Whoa, I didn't know that, very interesting! When I get some time this week I'll poke around and test out some changes. Haven't looked at this in a while...
Before you modify stuff, note that the @Dev-iL's fork is 11 commits ahead, so you might want to merge his fixes first before proceeding. I'm just mentioning it since both of you did these changes 2 years ago and probably forgot about it...
Activity
Refactor, add skeleton for extra code conversion
sco1 commentedon Apr 25, 2016
A caveat to this conversion is that the GUIs will still likely require R2014b or newer. The App Designer makes extensive use of dot notation to access properties of UI objects rather than
setorget. A warning to this effect will be included for users runningmlapp2classdefin MATLAB versions prior to R2014b.Though a fun project idea on its own, creating a parser to robustly handle these compatibility issues is beyond the scope of this project.
Add baseline support for UI object conversion
sco1 commentedon Apr 25, 2016
Another consideration is that a lot of the object properties and callbacks are new to R2016a, which isn't something that can be reliably caught without significant effort
Dev-iL commentedon Apr 25, 2016
For posterity: it may be possible to convert some App Designer elements to Java Swing components, e.g.:
Add more conversion regex, update readme
Add class property conversion for <R2014b
Dev-iL commentedon May 9, 2016
Here's a better demo of how to make a spinner and attach a callback to it:
altmany commentedon Nov 27, 2017
For the record, HG1 (R2014a and older) also supports dot-notation, if you simply ensure that all the relevant GUI/graphic handles are handle() objects rather than numeric. For example, the following code runs ok on HG1:
The nice thing about this is that it's fully backward-compatible, meaning that
hFig=handle(gcf)is transparent to HG2 and meaningful to HG1, so it can be used in Matlab code on both HG1 and HG2.sco1 commentedon Nov 27, 2017
Whoa, I didn't know that, very interesting! When I get some time this week I'll poke around and test out some changes. Haven't looked at this in a while...
altmany commentedon Nov 27, 2017
It actually even improves performance in some cases:
https://undocumentedmatlab.com/blog/performance-accessing-handle-properties
altmany commentedon Nov 28, 2017
Before you modify stuff, note that the @Dev-iL's fork is 11 commits ahead, so you might want to merge his fixes first before proceeding. I'm just mentioning it since both of you did these changes 2 years ago and probably forgot about it...